Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustc: Forbid interpolated tokens in the HIR #44601

Merged
merged 1 commit into from
Sep 19, 2017

Conversation

alexcrichton
Copy link
Member

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 #40946

@rust-highfive
Copy link
Collaborator

r? @nikomatsakis

(rust_highfive has picked a reviewer for you, use r? to override)

@alexcrichton
Copy link
Member Author

r? @nrc

cc @jseyfried

@rust-highfive rust-highfive assigned nrc and unassigned nikomatsakis Sep 15, 2017
@michaelwoerister
Copy link
Member

Looks great! @jseyfried or @nrc, would you care to review this?

@alexcrichton alexcrichton added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 15, 2017
@nrc
Copy link
Member

nrc commented Sep 16, 2017

@bors: r+

@bors
Copy link
Contributor

bors commented Sep 16, 2017

📌 Commit d3205f1 has been approved by nrc

@TimNN
Copy link
Contributor

TimNN commented Sep 17, 2017

@bors r-

  • compile-fail/hygiene/globs.rs causes an ICE
  • compile-fail/hygiene/nested_macro_privacy.rs: expected error not found: field i of struct foo::S is private

@alexcrichton
Copy link
Member Author

@bors: r=nrc

@bors
Copy link
Contributor

bors commented Sep 17, 2017

📌 Commit 52184d6 has been approved by nrc

@bors
Copy link
Contributor

bors commented Sep 18, 2017

⌛ Testing commit 52184d6e609cba80e744117dd43c1b1b41eec93f with merge 53c2fd1ca517668767caeee79127c32d39a9e496...

@bors
Copy link
Contributor

bors commented Sep 18, 2017

💔 Test failed - status-appveyor

@kennytm
Copy link
Member

kennytm commented Sep 18, 2017

@bors retry #43402

