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

Remove obsolete workaround. #85266

Merged
merged 2 commits into from
May 31, 2021
Merged

Remove obsolete workaround. #85266

merged 2 commits into from
May 31, 2021

Conversation

cjgillot
Copy link
Contributor

@cjgillot cjgillot commented May 13, 2021

The regression test for #62649 appears to pass even without the workaround.

@rust-highfive
Copy link
Collaborator

r? @Mark-Simulacrum

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 13, 2021
@rust-log-analyzer

This comment has been minimized.

@Mark-Simulacrum
Copy link
Member

Hm, the comment says "one such bug"... I wonder if we have tests for all of them.

cc @rust-lang/wg-incr-comp

@spastorino
Copy link
Member

spastorino commented May 13, 2021

So I guess we are also saying that #62649 is not a bug anymore? where does #62649 works? nightly, beta, stable? should we close the issue?.

Edit: I see there are attempts to fix the mentioned issue at #75641 and there were heavy changes to incr. comp. anyway not 100% sure when was this issue fixed and if it's already fixed on stable and beta.

@cjgillot
Copy link
Contributor Author

Long explanation:

This match triggers when we are trying to force the dep-node for hir_owner or hir_owner_nodes with a non-owning def-id (both work exactly the same way).
An invariant of lowering, enforced by HIR indexing is that local_def_id_to_hir_id(id).owner is either id or its parent (there is a debug_assert).
The second branch of the workaround is already checked in the query forcing code, when attempting to reconstruct the query key from the hash.

The first branch of the is more interesting. It triggers when hir_owner is forced with a non-owning def-id. The query computes index_hir().map[id].signature. For non-owning def-ids, HIR indexing builds index_hir().map[id].signature to be Some(..) iff the id is an owner. On the converse, which is the case at hand, hir_owner returns None.

As HIR accesses are built so as never to knowingly access those Nones *. As a consequence, the compilation session which forced this node had a Some(..) value. As a consequence, the query will be red.

* There is an exception for non-exported macros, which I plan to remove because I get bitten every time.

@Mark-Simulacrum
Copy link
Member

r? @michaelwoerister perhaps?

@michaelwoerister
Copy link
Member

OK, this looks good to me. However, we should use this PR as an opportunity to document the invariants @cjgillot mentions, in particular it would be great to do (at least) the following:

  • Add a doc string to rustc_middle::hir::IndexedHir::map that describes what the map contains. I assume that there is an entry for every DefId in the local crate - but since not every DefId will also be a HIR owner we should explain what the corresponding HirOwnerData looks like for non-owning nodes.
  • Add a doc string that explains a bit more about the rustc_middle::hir::IndexedHir::parenting field. What keys are expected to be in there, for example.
  • Add a doc string to the rustc_middle::hir::HirOwnerData::signature field. When is this None?
  • Add a doc string to the rustc_middle::hir::HirOwnerData::with_bodies field. When is this None?

Also I have some questions:

  • Why is rustc_middle::hir::HirOwnerData::with_bodies not just called by bodies? The name is a bit unexpected. Is there more to it? If so it would be great to document it.
  • Is there ever a case where HirOwnerData::signature is Some but HirOwnerData::with_bodies is None? If not, can we use Option<HirOwnerData> in IndexedHir::map?
  • Why is HirOwnerData::with_bodies a mut reference?

@michaelwoerister
Copy link
Member

Thanks, @cjgillot! That looks like a nice little improvement overall.

@bors r+ rollup=never

@bors
Copy link
Contributor

bors commented May 31, 2021

📌 Commit 4f8e34c has been approved by michaelwoerister

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 31, 2021
@bors
Copy link
Contributor

bors commented May 31, 2021

⌛ Testing commit 4f8e34c with merge 91ddf3e...

@bors
Copy link
Contributor

bors commented May 31, 2021

☀️ Test successful - checks-actions
Approved by: michaelwoerister
Pushing 91ddf3e to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 31, 2021
@bors bors merged commit 91ddf3e into rust-lang:master May 31, 2021
@rustbot rustbot added this to the 1.54.0 milestone May 31, 2021
@cjgillot cjgillot deleted the hir-dep-clean branch May 31, 2021 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. 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