rust-lang / rust-lang/rust

Tracking issue for removing unnecessary `ty::Const::{normalize,eval}` calls from the type system

Open
#130,704 6 comments 4 reactions 1 assignee View on GitHub

@compiler-errors is already working on this.

Since Sep 22, 2024.

A-const-generics T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

We want to remove calls to ty::Const::{normalize,eval,eval_to_*} because they won't work correctly with future reformulations of GCE, and because they're unnecessary with non-GCE consts. This issue tracks doing that so I won't forget. Boxy can probably write more motivation here idk

Boxy rationale:

with min_generic_const_args and associated_const_equality featuers normalization of type system constants will be behaving much more like types. They'll return nested goals, access in scope whjere clauses such as T: Trait<ASSOC = 10> in order to normalize instead of simply "evaluating".

This means that the only correct way to normalize a ty::Const will be to use the "normal" normalization routines such as normalize_erasing_regions or infcx/ocx/fcx.normalize. With that in mind all of the eval_x and normalize methods on ty::Const become massive footguns as they are never correct to use.

  • Remove eval calls from codegen (#130644)
    • Replace calls to eval_bits with try_to_bits, which I forgot in codegen lol
  • Normalize writeback results (#130645)
    • Replace calls to eval from mir_build and pattern_analysis in now that writeback results are normalized (#130715)
  • Add structurally_resolve_const for use in FnCtxt/hir_typeck (#130714)
    • Replace calls to eval_* with structurally_resolve + try_to_* in hir typeck
  • Audit remaining calls to eva;/normalize post-borrowck, replacing them with their try_to_* variants + possibly normalizing depending on the source of the const.

More:

  • #130712

cc @BoxyUwU

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.