-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Improve the readability of List<T>
.
#91617
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I like very much the fact that it points out that interning is (expected) to be provided at an outer layer, even though this type expects such semantics 👌
data: [T; 0], | ||
|
||
opaque: OpaqueListContents, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To expand on what I mentioned on Zulip, note here that data
and opaque
are deeply intertwined; having them laid out in such a bare fashion is thus an itsy bit error-prone. That is, compare the current definition, even with your great comments added to it, to:
#[repr(C)]
pub struct List<T> {
len: usize,
/// `len` elements are expected to be present.
data: ThinDst<[T]>,
}
/// Const-assert that a pointer to a `List<T>` is thin.
const _: () = {
let _ = ::core::mem::transmute::<&List<u8>, usize>;
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you happy with this part of the code as is, or are you suggesting that I change it to what's in the Playground link?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't claim which one is better in a vacuum: I like my suggestion since it reads quite well at the level of the definition of List<T>
, but now it's the definition of ThinDst
which may seem a bit too "messy" for compiler code. So just let it be, unless other people were to chime in in defense of the ThinDst
helper
b7dbdb6
to
a1628a0
Compare
Thanks for the good comments, I have addressed them and updated the code. |
This comment has been minimized.
This comment has been minimized.
a1628a0
to
e73ce93
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some additional small nits, deal with them as you like.
after that r=me
This commit does the following. - Expands on some of the things already mentioned in comments. - Describes the uniqueness assumption, which is critical but wasn't mentioned at all. - Rewrites `empty()` into a clearer form, as provided by Daniel Henry-Mantilla on Zulip. - Reorders things slightly so that more important things are higher up, and incidental things are lower down, which makes reading the code easier.
e73ce93
to
769a707
Compare
New code is up. Gotta be close to an r+ by now 😀 |
@bors r+ |
📌 Commit 769a707 has been approved by |
…y, r=lcnr Improve the readability of `List<T>`. This commit does the following. - Expands on some of the things already mentioned in comments. - Describes the uniqueness assumption, which is critical but wasn't mentioned at all. - Rewrites `empty()` into a clearer form, as provided by Daniel Henry-Mantilla on Zulip. - Reorders things slightly so that more important things are higher up, and incidental things are lower down, which makes reading the code easier. r? `@lcnr`
…y, r=lcnr Improve the readability of `List<T>`. This commit does the following. - Expands on some of the things already mentioned in comments. - Describes the uniqueness assumption, which is critical but wasn't mentioned at all. - Rewrites `empty()` into a clearer form, as provided by Daniel Henry-Mantilla on Zulip. - Reorders things slightly so that more important things are higher up, and incidental things are lower down, which makes reading the code easier. r? ``@lcnr``
…y, r=lcnr Improve the readability of `List<T>`. This commit does the following. - Expands on some of the things already mentioned in comments. - Describes the uniqueness assumption, which is critical but wasn't mentioned at all. - Rewrites `empty()` into a clearer form, as provided by Daniel Henry-Mantilla on Zulip. - Reorders things slightly so that more important things are higher up, and incidental things are lower down, which makes reading the code easier. r? ```@lcnr```
…askrgr Rollup of 7 pull requests Successful merges: - rust-lang#91617 (Improve the readability of `List<T>`.) - rust-lang#91640 (Simplify collection of in-band lifetimes) - rust-lang#91682 (rustdoc: Show type layout for type aliases) - rust-lang#91711 (Improve `std::iter::zip` example) - rust-lang#91717 (Add deprecation warning for --passes) - rust-lang#91718 (give more help in the unaligned_references lint) - rust-lang#91782 (Correct since attribute for `is_symlink` feature) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This commit does the following.
mentioned at all.
empty()
into a clearer form, as provided by DanielHenry-Mantilla on Zulip.
are higher up, and incidental things are lower down, which makes
reading the code easier.
r? @lcnr