Skip to content

Improve polymorphization of raw pointer formatting#157714

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
hanna-kruppe:fmt-pointer
Jun 13, 2026
Merged

Improve polymorphization of raw pointer formatting#157714
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
hanna-kruppe:fmt-pointer

Conversation

@hanna-kruppe

@hanna-kruppe hanna-kruppe commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

View all comments

This reduces the amount of LLVM IR rustc generates for basically every use of fmt::Pointer by several hundred lines per pointee type. Most of the gain is from side-stepping a code size issue with the current implementation of Formatter::with_field. But even if those were fixed, it would still be an improvement:

  • The "is it a thin pointer?" check can't be eliminated during codegen, so rustc codegens both branches for every pointer type and LLVM has to clean it up later.
  • For wide pointers, the use of DebugStruct isn't a lot of code, but it's still a bit of extra code per wide pointer type that can easily be shared across all wide pointer types.

This reduces the amount of LLVM IR rustc generates for basically every
use of `fmt::Pointer` by several hundred lines per pointee type. Most of
the gain is from side-stepping a code size issue with the current
implementation of `Formatter::with_field`. But even if those were fixed,
it would still be an improvement:

* The "is it a thin pointer?" check can't be eliminated during codegen,
  so rustc codegens *both* branches for every pointer type and LLVM has
  to clean it up later.
* For wide pointers, the use of `DebugStruct` isn't a *lot* of code, but
  it's still a bit of extra code per wide pointer type that can easily
  be shared across all wide pointer types.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jun 10, 2026
@rustbot

rustbot commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Failed to set assignee to LawnGnome: req=https://api.github.com/repos/rust-lang/rust/issues/157714/assignees (x-github-request-id: 4B19:AA77B:90C467D:9232340:6A2989F8): {
"message": "Requires authentication",
"documentation_url": "https://docs.github.com/rest",
"status": "401"
}

Note: Only org members with at least the repository "read" role, users with write permissions, or people who have commented on the PR may be assigned.

@rustbot

rustbot commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

r? @LawnGnome

rustbot has assigned @LawnGnome.
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 10 candidates
  • Random selection from LawnGnome, Mark-Simulacrum, clarfonthey, jhpratt

@Kobzol

Kobzol commented Jun 10, 2026

Copy link
Copy Markdown
Member

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 10, 2026
@rust-bors

rust-bors Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

❌ Encountered an error while executing command

@hanna-kruppe hanna-kruppe changed the title improve polymorphization of raw pointer formatting Improve polymorphization of raw pointer formatting Jun 10, 2026
@Kobzol

Kobzol commented Jun 12, 2026

Copy link
Copy Markdown
Member

@bors try

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jun 12, 2026
Improve polymorphization of raw pointer formatting
@rust-bors

rust-bors Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 8a88eb6 (8a88eb633379915cf400b6d8ef34a80d1048e88b, parent: 09a371361240e42b0d69438fd1179efcf212e576)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (8a88eb6): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.

@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
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.2% [-0.2%, -0.2%] 1
All ❌✅ (primary) - - 0

Max RSS (memory usage)

This perf run didn't have relevant results for this metric.

Cycles

