Skip to content

Collect lang items on the AST instead of HIR #115178

Open
@cjgillot

Description

Lang items are collected on HIR in rustc_passes::lang_items.
However, AST -> HIR lowering may need to know of some lang items, for instance for loops of async desugaring.
Having lang items ready before lowering may simplify those code paths.

This requires re-implementing lang item collection on AST instead of HIR.
The simplest way is to make rustc_passes::lang_items::LanguageItemCollector a rustc_ast::Visitor, and have get_lang_items use it to visit the full crate. The AST is accessible using the second field of tcx.resolver_for_lowering(()).borrow().

A statement tcx.ensure_with_value().get_lang_items(LOCAL_CRATE) needs to be added at the top of rustc_ast_lowering::lower_to_hir to ensure that the computation is done before dropping the AST.

Once that is done, hir::QPath::LangItem and hir::GenericBound::LangItemTrait variants can be removed from HIR, replaced by actual resolutions of the lang items. (For particular cases, see how those variants are constructed and used.)

Please contact me on zulip for any question.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-astArea: ASTA-lang-itemArea: Language itemsC-cleanupCategory: PRs that clean code up or issues documenting cleanup.E-help-wantedCall for participation: Help is requested to fix this issue.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.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