Implement MIR lowering for unsafe binders by compiler-errors · Pull Request #130514 · rust-lang/rust (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation29 Commits3 Checks6 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

compiler-errors

This is the final bit of the unsafe binders puzzle. It implements MIR, CTFE, and codegen for unsafe binders, and enforces that (for now) they are Copy. Later on, I'll introduce a new trait that relaxes this requirement to being "is Copy or ManuallyDrop<T>" which more closely models how we treat union fields.

Namely, wrapping unsafe binders is now Rvalue::WrapUnsafeBinder, which acts much like an Rvalue::Aggregate. Unwrapping unsafe binders are implemented as a MIR projection ProjectionElem::UnwrapUnsafeBinder, which acts much like ProjectionElem::Field.

Tracking:

@compiler-errors compiler-errors changed the titleInitial implementation of unsafe binders Initial implementation of unsafe binder types

Sep 18, 2024

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors

@rust-log-analyzer

This comment has been minimized.

@bors

@Dylan-DPC Dylan-DPC added S-experimental

Status: Ongoing experiment that does not require reviewing and won't be merged in its current state.

and removed S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

labels

Nov 20, 2024

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request

Dec 13, 2024

@matthiaskrgr

…, r=oli-obk

Add AST support for unsafe binders

I'm splitting up rust-lang#130514 into pieces. It's impossible for me to keep up with a huge PR like that. I'll land type system support for this next, probably w/o MIR lowering, which will come later.

r? @oli-obk cc @BoxyUwU and @lcnr who also may want to look at this, though this PR doesn't do too much yet

rust-timer added a commit to rust-lang-ci/rust that referenced this pull request

Dec 14, 2024

@rust-timer

Rollup merge of rust-lang#134140 - compiler-errors:unsafe-binders-ast, r=oli-obk

Add AST support for unsafe binders

I'm splitting up rust-lang#130514 into pieces. It's impossible for me to keep up with a huge PR like that. I'll land type system support for this next, probably w/o MIR lowering, which will come later.

r? @oli-obk cc @BoxyUwU and @lcnr who also may want to look at this, though this PR doesn't do too much yet

@rust-log-analyzer

This comment has been minimized.

flip1995 pushed a commit to flip1995/rust that referenced this pull request

Dec 15, 2024

@matthiaskrgr

…, r=oli-obk

Add AST support for unsafe binders

I'm splitting up rust-lang#130514 into pieces. It's impossible for me to keep up with a huge PR like that. I'll land type system support for this next, probably w/o MIR lowering, which will come later.

r? @oli-obk cc @BoxyUwU and @lcnr who also may want to look at this, though this PR doesn't do too much yet

@bors

@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 17, 2024

@rust-log-analyzer

This comment has been minimized.

@bors

compiler-errors

compiler-errors

@@ -0,0 +1,41 @@
//@ known-bug: unknown

Choose a reason for hiding this comment

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

This test will (after I add a new trait instead of using Copy) demonstrate that we reason about moves correctly with unsafe binders.

oli-obk

oli-obk

oli-obk

