Uh oh!
There was an error while loading. Please reload this page.
rustc: Forbid interpolated tokens in the HIR - #44601
Conversation
rust-highfive
commented
Sep 15, 2017
(rust_highfive has picked a reviewer for you, use r? to override) |
alexcrichton
commented
Sep 15, 2017
r? @nrc cc @jseyfried |
michaelwoerister
commented
Sep 15, 2017
Looks great! @jseyfried or @nrc, would you care to review this? |
nrc
commented
Sep 16, 2017
@bors: r+ |
bors
commented
Sep 16, 2017
📌 Commit d3205f1 has been approved by |
TimNN
commented
Sep 17, 2017
@bors r-
|
d3205f1 to
52184d6Comparealexcrichton
commented
Sep 17, 2017
@bors: r=nrc |
bors
commented
Sep 17, 2017
📌 Commit 52184d6 has been approved by |
bors
commented
Sep 18, 2017
⌛ Testing commit 52184d6e609cba80e744117dd43c1b1b41eec93f with merge 53c2fd1ca517668767caeee79127c32d39a9e496... |
bors
commented
Sep 18, 2017
💔 Test failed - status-appveyor |
kennytm
commented
Sep 18, 2017
Details |
bors
commented
Sep 18, 2017
☔ The latest upstream changes (presumably #44678) made this pull request unmergeable. Please resolve the merge conflicts. |
Right now the HIR contains raw `syntax::ast::Attribute` structure but nowadays
these can contain arbitrary tokens. One variant of the `Token` enum is an
"interpolated" token which basically means to shove all the tokens for a
nonterminal in this position. A "nonterminal" in this case is roughly analagous
to a macro argument:
macro_rules! foo {
($a:expr) => {
// $a is a nonterminal as an expression
}
}
Currently nonterminals contain namely items and expressions, and this poses a
problem for incremental compilation! With incremental we want a stable hash of
all HIR items, but this means we may transitively need a stable hash *of the
entire AST*, which is certainly not stable w/ node ids and whatnot. Hence today
there's a "bug" where the "stable hash" of an AST is just the raw hash value of
the AST, and this only arises with interpolated nonterminals. The downside of
this approach, however, is that a bunch of errors get spewed out during
compilation about how this isn't a great idea.
This PR is focused at fixing these warnings, basically deleting them from the
compiler. The implementation here is to alter attributes as they're lowered from
the AST to HIR, expanding all nonterminals in-place as we see them. This code
for expanding a nonterminal to a token stream already exists for the
`proc_macro` crate, so we basically just reuse the same implementation there.
After this PR it's considered a bug to have an `Interpolated` token and hence
the stable hash implementation simply uses `bug!` in this location.
Closesrust-lang#4094652184d6 to
0694e4fComparealexcrichton
commented
Sep 19, 2017
@bors: r=nrc |
bors
commented
Sep 19, 2017
📌 Commit 0694e4f has been approved by |
bors
commented
Sep 19, 2017
rustc: Forbid interpolated tokens in the HIR
Right now the HIR contains raw `syntax::ast::Attribute` structure but nowadays
these can contain arbitrary tokens. One variant of the `Token` enum is an
"interpolated" token which basically means to shove all the tokens for a
nonterminal in this position. A "nonterminal" in this case is roughly analagous
to a macro argument:
macro_rules! foo {
($a:expr) => {
// $a is a nonterminal as an expression
}
}
Currently nonterminals contain namely items and expressions, and this poses a
problem for incremental compilation! With incremental we want a stable hash of
all HIR items, but this means we may transitively need a stable hash *of the
entire AST*, which is certainly not stable w/ node ids and whatnot. Hence today
there's a "bug" where the "stable hash" of an AST is just the raw hash value of
the AST, and this only arises with interpolated nonterminals. The downside of
this approach, however, is that a bunch of errors get spewed out during
compilation about how this isn't a great idea.
This PR is focused at fixing these warnings, basically deleting them from the
compiler. The implementation here is to alter attributes as they're lowered from
the AST to HIR, expanding all nonterminals in-place as we see them. This code
for expanding a nonterminal to a token stream already exists for the
`proc_macro` crate, so we basically just reuse the same implementation there.
After this PR it's considered a bug to have an `Interpolated` token and hence
the stable hash implementation simply uses `bug!` in this location.
Closes#40946bors
commented
Sep 19, 2017
☀️ Test successful - status-appveyor, status-travis |
Manishearth
commented
Sep 21, 2017
This may have caused a regression wrt doc attributes |
This commit fixes a regression from rust-lang#44601 where lowering attribute to HIR now involves expanding interpolated tokens to their actual tokens. In that commit all interpolated tokens were surrounded with a `DelimToken::None` group of tokens, but this ended up causing regressions like rust-lang#44730 where the various attribute parsers in `syntax/attr.rs` weren't ready to cope with `DelimToken::None`. Instead of fixing the parser in `attr.rs` this commit instead opts to just avoid the `DelimToken::None` in the first place, ensuring that the token stream should look the same as it did before where possible. Closesrust-lang#44730
rustc: Don't use DelimToken::None if possible This commit fixes a regression from rust-lang#44601 where lowering attribute to HIR now involves expanding interpolated tokens to their actual tokens. In that commit all interpolated tokens were surrounded with a `DelimToken::None` group of tokens, but this ended up causing regressions like rust-lang#44730 where the various attribute parsers in `syntax/attr.rs` weren't ready to cope with `DelimToken::None`. Instead of fixing the parser in `attr.rs` this commit instead opts to just avoid the `DelimToken::None` in the first place, ensuring that the token stream should look the same as it did before where possible. Closesrust-lang#44730
Right now the HIR contains raw
syntax::ast::Attributestructure but nowadaysthese can contain arbitrary tokens. One variant of the
Tokenenum is an"interpolated" token which basically means to shove all the tokens for a
nonterminal in this position. A "nonterminal" in this case is roughly analagous
to a macro argument:
Currently nonterminals contain namely items and expressions, and this poses a
problem for incremental compilation! With incremental we want a stable hash of
all HIR items, but this means we may transitively need a stable hash of the
entire AST, which is certainly not stable w/ node ids and whatnot. Hence today
there's a "bug" where the "stable hash" of an AST is just the raw hash value of
the AST, and this only arises with interpolated nonterminals. The downside of
this approach, however, is that a bunch of errors get spewed out during
compilation about how this isn't a great idea.
This PR is focused at fixing these warnings, basically deleting them from the
compiler. The implementation here is to alter attributes as they're lowered from
the AST to HIR, expanding all nonterminals in-place as we see them. This code
for expanding a nonterminal to a token stream already exists for the
proc_macrocrate, so we basically just reuse the same implementation there.After this PR it's considered a bug to have an
Interpolatedtoken and hencethe stable hash implementation simply uses
bug!in this location.Closes#40946