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

Represent type-level consts with new-and-improved hir::ConstArg #125915

Merged
merged 10 commits into from
Jul 19, 2024

Commits on Jul 17, 2024

  1. Add current_def_id_parent to LoweringContext

    This is needed to track anon const parents properly once we implement
    `ConstArgKind::Path` (which requires moving anon const def-creation
    outside of `DefCollector`):
    
        Why do we need this in addition to [`Self::current_hir_id_owner`]?
    
        Currently (as of June 2024), anonymous constants are not HIR owners;
        however, they do get their own DefIds. Some of these DefIds have to be
        created during AST lowering, rather than def collection, because we
        can't tell until after name resolution whether an anonymous constant
        will end up instead being a [`rustc_hir::ConstArgKind::Path`]. However,
        to compute which generics are available to an anonymous constant nested
        inside another, we need to make sure that the parent is recorded as the
        parent anon const, not the enclosing item. So we need to track parent
        defs differently from HIR owners, since they will be finer-grained in
        the case of anon consts.
    camelid committed Jul 17, 2024
    Configuration menu
    Copy the full SHA
    71f8aed View commit details
    Browse the repository at this point in the history
  2. hir: Create hir::ConstArgKind enum

    This will allow lowering const params to a dedicated enum variant, rather
    than to an `AnonConst` that is later examined during `ty` lowering.
    camelid committed Jul 17, 2024
    Configuration menu
    Copy the full SHA
    11b144a View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    7d7be2f View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    e7c85cb View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    8818708 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    67fccb7 View commit details
    Browse the repository at this point in the history
  7. Use ConstArg for const param defaults

    Now everything that actually affects the type system (i.e., excluding
    const blocks, enum variant discriminants, etc.) *should* be using
    `ConstArg`.
    camelid committed Jul 17, 2024
    Configuration menu
    Copy the full SHA
    1c49d40 View commit details
    Browse the repository at this point in the history
  8. Add ConstArgKind::Path and make ConstArg its own HIR node

    This is a very large commit since a lot needs to be changed in order to
    make the tests pass. The salient changes are:
    
    - `ConstArgKind` gets a new `Path` variant, and all const params are now
      represented using it. Non-param paths still use `ConstArgKind::Anon`
      to prevent this change from getting too large, but they will soon use
      the `Path` variant too.
    
    - `ConstArg` gets a distinct `hir_id` field and its own variant in
      `hir::Node`. This affected many parts of the compiler that expected
      the parent of an `AnonConst` to be the containing context (e.g., an
      array repeat expression). They have been changed to check the
      "grandparent" where necessary.
    
    - Some `ast::AnonConst`s now have their `DefId`s created in
      rustc_ast_lowering rather than `DefCollector`. This is because in some
      cases they will end up becoming a `ConstArgKind::Path` instead, which
      has no `DefId`. We have to solve this in a hacky way where we guess
      whether the `AnonConst` could end up as a path const since we can't
      know for sure until after name resolution (`N` could refer to a free
      const or a nullary struct). If it has no chance as being a const
      param, then we create a `DefId` in `DefCollector` -- otherwise we
      decide during ast_lowering. This will have to be updated once all path
      consts use `ConstArgKind::Path`.
    
    - We explicitly use `ConstArgHasType` for array lengths, rather than
      implicitly relying on anon const type feeding -- this is due to the
      addition of `ConstArgKind::Path`.
    
    - Some tests have their outputs changed, but the changes are for the
      most part minor (including removing duplicate or almost-duplicate
      errors). One test now ICEs, but it is for an incomplete, unstable
      feature and is now tracked at rust-lang#127009.
    camelid committed Jul 17, 2024
    Configuration menu
    Copy the full SHA
    37ed7a4 View commit details
    Browse the repository at this point in the history

Commits on Jul 18, 2024

  1. Clarify docs explaining purpose of ConstArg

    Co-authored-by: Boxy <rust@boxyuwu.dev>
    camelid and BoxyUwU committed Jul 18, 2024
    Configuration menu
    Copy the full SHA
    2e4a0e3 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    c8457e6 View commit details
    Browse the repository at this point in the history