1267: Macro expand to r=edwin0cheng a=matklad
closes#1264
The core problem this PR is trying to wrangle is that macros can expand to different stuffs, depending on context.
That is, `foo!()` on the top-level expands to a list of items, but the same `foo!()` in expression position expands to expression.
Our current `hir_parse(HirFileId) -> TreeArc<SourceFile>` does not really support this.
So, the plan is to change `hir_parse` to untyped inreface (`TreeArc<Syntaxnode>`), and add `expands_to` field to `MacroCallLoc`, such that the *target* of macro expansion is selected by the calling code and is part of macro id.
This unfortunately looses some type-safety :(
Moreover, this doesn't really fix#1264 by itself, because we die due to some other error inside macro expansion: expander fails to produce a tree with a single root, which trips assert inside rowan.
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
1272: Error out non single root token tree conversion r=matklad a=edwin0cheng
This PR add a check to prevent non single root token tree conversion between token trees and syntax tree.
It should prevent the assert produced in #1267.
Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
1270: Increase Chalk solver max_size back to 4 r=flodiebold a=flodiebold
Reducing it to 2 was just a failed attempt to see whether that would help fix
some slow cases; in fact, it can create new slow cases by replacing concrete
types by variables.
Co-authored-by: Florian Diebold <flodiebold@gmail.com>
Reducing it to 2 was just a failed attempt to see whether that would help fix
some slow cases; in fact, it can create new slow cases by replacing concrete
types by variables.
1266: Chalk integration / method resolution fixes r=matklad a=flodiebold
- fix impl blocks with unresolved target trait being treated as inherent impls
- add traits from prelude for method resolution, and deduplicate them
- blacklist some traits from being considered in where clauses, namely `Send`, `Sync`, `Sized`, and the `Fn` traits. We don't handle these correctly yet for several reasons, and this makes us much less likely to run into cases where Chalk gets very slow (because these usually only happen if there is no solution, and that's more likely to happen for these traits).
- when there's an errored where clause, return just that one (since it will be always false anyway). This also makes things easier on Chalk ;)
Co-authored-by: Florian Diebold <flodiebold@gmail.com>
For Send/Sync/Sized, we don't handle auto traits correctly yet and because they
have a lot of impls, they can easily lead to slowdowns. In the case of
Fn/FnMut/FnOnce, we don't parse the special Fn notation correctly yet and don't
handle closures yet, so we are very unlikely to find an impl.
1262: Where clauses and other Chalk improvements r=matklad a=flodiebold
This adds support for where clauses to the Chalk integration; it also adds FnDef lowering and partly handles auto traits.
One thing I'm not sure about is the error handling -- what do we do if we can't
resolve a trait reference in a where clause? For impls, I think it's clear we
need to disregard the impl for trait solving. I've solved this for now by
introducing an 'unknown trait' that has no impls, so if we encounter an unknown
trait we can use that and basically get a where clause that's always false. (The
alternative would be somehow not returning the impl to Chalk at all, but we
would need to know that we need to do that in `impls_for_trait` already, and we
don't resolve anything there.)
A bit surprisingly, this has almost no impact on the type inference stats for RA, probably because of missing edge cases. Probably impl Trait support and closure support will do more.
Co-authored-by: Florian Diebold <flodiebold@gmail.com>
This is slightly hacky, but maybe more elegant than alternative solutions: We
just use a hardcoded Chalk trait ID which we special-case to have no impls.
1251: Chalk integration improvements r=matklad a=flodiebold
A few improvements that came up while working on where clause support:
- turn `implements` into a query again to improve performance
- allow skipping to a specific function with `analysis-stats`, e.g. `ra_cli analysis-stats --only world_symbols`
- deduplicate impls in impls_for_trait -- previously many impls e.g. from std where repeated many times, this should help performance as well...
- add a `HirDisplay` implementation for TraitRef (not used here anywhere, but useful for debugging)
Co-authored-by: Florian Diebold <flodiebold@gmail.com>
1253: Share literal validation logic with compiler r=matklad a=matklad
This is neat: the unescape module is literary what compiler is using right now:
c6ac575648/src/libsyntax/parse/unescape.rs
So, yeah, code sharing via copy-paste!
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>