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

rustc: Remove HirId from queries #44435

Merged
merged 1 commit into from
Sep 11, 2017
Merged

Conversation

alexcrichton
Copy link
Member

This'll allow us to reconstruct query parameters purely from the DepNode
they're associated with.

Closes #44414

@rust-highfive
Copy link
Collaborator

r? @arielb1

(rust_highfive has picked a reviewer for you, use r? to override)

@alexcrichton
Copy link
Member Author

r? @michaelwoerister

@@ -836,11 +836,11 @@ pub struct GlobalCtxt<'tcx> {
// Records the free variables refrenced by every closure
// expression. Do not track deps for this, just recompute it from
// scratch every time.
freevars: FxHashMap<HirId, Rc<Vec<hir::Freevar>>>,
freevars: FxHashMap<DefId, Rc<Vec<hir::Freevar>>>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe there's DefIdMap and DefIdSet aliases which could be used for these changes.

let hir_id = self.hir.node_to_hir_id(fid);
match self.freevars(hir_id) {
let def_id = self.hir.local_def_id(fid);
match self.freevars(def_id) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So with_freevars used to be a thing because of a RefCell. Can it be removed in favor of tcx.freevars(def_id)? All callers should, ironically, already have a closure DefId around.

@kennytm
Copy link
Member

kennytm commented Sep 9, 2017

Could not compile core

[00:17:57] error: internal compiler error: unexpected panic
[00:17:57] 
[00:17:57] note: the compiler unexpectedly panicked. this is a bug.
[00:17:57] 
[00:17:57] note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
[00:17:57] 
[00:17:57] note: rustc 1.22.0-dev running on x86_64-unknown-linux-gnu
[00:17:57] 
[00:17:57] thread 'rustc' panicked at '/checkout/src/librustc/hir/map/mod.rs:330: local_def_id: no entry for `291005`, which has a map of `Some(EntryLifetime(NodeId(192109), DepNodeIndex { index: 4294967295 }, lifetime(291005: )))`', /checkout/src/librustc/session/mod.rs:889:25
[00:17:57] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[00:17:57] 
[00:17:57] error: Could not compile `core`.

@bors
Copy link
Contributor

bors commented Sep 9, 2017

☔ The latest upstream changes (presumably #44335) made this pull request unmergeable. Please resolve the merge conflicts.

@michaelwoerister
Copy link
Member

Thanks, @alexcrichton!

Unfortunately it won't be as easy as just replacing HirId with DefId here because not every HirId has a corresponding DefId. For example, HIR expressions don't have a DefId, so moving in_scope_traits to DefId also involves storing things in a two-level map, so that it can look something like this:

impl TyCtxt {
    fn in_scope_traits_of_expr(self, hir_id: HirId) -> Option<Rc<Vec<TraitCandidate>>> {
        // Get the map for the item containing the HirId. This is a query:
        let map_for_containing_item = self.in_scope_traits_of_item(hir_id.owner);
        // From that item-local map get actual return value
        map_for_containing_item.get(hir_id.local_id).cloned()
    }
}

@alexcrichton
Copy link
Member Author

Heh yeah the panics figured that out pretty quickly here! I'll work on making these sub-maps.

@alexcrichton alexcrichton force-pushed the in-scope branch 2 times, most recently from 14c68ee to 7e49951 Compare September 9, 2017 21:45
@alexcrichton
Copy link
Member Author

Alright I believe the necessary maps have been transitioned, re-r? @michaelwoerister

@@ -570,8 +570,8 @@ define_dep_nodes!( <'tcx>
[] UsedCrateSource(CrateNum),
[] PostorderCnums,

[] Freevars(HirId),
[] MaybeUnusedTraitImport(HirId),
[] Freevars(DefIndex),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use DefId here? Closures have DefIds.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed! Got a bit overzealous with DefIndex

Copy link
Member

@michaelwoerister michaelwoerister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me except for that one performance concern.

let id = tcx.hir.definitions().find_node_for_hir_id(id);
assert_eq!(id.krate, LOCAL_CRATE);
let hir_id = tcx.hir.definitions().def_index_to_hir_id(id.index);
let id = tcx.hir.definitions().find_node_for_hir_id(hir_id);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, I should better have listened to @arielb1 and marked find_node_for_hir_id as super-slow somehow. It does a linear search over all NodeIds 😰

But it seems that what you're doing here is equivalent to tcx.hir.as_local_node_id(id).unwrap()?

Copy link
Member

@eddyb eddyb Sep 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does find_node_for_hir_id exist? I've introduced hir_to_node_id. (EDIT: I generated a reverse HashMap for that purpose)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see. It does exist because I wanted to avoid building that reverse mapping because it was only needed in error reporting. It's probably cheap to build though, especially now that locals don't have DefIds anymore.

@alexcrichton
Copy link
Member Author

@bors: r=michaelwoerister

@bors
Copy link
Contributor

bors commented Sep 11, 2017

📌 Commit 772ca85 has been approved by michaelwoerister

@carols10cents carols10cents added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Sep 11, 2017
This'll allow us to reconstruct query parameters purely from the `DepNode`
they're associated with. Some queries could move straight to `HirId` but others
that don't always have a correspondance between `HirId` and `DefId` moved to
two-level maps where the query operates over a `DefIndex`, returning a map,
which is then keyed off `ItemLocalId`.

Closes rust-lang#44414
@alexcrichton
Copy link
Member Author

@bors: r=michaelwoerister

@bors
Copy link
Contributor

bors commented Sep 11, 2017

📌 Commit caaf365 has been approved by michaelwoerister

@bors
Copy link
Contributor

bors commented Sep 11, 2017

⌛ Testing commit caaf365 with merge efa3ec6...

bors added a commit that referenced this pull request Sep 11, 2017
rustc: Remove HirId from queries

This'll allow us to reconstruct query parameters purely from the `DepNode`
they're associated with.

Closes #44414
@bors
Copy link
Contributor

bors commented Sep 11, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: michaelwoerister
Pushing efa3ec6 to master...

@bors bors merged commit caaf365 into rust-lang:master Sep 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants