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

Enforce type of const param correctly in MIR typeck #138283

Merged
merged 1 commit into from
Mar 15, 2025

Conversation

compiler-errors
Copy link
Member

Properly intercepts and then annotates the type for a ConstKind::Param in the MIR.

This code should probably be cleaned up, it's kinda spaghetti, but no better structure really occurred to me when writing this case.

We could probably gate this behind the feature gate or add a fast path when the args have no free regions if perf is bad.

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 Mar 9, 2025
@compiler-errors
Copy link
Member Author

@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 Mar 9, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 9, 2025
… r=<try>

Enforce type of const param correctly in MIR typeck

Properly intercepts and then annotates the type for a `ConstKind::Param` in the MIR.

This code should probably be cleaned up, it's kinda spaghetti, but no better structure really occurred to me when writing this case.

We could probably gate this behind the feature gate or add a fast path when the args have no free regions if perf is bad.

r? `@BoxyUwU`
@bors
Copy link
Contributor

bors commented Mar 9, 2025

⌛ Trying commit c745d61 with merge f102e38...

@rust-log-analyzer

This comment has been minimized.

@compiler-errors
Copy link
Member Author

Forgor the stderr test, will push when try build is done.

@bors
Copy link
Contributor

bors commented Mar 9, 2025

☀️ Try build successful - checks-actions
Build commit: f102e38 (f102e383e684e4400055503ebc792bf06fd2340c)

@rust-timer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (f102e38): comparison URL.

Overall result: no relevant changes - 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 benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

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

Cycles

Results (primary 2.2%)

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.2% [2.2%, 2.2%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.2% [2.2%, 2.2%] 1

Binary size

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

Bootstrap: 769.881s -> 768.249s (-0.21%)
Artifact size: 361.99 MiB -> 362.01 MiB (0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 10, 2025
@BoxyUwU
Copy link
Member

BoxyUwU commented Mar 11, 2025

Can you add a test case that doesn't rely on generic_const_parameter_types too?

#![feature(adt_const_params, unsized_const_params)]

use std::marker::ConstParamTy_;

trait Trait<'a> {
    type Assoc: ConstParamTy_;
}

fn foo<'a, const N: <u8 as Trait<'static>>::Assoc>()
where
    for<'b> u8: Trait<'b>
{
    // Should error but doesn't on nightly
    let _: <u8 as Trait<'a>>::Assoc = N;
}

I don't think you can do it without unsized_const_params as you'd need a way to write a lifetime generic adt that's invariant over its lifetime parameter and also passes the builtin checks for ConstParamTy. If for<T> PhantomData<T>: ConstParamTy_ held then that'd be trivial to do but otherwise... 🤔

@BoxyUwU BoxyUwU added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 11, 2025
@compiler-errors
Copy link
Member Author

Added a test with a fun trick to create a type that has invariant lifetimes but also is ConstParamTy lol

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 11, 2025
@BoxyUwU
Copy link
Member

BoxyUwU commented Mar 11, 2025

thx gamer, r=me if/when CI passes

@compiler-errors
Copy link
Member Author

This will conflict with #138357. I'll rebase it in a bit.

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 11, 2025
@bors
Copy link
Contributor

bors commented Mar 13, 2025

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

@rust-log-analyzer

This comment has been minimized.

@compiler-errors
Copy link
Member Author

@bors r=BoxyUwU rollup

@bors
Copy link
Contributor

bors commented Mar 15, 2025

📌 Commit 0160c60 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 Mar 15, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 15, 2025
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#138283 (Enforce type of const param correctly in MIR typeck)
 - rust-lang#138439 (feat: check ARG_MAX on Unix platforms)
 - rust-lang#138502 (resolve: Avoid some unstable iteration)
 - rust-lang#138514 (Remove fake borrows of refs that are converted into non-refs in `MakeByMoveBody`)
 - rust-lang#138524 (Mark myself as unavailable for reviews temporarily)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit a384039 into rust-lang:master Mar 15, 2025
6 checks passed
@rustbot rustbot added this to the 1.87.0 milestone Mar 15, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Mar 15, 2025
Rollup merge of rust-lang#138283 - compiler-errors:enforce-const-param, r=BoxyUwU

Enforce type of const param correctly in MIR typeck

Properly intercepts and then annotates the type for a `ConstKind::Param` in the MIR.

This code should probably be cleaned up, it's kinda spaghetti, but no better structure really occurred to me when writing this case.

We could probably gate this behind the feature gate or add a fast path when the args have no free regions if perf is bad.

r? `@BoxyUwU`
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants