Skip to content

Update __rust_[rd]ealloc to take NonNull<u8> instead of *mut u8#153251

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
scottmcm:deallocate-nonnull
Mar 2, 2026
Merged

Update __rust_[rd]ealloc to take NonNull<u8> instead of *mut u8#153251
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
scottmcm:deallocate-nonnull

Conversation

@scottmcm
Copy link
Member

@scottmcm scottmcm commented Mar 1, 2026

Passing null to it is already UB per Miri anyway, and this is ABI-compatible as NonNull is repr(transparent).

Inspired by #152702 (comment) ; Similar to #152605 which changed align: usize to align: ptr::Alignment.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 1, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 1, 2026

r? @joboet

rustbot has assigned @joboet.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 7 candidates
  • Random selection from Mark-Simulacrum, joboet

Comment on lines -98 to +95
StorageLive(_9);
_9 = copy _8 as *mut u8 (Transmute);
_10 = alloc::alloc::__rust_dealloc(move _9, move _5, move _6) -> [return: bb3, unwind unreachable];
_9 = alloc::alloc::__rust_dealloc(move _8, move _5, move _6) -> [return: bb3, unwind unreachable];
Copy link
Member Author

Choose a reason for hiding this comment

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

Notably, this lets us avoid the transmute back from NonNull to *mut.

All the alloc code is doing the NonNull conversion in practice anyway, as it's using https://doc.rust-lang.org/std/alloc/struct.Global.html#method.deallocate not the alloc::dealloc function directly.

@joboet
Copy link
Member

joboet commented Mar 1, 2026

Makes sense to me. Let's see if this has any effect on performance...
@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 1, 2026
rust-bors bot pushed a commit that referenced this pull request Mar 1, 2026
Update `__rust_[rd]ealloc` to take `NonNull<u8>` instead of `*mut u8`
@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 1, 2026

☀️ Try build successful (CI)
Build commit: 0fd2a86 (0fd2a86d7a2a7268acb5d51b0f12ac84d755c77f, parent: 765fd2d8c77a570e7069d9f30bb6d3d8fe437f9e)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (0fd2a86): comparison URL.

Overall result: ❌ regressions - no action needed

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.9% [0.9%, 0.9%] 1
Regressions ❌
(secondary)
0.5% [0.5%, 0.5%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.9% [0.9%, 0.9%] 1

Max RSS (memory usage)

Results (primary -0.1%, secondary 2.3%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
3.2% [2.4%, 4.0%] 3
Regressions ❌
(secondary)
2.3% [2.3%, 2.3%] 1
Improvements ✅
(primary)
-3.4% [-4.9%, -2.2%] 3
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.1% [-4.9%, 4.0%] 6

Cycles

Results (secondary -6.3%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-6.3% [-7.2%, -5.2%] 3
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 477.793s -> 479.944s (0.45%)
Artifact size: 397.19 MiB -> 395.22 MiB (-0.50%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 1, 2026
@scottmcm
Copy link
Member Author

scottmcm commented Mar 1, 2026

That perf run looks fine to me. The one icount regression looks like just inlining noise from different MIR
image

With no cycle regressions I think there's nothing problematic.

@joboet
Copy link
Member

joboet commented Mar 1, 2026

Yeah, that looks acceptable.
@bors r+

@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 1, 2026

📌 Commit 2c6ec51 has been approved by joboet

It is now in the queue for this repository.

@rust-bors rust-bors bot 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 1, 2026
@rust-bors

This comment has been minimized.

#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
unsafe fn dealloc_nonnull(ptr: NonNull<u8>, layout: Layout) {
unsafe { __rust_dealloc(ptr, layout.size(), layout.alignment()) }
}
Copy link
Member

Choose a reason for hiding this comment

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

Might be worth it to manually inline these functions. They are tiny and not even encapsulating any unsafeness or tricky logic. Would make optimizations slightly faster and backtraces slightly shorter.

Copy link
Member Author

Choose a reason for hiding this comment

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

I would expect that it's already disappeared in the shipped liballoc rlib since the mir inliner should have done that for us already. So it would remove a inlined entry in the mir scopes, but that's it, afaict.

Copy link
Member

Choose a reason for hiding this comment

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

MIR inlined calls do still show in backtraces.

@rust-bors rust-bors bot added merged-by-bors This PR was explicitly merged by bors. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 2, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 2, 2026

☀️ Test successful - CI
Approved by: joboet
Duration: 3h 51m 12s
Pushing 8d50bcc to main...

@rust-bors rust-bors bot merged commit 8d50bcc into rust-lang:main Mar 2, 2026
13 checks passed
@rustbot rustbot added this to the 1.96.0 milestone Mar 2, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing ddd36bd (parent) -> 8d50bcc (this PR)

Test differences

Show 11 test diffs

11 doctest diffs were found. These are ignored, as they are noisy.

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 8d50bccc5bd70be9f5a2fc98c0857e24b3dcdf85 --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. x86_64-rust-for-linux: 52m 46s -> 42m 43s (-19.0%)
  2. x86_64-gnu-gcc: 1h 8m -> 55m 20s (-18.7%)
  3. aarch64-gnu-llvm-20-1: 1h 1m -> 52m 58s (-13.9%)
  4. i686-gnu-1: 2h 23m -> 2h 6m (-12.1%)
  5. pr-check-1: 30m 53s -> 27m 42s (-10.3%)
  6. i686-gnu-2: 1h 41m -> 1h 30m (-10.3%)
  7. dist-apple-various: 1h 43m -> 1h 53m (+9.6%)
  8. i686-gnu-nopt-1: 2h 19m -> 2h 6m (-9.3%)
  9. pr-check-2: 42m 29s -> 38m 33s (-9.3%)
  10. x86_64-gnu-aux: 2h 24m -> 2h 11m (-9.0%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (8d50bcc): comparison URL.

Overall result: ❌ regressions - no action needed

@rustbot label: -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.8% [0.8%, 0.8%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.8% [0.8%, 0.8%] 1

Max RSS (memory usage)

Results (primary 1.6%, secondary 1.4%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
4.2% [2.2%, 7.8%] 5
Regressions ❌
(secondary)
4.7% [1.1%, 8.3%] 2
Improvements ✅
(primary)
-2.7% [-2.7%, -2.6%] 3
Improvements ✅
(secondary)
-5.3% [-5.3%, -5.3%] 1
All ❌✅ (primary) 1.6% [-2.7%, 7.8%] 8

Cycles

Results (primary 2.0%, secondary -1.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.0% [2.0%, 2.0%] 1
Regressions ❌
(secondary)
4.6% [4.6%, 4.6%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.8% [-4.5%, -3.1%] 2
All ❌✅ (primary) 2.0% [2.0%, 2.0%] 1

Binary size

Results (primary 0.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.6% [0.6%, 0.6%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.6% [-0.6%, -0.6%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.0% [-0.6%, 0.6%] 2

Bootstrap: 478.623s -> 479.657s (0.22%)
Artifact size: 397.00 MiB -> 396.97 MiB (-0.01%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-bors This PR was explicitly merged by bors. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants