-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Make Allocation::bytes private #63561
Conversation
r? @cramertj (rust_highfive has picked a reviewer for you, use r? to override) |
r? @RalfJung |
e4b3045
to
0dcc038
Compare
Changed |
I edited your OP to say "Fixes: #issue"; that will make GitHub auto-close it when the PR gets merged. |
0dcc038
to
6e30b33
Compare
Removed |
The |
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.
This looks good overall, my notes are mostly editorial / ask for more comments.
Note that I'll be on conference next week and won't have time for reviews.
/// Note that the bytes of a pointer represent the offset of the pointer | ||
pub bytes: Vec<u8>, | ||
/// Note that the bytes of a pointer represent the offset of the pointer. | ||
bytes: Vec<u8>, | ||
/// Maps from byte addresses to extra data for each pointer. | ||
/// Only the first byte of a pointer is inserted into the map; i.e., | ||
/// every entry in this map applies to `pointer_size` consecutive bytes starting | ||
/// at the given offset. | ||
pub relocations: Relocations<Tag>, |
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.
Can you make this private and provide a read-only accessor, similar to what you did for undef_mask
?
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.
There already exists a method relocations
, which returns relocations within a range specified by ptr
and size
, so I'd name the corresponding accessor all_relocations
instead.
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.
Also, interpret/memory.rs
tries to access it directly. I'd move code in a similar manner as compressed undef mask.
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.
Sounds good
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'm not available until Wednesday next week but the rest should be ready.
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.
take all the time you need
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.
The name fn relocations
for the accessor is already taken:
rust/src/librustc/mir/interpret/allocation.rs
Lines 424 to 430 in 85ed538
/// Returns all relocations overlapping with the given ptr-offset pair. | |
pub fn relocations( | |
&self, | |
cx: &impl HasDataLayout, | |
ptr: Pointer<Tag>, | |
size: Size, | |
) -> &[(Size, (Tag, AllocId))] { |
I'd rename the existing method to get_relocations
which would be aligned with get_bytes
, check_bytes
, check_relocations
to be concerned with interpreter execution.
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.
Sounds good.
Makes me wonder who will even need the general read-only general accessor. Maybe that should also be raw_relocations
or so, to make it less appealing to call?
Direct access to the bytes was previously a problem (rust-lang#62931) where components would read their contents without properly checking relocations and/or definedness. Making bytes private instead of purely renaming them also helps in allowing amendments to their allocation scheme (such as eliding allocation for undef of constant regions).
Requires a manual implementation for Relocations since dereferencing to SortedMap is not always implemented but that one is far more trivial. Added fields could otherwise be silently forgotten since private fields make destructing outside the module possible only with `..` pattern which would then also be applicable to newly added public fields.
This also means that the compressed representation chosen may be optimized together with any changes to the undef_mask.
6e30b33
to
ddc7cc3
Compare
Moved the |
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.
LGTM, with the ntis fixed! However, I can't tell whether the arguments made in codegen_llvm
are correct. Handing over to
r? @oli-obk
r? @oli-obk (Doesn't look like the bots looks into reviews.) |
This improves the clarity of the documentation a bit since they can reference each other when reading the member docs in sequence.
@oli-obk I fixed the remaining nits from Ralf now, there are some unresolved review comments where you commented and I wasn't certain they were fully addressed. And the review of codegen is still oustanding as mentioned. Status should now be waiting on review. |
@bors r+ Oh, right. I reviewed those comments when you made them. Reviewed again, still all good. |
📌 Commit f3c435e has been approved by |
Make Allocation::bytes private Fixes #62931. Direct immutable access to the bytes is still possible but redirected through the new method `raw_bytes_with_undef_and_ptr`, similar to `get_bytes_with_undef_and_ptr` but without requiring an interpretation context and not doing *any* relocation or bounds checks. The `size` of the allocation is stored separately which makes access as `Size` and `usize` more ergonomic. cc: @RalfJung
☀️ Test successful - checks-azure |
📣 Toolstate changed by #63561! Tested on commit b505208. 💔 clippy-driver on windows: test-pass → build-fail (cc @Manishearth @llogiq @mcarton @oli-obk @phansch @flip1995, @rust-lang/infra). |
Tested on commit rust-lang/rust@b505208. Direct link to PR: <rust-lang/rust#63561> 💔 clippy-driver on windows: test-pass → build-fail (cc @Manishearth @llogiq @mcarton @oli-obk @phansch @flip1995, @rust-lang/infra). 💔 clippy-driver on linux: test-pass → build-fail (cc @Manishearth @llogiq @mcarton @oli-obk @phansch @flip1995, @rust-lang/infra). 💔 miri on windows: test-pass → build-fail (cc @oli-obk @RalfJung @eddyb, @rust-lang/infra). 💔 miri on linux: test-pass → build-fail (cc @oli-obk @RalfJung @eddyb, @rust-lang/infra).
Rustup to rust-lang/rust#63561 changelog: none
Avoid copying some undef memory in MIR Copying memory between allocations in MIR is not required to preserve the current representation of undef bytes. When the complete source of a copy is in undef state then there are no bytes that need to be copied and the function can return nearly immediately. In some cases this completely avoids writing to the allocation's memory with should have various benefits. This for example reduces required physical memory when interpreting `const fn` involving large uninitialized values, such as `MaybeUninit::uninit()`. (*This description has been changed from the original one after parts have been integrated into #63561 *)
Fixes #62931.
Direct immutable access to the bytes is still possible but redirected through the new method
raw_bytes_with_undef_and_ptr
, similar toget_bytes_with_undef_and_ptr
but without requiring an interpretation context and not doing any relocation or bounds checks. Thesize
of the allocation is stored separately which makes access asSize
andusize
more ergonomic.cc: @RalfJung