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

add #[rustc_layout(debug)] #69901

Merged
merged 6 commits into from
Mar 21, 2020
Merged

add #[rustc_layout(debug)] #69901

merged 6 commits into from
Mar 21, 2020

Conversation

RalfJung
Copy link
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
Collaborator

r? @cramertj

(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 Mar 10, 2020
@jonas-schievink
Copy link
Contributor

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

@RalfJung
Copy link
Member Author

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.

src/test/ui/layout/debug.rs Outdated Show resolved Hide resolved
@eddyb
Copy link
Member

eddyb commented Mar 10, 2020

cc @rust-lang/compiler

@cramertj
Copy link
Member

r? @eddyb

@rust-highfive rust-highfive assigned eddyb and unassigned cramertj Mar 10, 2020
@RalfJung
Copy link
Member Author

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

@eddyb
Copy link
Member

eddyb commented Mar 20, 2020

@bors r+ Thanks!

@bors
Copy link
Contributor

bors commented Mar 20, 2020

📌 Commit c62e36b 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 Mar 20, 2020
@rust-highfive

This comment has been minimized.

@eddyb
Copy link
Member

eddyb commented Mar 20, 2020

@bors r- (failed because formatting)

@bors bors 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
Member Author

Fixed that.

@bors r=eddyb

@bors
Copy link
Contributor

bors commented Mar 20, 2020

📌 Commit 7b49678 has been approved by eddyb

@bors bors 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
@bors bors 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. :)
@Centril
Copy link
Contributor

Centril commented Mar 21, 2020

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

@bors bors 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
Member Author

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
Member

eddyb commented Mar 21, 2020

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

@RalfJung
Copy link
Member Author

Yes that works, nice.

@bors r=eddyb

@bors
Copy link
Contributor

bors commented Mar 21, 2020

📌 Commit e548df7 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-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:master Mar 21, 2020
@RalfJung RalfJung deleted the rustc_layout branch March 21, 2020 16:57
@elichai
Copy link
Contributor

elichai commented Apr 6, 2020

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

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.

8 participants