Rollup merge of #36438 - jseyfried:node_ids_in_expansion, r=nrc
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`: -b54e1e3997: Differentiate between monotonic and non-monotonic expansion and only assign node ids during monotonic expansion. -78c0039878: Expand generated test harnesses and macro registries. -f3c2dca353: Remove scope placeholders from the crate root. -c86c8d41a2: Perform node id assignment and `macros_at_scope` construction during the `InvocationCollector` and `PlaceholderExpander` folds. -72a636975f: Move macro resolution into `librustc_resolve`. -20b43b2323: Rewrite the unit tests in `ext/expand.rs` as a `compile-fail` test. -a9821e1658: Refactor `ExtCtxt` to use a `Resolver` instead of a `MacroLoader`. -60440b226d: Refactor `noop_fold_stmt_kind` out of `noop_fold_stmt`. -50f94f6c95: Avoid needless reexpansions. r? @nrc
This commit is contained in:
commit
bab9238a1e
23 changed files with 693 additions and 719 deletions
|
|
@ -22,11 +22,11 @@ use syntax_pos::DUMMY_SP;
|
|||
|
||||
fn main() {
|
||||
let ps = syntax::parse::ParseSess::new();
|
||||
let mut loader = syntax::ext::base::DummyMacroLoader;
|
||||
let mut resolver = syntax::ext::base::DummyResolver;
|
||||
let mut cx = syntax::ext::base::ExtCtxt::new(
|
||||
&ps, vec![],
|
||||
syntax::ext::expand::ExpansionConfig::default("qquote".to_string()),
|
||||
&mut loader);
|
||||
&mut resolver);
|
||||
cx.bt_push(syntax::codemap::ExpnInfo {
|
||||
call_site: DUMMY_SP,
|
||||
callee: syntax::codemap::NameAndSpan {
|
||||
|
|
|
|||
46
src/test/compile-fail/macro-expansion-tests.rs
Normal file
46
src/test/compile-fail/macro-expansion-tests.rs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
mod macros_cant_escape_fns {
|
||||
fn f() {
|
||||
macro_rules! m { () => { 3 + 4 } }
|
||||
}
|
||||
fn g() -> i32 { m!() } //~ ERROR macro undefined
|
||||
}
|
||||
|
||||
mod macros_cant_escape_mods {
|
||||
mod f {
|
||||
macro_rules! m { () => { 3 + 4 } }
|
||||
}
|
||||
fn g() -> i32 { m!() } //~ ERROR macro undefined
|
||||
}
|
||||
|
||||
mod macros_can_escape_flattened_mods_test {
|
||||
#[macro_use]
|
||||
mod f {
|
||||
macro_rules! m { () => { 3 + 4 } }
|
||||
}
|
||||
fn g() -> i32 { m!() }
|
||||
}
|
||||
|
||||
fn macro_tokens_should_match() {
|
||||
macro_rules! m { (a) => { 13 } }
|
||||
m!(a);
|
||||
}
|
||||
|
||||
// should be able to use a bound identifier as a literal in a macro definition:
|
||||
fn self_macro_parsing() {
|
||||
macro_rules! foo { (zz) => { 287; } }
|
||||
fn f(zz: i32) {
|
||||
foo!(zz);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -25,11 +25,11 @@ use syntax_pos::DUMMY_SP;
|
|||
|
||||
fn main() {
|
||||
let ps = syntax::parse::ParseSess::new();
|
||||
let mut loader = syntax::ext::base::DummyMacroLoader;
|
||||
let mut resolver = syntax::ext::base::DummyResolver;
|
||||
let mut cx = syntax::ext::base::ExtCtxt::new(
|
||||
&ps, vec![],
|
||||
syntax::ext::expand::ExpansionConfig::default("qquote".to_string()),
|
||||
&mut loader);
|
||||
&mut resolver);
|
||||
cx.bt_push(syntax::codemap::ExpnInfo {
|
||||
call_site: DUMMY_SP,
|
||||
callee: syntax::codemap::NameAndSpan {
|
||||
|
|
|
|||
|
|
@ -21,11 +21,11 @@ use syntax_pos::DUMMY_SP;
|
|||
|
||||
fn main() {
|
||||
let ps = syntax::parse::ParseSess::new();
|
||||
let mut loader = syntax::ext::base::DummyMacroLoader;
|
||||
let mut resolver = syntax::ext::base::DummyResolver;
|
||||
let mut cx = syntax::ext::base::ExtCtxt::new(
|
||||
&ps, vec![],
|
||||
syntax::ext::expand::ExpansionConfig::default("qquote".to_string()),
|
||||
&mut loader);
|
||||
&mut resolver);
|
||||
cx.bt_push(syntax::codemap::ExpnInfo {
|
||||
call_site: DUMMY_SP,
|
||||
callee: syntax::codemap::NameAndSpan {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue