Skip to content

Collect lang items on the AST instead of HIR #115178

Closed

Description

@cjgillot

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

  1. added
    C-cleanupCategory: PRs that clean code up or issues documenting cleanup.
    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.
    E-help-wantedCall for participation: Help is requested to fix this issue.
    E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.
    on Aug 24, 2023
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Aug 24, 2023
  3. atsuzaki commented on Aug 24, 2023

    @atsuzaki
    Contributor

    @rustbot claim

  4. removed their assignment
    on Aug 26, 2023
  5. allaboutevemirolive commented on Aug 28, 2023

    @allaboutevemirolive
    Contributor

    @rustbot claim

  6. added and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Aug 29, 2023
  7. RickleAndMortimer commented on Sep 21, 2023

    @RickleAndMortimer
    Contributor

    Is this still being worked on? I'd like to take a look as well if we still need assistance for this issue

  8. 22 remaining items

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

Metadata

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