Results (primary -2.3%, secondary -2.6%)

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)
-2.3% [-2.3%, -2.3%] 1
Improvements ✅
(secondary)
-2.6% [-2.6%, -2.6%] 1
All ❌✅ (primary) -2.3% [-2.3%, -2.3%] 1

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 517.481s -> 518.904s (0.27%)
Artifact size: 401.31 MiB -> 401.37 MiB (0.02%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 12, 2026
@LawnGnome

Copy link
Copy Markdown
Contributor

Makes sense to me. Nice work!

@bors r+ rollup=never (given perf implications)

@rust-bors

rust-bors Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

📌 Commit c043f23 has been approved by LawnGnome

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 Jun 12, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jun 13, 2026
Improve polymorphization of raw pointer formatting

This reduces the amount of LLVM IR rustc generates for basically every use of `fmt::Pointer` by several hundred lines per pointee type. Most of the gain is from side-stepping a code size issue with the current implementation of `Formatter::with_field`. But even if those were fixed, it would still be an improvement:

* The "is it a thin pointer?" check can't be eliminated during codegen, so rustc codegens *both* branches for every pointer type and LLVM has to clean it up later.
* For wide pointers, the use of `DebugStruct` isn't a *lot* of code, but it's still a bit of extra code per wide pointer type that can easily be shared across all wide pointer types.
@rust-bors rust-bors Bot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jun 13, 2026
@rust-bors

rust-bors Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

💔 Test for d390a19 failed: CI. Failed job:

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

A job failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
  IMAGE: test-various
##[endgroup]
    Updating crates.io index
error: failed to get `adler2` as a dependency of package `miniz_oxide v0.8.8`
    ... which satisfies dependency `miniz_oxide = "^0.8.5"` of package `flate2 v1.1.9`
    ... which satisfies dependency `flate2 = "^1.1.9"` of package `citool v0.1.0 (/home/runner/work/rust/rust/src/ci/citool)`

Caused by:
  failed to load source for dependency `adler2`

Caused by:
  unable to update registry `crates-io`

Caused by:
  download of ad/le/adler2 failed

Caused by:
  curl failed

Caused by:

@JonathanBrouwer

Copy link
Copy Markdown
Contributor

@bors retry

@rust-bors rust-bors Bot added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jun 13, 2026
@rust-bors rust-bors Bot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 13, 2026
@JonathanBrouwer

Copy link
Copy Markdown
Contributor

@bors rollup=iffy
Perf is most likely noise

@rust-bors

rust-bors Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

⌛ Testing commit c043f23 with merge be2c792...

Workflow: https://github.com/rust-lang/rust/actions/runs/27461008959

rust-bors Bot pushed a commit that referenced this pull request Jun 13, 2026
Improve polymorphization of raw pointer formatting

This reduces the amount of LLVM IR rustc generates for basically every use of `fmt::Pointer` by several hundred lines per pointee type. Most of the gain is from side-stepping a code size issue with the current implementation of `Formatter::with_field`. But even if those were fixed, it would still be an improvement:

* The "is it a thin pointer?" check can't be eliminated during codegen, so rustc codegens *both* branches for every pointer type and LLVM has to clean it up later.
* For wide pointers, the use of `DebugStruct` isn't a *lot* of code, but it's still a bit of extra code per wide pointer type that can easily be shared across all wide pointer types.
@jhpratt

jhpratt commented Jun 13, 2026

Copy link
Copy Markdown
Member

yielding to encompassing rollup

@bors yield

@rust-bors

rust-bors Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Auto build was cancelled. Cancelled workflows:

The next pull request likely to be tested is #157852.

rust-bors Bot pushed a commit that referenced this pull request Jun 13, 2026
Rollup of 10 pull requests

Successful merges:

 - #157714 (Improve polymorphization of raw pointer formatting)
 - #157653 (remove AliasTerm::def_id())
 - #157773 (Remove AnonConstKind::GCA and reject generic anon consts)
 - #157846 (Avoid ICE in unconstrained generic parameter suggestion for enums)
 - #157594 (note which target a missing target_feature belongs to)
 - #157740 (rustdoc: correct doctest span for trailing semicolon after item)
 - #157782 (Added `PhantomPinned` diagnostic item and prevented dead field warning on `PhantomPinned`)
 - #157802 (Ensure that optimize attributes on closures are inherited by the shim.)
 - #157812 (rustc_public: implement `ty::Alias` conversion)
 - #157833 (Update wasm-component-ld to 0.5.25)
@rust-bors

rust-bors Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

⌛ Testing commit c043f23 with merge c180c64...

Workflow: https://github.com/rust-lang/rust/actions/runs/27461267747

rust-bors Bot pushed a commit that referenced this pull request Jun 13, 2026
Improve polymorphization of raw pointer formatting



This reduces the amount of LLVM IR rustc generates for basically every use of `fmt::Pointer` by several hundred lines per pointee type. Most of the gain is from side-stepping a code size issue with the current implementation of `Formatter::with_field`. But even if those were fixed, it would still be an improvement:

* The "is it a thin pointer?" check can't be eliminated during codegen, so rustc codegens *both* branches for every pointer type and LLVM has to clean it up later.
* For wide pointers, the use of `DebugStruct` isn't a *lot* of code, but it's still a bit of extra code per wide pointer type that can easily be shared across all wide pointer types.
@JonathanBrouwer

Copy link
Copy Markdown
Contributor

@bors yield
Yielding to enclosing rollup

@rust-bors

rust-bors Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Auto build was cancelled. Cancelled workflows:

The next pull request likely to be tested is #157852.

rust-bors Bot pushed a commit that referenced this pull request Jun 13, 2026
Rollup of 10 pull requests

Successful merges:

 - #157714 (Improve polymorphization of raw pointer formatting)
 - #157653 (remove AliasTerm::def_id())
 - #157773 (Remove AnonConstKind::GCA and reject generic anon consts)
 - #157846 (Avoid ICE in unconstrained generic parameter suggestion for enums)
 - #157594 (note which target a missing target_feature belongs to)
 - #157740 (rustdoc: correct doctest span for trailing semicolon after item)
 - #157782 (Added `PhantomPinned` diagnostic item and prevented dead field warning on `PhantomPinned`)
 - #157802 (Ensure that optimize attributes on closures are inherited by the shim.)
 - #157812 (rustc_public: implement `ty::Alias` conversion)
 - #157833 (Update wasm-component-ld to 0.5.25)
@rust-bors rust-bors Bot merged commit 7b303c6 into rust-lang:main Jun 13, 2026
13 of 14 checks passed
@rustbot rustbot added this to the 1.98.0 milestone Jun 13, 2026
rust-timer added a commit that referenced this pull request Jun 13, 2026
Rollup merge of #157714 - hanna-kruppe:fmt-pointer, r=LawnGnome

Improve polymorphization of raw pointer formatting

This reduces the amount of LLVM IR rustc generates for basically every use of `fmt::Pointer` by several hundred lines per pointee type. Most of the gain is from side-stepping a code size issue with the current implementation of `Formatter::with_field`. But even if those were fixed, it would still be an improvement:

* The "is it a thin pointer?" check can't be eliminated during codegen, so rustc codegens *both* branches for every pointer type and LLVM has to clean it up later.
* For wide pointers, the use of `DebugStruct` isn't a *lot* of code, but it's still a bit of extra code per wide pointer type that can easily be shared across all wide pointer types.
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. 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.

8 participants