Skip to content

Commit

Permalink
Move all the heavy lifting from TyCtxtAt::create_def into `TyCtxt::…
Browse files Browse the repository at this point in the history
…create_def`
  • Loading branch information
oli-obk committed Feb 14, 2024
1 parent 2e900ed commit 55f9aed
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
30 changes: 17 additions & 13 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,22 @@ impl<'tcx> TyCtxtAt<'tcx> {
name: Symbol,
def_kind: DefKind,
) -> TyCtxtFeed<'tcx, LocalDefId> {
let feed = self.tcx.create_def(parent, name, def_kind);

feed.def_span(self.span);
feed
}
}

impl<'tcx> TyCtxt<'tcx> {
/// `tcx`-dependent operations performed for every created definition.
pub fn create_def(
self,
parent: LocalDefId,
name: Symbol,
def_kind: DefKind,
) -> TyCtxtFeed<'tcx, LocalDefId> {
let data = def_kind.def_path_data(name);
// The following call has the side effect of modifying the tables inside `definitions`.
// These very tables are relied on by the incr. comp. engine to decode DepNodes and to
// decode the on-disk cache.
Expand All @@ -1060,18 +1076,6 @@ impl<'tcx> TyCtxtAt<'tcx> {
// This is fine because:
// - those queries are `eval_always` so we won't miss their result changing;
// - this write will have happened before these queries are called.
let def_id = self.tcx.create_def(parent, name, def_kind);

let feed = self.tcx.feed_local_def_id(def_id);
feed.def_span(self.span);
feed
}
}

impl<'tcx> TyCtxt<'tcx> {
/// `tcx`-dependent operations performed for every created definition.
pub fn create_def(self, parent: LocalDefId, name: Symbol, def_kind: DefKind) -> LocalDefId {
let data = def_kind.def_path_data(name);
let def_id = self.untracked.definitions.write().create_def(parent, data);

// This function modifies `self.definitions` using a side-effect.
Expand All @@ -1091,7 +1095,7 @@ impl<'tcx> TyCtxt<'tcx> {
feed.visibility(ty::Visibility::Restricted(parent_mod));
}

def_id
feed
}

pub fn iter_local_def_id(self) -> impl Iterator<Item = LocalDefId> + 'tcx {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ impl<'tcx> Resolver<'_, 'tcx> {
);

// FIXME: remove `def_span` body, pass in the right spans here and call `tcx.at().create_def()`
let def_id = self.tcx.create_def(parent, name, def_kind);
let def_id = self.tcx.create_def(parent, name, def_kind).def_id();

// Create the definition.
if expn_id != ExpnId::root() {
Expand Down

0 comments on commit 55f9aed

Please sign in to comment.