Skip to content

Query cycle before ast lowered turns into dumpster fire #103844

Open
@camsteffen

Description

@camsteffen

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-contributor-roadblockArea: Makes things more difficult for new or seasoned contributors to RustA-frontendArea: Compiler frontend (errors, parsing and HIR)A-query-systemArea: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html)C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions