Skip to content

add #[rustc_layout(debug)] - #69901

Merged
bors merged 6 commits into
rust-lang:masterfrom
RalfJung:rustc_layout
Mar 21, 2020
Merged

add #[rustc_layout(debug)]#69901
bors merged 6 commits into
rust-lang:masterfrom
RalfJung:rustc_layout

Conversation

@RalfJung

Copy link
Copy Markdown
Member

@eddyb recently told me about the #[rustc_layout] attribute, and I think it would be very useful if it could be used to print all the layout information Rust has about a type. When working with layouts (e.g. in Miri), it is often not clear how certain surface language features get represented internally. I have some awful hacks locally to be able to dump this debug information; with this attribute I could get it on the playground which is so much better. :)

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @cramertj

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

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 10, 2020
@jonas-schievink

Copy link
Copy Markdown
Contributor

Cool! This will be helpful for testing generator layout optimizations in the future.

@RalfJung

Copy link
Copy Markdown
MemberAuthor

I figured it would be useful for tons of stuff. :) We have to think of some ways to make sure that the right people even know about it... like finding a good place in the rustc dev guide to mention it. I also plan to write a blog post.

Comment threadsrc/test/ui/layout/debug.rs Outdated
@eddyb

Copy link
Copy Markdown
Contributor

cc @rust-lang/compiler

@cramertj

Copy link
Copy Markdown
Member

r? @eddyb

@rust-highfiverust-highfive assigned eddyb and unassigned cramertjMar 10, 2020
@RalfJung

Copy link
Copy Markdown
MemberAuthor

@eddyb I made this work on type definitions, not just type aliases.

@eddyb

Copy link
Copy Markdown
Contributor

@bors r+ Thanks!

@bors

bors commented Mar 20, 2020

Copy link
Copy Markdown
Collaborator

📌 Commit c62e36b has been approved by eddyb

@borsbors 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 Mar 20, 2020
@rust-highfive

This comment has been minimized.

@eddyb

Copy link
Copy Markdown
Contributor

@bors r- (failed because formatting)

@borsbors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 20, 2020
@RalfJung

Copy link
Copy Markdown
MemberAuthor

Fixed that.

@bors r=eddyb

@bors

bors commented Mar 20, 2020

Copy link
Copy Markdown
Collaborator

📌 Commit 7b49678 has been approved by eddyb

@borsbors removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Mar 20, 2020
@borsbors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Mar 20, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Mar 21, 2020
add #[rustc_layout(debug)]
@eddyb recently told me about the `#[rustc_layout]` attribute, and I think it would be very useful if it could be used to print all the layout information Rust has about a type. When working with layouts (e.g. in Miri), it is often not clear how certain surface language features get represented internally. I have some awful hacks locally to be able to dump this debug information; with this attribute I could get it on the playground which is so much better. :)
Centril added a commit to Centril/rust that referenced this pull request Mar 21, 2020
add #[rustc_layout(debug)]
@eddyb recently told me about the `#[rustc_layout]` attribute, and I think it would be very useful if it could be used to print all the layout information Rust has about a type. When working with layouts (e.g. in Miri), it is often not clear how certain surface language features get represented internally. I have some awful hacks locally to be able to dump this debug information; with this attribute I could get it on the playground which is so much better. :)
@CentrilCentril mentioned this pull request Mar 21, 2020
@Centril

Copy link
Copy Markdown
Contributor

Failed in #70203 (comment), @bors r-

@borsbors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 21, 2020
@RalfJung

Copy link
Copy Markdown
MemberAuthor

Looks like "preferred alignment" differs for some platforms:

---- [ui] ui/layout/debug.rs stdout ----
diff of stderr:
37 pow2: 0,
189 },
190 pref: Align {
- pow2: 3,
+ pow2: 2,
192 },
193 },
194 size: Size {
245 pow2: 2,
246 },
247 pref: Align {
- pow2: 3,
+ pow2: 2,
249 },
250 },
251 size: Size {
275 pow2: 2,
276 },
277 pref: Align {
- pow2: 3,
+ pow2: 2,
279 },
280 },
281 size: Size {
319 pow2: 2,
320 },
321 pref: Align {
- pow2: 3,
+ pow2: 2,
323 },
324 },
325 size: Size {

@eddyb should I just normalize all pow2: [0-9]+ to pow2: $ALIGN to skip this problems?

@eddyb

Copy link
Copy Markdown
Contributor

@RalfJung Does this work? pref: Align \{\n *pow2: [1-3],\n *\} to pref: $PREF_ALIGN.

@RalfJung

Copy link
Copy Markdown
MemberAuthor

Yes that works, nice.

@bors r=eddyb

@bors

bors commented Mar 21, 2020

Copy link
Copy Markdown
Collaborator

📌 Commit e548df7 has been approved by eddyb

@borsbors 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 21, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 21, 2020
Rollup of 6 pull requests
Successful merges:
- rust-lang#69497 (Don't unwind when hitting the macro expansion recursion limit)
- rust-lang#69901 (add #[rustc_layout(debug)])
- rust-lang#69910 (Avoid query type in generics)
- rust-lang#69955 (Fix abort-on-eprintln during process shutdown)
- rust-lang#70032 (put type params in front of const params in generics_of)
- rust-lang#70119 (rustc: use LocalDefId instead of DefId in TypeckTables.)
Failed merges:
r? @ghost
@bors
bors merged commit fd3f917 into rust-lang:masterMar 21, 2020
@RalfJung
RalfJung deleted the rustc_layout branch March 21, 2020 16:57
@elichai

Copy link
Copy Markdown
Contributor

That's awesome!
I was just looking for exactly that for C++ in the last few days :)

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: 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.

8 participants

@RalfJung@rust-highfive@jonas-schievink@eddyb@cramertj@bors@Centril@elichai