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

Move Const::{from_anon_const,try_from_lit} to hir_ty_lowering #133610

Merged
merged 2 commits into from
Dec 3, 2024

Conversation

camelid
Copy link
Member

@camelid camelid commented Nov 29, 2024

Fixes #128176.
This accomplishes one of the followup items from #131081.

These operations are much more about lowering the HIR than about
Consts themselves. They fit better in hir_ty_lowering with
lower_const_arg (formerly Const::from_const_arg) and the rest.

To accomplish this, const_evaluatable_predicates_of had to be changed
to not use from_anon_const anymore. Instead of visiting the HIR and
lowering anon consts on the fly, it now visits the rustc_middle::ty
data structures instead and directly looks for UnevaluatedConsts. This
approach was proposed in:
#131081 (comment)

r? @BoxyUwU

@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. labels Nov 29, 2024
@rustbot
Copy link
Collaborator

rustbot commented Nov 29, 2024

HIR ty lowering was modified

cc @fmease

@camelid camelid added the A-const-generics Area: const generics (parameters and arguments) label Nov 29, 2024
Comment on lines -417 to -419
if let Some(generics) = node.generics() {
debug!("const_evaluatable_predicates_of({:?}): visit_generics", def_id);
collector.visit_generics(generics);
Copy link
Member Author

Choose a reason for hiding this comment

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

I couldn't really think of anything that would need this, nor what the rustc_middle::ty-equivalent would be. All the tests passed though.

Copy link
Member

Choose a reason for hiding this comment

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

yeah its a bit weird, hir::Generics is some amalgamation of generics_of, and some predicates_of (inline written bounds, e.g. <T: Trait>). We don't really care about generics_of since we don't want to add const evaluatable bounds for const parameter defaults, and any const arguments in types of const parmeters (e.g. <const N: Bar<{ 10 }>>) must be fully concrete so there's no need to add const evaluatable bounds for them.

So yeah 👍 to removing this

@rust-log-analyzer

This comment has been minimized.

@camelid
Copy link
Member Author

camelid commented Nov 29, 2024

Curious if this improves performance since we no longer re-lower const args.

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 29, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 29, 2024
Move `Const::{from_anon_const,try_from_lit}` to hir_ty_lowering

Fixes rust-lang#128176.
This accomplishes one of the followup items from rust-lang#131081.

These operations are much more about lowering the HIR than about
`Const`s themselves. They fit better in hir_ty_lowering with
`lower_const_arg` (formerly `Const::from_const_arg`) and the rest.

To accomplish this, `const_evaluatable_predicates_of` had to be changed
to not use `from_anon_const` anymore. Instead of visiting the HIR and
lowering anon consts on the fly, it now visits the `rustc_middle::ty`
data structures instead and directly looks for `UnevaluatedConst`s. This
approach was proposed in:
rust-lang#131081 (comment)

r? `@BoxyUwU`
@bors
Copy link
Contributor

bors commented Nov 29, 2024

⌛ Trying commit 352a6c8 with merge 16870bf...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Nov 29, 2024

☀️ Try build successful - checks-actions
Build commit: 16870bf (16870bffd86d10e5ea2f720601410e5fdeeed00a)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (16870bf): comparison URL.

Overall result: ❌ regressions - no action needed

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.9% [0.9%, 0.9%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary 0.8%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
2.9% [1.1%, 4.6%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.2% [-1.4%, -1.0%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.8% [-1.4%, 4.6%] 4

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 773.667s -> 772.898s (-0.10%)
Artifact size: 331.97 MiB -> 331.97 MiB (-0.00%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 29, 2024
Copy link
Member

@BoxyUwU BoxyUwU left a comment

Choose a reason for hiding this comment

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

very cool! :3 small review + fixing the intra doc link that's now broken then should be good to go

//@ known-bug: rust-lang/rust#128176
//@ check-pass

// Regression test for #128176.
Copy link
Member

@BoxyUwU BoxyUwU Nov 29, 2024

Choose a reason for hiding this comment

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

Suggested change
// Regression test for #128176.
// Regression test for #128176. Previously we would call `type_of` on the `1` anon const before the anon const had been lowered and had the `type_of` fed with a result.

@BoxyUwU
Copy link
Member

BoxyUwU commented Nov 29, 2024

I wouldn't have really expected any perf effects since most of this PR only has an effect under generic_const_exprs so good that it's neutral :3

@BoxyUwU
Copy link
Member

BoxyUwU commented Nov 30, 2024

@bors r+

don't need to block this PR on figuring out exactly why that test stopped ICEing since its gce only

@bors
Copy link
Contributor

bors commented Nov 30, 2024

📌 Commit 5c37ec1 has been approved by BoxyUwU

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Nov 30, 2024

🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened.

@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 30, 2024
@BoxyUwU
Copy link
Member

BoxyUwU commented Dec 2, 2024

@bors rollup=maybe

@bors
Copy link
Contributor

bors commented Dec 2, 2024

☔ The latest upstream changes (presumably #133728) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors removed the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Dec 2, 2024
@bors bors added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Dec 2, 2024
@rust-log-analyzer

This comment has been minimized.

These operations are much more about lowering the HIR than about
`Const`s themselves. They fit better in hir_ty_lowering with
`lower_const_arg` (formerly `Const::from_const_arg`) and the rest.

To accomplish this, `const_evaluatable_predicates_of` had to be changed
to not use `from_anon_const` anymore. Instead of visiting the HIR and
lowering anon consts on the fly, it now visits the `rustc_middle::ty`
data structures instead and directly looks for `UnevaluatedConst`s. This
approach was proposed in:
rust-lang#131081 (comment)
@camelid
Copy link
Member Author

camelid commented Dec 2, 2024

@bors r=BoxyUwU

@bors
Copy link
Contributor

bors commented Dec 2, 2024

📌 Commit dcf332b has been approved by BoxyUwU

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 2, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 3, 2024
…llaumeGomez

Rollup of 10 pull requests

Successful merges:

 - rust-lang#131713 (Stabilize `const_maybe_uninit_write`)
 - rust-lang#133535 (show forbidden_lint_groups in future-compat reports)
 - rust-lang#133610 (Move `Const::{from_anon_const,try_from_lit}` to hir_ty_lowering)
 - rust-lang#133701 (Use c"lit" for CStrings without unwrap)
 - rust-lang#133704 (fix ICE when promoted has layout size overflow)
 - rust-lang#133705 (add "profiler" and "optimized-compiler-builtins" option coverage for ci-rustc)
 - rust-lang#133710 (Reducing `target_feature` check-cfg merge conflicts)
 - rust-lang#133732 (Fix `-Zdump-mir-dataflow`)
 - rust-lang#133746 (Change `AttrArgs::Eq` to a struct variant)
 - rust-lang#133763 (Fix `f16::midpoint` const feature gate)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 6f0d15a into rust-lang:master Dec 3, 2024
6 checks passed
@rustbot rustbot added this to the 1.85.0 milestone Dec 3, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Dec 3, 2024
Rollup merge of rust-lang#133610 - camelid:move-from_anon_const, r=BoxyUwU

Move `Const::{from_anon_const,try_from_lit}` to hir_ty_lowering

Fixes rust-lang#128176.
This accomplishes one of the followup items from rust-lang#131081.

These operations are much more about lowering the HIR than about
`Const`s themselves. They fit better in hir_ty_lowering with
`lower_const_arg` (formerly `Const::from_const_arg`) and the rest.

To accomplish this, `const_evaluatable_predicates_of` had to be changed
to not use `from_anon_const` anymore. Instead of visiting the HIR and
lowering anon consts on the fly, it now visits the `rustc_middle::ty`
data structures instead and directly looks for `UnevaluatedConst`s. This
approach was proposed in:
rust-lang#131081 (comment)

r? `@BoxyUwU`
@camelid camelid deleted the move-from_anon_const branch December 3, 2024 05:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ICE: unexpected const arg parent in type_of()
6 participants