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

Query cycle before ast lowered turns into dumpster fire #103844

Open
camsteffen opened this issue Nov 1, 2022 · 0 comments
Open

Query cycle before ast lowered turns into dumpster fire #103844

camsteffen opened this issue Nov 1, 2022 · 0 comments
Labels
A-contributor-roadblock Area: Makes things more difficult for new contributors to rust itself A-frontend Area: Compiler frontend (errors, parsing and HIR) A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@camsteffen
Copy link
Contributor

This is mostly just a rustc developer experience issue that crops up if you accidentally introduce a query cycle before ast lowering completes. After this happened to me a few times, I finally understand what is happening so I figured I should document it.

If a query cycle occurs before or during ast lowering, then rustc winds up querying for the HIR while trying to collect info about the cycle to report it, and this leads to another cycle and more panics, which is rather confusing to behold. The root issue is that we try to call the def_span and def_kind queries in the following places:

Some(key.default_span(*tcx))

(default_span is implemented using def_span if the key is DefId or LocalDefId)

def_id.and_then(|def_id| def_id.as_local()).and_then(|def_id| tcx.opt_def_kind(def_id))

Some ideas:

  1. Use source_span instead of def_span
  2. Add a way to get def_span and/or def_kind from AST (probably only for diagnostics cases like this)
  3. Add a way to detect if AST has been lowered, and skip those queries if not
@camsteffen camsteffen added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Nov 1, 2022
@camsteffen camsteffen changed the title Query cycle before ast lowering turns into dumpster fire Query cycle before ast lowered turns into dumpster fire Nov 1, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Nov 3, 2022
…aller, r=compiler-errors

Add track_caller to some Lock methods

Would have helped to diagnose rust-lang#103844.
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Nov 3, 2022
…aller, r=compiler-errors

Add track_caller to some Lock methods

Would have helped to diagnose rust-lang#103844.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 4, 2022
…aller, r=compiler-errors

Add track_caller to some Lock methods

Would have helped to diagnose rust-lang#103844.
@fmease fmease added A-frontend Area: Compiler frontend (errors, parsing and HIR) C-enhancement Category: An issue proposing an enhancement or a PR with one. A-contributor-roadblock Area: Makes things more difficult for new contributors to rust itself A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) labels Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-contributor-roadblock Area: Makes things more difficult for new contributors to rust itself A-frontend Area: Compiler frontend (errors, parsing and HIR) A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants