-
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
Add allocate_bytes and refactor allocate_str in InterpCx for raw byte… #133861
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @estebank (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
r? @RalfJung |
Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri Some changes occurred to the CTFE machinery cc @rust-lang/wg-const-eval |
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.
Thanks for the PR! I have a few minor comments.
let ptr = if mutbl.is_not() { | ||
// Use dedup'd allocation function. | ||
// Deduplicate immutable allocations using a salted hash |
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.
You have changed all the comments in this function. The new comments aren't wrong, but they are also not clearly better than the old ones. Why have you rewritten them?
The salted hash part isn't relevant here, what is relevant is that we use the dedup
function, so for this line here please restore the previous comment.
When your comment is a sentence, please make sure to end it in .
.
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.
Ah, Apologies for my earlier misunderstanding based on the function name. I’ve restored the original comments as per your feedback.
&mut self, | ||
str: &str, | ||
bytes: &[u8], | ||
align: Align, | ||
kind: MemoryKind<M::MemoryKind>, | ||
mutbl: Mutability, | ||
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>> { |
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 think returning this as a Pointer
makes more sense, given that we don't know which type the caller needs.
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 agree that returning InterpResult<'tcx, Pointer<M::Provenance>>
as a pointer fits this context better. Great suggestion!
@rustbot author Once the PR is ready for review again, please write |
Thank you for taking the time to review and provide comments. I've addressed them all, and I hope the changes are now ready for intake. |
@rustbot 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.
Just one final nit. :) And then please squash the PR into a single commit.
@rustbot author |
@rustbot ready |
You skipped the "squashing into a single commit" part. :) @rustbot author |
… allocation Signed-off-by: shamb0 <r.raajey@gmail.com>
e4de6a4
to
9b07e75
Compare
Apologies for missing this step—I overlooked it while managing multiple tasks. I truly appreciate your patience and dedication to maintaining quality. I’ve now understood the workflow and will ensure this doesn’t happen again in the future. Thank you! :) |
@rustbot ready |
No worries, and thanks for swiftly dealing with all my feedback. :) @bors r+ rollup |
…str, r=RalfJung Add allocate_bytes and refactor allocate_str in InterpCx for raw byte… Fixes rust-lang/miri#4025 This PR introduces a new `allocate_bytes` function in InterpCx and refactors `allocate_str` to use it internally. This change improves memory allocation handling in the interpreter by: 1. Adding `allocate_bytes`: - Direct byte slice allocation support - Handles both mutable and immutable allocations - Maintains proper memory alignment and deduplication 2. Refactoring `allocate_str`: - Now uses `allocate_bytes` internally - Adds string-specific metadata handling - Preserves existing string allocation behavior This is part 1 of the planned changes to improve timezone string handling in Miri. A follow-up PR will update Miri's timezone logic to use this new allocation mechanism. Related: rust-lang/miri#4069
…kingjubilee Rollup of 10 pull requests Successful merges: - rust-lang#133522 (Don't suggest restricting bound with unstable traits on stable and mention it's unstable on nightly) - rust-lang#133733 ( compiletest: show the difference between the normalized output and the actual output for lines which didn't match) - rust-lang#133861 (Add allocate_bytes and refactor allocate_str in InterpCx for raw byte…) - rust-lang#133967 ([AIX] Pass -bnoipath when adding rust upstream dynamic crates) - rust-lang#133976 (Removed Unnecessary Spaces From RELEASES.md) - rust-lang#133980 ([AIX] Remove option "-n" from AIX "ln" command) - rust-lang#133987 (Define acronym for thread local storage) - rust-lang#133992 (Actually walk into lifetimes and attrs in `EarlyContextAndPass`) - rust-lang#133993 (Fix: typo in E0751 error explanation) - rust-lang#133996 (Move most tests for `-l` and `#[link(..)]` into `tests/ui/link-native-libs`) r? `@ghost` `@rustbot` modify labels: rollup
…kingjubilee Rollup of 10 pull requests Successful merges: - rust-lang#133522 (Don't suggest restricting bound with unstable traits on stable and mention it's unstable on nightly) - rust-lang#133733 ( compiletest: show the difference between the normalized output and the actual output for lines which didn't match) - rust-lang#133861 (Add allocate_bytes and refactor allocate_str in InterpCx for raw byte…) - rust-lang#133967 ([AIX] Pass -bnoipath when adding rust upstream dynamic crates) - rust-lang#133976 (Removed Unnecessary Spaces From RELEASES.md) - rust-lang#133980 ([AIX] Remove option "-n" from AIX "ln" command) - rust-lang#133987 (Define acronym for thread local storage) - rust-lang#133992 (Actually walk into lifetimes and attrs in `EarlyContextAndPass`) - rust-lang#133993 (Fix: typo in E0751 error explanation) - rust-lang#133996 (Move most tests for `-l` and `#[link(..)]` into `tests/ui/link-native-libs`) r? `@ghost` `@rustbot` modify labels: rollup
…str, r=RalfJung Add allocate_bytes and refactor allocate_str in InterpCx for raw byte… Fixes rust-lang/miri#4025 This PR introduces a new `allocate_bytes` function in InterpCx and refactors `allocate_str` to use it internally. This change improves memory allocation handling in the interpreter by: 1. Adding `allocate_bytes`: - Direct byte slice allocation support - Handles both mutable and immutable allocations - Maintains proper memory alignment and deduplication 2. Refactoring `allocate_str`: - Now uses `allocate_bytes` internally - Adds string-specific metadata handling - Preserves existing string allocation behavior This is part 1 of the planned changes to improve timezone string handling in Miri. A follow-up PR will update Miri's timezone logic to use this new allocation mechanism. Related: rust-lang/miri#4069
[TEST] Rollup of 5 pull requests Successful merges: - rust-lang#133733 ( compiletest: show the difference between the normalized output and the actual output for lines which didn't match) - rust-lang#133861 (Add allocate_bytes and refactor allocate_str in InterpCx for raw byte…) - rust-lang#133967 ([AIX] Pass -bnoipath when adding rust upstream dynamic crates) - rust-lang#133976 (Removed Unnecessary Spaces From RELEASES.md) - rust-lang#133980 ([AIX] Remove option "-n" from AIX "ln" command) r? `@ghost` `@rustbot` modify labels: rollup try-job: i686-mingw
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#131669 (lint: change help for pointers to dyn types in FFI) - rust-lang#133104 (crashes: add test for rust-lang#131451) - rust-lang#133767 (Add more info on type/trait mismatches for different crate versions) - rust-lang#133861 (Add allocate_bytes and refactor allocate_str in InterpCx for raw byte…) - rust-lang#133976 (Removed Unnecessary Spaces From RELEASES.md) - rust-lang#133987 (Define acronym for thread local storage) - rust-lang#133992 (Actually walk into lifetimes and attrs in `EarlyContextAndPass`) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#133861 - shamb0:refactor_InterpCx_allocate_str, r=RalfJung Add allocate_bytes and refactor allocate_str in InterpCx for raw byte… Fixes rust-lang/miri#4025 This PR introduces a new `allocate_bytes` function in InterpCx and refactors `allocate_str` to use it internally. This change improves memory allocation handling in the interpreter by: 1. Adding `allocate_bytes`: - Direct byte slice allocation support - Handles both mutable and immutable allocations - Maintains proper memory alignment and deduplication 2. Refactoring `allocate_str`: - Now uses `allocate_bytes` internally - Adds string-specific metadata handling - Preserves existing string allocation behavior This is part 1 of the planned changes to improve timezone string handling in Miri. A follow-up PR will update Miri's timezone logic to use this new allocation mechanism. Related: rust-lang/miri#4069
Fixes rust-lang/miri#4025
This PR introduces a new
allocate_bytes
function in InterpCx and refactorsallocate_str
to use it internally. This change improves memory allocation handling in the interpreter by:Adding
allocate_bytes
:Refactoring
allocate_str
:allocate_bytes
internallyThis is part 1 of the planned changes to improve timezone string handling in Miri. A follow-up PR will update Miri's timezone logic to use this new allocation mechanism.
Related: rust-lang/miri#4069