1
Fork 0
rust/compiler/rustc_span/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
..
analyze_source_file remove redundant closures (clippy::redundant_closure) 2021-01-03 13:34:24 +01:00
lev_distance Improve method name suggestions 2022-04-03 16:38:57 +01:00
source_map Fix #103451, find_width_of_character_at_span return width with 1 when reaching end 2022-10-25 21:16:12 +08:00
symbol Move the Lock into symbol::Interner 2021-09-15 18:46:45 +02:00
analyze_source_file.rs more clippy::complexity fixes 2022-12-15 00:09:10 +01:00
caching_source_map_view.rs Remove useless borrows and derefs 2022-12-01 17:34:43 +00:00
def_id.rs A few small cleanups for newtype_index 2022-12-18 21:47:28 +01:00
edition.rs Create 2024 edition 2022-04-02 02:45:49 -04:00
fatal_error.rs Make fatal DiagnosticBuilder yield never 2022-03-27 22:25:32 -07:00
hygiene.rs Auto merge of #84762 - cjgillot:resolve-span-opt, r=petrochenkov 2023-01-02 13:10:16 +00:00
lev_distance.rs Improve method name suggestions 2022-04-03 16:38:57 +01:00
lib.rs document that Span::to can go backwards 2022-12-25 17:41:31 +01:00
profiling.rs extend EventArgRecorder into span-aware SpannedEventArgRecorder 2022-04-22 18:06:21 +02:00
source_map.rs Improve debug logs of find_width_of_character_at_span 2022-12-27 22:18:22 +01:00
span_encoding.rs Encode span parent in the inlined representation. 2022-12-25 16:41:33 +00:00
symbol.rs Revert "Implement allow-by-default multiple_supertrait_upcastable lint" 2022-12-29 00:47:23 -08:00
tests.rs Lazify SourceFile::lines. 2022-06-01 10:36:39 +10:00