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

miri: accept extern types in structs if they are the only field #55672

Merged
merged 6 commits into from
Nov 19, 2018

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Nov 4, 2018

@rust-highfive
Copy link
Collaborator

r? @varkor

(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 4, 2018
@eddyb
Copy link
Member

eddyb commented Nov 4, 2018

I would prefer it if this was based on offset being 0, not field count.

@RalfJung
Copy link
Member Author

RalfJung commented Nov 4, 2018

Like this?

@eddyb
Copy link
Member

eddyb commented Nov 4, 2018

I'm not sure the alignment condition is needed, since 0 is aligned to infinity, but I don't think it hurts.

@@ -354,7 +354,8 @@ where
let (meta, offset) = if field_layout.is_unsized() {
// re-use parent metadata to determine dynamic field layout
let (_, align) = self.size_and_align_of(base.meta, field_layout)?
.expect("Fields cannot be extern types");
// If this is an extern type, we fall back to its static size and alignment.
.unwrap_or_else(|| base.layout.size_and_align());
Copy link
Member

Choose a reason for hiding this comment

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

Interestingly, we can make size_and_align_of error, but have a separate align_of that works even for extern type. Only the alignment is used here, anyway!

Copy link
Member

Choose a reason for hiding this comment

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

Oh, you can also just move the Option to be around the size, but not the alignment.

Copy link
Member Author

Choose a reason for hiding this comment

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

I could, but I'd rather wait for the decision to treat the size_of_val and align_of_val intrinsics asymmetrically before doing that.

extern type will likely get alignment 1 currently, which is likely not actually correct for the type they are opaquely representing, so I am a bit worried about unilaterally implementing such behavior.

Copy link
Member

Choose a reason for hiding this comment

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

You can't access that alignment without first having a reference, so having it too high would be a problem (the assumption might not be guaranteed by what you're FFI-ing to), but having it too low wouldn't break anything (other than field offsets).

So the way I see it, the alignment is only a lower bound, and 1 is fine, unless you want to use it as an aligned field in a struct.

Anyway, my concern is also kind of a confusing code thing.
You could also add a .map(|(_, align)| align) before unwrap_or_else, which would mean the code and the comment wouldn't mention the "size" of the extern type.

Copy link
Member Author

Choose a reason for hiding this comment

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

You can't access that alignment without first having a reference, so having it too high would be a problem (the assumption might not be guaranteed by what you're FFI-ing to), but having it too low wouldn't break anything (other than field offsets).

Oh that's a good point. We cannot create such references ourselves anyway as we cannot have data of that type.

Still I think miri shouldn't move ahead of the rest of the decision process here.

I will implement your map suggestion.

Copy link
Member Author

Choose a reason for hiding this comment

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

I implemented what you suggested.

@eddyb
Copy link
Member

eddyb commented Nov 5, 2018

@bors r+

@bors
Copy link
Contributor

bors commented Nov 5, 2018

📌 Commit a6622c2 has been approved by eddyb

@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 5, 2018
// FIXME: Once we have made decisions for how to handle size and alignment
// of `extern type`, this should be adapted. It is just a temporary hack
// to get some code to work that probably ought to work.
.unwrap_or_else(|| base.layout.align);
Copy link
Member Author

Choose a reason for hiding this comment

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

Should this really be base.layout, not field_layout?

@RalfJung
Copy link
Member Author

RalfJung commented Nov 5, 2018

Hm actually I am not entirely sure I got this right, will this error out appropriately when there are other fields? It will error out in size_and_align_of, but what about mplace_field? It does not do any such check.

@eddyb
Copy link
Member

eddyb commented Nov 5, 2018

@RalfJung Ah, yeah, you probably want it in both. This is why decoupling alignment from size should help - size and offset computation are similar/equivalent, whereas alignment is simpler.

@RalfJung
Copy link
Member Author

RalfJung commented Nov 6, 2018

Offset computation of a field only uses the field's alignment, though (and the offsets data in the layout).

@RalfJung
Copy link
Member Author

RalfJung commented Nov 6, 2018

I fixed that, I think.

@RalfJung RalfJung added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 6, 2018
@eddyb
Copy link
Member

eddyb commented Nov 6, 2018

@bors r+

@bors
Copy link
Contributor

bors commented Nov 6, 2018

📌 Commit ba0bab3 has been approved by eddyb

@bors
Copy link
Contributor

bors commented Nov 16, 2018

⌛ Testing commit ba0bab3 with merge b2282c6f23a0d1c0e850f6cf871e5cbe8b1985f9...

@bors
Copy link
Contributor

bors commented Nov 16, 2018

💔 Test failed - status-appveyor

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 16, 2018
@RalfJung
Copy link
Member Author

It's that timing test again:

failures:
    time::tests::instant_math

@bors retry

@rust-lang/infra maybe the permitted time difference should be increased to 500ms or so?

@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 16, 2018
kennytm added a commit to kennytm/rust that referenced this pull request Nov 17, 2018
miri: accept extern types in structs if they are the only field

Fixes rust-lang#55541

Cc @oli-obk @eddyb rust-lang#43467
@bors
Copy link
Contributor

bors commented Nov 17, 2018

⌛ Testing commit ba0bab3 with merge 54966b13b4f4b6d5d168c952194b6f9e2e73551b...

@bors
Copy link
Contributor

bors commented Nov 17, 2018

💔 Test failed - status-appveyor

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 17, 2018
@kennytm
Copy link
Member

kennytm commented Nov 18, 2018

@bors retry

error: failed to remove file `C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\cit\t989\foo\target\release\libfoo.rmeta`
Caused by:
  Access is denied. (os error 5)

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

bors commented Nov 18, 2018

⌛ Testing commit ba0bab3 with merge a9b791b...

bors added a commit that referenced this pull request Nov 18, 2018
miri: accept extern types in structs if they are the only field

Fixes #55541

Cc @oli-obk @eddyb #43467
@bors
Copy link
Contributor

bors commented Nov 19, 2018

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

@bors bors merged commit ba0bab3 into rust-lang:master Nov 19, 2018
@RalfJung RalfJung deleted the miri-extern-types branch November 30, 2018 08:28
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.

7 participants