Skip to content
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

Split up Definitions and ResolverAstLowering. #98106

Merged
merged 7 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {

// Wrap the expression in an AnonConst.
let parent_def_id = self.current_hir_id_owner;
let node_id = self.resolver.next_node_id();
let node_id = self.next_node_id();
self.create_def(
parent_def_id,
node_id,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
for (idx, arg) in args.into_iter().enumerate() {
if legacy_args_idx.contains(&idx) {
let parent_def_id = self.current_hir_id_owner;
let node_id = self.resolver.next_node_id();
let node_id = self.next_node_id();

// Add a definition for the in-band const def.
self.create_def(
Expand Down Expand Up @@ -724,7 +724,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
};

// `::std::task::Poll::Ready(result) => break result`
let loop_node_id = self.resolver.next_node_id();
let loop_node_id = self.next_node_id();
let loop_hir_id = self.lower_node_id(loop_node_id);
let ready_arm = {
let x_ident = Ident::with_dummy_span(sym::result);
Expand Down
36 changes: 19 additions & 17 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
owner: NodeId,
f: impl FnOnce(&mut LoweringContext<'_, 'hir>) -> hir::OwnerNode<'hir>,
) {
let next_node_id = self.resolver.next_node_id;
let mut lctx = LoweringContext {
// Pseudo-globals.
sess: &self.sess,
Expand All @@ -79,6 +80,8 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
node_id_to_local_id: Default::default(),
local_id_to_def_id: SortedMap::new(),
trait_map: Default::default(),
local_node_id_to_def_id: FxHashMap::default(),
next_node_id,

// Lowering state.
catch_scope: None,
Expand Down Expand Up @@ -126,8 +129,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {

#[instrument(level = "debug", skip(self, c))]
fn lower_crate(&mut self, c: &Crate) {
debug_assert_eq!(self.resolver.local_def_id(CRATE_NODE_ID), CRATE_DEF_ID);

debug_assert_eq!(self.resolver.node_id_to_def_id[&CRATE_NODE_ID], CRATE_DEF_ID);
self.with_lctx(CRATE_NODE_ID, |lctx| {
let module = lctx.lower_mod(&c.items, &c.spans);
lctx.lower_attrs(hir::CRATE_HIR_ID, &c.attrs);
Expand All @@ -141,7 +143,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
}

fn lower_assoc_item(&mut self, item: &AssocItem, ctxt: AssocCtxt) {
let def_id = self.resolver.local_def_id(item.id);
let def_id = self.resolver.node_id_to_def_id[&item.id];

let parent_id = {
let parent = self.definitions.def_key(def_id).parent;
Expand Down Expand Up @@ -185,7 +187,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}

pub(super) fn lower_item_ref(&mut self, i: &Item) -> SmallVec<[hir::ItemId; 1]> {
let mut node_ids = smallvec![hir::ItemId { def_id: self.resolver.local_def_id(i.id) }];
let mut node_ids = smallvec![hir::ItemId { def_id: self.local_def_id(i.id) }];
if let ItemKind::Use(ref use_tree) = &i.kind {
self.lower_item_id_use_tree(use_tree, i.id, &mut node_ids);
}
Expand All @@ -201,7 +203,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
match tree.kind {
UseTreeKind::Nested(ref nested_vec) => {
for &(ref nested, id) in nested_vec {
vec.push(hir::ItemId { def_id: self.resolver.local_def_id(id) });
vec.push(hir::ItemId { def_id: self.local_def_id(id) });
self.lower_item_id_use_tree(nested, id, vec);
}
}
Expand All @@ -210,7 +212,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
for (_, &id) in
iter::zip(self.expect_full_res_from_use(base_id).skip(1), &[id1, id2])
{
vec.push(hir::ItemId { def_id: self.resolver.local_def_id(id) });
vec.push(hir::ItemId { def_id: self.local_def_id(id) });
}
}
}
Expand Down Expand Up @@ -475,7 +477,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
ItemKind::MacroDef(MacroDef { ref body, macro_rules }) => {
let body = P(self.lower_mac_args(body));
let macro_kind = self.resolver.decl_macro_kind(self.resolver.local_def_id(id));
let macro_kind = self.resolver.decl_macro_kind(self.local_def_id(id));
hir::ItemKind::Macro(ast::MacroDef { body, macro_rules }, macro_kind)
}
ItemKind::MacCall(..) => {
Expand Down Expand Up @@ -535,7 +537,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
// Essentially a single `use` which imports two names is desugared into
// two imports.
for new_node_id in [id1, id2] {
let new_id = self.resolver.local_def_id(new_node_id);
let new_id = self.local_def_id(new_node_id);
let Some(res) = resolutions.next() else {
// Associate an HirId to both ids even if there is no resolution.
let _old = self.children.insert(
Expand All @@ -548,7 +550,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let ident = *ident;
let mut path = path.clone();
for seg in &mut path.segments {
seg.id = self.resolver.next_node_id();
seg.id = self.next_node_id();
}
let span = path.span;

Expand Down Expand Up @@ -611,13 +613,13 @@ impl<'hir> LoweringContext<'_, 'hir> {

// Add all the nested `PathListItem`s to the HIR.
for &(ref use_tree, id) in trees {
let new_hir_id = self.resolver.local_def_id(id);
let new_hir_id = self.local_def_id(id);

let mut prefix = prefix.clone();

// Give the segments new node-ids since they are being cloned.
for seg in &mut prefix.segments {
seg.id = self.resolver.next_node_id();
seg.id = self.next_node_id();
}

// Each `use` import is an item and thus are owners of the
Expand Down Expand Up @@ -691,7 +693,7 @@ impl<'hir> LoweringContext<'_, 'hir> {

fn lower_foreign_item_ref(&mut self, i: &ForeignItem) -> hir::ForeignItemRef {
hir::ForeignItemRef {
id: hir::ForeignItemId { def_id: self.resolver.local_def_id(i.id) },
id: hir::ForeignItemId { def_id: self.local_def_id(i.id) },
ident: self.lower_ident(i.ident),
span: self.lower_span(i.span),
}
Expand Down Expand Up @@ -847,7 +849,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
AssocItemKind::MacCall(..) => unimplemented!(),
};
let id = hir::TraitItemId { def_id: self.resolver.local_def_id(i.id) };
let id = hir::TraitItemId { def_id: self.local_def_id(i.id) };
let defaultness = hir::Defaultness::Default { has_value: has_default };
hir::TraitItemRef {
id,
Expand Down Expand Up @@ -927,7 +929,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let has_value = true;
let (defaultness, _) = self.lower_defaultness(i.kind.defaultness(), has_value);
hir::ImplItemRef {
id: hir::ImplItemId { def_id: self.resolver.local_def_id(i.id) },
id: hir::ImplItemId { def_id: self.local_def_id(i.id) },
ident: self.lower_ident(i.ident),
span: self.lower_span(i.span),
defaultness,
Expand Down Expand Up @@ -1339,7 +1341,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
generics
.params
.iter()
.any(|p| def_id == self.resolver.local_def_id(p.id).to_def_id())
.any(|p| def_id == self.local_def_id(p.id).to_def_id())
}
// Either the `bounded_ty` is not a plain type parameter, or
// it's not found in the generic type parameters list.
Expand Down Expand Up @@ -1443,7 +1445,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
match kind {
GenericParamKind::Const { .. } => None,
GenericParamKind::Type { .. } => {
let def_id = self.resolver.local_def_id(id).to_def_id();
let def_id = self.local_def_id(id).to_def_id();
let ty_path = self.arena.alloc(hir::Path {
span: param_span,
res: Res::Def(DefKind::TyParam, def_id),
Expand All @@ -1466,7 +1468,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let res = self.resolver.get_lifetime_res(id).unwrap_or_else(|| {
panic!("Missing resolution for lifetime {:?} at {:?}", id, ident.span)
});
let lt_id = self.resolver.next_node_id();
let lt_id = self.next_node_id();
let lifetime = self.new_named_lifetime_with_res(lt_id, ident_span, ident, res);
Some(hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
lifetime,
Expand Down
Loading