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

Consolidate type system const evaluation under traits::evaluate_const #132927

Merged
merged 1 commit into from
Nov 12, 2024

Conversation

BoxyUwU
Copy link
Member

@BoxyUwU BoxyUwU commented Nov 12, 2024

Part of #130704

Fixes #128232
Fixes #118545

Removes ty::Const::{normalize_internal, eval_valtree} and InferCtxt::(try_)const_eval_resolve, consolidating the associated logic into evaluate_const in rustc_trait_selection. This results in an API for ty::Const that is free of any normalization/evaluation functions that would be incorrect to use under min_generic_const_args/associated_const_equality/generic_const_exprs or, more generally, that would be incorrect to use in the presence of generic type system constants.

Moving this logic to rustc_trait_selection and out of rustc_middle is also a pre-requisite for ensuring that we do not evaluate constants whose where clauses do not hold.

From this point it should be relatively simple (hah) to implement more complex normalization of type system constants such as: checking wf'ness before invoking CTFE machinery, or being able to normalize const aliases that still refer to generic parameters.

r? @compiler-errors

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Nov 12, 2024
@rustbot
Copy link
Collaborator

rustbot commented Nov 12, 2024

Some changes occurred in match checking

cc @Nadrieril

Some changes occurred to the core trait solver

cc @rust-lang/initiative-trait-system-refactor

Comment on lines -95 to -96
// FIXME: We should only try to evaluate a given constant here if it is fully concrete
// as we don't want to allow things like `[u8; std::mem::size_of::<*mut T>()]`.
Copy link
Member Author

@BoxyUwU BoxyUwU Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try_evaluate_const will be responsible for not evaluating if generic parameters are being used (either directly or indirectly through ctfe machinery returning TooGeneric)

compiler/rustc_middle/src/mir/consts.rs Show resolved Hide resolved
compiler/rustc_middle/src/mir/consts.rs Show resolved Hide resolved
@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some initial thoughts

@compiler-errors
Copy link
Member

clippy moment :ferrisClueless:

@rust-log-analyzer

This comment has been minimized.

@BoxyUwU BoxyUwU force-pushed the consolidate_type_system_const_eval branch from 5558a84 to b77593e Compare November 12, 2024 01:49
@rustbot
Copy link
Collaborator

rustbot commented Nov 12, 2024

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@BoxyUwU BoxyUwU force-pushed the consolidate_type_system_const_eval branch from b77593e to 47948d5 Compare November 12, 2024 02:08
@compiler-errors
Copy link
Member

r=me when green

@rust-log-analyzer

This comment has been minimized.

@BoxyUwU BoxyUwU force-pushed the consolidate_type_system_const_eval branch from 47948d5 to bea0148 Compare November 12, 2024 02:54
@BoxyUwU
Copy link
Member Author

BoxyUwU commented Nov 12, 2024

@bors r=compiler-errors

@bors
Copy link
Contributor

bors commented Nov 12, 2024

📌 Commit bea0148 has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 12, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 12, 2024
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#132651 (Remove attributes from generics in built-in derive macros)
 - rust-lang#132668 (Feature gate yield expressions not in 2024)
 - rust-lang#132771 (test(configure): cover `parse_args` in `src/bootstrap/configure.py`)
 - rust-lang#132895 (Generalize `NonNull::from_raw_parts` per ACP362)
 - rust-lang#132914 (Update grammar in std::cell docs.)
 - rust-lang#132927 (Consolidate type system const evaluation under `traits::evaluate_const`)
 - rust-lang#132935 (Make sure to ignore elided lifetimes when pointing at args for fulfillment errors)
 - rust-lang#132941 (Subtree update of `rust-analyzer`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit ea61714 into rust-lang:master Nov 12, 2024
6 checks passed
@rustbot rustbot added this to the 1.84.0 milestone Nov 12, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 12, 2024
Rollup merge of rust-lang#132927 - BoxyUwU:consolidate_type_system_const_eval, r=compiler-errors

Consolidate type system const evaluation under `traits::evaluate_const`

Part of rust-lang#130704

Fixes rust-lang#128232
Fixes rust-lang#118545

Removes `ty::Const::{normalize_internal, eval_valtree}` and `InferCtxt::(try_)const_eval_resolve`, consolidating the associated logic into `evaluate_const` in `rustc_trait_selection`. This results in an API for `ty::Const` that is free of any normalization/evaluation functions that would be incorrect to use under `min_generic_const_args`/`associated_const_equality`/`generic_const_exprs` or, more generally, that would be incorrect to use in the presence of generic type system constants.

Moving this logic to `rustc_trait_selection` and out of `rustc_middle` is also a pre-requisite for ensuring that we do not evaluate constants whose where clauses do not hold.

From this point it should be relatively simple (hah) to implement more complex normalization of type system constants such as: checking wf'ness before invoking CTFE machinery, or being able to normalize const aliases that still refer to generic parameters.

r? `@compiler-errors`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)
Projects
None yet
5 participants