diff options
| author | bors <bors@rust-lang.org> | 2021-09-11 23:35:28 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-09-11 23:35:28 +0000 |
| commit | 8743472386095d8d6f2e2757958f71879d9dfe84 (patch) | |
| tree | ec0e0843f2cf9df79b9bd59fbaaa32360dc7deea /src | |
| parent | e014277b07049f0638662f4040c2af7b119cc8a4 (diff) | |
| parent | 127ec9a8c94419669b22079c988e38638b58395f (diff) | |
| download | rust-8743472386095d8d6f2e2757958f71879d9dfe84.tar.gz rust-8743472386095d8d6f2e2757958f71879d9dfe84.zip | |
Auto merge of #84373 - cjgillot:resolve-span, r=michaelwoerister,petrochenkov
Encode spans relative to the enclosing item The aim of this PR is to avoid recomputing queries when code is moved without modification. MCP at https://github.com/rust-lang/compiler-team/issues/443 This is achieved by : 1. storing the HIR owner LocalDefId information inside the span; 2. encoding and decoding spans relative to the enclosing item in the incremental on-disk cache; 3. marking a dependency to the `source_span(LocalDefId)` query when we translate a span from the short (`Span`) representation to its explicit (`SpanData`) representation. Since all client code uses `Span`, step 3 ensures that all manipulations of span byte positions actually create the dependency edge between the caller and the `source_span(LocalDefId)`. This query return the actual absolute span of the parent item. As a consequence, any source code motion that changes the absolute byte position of a node will either: - modify the distance to the parent's beginning, so change the relative span's hash; - dirty `source_span`, and trigger the incremental recomputation of all code that depends on the span's absolute byte position. With this scheme, I believe the dependency tracking to be accurate. For the moment, the spans are marked during lowering. I'd rather do this during def-collection, but the AST MutVisitor is not practical enough just yet. The only difference is that we attach macro-expanded spans to their expansion point instead of the macro itself.
Diffstat (limited to 'src')
| -rw-r--r-- | src/macros.rs | 7 | ||||
| -rw-r--r-- | src/utils.rs | 4 |
2 files changed, 8 insertions, 3 deletions
diff --git a/src/macros.rs b/src/macros.rs index 779a1149f41..927187dfd8a 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1247,7 +1247,12 @@ impl MacroParser { let data = delimited_span.entire().data(); ( data.hi, - Span::new(data.lo + BytePos(1), data.hi - BytePos(1), data.ctxt), + Span::new( + data.lo + BytePos(1), + data.hi - BytePos(1), + data.ctxt, + data.parent, + ), delimited_span.entire(), ) } diff --git a/src/utils.rs b/src/utils.rs index 06159a1b26e..29e1e070d41 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -356,11 +356,11 @@ macro_rules! source { } pub(crate) fn mk_sp(lo: BytePos, hi: BytePos) -> Span { - Span::new(lo, hi, SyntaxContext::root()) + Span::new(lo, hi, SyntaxContext::root(), None) } pub(crate) fn mk_sp_lo_plus_one(lo: BytePos) -> Span { - Span::new(lo, lo + BytePos(1), SyntaxContext::root()) + Span::new(lo, lo + BytePos(1), SyntaxContext::root(), None) } // Returns `true` if the given span does not intersect with file lines. |