[01:21:38] failures:
[01:21:38] 
[01:21:38] ---- [run-make] run-make\issue-26092 stdout ----
[01:21:38] 	
[01:21:38] error: make failed
[01:21:38] status: exit code: 2
[01:21:38] command: "make"
[01:21:38] stdout:
[01:21:38] ------------------------------------------
[01:21:38] PATH="/c/projects/rust/build/x86_64-pc-windows-msvc/test/run-make/issue-26092.stage2-x86_64-pc-windows-msvc:C:\projects\rust\build\x86_64-pc-windows-msvc\stage2\bin:/c/Program Files (x86)/Windows Kits/10/bin/x64:/c/Program Files (x86)/Windows Kits/10/bin/10.0.14393.0/x64:/c/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64:/c/projects/rust/build/x86_64-pc-windows-msvc/stage0-tools/x86_64-pc-windows-msvc/release/deps:/c/projects/rust/build/x86_64-pc-windows-msvc/stage0-sysroot/lib/rustlib/x86_64-pc-windows-msvc/lib:/c/Program Files (x86)/Inno Setup 5:/c/Python27:/mingw64/bin:/usr/bin:/c/Perl/site/bin:/c/Perl/bin:/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0:/c/Program Files/7-Zip:/c/Program Files/Microsoft/Web Platform Installer:/c/Tools/GitVersion:/c/Tools/PsTools:/c/Program Files/Git LFS:/c/Program Files (x86)/Subversion/bin:/c/Program Files/Microsoft SQL Server/120/Tools/Binn:/c/Program Files/Microsoft SQL Server/Client SDK/ODBC/110/Tools/Binn:/c/Program Files (x86)/Microsoft SQL Server/120/Tools/Binn:/c/Program Files/Microsoft SQL Server/120/DTS/Binn:/c/Program Files (x86)/Microsoft SQL Server/120/Tools/Binn/ManagementStudio:/c/Tools/WebDriver:/c/Program Files (x86)/Microsoft SDKs/TypeScript/1.4:/c/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/PrivateAssemblies:/c/Program Files (x86)/Microsoft SDKs/Azure/CLI/wbin:/c/Ruby193/bin:/c/Tools/NUnit/bin:/c/Tools/xUnit:/c/Tools/MSpec:/c/Tools/Coverity/bin:/c/Program Files (x86)/CMake/bin:/c/go/bin:/c/Program Files/Java/jdk1.8.0/bin:/c/Python27:/c/Program Files/nodejs:/c/Program Files (x86)/iojs:/c/Program Files/iojs:/c/Users/appveyor/AppData/Roaming/npm:/c/Program Files/Microsoft SQL Server/130/Tools/Binn:/c/Program Files (x86)/MSBuild/14.0/Bin:/c/Tools/NuGet:/c/Program Files (x86)/Microsoft Visual Studio 14.0/Common7/IDE/CommonExtensions/Microsoft/TestWindow:/c/Program Files/Microsoft DNX/Dnvm:/c/Program Files/Microsoft SQL Server/Client SDK/ODBC/130/Tools/Binn:/c/Program Files (x86)/Microsoft SQL Server/130/Tools/Binn:/c/Program Files (x86)/Microsoft SQL Server/130/DTS/Binn:/c/Program Files/Microsoft SQL Server/130/DTS/Binn:/c/Program Files (x86)/Microsoft SQL Server/110/DTS/Binn:/c/Program Files (x86)/Microsoft SQL Server/120/DTS/Binn:/c/Program Files (x86)/Apache/Maven/bin:/c/Python27/Scripts:/c/Tools/NUnit3:/c/Program Files/Mercurial:/c/Program Files/LLVM/bin:/c/Program Files/dotnet:/c/Program Files/erl8.3/bin:/c/Tools/curl/bin:/c/Program Files/Amazon/AWSCLI:/c/Program Files (x86)/Microsoft SQL Server/140/DTS/Binn:/c/Program Files (x86)/Microsoft Visual Studio 14.0/Common7/IDE/Extensions/Microsoft/SQLDB/DAC/140:/c/Program Files (x86)/Yarn/bin:/c/Program Files/Git/cmd:/c/Program Files/Git/usr/bin:/c/ProgramData/chocolatey/bin:/c/Tools/vcpkg:/c/Program Files (x86)/nodejs:/c/Program Files/Microsoft Service Fabric/bin/Fabric/Fabric.Code:/c/Program Files/Microsoft SDKs/Service Fabric/Tools/ServiceFabricLocalClusterManager:/c/Users/appveyor/AppData/Local/Yarn/bin:/c/Users/appveyor/AppData/Roaming/npm:/c/Program Files/AppVeyor/BuildAgent:/c/projects/rust:/c/projects/rust/handle" 'C:\projects\rust\build\x86_64-pc-windows-msvc\stage2\bin\rustc.exe' --out-dir /c/projects/rust/build/x86_64-pc-windows-msvc/test/run-make/issue-26092.stage2-x86_64-pc-windows-msvc -L /c/projects/rust/build/x86_64-pc-windows-msvc/test/run-make/issue-26092.stage2-x86_64-pc-windows-msvc  -o "" blank.rs 2>&1 | \
[01:21:38] 		grep -i 'No such file or directory'
[01:21:38] 
[01:21:38] ------------------------------------------
[01:21:38] stderr:
[01:21:38] ------------------------------------------
[01:21:38] make: *** [Makefile:4: all] Error 1
[01:21:38] 
[01:21:38] ------------------------------------------
[01:21:38] 
[01:21:38] thread '[run-make] run-make\issue-26092' panicked at 'explicit panic', src\tools\compiletest\src\runtest.rs:2433:8
[01:21:38] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[01:21:38] 
[01:21:38] 
[01:21:38] failures:
[01:21:38]     [run-make] run-make\issue-26092

@bors
Copy link
Contributor

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.

Closes rust-lang#40946
@alexcrichton
Copy link
Member Author

@bors: r=nrc

@bors
Copy link
Contributor

bors commented Sep 19, 2017

📌 Commit 0694e4f has been approved by nrc

@bors
Copy link
Contributor

bors commented Sep 19, 2017

⌛ Testing commit 0694e4f with merge 5d5dcae...

bors added a commit that referenced this pull request 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 #40946
@bors
Copy link
Contributor

bors commented Sep 19, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: nrc
Pushing 5d5dcae to master...

@Manishearth
Copy link
Member

This may have caused a regression wrt doc attributes

#44730

alexcrichton added a commit to alexcrichton/rust that referenced this pull request Sep 21, 2017
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.

Closes rust-lang#44730
frewsxcv added a commit to frewsxcv/rust that referenced this pull request Sep 23, 2017
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.

Closes rust-lang#44730
@alexcrichton alexcrichton deleted the lower-attributes-in-hir branch September 23, 2017 04:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

warning: Quasi-quoting might make incremental compilation very inefficient: NtIdent(..)
9 participants