Skip to content

opportunistically evaluate constants while populating mir::Body::required_consts #71802

Open
@oli-obk

Description

We can evaluate all constants that do not depend on generic parameters in

if let ConstKind::Unevaluated(_, _, _) = const_kind {

We make that a MutVisitor that evaluates all constants that it can and replaces them in-place and only adds those that it couldn't evaluate to the required_const list.

This way we never have to evaluate another constant in the entire MIR optimization pipeline, because we know none can be evaluated (modulo those that we already evaluate for merging required_consts during inlining.

cc @rust-lang/wg-mir-opt I think I like having the above invariant. It will make working with constants in MIR much simpler and make any kind of error handling that would have to be implemented unified into a single location.

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-mir-optArea: MIR optimizationsA-mir-opt-inliningArea: MIR inliningC-cleanupCategory: PRs that clean code up or issues documenting cleanup.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