1
Fork 0
rust/compiler/rustc_expand/src
bors fb9dfa8cef Auto merge of #84762 - cjgillot:resolve-span-opt, r=petrochenkov
Encode spans relative to the enclosing item -- enable on nightly

Follow-up to #84373 with the flag `-Zincremental-relative-spans` set by default.

This PR seeks to remove one of the main shortcomings of incremental: the handling of spans.
Changing the contents of a function may require redoing part of the compilation process for another function in another file because of span information is changed.
Within one file: all the spans in HIR change, so typechecking had to be re-done.
Between files: spans of associated types/consts/functions change, so type-based resolution needs to be re-done (hygiene information is stored in the span).

The flag `-Zincremental-relative-spans` encodes local spans relative to the span of an item, stored inside the `source_span` query.

Trap: stashed diagnostics are referenced by the "raw" span, so stealing them requires to remove the span's parent.

In order to avoid too much traffic in the span interner, span encoding uses the `ctxt_or_tag` field to encode:
- the parent when the `SyntaxContext` is 0;
- the `SyntaxContext` when the parent is `None`.
Even with this, the PR creates a lot of traffic to the Span interner, when a Span has both a LocalDefId parent and a non-root SyntaxContext. They appear in lowering, when we add a parent to all spans, including those which come from macros, and during inlining when we mark inlined spans.

The last commit changes how queries of `LocalDefId` manage their cache. I can put this in a separate PR if required.

Possible future directions:
- validate that all spans are marked in HIR validation;
- mark macro-expanded spans relative to the def-site and not the use-site.
2023-01-02 13:10:16 +00:00
..
mbe Merge multiple mutable borrows of immutable binding errors 2023-01-01 10:09:26 -08:00
mut_visit rustc_ast: Turn MutVisitor::token_visiting_enabled into a constant 2021-10-18 00:23:24 +03:00
parse Split MacArgs in two. 2022-11-22 09:04:15 +11:00
tokenstream Remove TokenStreamBuilder. 2022-10-05 12:42:54 +11:00
base.rs Auto merge of #105160 - nnethercote:rm-Lit-token_lit, r=petrochenkov 2022-12-12 05:16:50 +00:00
build.rs Rollup merge of #106221 - Nilstrieb:rptr-more-like-ref-actually, r=compiler-errors 2022-12-29 13:16:04 +01:00
config.rs Migrate parts of rustc_expand to session diagnostics 2022-12-10 11:02:41 +01:00
errors.rs Migrate parts of rustc_expand to session diagnostics 2022-12-10 11:02:41 +01:00
expand.rs Only enable relative span hashing on nightly. 2022-12-25 18:48:36 +00:00
lib.rs Migrate parts of rustc_expand to session diagnostics 2022-12-10 11:02:41 +01:00
mbe.rs Move macro_rules diagnostics to diagnostics module 2022-11-20 13:06:44 +01:00
module.rs Migrate parts of rustc_expand to session diagnostics 2022-12-10 11:02:41 +01:00
placeholders.rs Split MacArgs in two. 2022-11-22 09:04:15 +11:00
proc_macro.rs Add the #[derive_const] attribute 2022-09-20 11:57:58 +00:00
proc_macro_server.rs Remove three uses of LitKind::synthesize_token_lit. 2022-12-05 16:33:20 +11:00
tests.rs Migrate parts of rustc_expand to session diagnostics 2022-12-10 11:02:41 +01:00