Skip to content

Use a loop to avoid emitting long sequences of retags. - #163567

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
BorrowSanitizer:codegen-retag-fix-loop
Oct 5, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
BorrowSanitizer:codegen-retag-fix-loop

Conversation

@icmccorm

Copy link
Copy Markdown
Contributor

See MCP #958 for context on -Zcodegen-emit-retag.

If we need to retag an array of references, then we will retag every element of the array. This does not scale for large arrays. For example:

const N: usize = 100_000;

fn example(array: [&u32; N]) {}

fn main() {
    example([&0; N]);
}

This program will cause rustc to hang at -O0 with -Zcodegen-emit-retag. In the body of example, we need to ensure that every element of array receives a function-entry retag, so we emit 100,000 retag function calls within a single basic block!

This PR fixes this issue by adjusting how we retag the contents of arrays. Instead of retagging ever element in succession, we emit a loop that applies a single retag call to every element of the array. I have tested it on BorrowSanitizer's test suite.

Also, I saw the new #FIXME comment about supporting repr(simd) types. Some of the changes that I made here will be helpful for fixing that issue in a subsequent PR.

cc: @mojeanmac
r? @saethlin

@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. labels Sep 30, 2026
@saethlin

saethlin commented Oct 5, 2026

Copy link
Copy Markdown
Member

@bors r+ rollup

@rust-bors

rust-bors Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

📌 Commit e7d3ffc has been approved by saethlin

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 Oct 5, 2026
rust-bors Bot pushed a commit that referenced this pull request Oct 5, 2026
Rollup of 3 pull requests

Successful merges:

 - #153160 (Fix relative extern URL depth on source pages)
 - #163529 (Const analysis cleanups)
 - #163567 (Use a loop to avoid emitting long sequences of retags.)
@rust-bors
rust-bors Bot merged commit 447d1ef into rust-lang:main Oct 5, 2026
13 checks passed
@rustbot rustbot added this to the 1.101.0 milestone Oct 5, 2026
rust-bors Bot pushed a commit that referenced this pull request Oct 5, 2026
Rollup merge of #163567 - BorrowSanitizer:codegen-retag-fix-loop, r=saethlin

Use a loop to avoid emitting long sequences of retags.

See MCP [#958](rust-lang/compiler-team#958) for context on `-Zcodegen-emit-retag`.

If we need to retag an array of references, then we will retag every element of the array. This does not scale for large arrays. For example:
```rust
const N: usize = 100_000;

fn example(array: [&u32; N]) {}

fn main() {
    example([&0; N]);
}
```
This program will cause `rustc` to hang at `-O0` with `-Zcodegen-emit-retag`. In the body of `example`, we need to ensure that every element of `array` receives a function-entry retag, so we emit 100,000 retag function calls within a single basic block!

This PR fixes this issue by adjusting how we retag the contents of arrays. Instead of retagging ever element in succession, we emit a loop that applies a single retag call to every element of the array. I have tested it on BorrowSanitizer's test suite.

Also, I saw the new `#FIXME` comment about supporting `repr(simd)` types. Some of the changes that I made here will be helpful for fixing that issue in a subsequent PR.

cc: @mojeanmac
r? @saethlin
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-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants