Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upDon't store a `Span` for `ExprKind::Lit` in the AST. #58284
Conversation
rust-highfive
assigned
eddyb
Feb 8, 2019
This comment has been minimized.
This comment has been minimized.
r? @eddyb (rust_highfive has picked a reviewer for you, use r? to override) |
rust-highfive
added
the
S-waiting-on-review
label
Feb 8, 2019
petrochenkov
reviewed
Feb 8, 2019
{ let hi = self.prev_span; | ||
let expr_span = lo.to(hi); | ||
expr_span | ||
}); |
This comment has been minimized.
This comment has been minimized.
petrochenkov
Feb 8, 2019
Contributor
This looks a bit suspicious.
Have you checked whether this assertion passes on literals passed to macros via literal
and expr
matchers?
This comment has been minimized.
This comment has been minimized.
petrochenkov
Feb 8, 2019
Contributor
For
macro m { ... let x = $literal + y; ... }
m!(10);
I'd expect the expression span to point to $literal
, but the literal span to point to 10
.
This comment has been minimized.
This comment has been minimized.
petrochenkov
Feb 8, 2019
•
Contributor
For expressions (and other fragments) passed through multiple matchers it would be nice to keep all the "backtrace" of spans by wrapping fragments into "invisible parentheses" on each substitution, but this isn't generally done now.
This comment has been minimized.
This comment has been minimized.
nnethercote
Feb 8, 2019
Author
Contributor
I ran the tests and they passed. (In contrast, I tried doing the same no-span-for-literals transformation for HIR and the tests failed; that's how I found out about HIR's lack of parentheses being a problem.)
More compellingly, if you look at the code you can see that I haven't changed behaviour at all: parse_lit
uses self.span.to(self.prev_span)
for the span, where self.span
is obtained at the start of parse_lit
and self.prev_span
is obtained at the end. And the new code does the same.
This comment has been minimized.
This comment has been minimized.
petrochenkov
Feb 9, 2019
•
Contributor
More compellingly, if you look at the code you can see that I haven't changed behaviour at all
OK.
This still goes into the wrong direction IMO, because the spans should ideally be different even if they are not right now.
I'll leave this to eddyb to decide, if AST is going to be radically rewritten for incremental parsing/expansion, then details like this won't matter anyway.
This comment has been minimized.
This comment has been minimized.
|
nnethercote commentedFeb 8, 2019
Because it's always the same as the
Span
for the surroundingExpr
.This reduces instruction counts on various benchmarks by up to 0.5%.