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

drop glue takes in mutable references, it should reflect that in its type #56165

Merged
merged 3 commits into from
Dec 1, 2018

Conversation

RalfJung
Copy link
Member

When drop glue begins, it should retag, like all functions taking references do. But to do that, it needs to take the reference at a proper type: &mut T, not *mut T.

Failing to retag can mean that the memory the reference points to remains frozen, and EscapeToRaw on a frozen location is a NOP, meaning later mutations cause a Stacked Borrows violation.

Cc @nikomatsakis @gankro because Stacked Borrows
Cc @eddyb for the changes to miri argument passing (the intention is to allow passing *mut [u8] when &mut [u8] is expected and vice versa)

@rust-highfive
Copy link
Collaborator

r? @dtolnay

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 22, 2018
@@ -196,6 +196,9 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
// that will take care to make it UB to leave the range, just
// like for transmute).
caller.value == callee.value,
(layout::Abi::ScalarPair(ref caller1, ref caller2),
layout::Abi::ScalarPair(ref callee1, ref callee2)) =>
caller1.value == callee1.value && caller2.value == callee2.value,
Copy link
Member

Choose a reason for hiding this comment

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

Are you not using FnType yet :P? Anyway this seems... fine.
But only for the Rust ABI so you might want to add that as a condition, if it's not already.
(ScalarPair is considered an aggregate and follows more complex rules, in non-Rust ABIs)

Copy link
Member Author

Choose a reason for hiding this comment

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

Which rules for aggregates can there be when the ABIs are the same except for the ranges...? I thought these ABIs encode everything.^^

Are you not using FnType yet :P?

Nope, you didn't yet convince me that it would make anything simpler.^^

Copy link
Member

Choose a reason for hiding this comment

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

Abi does not encode everything, no. C ABIs can depend on details of the C type definition, which is annoying but FnType contains all of that information.

Nope, you didn't yet convince me that it would make anything simpler.^^

It would make things correct, which seems more important than simplicity. It's not like that hard to use, just have to move some code from rustc_codegen_ssa and then compare ArgType pairwise.

(assuming you don't want to emulate the runtime behavior of mismatched ABIs :P)

Copy link
Member Author

Choose a reason for hiding this comment

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

C ABIs can depend on details of the C type definition, which is annoying but FnType contains all of that information.

Ouch. Okay, I will restrict type mismatches to Rust Abi functions.

assuming you don't want to emulate the runtime behavior of mismatched ABIs :P

You assume correctly. :P

It's not like that hard to use, just have to move some code from rustc_codegen_ssa and then compare ArgType pairwise.

Would you mentor someone? I could open an E-mentor issue.

Copy link
Member

Choose a reason for hiding this comment

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

Would you mentor someone? I could open an E-mentor issue.

Sure, always happy to mentor compiler cleanups!

The main issue to moving that stuff around is pointee_info_at (it would have to be moved to rustc::ty::layout, as an additional method in TyLayoutMethods):

if let Some(pointee) = layout.pointee_info_at(cx, offset) {

Everything else is mostly relying on rustc_target doing the heavy lifting, already.

Copy link
Member Author

Choose a reason for hiding this comment

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

But only for the Rust ABI so you might want to add that as a condition

Done.

@eddyb
Copy link
Member

eddyb commented Nov 22, 2018

r? @nikomatsakis

@rust-highfive

This comment has been minimized.

@Centril Centril added T-lang Relevant to the language team, which will review and decide on the PR/issue. and removed T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Nov 23, 2018
Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

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

r=me modulo what @eddyb says about the rust_abi check

if !rust_abi {
// Don't risk anything
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This changes the behavior in the case of (Scalar, Scalar) pairs, right? (They didn't use to be dependent on the rust_abi) -- @eddyb is that what you intended?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, scalar pairs are only used in the Rust ABI, two types with the same scalar pair optimization can have incompatible by-value ABI with extern "C".

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. It also changes behavior on non-Rust ABIs for Scalar, where we no longer allow any kind of mismatch -- mostly for consistency.

@RalfJung
Copy link
Member Author

r=me modulo what @eddyb says about the rust_abi check

@eddyb are there any concerns left?

@eddyb
Copy link
Member

eddyb commented Nov 26, 2018

@bors r=eddyb,nikomatsakis

@bors
Copy link
Contributor

bors commented Nov 26, 2018

📌 Commit d9de72f has been approved by eddyb,nikomatsakis

@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 26, 2018
pietroalbini added a commit to pietroalbini/rust that referenced this pull request Nov 28, 2018
…komatsakis

drop glue takes in mutable references, it should reflect that in its type

When drop glue begins, it should retag, like all functions taking references do. But to do that, it needs to take the reference at a proper type: `&mut T`, not `*mut T`.

Failing to retag can mean that the memory the reference points to remains frozen, and `EscapeToRaw` on a frozen location is a NOP, meaning later mutations cause a Stacked Borrows violation.

Cc @nikomatsakis @gankro because Stacked Borrows
Cc @eddyb for the changes to miri argument passing (the intention is to allow passing `*mut [u8]` when `&mut [u8]` is expected and vice versa)
pietroalbini added a commit to pietroalbini/rust that referenced this pull request Nov 29, 2018
…komatsakis

drop glue takes in mutable references, it should reflect that in its type

When drop glue begins, it should retag, like all functions taking references do. But to do that, it needs to take the reference at a proper type: `&mut T`, not `*mut T`.

Failing to retag can mean that the memory the reference points to remains frozen, and `EscapeToRaw` on a frozen location is a NOP, meaning later mutations cause a Stacked Borrows violation.

Cc @nikomatsakis @gankro because Stacked Borrows
Cc @eddyb for the changes to miri argument passing (the intention is to allow passing `*mut [u8]` when `&mut [u8]` is expected and vice versa)
@bors
Copy link
Contributor

bors commented Dec 1, 2018

⌛ Testing commit d9de72f with merge d3ed348...

bors added a commit that referenced this pull request Dec 1, 2018
drop glue takes in mutable references, it should reflect that in its type

When drop glue begins, it should retag, like all functions taking references do. But to do that, it needs to take the reference at a proper type: `&mut T`, not `*mut T`.

Failing to retag can mean that the memory the reference points to remains frozen, and `EscapeToRaw` on a frozen location is a NOP, meaning later mutations cause a Stacked Borrows violation.

Cc @nikomatsakis @gankro because Stacked Borrows
Cc @eddyb for the changes to miri argument passing (the intention is to allow passing `*mut [u8]` when `&mut [u8]` is expected and vice versa)
@bors
Copy link
Contributor

bors commented Dec 1, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: eddyb,nikomatsakis
Pushing d3ed348 to master...

@bors bors merged commit d9de72f into rust-lang:master Dec 1, 2018
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants