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

Deny more ~const trait bounds #117817

Merged
merged 1 commit into from
Nov 12, 2023
Merged

Conversation

fmease
Copy link
Member

@fmease fmease commented Nov 11, 2023

thereby fixing a family of ICEs (delayed bugs) for feature(const_trait_impl, effects) code.

As discussed
r? @fee1-dead

@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 11, 2023
@fmease fmease added F-const_trait_impl `#![feature(const_trait_impl)]` and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 11, 2023
@matthiaskrgr
Copy link
Member

Does this fix any of these? :D
https://github.com/rust-lang/rust/issues?q=is%3Aissue+is%3Aopen+author%3Amatthiaskrgr+effects

Copy link
Member

@fee1-dead fee1-dead left a comment

Choose a reason for hiding this comment

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

personally speaking I'd rather make Some(DisalloweTildeConstContext) the default

sure, let's do that!

compiler/rustc_ast_passes/src/ast_validation.rs Outdated Show resolved Hide resolved
@fmease fmease added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 11, 2023
@fmease fmease force-pushed the deny-more-tilde-const branch from e345737 to 2fe9827 Compare November 11, 2023 17:34
@fmease fmease 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 Nov 11, 2023
@fmease
Copy link
Member Author

fmease commented Nov 11, 2023

Does this fix any of these? :D

No, it doesn't :|

@fmease fmease force-pushed the deny-more-tilde-const branch from 2fe9827 to 8ce5d78 Compare November 11, 2023 23:00

self.visit_vis(&item.vis);
self.visit_ident(item.ident);
self.with_tilde_const(None, |this| this.visit_generics(generics));
Copy link
Member Author

@fmease fmease Nov 12, 2023

Choose a reason for hiding this comment

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

Currently permitting ~const trait bounds on inherent impls not to regress rfc-2632-const-trait-impl/tilde_const_on_impl_bound.rs. Not sure if the following code should compile at some point:

struct Struct;
#[const_trait] trait Trait {}
impl<T: ~const Trait> Struct {
    const fn f(_: T) {}
}

If I were to straight up deny ~const here, it'd obviously fix #117004. I haven't tested yet if the ~const lowering code can properly lower the code above.

Copy link
Member

Choose a reason for hiding this comment

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

We should probably deny this first. We don't really need this to work and making it work certainly adds to the overhead. Perhaps a followup PR? Or I can do that. Thanks for working on this! :)

Copy link
Member

Choose a reason for hiding this comment

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

I think we should deny ~const here. If we want to be able to use Trait in const fn f, I think the user should need to write:

struct Struct;
#[const_trait] trait Trait {}
impl<T: Trait> Struct {
    const fn f(_: T) where T: ~const Trait {}
}

at least in my opinion.

.trait = this trait is not a `#[const_trait]`, so it cannot have `~const` trait bounds
.impl = this impl is not `const`, so it cannot have `~const` trait bounds
.object = trait objects cannot have `~const` trait bounds
.item = this item cannot have `~const` trait bounds
Copy link
Member

@fee1-dead fee1-dead Nov 12, 2023

Choose a reason for hiding this comment

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

This is quite ambiguous and we'd probably always want to have a reason.. OTOH, we don't want to allow tilde const for these "unknown" cases. Would be nice if this was turned into a span_bug! so that a more specific context is always defined.

No need for this PR to have this though.

@fee1-dead
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Nov 12, 2023

📌 Commit 8ce5d78 has been approved by fee1-dead

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, 2023
@bors
Copy link
Contributor

bors commented Nov 12, 2023

⌛ Testing commit 8ce5d78 with merge a04d56b...

@bors
Copy link
Contributor

bors commented Nov 12, 2023

☀️ Test successful - checks-actions
Approved by: fee1-dead
Pushing a04d56b to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Nov 12, 2023
@bors bors merged commit a04d56b into rust-lang:master Nov 12, 2023
12 checks passed
@rustbot rustbot added this to the 1.76.0 milestone Nov 12, 2023
@fmease fmease deleted the deny-more-tilde-const branch November 12, 2023 07:12
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (a04d56b): comparison URL.

Overall result: ❌ regressions - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

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

Max RSS (memory usage)

Results

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

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: 674.671s -> 675.185s (0.08%)
Artifact size: 311.12 MiB -> 311.12 MiB (0.00%)

@fmease
Copy link
Member Author

fmease commented Nov 12, 2023

perf regression looks kinda spurious

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 18, 2023
…headers, r=fee1-dead

Deny `~const` trait bounds in inherent impl headers

Follow-up to rust-lang#117817.
Implements rust-lang#117817 (comment).

Fixes rust-lang#117004.

r? fee1-dead or compiler
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Dec 18, 2023
Rollup merge of rust-lang#119059 - fmease:no-tilde-const-in-inh-impl-headers, r=fee1-dead

Deny `~const` trait bounds in inherent impl headers

Follow-up to rust-lang#117817.
Implements rust-lang#117817 (comment).

Fixes rust-lang#117004.

r? fee1-dead or compiler
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Dec 19, 2023
…r=fee1-dead

Deny `~const` trait bounds in inherent impl headers

Follow-up to #117817.
Implements rust-lang/rust#117817 (comment).

Fixes #117004.

r? fee1-dead or compiler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-const_trait_impl `#![feature(const_trait_impl)]` merged-by-bors This PR was explicitly merged by bors. 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.

7 participants