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 Vec visualization to understand capacity #79655

Merged
merged 3 commits into from
Jan 21, 2021
Merged

Conversation

pickfire
Copy link
Contributor

@pickfire pickfire commented Dec 3, 2020

Visualize vector while differentiating between stack and heap.

Inspired by cheats.rs, as this is probably the first place beginner go,
they could understand stack and heap, length and capacity with this. Not
sure if adding this means we should add to other places too.

Superseeds #76066

r? @m-ou-se

cc @the8472 I put back the order of the fields as it feels weird, the note already explains that the order of fields is not guaranteed

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 3, 2020
@the8472
Copy link
Member

the8472 commented Dec 3, 2020

The shown field order is does not match the implementation, which is exactly what I was asking for. So all is good.

library/alloc/src/vec.rs Outdated Show resolved Hide resolved
library/alloc/src/vec.rs Outdated Show resolved Hide resolved
@pickfire
Copy link
Contributor Author

pickfire commented Dec 3, 2020

The shown field order is does not match the implementation, which is exactly what I was asking for. So all is good.

Yes but it may be confusing to read when most of the other parts have the same order. What is good is that we can explain that the order is not fixed which we did.

@m-ou-se
Copy link
Member

m-ou-se commented Dec 8, 2020

I'm not sure the label stack* with the additional note makes things clearer. The Vec might also exist as a static, which is neither the heap nor the stack. Maybe just removing it, or using something like "the Vec object" without specifying its location, would be better.

Can you also address any questions/comments left on #76066?

Specifically:

A bit later in the text, in the "Guarantees" section, this layout is explained in words. Maybe this visualisation should be put there instead? (Right after the sentence ending in logically uninitialized, contiguous elements.)

@pickfire
Copy link
Contributor Author

pickfire commented Dec 9, 2020

I'm not sure the label stack* with the additional note makes things clearer. The Vec might also exist as a static, which is neither the heap nor the stack. Maybe just removing it, or using something like "the Vec object" without specifying its location, would be better.

Oh, I didn't know about static.

Can you also address any questions/comments left on #76066?

Added.

@bors
Copy link
Contributor

bors commented Dec 31, 2020

☔ The latest upstream changes (presumably #80530) made this pull request unmergeable. Please resolve the merge conflicts.

@pickfire
Copy link
Contributor Author

Is there any other comments or maybe I should resolve it?

Visualize vector while differentiating between stack and heap.

Inspired by cheats.rs, as this is probably the first place beginner go,
they could understand stack and heap, length and capacity with this. Not
sure if adding this means we should add to other places too.

Superseeds rust-lang#76066
@pickfire
Copy link
Contributor Author

Ping, I fixed the conflicts.

Copy link
Member

@m-ou-se m-ou-se left a comment

Choose a reason for hiding this comment

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

Sorry for the delay.

Looks good to me. One small comment:

library/alloc/src/vec/mod.rs Outdated Show resolved Hide resolved
@m-ou-se
Copy link
Member

m-ou-se commented Jan 21, 2021

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Jan 21, 2021

📌 Commit 9844d9e has been approved by m-ou-se

@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 Jan 21, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 21, 2021
Rollup of 11 pull requests

Successful merges:

 - rust-lang#79655 (Add Vec visualization to understand capacity)
 - rust-lang#80172 (Use consistent punctuation for 'Prelude contents' docs)
 - rust-lang#80429 (Add regression test for mutual recursion in obligation forest)
 - rust-lang#80601 (Improve grammar in documentation of format strings)
 - rust-lang#81046 (Improve unknown external crate error)
 - rust-lang#81178 (Visit only terminators when removing landing pads)
 - rust-lang#81179 (Fix broken links with `--document-private-items` in the standard library)
 - rust-lang#81184 (Remove unnecessary `after_run` function)
 - rust-lang#81185 (Fix ICE in mir when evaluating SizeOf on unsized type)
 - rust-lang#81187 (Fix typo in counters.rs)
 - rust-lang#81219 (Document security implications of std::env::temp_dir)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit a18813f into rust-lang:master Jan 21, 2021
@rustbot rustbot added this to the 1.51.0 milestone Jan 21, 2021
@pickfire pickfire deleted the visual-vec branch January 21, 2021 18:09
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