Skip to content

Commit

Permalink
metadata: Tweak the way in which declarative macros are encoded
Browse files Browse the repository at this point in the history
To make the `macro_rules` flag more readily available without decoding everything else
  • Loading branch information
petrochenkov committed Feb 24, 2022
1 parent 17b1afd commit 50568b8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Expand Up @@ -5,6 +5,7 @@ use crate::rmeta::table::{FixedSizeEncoding, Table};
use crate::rmeta::*;

use rustc_ast as ast;
use rustc_ast::ptr::P;
use rustc_attr as attr;
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxHashMap;
Expand Down Expand Up @@ -1402,9 +1403,11 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
tcx.arena.alloc_from_iter(self.root.exported_symbols.decode((self, tcx)))
}

fn get_macro(self, id: DefIndex, sess: &Session) -> MacroDef {
fn get_macro(self, id: DefIndex, sess: &Session) -> ast::MacroDef {
match self.kind(id) {
EntryKind::MacroDef(macro_def) => macro_def.decode((self, sess)),
EntryKind::MacroDef(mac_args, macro_rules) => {
ast::MacroDef { body: P(mac_args.decode((self, sess))), macro_rules }
}
_ => bug!(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/rmeta/encoder.rs
Expand Up @@ -1407,7 +1407,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
EntryKind::Fn(self.lazy(data))
}
hir::ItemKind::Macro(ref macro_def, _) => {
EntryKind::MacroDef(self.lazy(macro_def.clone()))
EntryKind::MacroDef(self.lazy(&*macro_def.body), macro_def.macro_rules)
}
hir::ItemKind::Mod(ref m) => {
return self.encode_info_for_mod(item.def_id, m);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_metadata/src/rmeta/mod.rs
Expand Up @@ -2,7 +2,7 @@ use decoder::Metadata;
use def_path_hash_map::DefPathHashMapRef;
use table::{Table, TableBuilder};

use rustc_ast::{self as ast, MacroDef};
use rustc_ast as ast;
use rustc_attr as attr;
use rustc_data_structures::svh::Svh;
use rustc_data_structures::sync::MetadataRef;
Expand Down Expand Up @@ -350,7 +350,7 @@ enum EntryKind {
Fn(Lazy<FnData>),
ForeignFn(Lazy<FnData>),
Mod(Lazy<[ModChild]>),
MacroDef(Lazy<MacroDef>),
MacroDef(Lazy<ast::MacArgs>, /*macro_rules*/ bool),
ProcMacro(MacroKind),
Closure,
Generator,
Expand Down

0 comments on commit 50568b8

Please sign in to comment.