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

Reimplement ~const trait specialization #133325

Merged
merged 2 commits into from
Dec 3, 2024

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Nov 22, 2024

Reimplement const specialization. We need this for PartialEq constification :)

r? lcnr

@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 22, 2024
@compiler-errors compiler-errors changed the title Const spec Reimplement ~const trait specialization Nov 22, 2024
}

debug!("fulfill_implication: an impl for {:?} specializes {:?}", source_trait, target_trait);
// If the parent impl is const, then the specializing impl must be const.
Copy link
Member Author

@compiler-errors compiler-errors Nov 22, 2024

Choose a reason for hiding this comment

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

Note to self: Actually I don't know if this is correct -- well, it's not sufficient.

const trait Bar {}
impl const Bar for T {}

const trait Foo {}
impl const Foo for T where T: ~const Bar {}
// specializing impl:
impl Foo for (T,) {}

The specializing impl satisfies (T,): ~const Bar because of the blanket impl, but it's still less const than the parent impl. I think we need to check that the specializing impl is also conditionally const, and then bail.

@compiler-errors
Copy link
Member Author

@rustbot author

@rustbot rustbot 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 Nov 22, 2024
@compiler-errors compiler-errors force-pushed the const-spec branch 2 times, most recently from d1b64f1 to ebfd56f Compare November 23, 2024 01:00
@compiler-errors
Copy link
Member Author

@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 Nov 23, 2024
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.

not 100% confident that I can review the specialization impl, but the tests lgtm.

@@ -230,23 +231,26 @@ pub(super) fn specialization_enabled_in(tcx: TyCtxt<'_>, _: LocalCrate) -> bool
/// `impl1` specializes `impl2` if it applies to a subset of the types `impl2` applies
Copy link
Contributor

Choose a reason for hiding this comment

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

comment is outdated after your rename

Copy link
Contributor

@lcnr lcnr Dec 2, 2024

Choose a reason for hiding this comment

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

also, I feel like it's very helpful to explicitly write down "We therefore prove that the specializing impl implies the parent impl".

Because then it feels clear why we're instantiating the specializing impl with placeholders and the parent impl with existentials and prove all bounds of the parent impül

Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

nit, r=lcnr,fee1-dead

@compiler-errors
Copy link
Member Author

@bors r=lcnr,fee1-dead

@bors
Copy link
Contributor

bors commented Dec 2, 2024

📌 Commit 9bda88b has been approved by lcnr,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 Dec 2, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 3, 2024
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#132723 (Unify `sysroot_target_{bin,lib}dir` handling)
 - rust-lang#133041 (Print name of env var in `--print=deployment-target`)
 - rust-lang#133325 (Reimplement `~const` trait specialization)
 - rust-lang#133395 (Add simd_relaxed_fma intrinsic)
 - rust-lang#133517 (Deeply normalize when computing implied outlives bounds)
 - rust-lang#133785 (Add const evaluation error UI test.)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 8aa5853 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#133325 - compiler-errors:const-spec, r=lcnr,fee1-dead

Reimplement `~const` trait specialization

Reimplement const specialization. We need this for `PartialEq` constification :)

r? lcnr
@compiler-errors compiler-errors deleted the const-spec branch December 3, 2024 23:26
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.

5 participants