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

Enable coinduction support for Safe Transmute #113175

Merged
merged 1 commit into from
Jul 11, 2023

Conversation

bryangarza
Copy link
Contributor

This patch adds the #[rustc_coinductive] annotation to BikeshedIntrinsicFrom, so that it's possible to compute transmutability for recursive types.

Motivation

Safe Transmute currently already supports references (#110662). However, if a type is implemented recursively, it leads to an infinite loop when we try to check if transmutation is safe.

A couple simple examples that one might want to write, that are currently not possible to check transmutability for:

#[repr(C)] struct A(&'static B);
#[repr(C)] struct B(&'static A);
#[repr(C)]
enum IList<'a> { Nil, Cons(isize, &'a IList<'a>) }
#[repr(C)]
enum UList<'a> { Nil, Cons(usize, &'a UList<'a>) }

Previously, @jswrenn was considering writing a co-inductive solver from scratch, just for the rustc_tranmsute crate. Later on as I started working on Safe Transmute myself, I came across the #[rustc_coinductive] annotation, which is currently only being used for the Sized trait. Leveraging this trait actually solved the problem entirely, and it saves a lot of duplicate work that would have had to happen in rustc_transmute.

This patch adds the `#[rustc_coinductive]` annotation to
`BikeshedIntrinsicFrom`, so that it's possible to compute transmutability for
recursive types.
@rustbot
Copy link
Collaborator

rustbot commented Jun 29, 2023

r? @b-naber

(rustbot has picked a reviewer for you, use r? to override)

@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. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jun 29, 2023
@bryangarza
Copy link
Contributor Author

r? @compiler-errors

@rustbot rustbot assigned compiler-errors and unassigned b-naber Jun 29, 2023
@compiler-errors compiler-errors added T-types Relevant to the types team, which will review and decide on the PR/issue. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jun 29, 2023
@compiler-errors
Copy link
Member

This PR marks the BikeshedIntrinsicFrom ("the safe transmute") trait as coinductive.

We shouldn't be committing to too much by making this trait coinductive, given that 1. it's not intended to be user implementable and has no user-written implementations, 2. it has no supertraits, and 3. is unstable.

@rfcbot fcp merge

@rfcbot
Copy link

rfcbot commented Jun 29, 2023

Team member @compiler-errors has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Jun 29, 2023
@compiler-errors compiler-errors changed the title Enable co-induction support for Safe Transmute Enable coinduction support for Safe Transmute Jun 29, 2023
@BoxyUwU
Copy link
Member

BoxyUwU commented Jun 30, 2023

I think it would be good for lcnr to have a look at this since afaik they have a good understanding of coinduction.

@lcnr
Copy link
Contributor

lcnr commented Jun 30, 2023

@rfcbot reviewed

@rfcbot rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Jun 30, 2023
@rfcbot
Copy link

rfcbot commented Jun 30, 2023

🔔 This is now entering its final comment period, as per the review above. 🔔

@compiler-errors compiler-errors added S-waiting-on-fcp Status: PR is in FCP and is awaiting for FCP to complete. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 3, 2023
@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Jul 10, 2023
@rfcbot
Copy link

rfcbot commented Jul 10, 2023

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jul 10, 2023

📌 Commit 6b214bb has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jul 10, 2023
@bors
Copy link
Contributor

bors commented Jul 11, 2023

⌛ Testing commit 6b214bb with merge b3ab80c...

@bors
Copy link
Contributor

bors commented Jul 11, 2023

☀️ Test successful - checks-actions
Approved by: compiler-errors
Pushing b3ab80c to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 11, 2023
@bors bors merged commit b3ab80c into rust-lang:master Jul 11, 2023
@rustbot rustbot added this to the 1.73.0 milestone Jul 11, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (b3ab80c): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

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

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

Cycles

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

Binary size

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

Bootstrap: 655.7s -> 656.645s (0.14%)

@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Jul 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. 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. S-waiting-on-fcp Status: PR is in FCP and is awaiting for FCP to complete. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants