Skip to content

Commit d986bbe

Browse files
committed
Implement stackless expansion.
1 parent c07ff8d commit d986bbe

File tree

4 files changed

+191
-178
lines changed

4 files changed

+191
-178
lines changed

src/libsyntax/ext/base.rs

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,6 @@ impl<'a> ExtCtxt<'a> {
646646
}
647647

648648
pub fn bt_push(&mut self, ei: ExpnInfo) {
649-
self.recursion_count += 1;
650649
if self.recursion_count > self.ecfg.recursion_limit {
651650
self.span_fatal(ei.call_site,
652651
&format!("recursion limit reached while expanding the macro `{}`",
@@ -660,17 +659,7 @@ impl<'a> ExtCtxt<'a> {
660659
callee: ei.callee
661660
});
662661
}
663-
pub fn bt_pop(&mut self) {
664-
match self.backtrace {
665-
NO_EXPANSION => self.bug("tried to pop without a push"),
666-
expn_id => {
667-
self.recursion_count -= 1;
668-
self.backtrace = self.codemap().with_expn_info(expn_id, |expn_info| {
669-
expn_info.map_or(NO_EXPANSION, |ei| ei.call_site.expn_id)
670-
});
671-
}
672-
}
673-
}
662+
pub fn bt_pop(&mut self) {}
674663

675664
pub fn insert_macro(&mut self, def: ast::MacroDef) {
676665
if def.export {
@@ -799,8 +788,6 @@ impl<'a> ExtCtxt<'a> {
799788
self.crate_root = Some("std");
800789
}
801790

802-
// User extensions must be added before expander.load_macros is called,
803-
// so that macros from external crates shadow user defined extensions.
804791
for (name, extension) in user_exts {
805792
self.syntax_env.insert(name, extension);
806793
}
@@ -900,7 +887,7 @@ pub fn get_exprs_from_tts(cx: &mut ExtCtxt,
900887
/// This environment maps Names to SyntaxExtensions.
901888
pub struct SyntaxEnv {
902889
module_data: Vec<ModuleData>,
903-
current_module: Module,
890+
pub current_module: Module,
904891

905892
/// All bang-style macro/extension names
906893
/// encountered so far; to be used for diagnostics in resolve
@@ -940,10 +927,6 @@ impl SyntaxEnv {
940927
&self.module_data[module.0 as usize]
941928
}
942929

943-
pub fn set_current_module(&mut self, module: Module) -> Module {
944-
::std::mem::replace(&mut self.current_module, module)
945-
}
946-
947930
pub fn paths(&self) -> Rc<ModulePaths> {
948931
self.data(self.current_module).paths.clone()
949932
}
@@ -994,8 +977,6 @@ impl SyntaxEnv {
994977
}
995978

996979
pub fn is_crate_root(&mut self) -> bool {
997-
// The first frame is pushed in `SyntaxEnv::new()` and the second frame is
998-
// pushed when folding the crate root pseudo-module (c.f. noop_fold_crate).
999-
self.current_module.0 <= 1
980+
self.current_module == Module(0)
1000981
}
1001982
}

0 commit comments

Comments
 (0)