@@ -66,6 +66,10 @@ impl<'tcx> Iterator for Prefixes<'tcx> {
self.next = Some(cursor_base);
return Some(cursor);
}
ProjectionElem::UnwrapUnsafeBinder(_) => {
self.next = Some(cursor_base);
return Some(cursor);

Choose a reason for hiding this comment

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

Why not just roll over unwrapunsafebinder just like with opaquecast?

Choose a reason for hiding this comment

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

On the contrary, why is it valid to ignore this projection elem? I want to make sure I'm visiting it when tracking moves, right? Or am I misunderstanding how these prefixes are used?

In my brain, unsafe binders are equivalent to structs with a single field, so we should be treating this much like a field elem.

Choose a reason for hiding this comment

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

These are just used for improving diagnostics, to be able to inform ppl when to split their borrows. It is useful to handle field accesses here, because borrowck can understand that any projection that goes through a field does not conflict with a projection that goes through another field. I unfortunately can't figure out how to make it care about the unsafe wrapper at all, so... 🤷 let's go with this and figure things out when we actually are using unsafe binders a lot and see some real world examples and conflicts.

@oli-obk

@bors

📌 Commit 442b9a9 has been approved by oli-obk

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

Feb 1, 2025

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request

Feb 1, 2025

@matthiaskrgr

…oli-obk

Implement MIR lowering for unsafe binders

This is the final bit of the unsafe binders puzzle. It implements MIR, CTFE, and codegen for unsafe binders, and enforces that (for now) they are Copy. Later on, I'll introduce a new trait that relaxes this requirement to being "is Copy or ManuallyDrop<T>" which more closely models how we treat union fields.

Namely, wrapping unsafe binders is now Rvalue::WrapUnsafeBinder, which acts much like an Rvalue::Aggregate. Unwrapping unsafe binders are implemented as a MIR projection ProjectionElem::UnwrapUnsafeBinder, which acts much like ProjectionElem::Field.

Tracking:

bors added a commit to rust-lang-ci/rust that referenced this pull request

Feb 1, 2025

@bors

…iaskrgr

Rollup of 7 pull requests

Successful merges:

r? @ghost @rustbot modify labels: rollup

bors added a commit to rust-lang-ci/rust that referenced this pull request

Feb 1, 2025

@bors

…iaskrgr

Rollup of 6 pull requests

Successful merges:

r? @ghost @rustbot modify labels: rollup

bors added a commit to rust-lang-ci/rust that referenced this pull request

Feb 1, 2025

@bors

…iaskrgr

Rollup of 6 pull requests

Successful merges:

r? @ghost @rustbot modify labels: rollup

rust-timer added a commit to rust-lang-ci/rust that referenced this pull request

Feb 1, 2025

@rust-timer

Rollup merge of rust-lang#130514 - compiler-errors:unsafe-binders, r=oli-obk

Implement MIR lowering for unsafe binders

This is the final bit of the unsafe binders puzzle. It implements MIR, CTFE, and codegen for unsafe binders, and enforces that (for now) they are Copy. Later on, I'll introduce a new trait that relaxes this requirement to being "is Copy or ManuallyDrop<T>" which more closely models how we treat union fields.

Namely, wrapping unsafe binders is now Rvalue::WrapUnsafeBinder, which acts much like an Rvalue::Aggregate. Unwrapping unsafe binders are implemented as a MIR projection ProjectionElem::UnwrapUnsafeBinder, which acts much like ProjectionElem::Field.

Tracking:

flip1995 pushed a commit to flip1995/rust that referenced this pull request

Feb 6, 2025

@matthiaskrgr

…oli-obk

Implement MIR lowering for unsafe binders

This is the final bit of the unsafe binders puzzle. It implements MIR, CTFE, and codegen for unsafe binders, and enforces that (for now) they are Copy. Later on, I'll introduce a new trait that relaxes this requirement to being "is Copy or ManuallyDrop<T>" which more closely models how we treat union fields.

Namely, wrapping unsafe binders is now Rvalue::WrapUnsafeBinder, which acts much like an Rvalue::Aggregate. Unwrapping unsafe binders are implemented as a MIR projection ProjectionElem::UnwrapUnsafeBinder, which acts much like ProjectionElem::Field.

Tracking:

bjorn3 pushed a commit to bjorn3/rust that referenced this pull request

Feb 7, 2025

@matthiaskrgr

…oli-obk

Implement MIR lowering for unsafe binders

This is the final bit of the unsafe binders puzzle. It implements MIR, CTFE, and codegen for unsafe binders, and enforces that (for now) they are Copy. Later on, I'll introduce a new trait that relaxes this requirement to being "is Copy or ManuallyDrop<T>" which more closely models how we treat union fields.

Namely, wrapping unsafe binders is now Rvalue::WrapUnsafeBinder, which acts much like an Rvalue::Aggregate. Unwrapping unsafe binders are implemented as a MIR projection ProjectionElem::UnwrapUnsafeBinder, which acts much like ProjectionElem::Field.

Tracking:

carolynzech added a commit to carolynzech/kani that referenced this pull request

Feb 10, 2025

@carolynzech

carolynzech added a commit to carolynzech/kani that referenced this pull request

Feb 10, 2025

@carolynzech

github-merge-queue bot pushed a commit to model-checking/kani that referenced this pull request

Feb 11, 2025

@carolynzech

github-actions bot pushed a commit to tautschnig/verify-rust-std that referenced this pull request

Mar 11, 2025

@matthiaskrgr

…, r=oli-obk

Add AST support for unsafe binders

I'm splitting up rust-lang#130514 into pieces. It's impossible for me to keep up with a huge PR like that. I'll land type system support for this next, probably w/o MIR lowering, which will come later.

r? @oli-obk cc @BoxyUwU and @lcnr who also may want to look at this, though this PR doesn't do too much yet

Labels

A-rustdoc-json

Area: Rustdoc JSON backend

PG-exploit-mitigations

Project group: Exploit mitigations

S-experimental

Status: Ongoing experiment that does not require reviewing and won't be merged in its current state.

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.

T-libs

Relevant to the library team, which will review and decide on the PR/issue.

WG-trait-system-refactor

The Rustc Trait System Refactor Initiative (-Znext-solver)