-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Assign node ids during macro expansion #36438
Conversation
07ce0ae
to
cb957a7
Compare
|
||
// create a really evil test case where a $x appears inside a binding of $x | ||
// but *shouldn't* bind because it was inserted by a different macro.... | ||
// can't write this test case until we have macro-generating macros. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We now have a test like this -- c.f. #35453.
cb957a7
to
269cd05
Compare
269cd05
to
d3b08e5
Compare
cc @eddyb |
@@ -488,6 +489,9 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore { | |||
fn metadata_encoding_version(&self) -> &[u8] { bug!("metadata_encoding_version") } | |||
} | |||
|
|||
pub trait MacroLoader { | |||
fn load_crate(&mut self, _: &ast::Item, _: bool) -> Vec<LoadedMacro>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be useful to specify argument names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, done.
d3b08e5
to
6707331
Compare
the `InvocationCollector` and `PlaceholderExpander` folds.
only assign node ids during monotonic expansion.
6707331
to
b54e1e3
Compare
@bors: r+ |
📌 Commit b54e1e3 has been approved by |
⌛ Testing commit b54e1e3 with merge bcf6bd2... |
💔 Test failed - auto-win-gnu-32-opt-rustbuild |
@bors: retry On Tue, Sep 13, 2016 at 9:42 PM, bors notifications@github.com wrote:
|
Assign node ids during macro expansion After this PR, - The `ExtCtxt` can access `resolve`'s `Resolver` through the trait object `ext::base::Resolver`. - The `Resolver` trait object can load macros and replaces today's `MacroLoader` trait object. - The macro expander uses the `Resolver` trait object to resolve macro invocations. - The macro expander assigns node ids and builds the `Resolver`'s `macros_at_scope` map. - This is groundwork for merging import resolution and expansion. - Performance of expansion together with node id assignment improves by ~5%. **EDIT:** Since Github is reordering the commits, here is `git log`: - b54e1e3: Differentiate between monotonic and non-monotonic expansion and only assign node ids during monotonic expansion. - 78c0039: Expand generated test harnesses and macro registries. - f3c2dca: Remove scope placeholders from the crate root. - c86c8d4: Perform node id assignment and `macros_at_scope` construction during the `InvocationCollector` and `PlaceholderExpander` folds. - 72a6369: Move macro resolution into `librustc_resolve`. - 20b43b2: Rewrite the unit tests in `ext/expand.rs` as a `compile-fail` test. - a9821e1: Refactor `ExtCtxt` to use a `Resolver` instead of a `MacroLoader`. - 60440b2: Refactor `noop_fold_stmt_kind` out of `noop_fold_stmt`. - 50f94f6: Avoid needless reexpansions. r? @nrc
Originally, there has been a dedicated pass for renumbering AST NodeIds to have actual values. This pass had been added by commit a5ad4c3. Then, later, this step was moved to where it resides now, macro expansion. See commit c86c8d4 or PR rust-lang#36438. The comment snippet, added by the original commit, has survived the times without any change, becoming outdated at removal of the dedicated pass. Nowadays, grepping for the next_node_id function will show up multiple places in the compiler that call it, but the main rewriting that the comment talks about is still done in the expansion step, inside an innocious looking visit_id function that's called during macro invocation collection.
…=oli-obk The renumber pass is long gone Originally, there has been a dedicated pass for renumbering AST NodeIds to have actual values. This pass had been added by commit a5ad4c3. Then, later, this step was moved to where it resides now, macro expansion. See commit c86c8d4 or PR rust-lang#36438. The comment snippet, added by the original commit, has survived the times without any change, becoming outdated at removal of the dedicated pass. Nowadays, grepping for the next_node_id function will show up multiple places in the compiler that call it, but the main rewriting that the comment talks about is still done in the expansion step, inside an innocious looking visit_id function that's called during macro invocation collection.
…=oli-obk The renumber pass is long gone Originally, there has been a dedicated pass for renumbering AST NodeIds to have actual values. This pass had been added by commit a5ad4c3. Then, later, this step was moved to where it resides now, macro expansion. See commit c86c8d4 or PR rust-lang#36438. The comment snippet, added by the original commit, has survived the times without any change, becoming outdated at removal of the dedicated pass. Nowadays, grepping for the next_node_id function will show up multiple places in the compiler that call it, but the main rewriting that the comment talks about is still done in the expansion step, inside an innocious looking visit_id function that's called during macro invocation collection.
After this PR,
ExtCtxt
can accessresolve
'sResolver
through the trait objectext::base::Resolver
.Resolver
trait object can load macros and replaces today'sMacroLoader
trait object.Resolver
trait object to resolve macro invocations.Resolver
'smacros_at_scope
map.EDIT: Since Github is reordering the commits, here is
git log
:macros_at_scope
construction during theInvocationCollector
andPlaceholderExpander
folds.librustc_resolve
.ext/expand.rs
as acompile-fail
test.ExtCtxt
to use aResolver
instead of aMacroLoader
.noop_fold_stmt_kind
out ofnoop_fold_stmt
.r? @nrc