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

Implement more extra_traits #1271

Merged
merged 10 commits into from
Feb 24, 2019
Merged

Implement more extra_traits #1271

merged 10 commits into from
Feb 24, 2019

Conversation

Susurrus
Copy link
Contributor

Finishing the implementation of rust-lang/rust#57715 now that all platforms are tested in CI. I plan to expand this CI to all platforms that need this treatment (solarish, empscripten, freebsd, and netbsd), but thought I'd get the part I've already started running in CI since I can't test this changes locally.

@rust-highfive
Copy link

r? @gnzlbg

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

@gnzlbg
Copy link
Contributor

gnzlbg commented Feb 22, 2019

Cool! Thanks! Ping me when CI is green!

@Susurrus
Copy link
Contributor Author

So 1.24 is the cutoff for using unsafe around packed struct instances, but older versions are tested in CI. I think we need to do the same macro trick that you used elsewhere to get this code compiling on all CI targets.

@gnzlbg
Copy link
Contributor

gnzlbg commented Feb 23, 2019

The problem is that, if creating a reference to a packed struct field creates an unaligned reference, then the behavior is undefined.

That's the case irrespectively of whether one uses an unsafe block post Rust 1.24, or no unsafe block in older Rust versions.

@gnzlbg
Copy link
Contributor

gnzlbg commented Feb 23, 2019

You could just add an attribute to those methods to silence the unused unsafe warning (e.g. "#[allow(unused_unsafe)]"), but that does not make the behavior of these operations defined.

EDIT: you also cannot create an unaligned reference, and then cast it to a pointer, and then check whether it is aligned or not, because the UB happens before the check .

@gnzlbg
Copy link
Contributor

gnzlbg commented Feb 23, 2019

Instead of using references, you are probably better off copying the struct fields out of the struct into the stack frame, and then passing those (or references to those) to the formatter.

cc @Centril @RalfJung

@gnzlbg
Copy link
Contributor

gnzlbg commented Feb 23, 2019

Alternatively, one can take a reference to the struct, cast it to a pointer, and use pointer offsets to read from the struct fields. One'd need to compute the offsets manually, but the structs are repr(C), so this is possible (the rules are in the C standard). If these structs change, then all offset would need to be manually updated though.

@RalfJung
Copy link
Member

you are probably better off copying the struct fields out of the struct into the stack frame, and then passing those (or references to those) to the formatter.

Yes, that is the best approach IMO. You need a reference to call .field, so it needs to be aligned, so you need to make a copy.

src/unix/bsd/apple/mod.rs Outdated Show resolved Hide resolved
@Susurrus Susurrus force-pushed the more_debug_impls branch 4 times, most recently from 0d84124 to d5035cd Compare February 23, 2019 22:16
@Susurrus Susurrus force-pushed the more_debug_impls branch 2 times, most recently from f13fe7d to d795b07 Compare February 24, 2019 00:22
@Susurrus Susurrus changed the title [WIP] Implement more extra_traits Implement more extra_traits Feb 24, 2019
@Susurrus
Copy link
Contributor Author

Remaining failures are not due to this code change and for targets that are allowed to fail. I think this is all good now.

@gnzlbg
Copy link
Contributor

gnzlbg commented Feb 24, 2019

@bors: r+

@bors
Copy link
Contributor

bors commented Feb 24, 2019

📌 Commit d795b07 has been approved by gnzlbg

Copy link
Contributor

@gnzlbg gnzlbg left a comment

Choose a reason for hiding this comment

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

LGTM!

@bors
Copy link
Contributor

bors commented Feb 24, 2019

⌛ Testing commit d795b07 with merge 66f00d2...

bors added a commit that referenced this pull request Feb 24, 2019
Implement more extra_traits

Finishing the implementation of rust-lang/rust#57715 now that all platforms are tested in CI. I plan to expand this CI to all platforms that need this treatment (solarish, empscripten, freebsd, and netbsd), but thought I'd get the part I've already started running in CI since I can't test this changes locally.
@bors
Copy link
Contributor

bors commented Feb 24, 2019

☀️ Test successful - checks-cirrus, checks-travis, status-appveyor
Approved by: gnzlbg
Pushing 66f00d2 to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants