Separate macro_rules and macro_definition.

This commit is contained in:
Camille GILLOT 2022-07-06 11:11:11 +02:00
parent c485fccd81
commit b0b46c0a10
4 changed files with 13 additions and 11 deletions

View File

@ -1010,13 +1010,7 @@ fn for_each_module_child(
let span = self.get_span(child_index, sess); let span = self.get_span(child_index, sess);
let macro_rules = match kind { let macro_rules = match kind {
DefKind::Macro(..) => { DefKind::Macro(..) => {
self.root self.root.tables.macro_rules.get(self, child_index).is_some()
.tables
.macro_definition
.get(self, child_index)
.unwrap()
.decode((self, sess))
.macro_rules
} }
_ => false, _ => false,
}; };
@ -1326,7 +1320,10 @@ fn exported_symbols(
fn get_macro(self, id: DefIndex, sess: &Session) -> ast::MacroDef { fn get_macro(self, id: DefIndex, sess: &Session) -> ast::MacroDef {
match self.def_kind(id) { match self.def_kind(id) {
DefKind::Macro(_) => { DefKind::Macro(_) => {
self.root.tables.macro_definition.get(self, id).unwrap().decode((self, sess)) let macro_rules = self.root.tables.macro_rules.get(self, id).is_some();
let body =
self.root.tables.macro_definition.get(self, id).unwrap().decode((self, sess));
ast::MacroDef { macro_rules, body: ast::ptr::P(body) }
} }
_ => bug!(), _ => bug!(),
} }

View File

@ -1494,7 +1494,10 @@ fn encode_info_for_item(&mut self, def_id: DefId, item: &'tcx hir::Item<'tcx>) {
self.tables.constness.set(def_id.index, sig.header.constness); self.tables.constness.set(def_id.index, sig.header.constness);
} }
hir::ItemKind::Macro(ref macro_def, _) => { hir::ItemKind::Macro(ref macro_def, _) => {
record!(self.tables.macro_definition[def_id] <- macro_def); if macro_def.macro_rules {
self.tables.macro_rules.set(def_id.index, ());
}
record!(self.tables.macro_definition[def_id] <- &*macro_def.body);
} }
hir::ItemKind::Mod(ref m) => { hir::ItemKind::Mod(ref m) => {
return self.encode_info_for_mod(item.def_id, m); return self.encode_info_for_mod(item.def_id, m);

View File

@ -394,7 +394,9 @@ fn encode(&self, buf: &mut FileEncoder) -> LazyTables {
may_have_doc_links: Table<DefIndex, ()>, may_have_doc_links: Table<DefIndex, ()>,
variant_data: Table<DefIndex, LazyValue<VariantData>>, variant_data: Table<DefIndex, LazyValue<VariantData>>,
assoc_container: Table<DefIndex, ty::AssocItemContainer>, assoc_container: Table<DefIndex, ty::AssocItemContainer>,
macro_definition: Table<DefIndex, LazyValue<ast::MacroDef>>, // Slot is full when macro is macro_rules.
macro_rules: Table<DefIndex, ()>,
macro_definition: Table<DefIndex, LazyValue<ast::MacArgs>>,
proc_macro: Table<DefIndex, MacroKind>, proc_macro: Table<DefIndex, MacroKind>,
// Slot is full when there is a self parameter. // Slot is full when there is a self parameter.
fn_has_self_parameter: Table<DefIndex, ()>, fn_has_self_parameter: Table<DefIndex, ()>,

View File

@ -64,7 +64,7 @@ impl $crate::ty::ParameterizedOverTcx for $ty {
ty::adjustment::CoerceUnsizedInfo, ty::adjustment::CoerceUnsizedInfo,
ty::fast_reject::SimplifiedTypeGen<DefId>, ty::fast_reject::SimplifiedTypeGen<DefId>,
rustc_ast::Attribute, rustc_ast::Attribute,
rustc_ast::MacroDef, rustc_ast::MacArgs,
rustc_attr::ConstStability, rustc_attr::ConstStability,
rustc_attr::DefaultBodyStability, rustc_attr::DefaultBodyStability,
rustc_attr::Deprecation, rustc_attr::Deprecation,