Skip to content

GVN: Don't assume nested shared references are read-only.#157346

Open
dianqk wants to merge 2 commits into
rust-lang:mainfrom
dianqk:gvn-nest-ref
Open

GVN: Don't assume nested shared references are read-only.#157346
dianqk wants to merge 2 commits into
rust-lang:mainfrom
dianqk:gvn-nest-ref

Conversation

@dianqk
Copy link
Copy Markdown
Member

@dianqk dianqk commented Jun 3, 2026

Fixes #155884.

#150485 only checks the type, whether it is a reference, which is not enough. The PR extends to other types.

cc @RalfJung @saethlin

r? @cjgillot

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Jun 3, 2026

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@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 Jun 3, 2026
@dianqk
Copy link
Copy Markdown
Member Author

dianqk commented Jun 3, 2026

@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 Jun 3, 2026
rust-bors Bot pushed a commit that referenced this pull request Jun 3, 2026
 GVN: Don't assume nested shared references are read-only.
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Jun 3, 2026

☀️ Try build successful (CI)
Build commit: 0eeeb18 (0eeeb181f41359e276c1dae9eec938e457300cec, parent: d595fce01043347bf7f80e85b76dcc41b59a3e6e)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (0eeeb18): comparison URL.

Overall result: ❌✅ regressions and improvements - please read:

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@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.3% [0.1%, 1.0%] 12
Regressions ❌
(secondary)
0.3% [0.0%, 0.5%] 36
Improvements ✅
(primary)
-0.3% [-0.3%, -0.2%] 12
Improvements ✅
(secondary)
-0.3% [-1.0%, -0.0%] 12
All ❌✅ (primary) 0.0% [-0.3%, 1.0%] 24

Max RSS (memory usage)

Results (primary 3.6%)

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

mean range count
Regressions ❌
(primary)
4.9% [1.8%, 10.4%] 6
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-3.9% [-3.9%, -3.9%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 3.6% [-3.9%, 10.4%] 7

Cycles

Results (secondary -0.4%)

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)
7.2% [5.0%, 10.8%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.7% [-6.2%, -2.4%] 7
All ❌✅ (primary) - - 0

Binary size

Results (primary -0.0%, secondary 0.1%)

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

mean range count
Regressions ❌
(primary)
0.1% [0.0%, 0.6%] 19
Regressions ❌
(secondary)
0.1% [0.0%, 0.6%] 16
Improvements ✅
(primary)
-0.4% [-1.1%, -0.1%] 8
Improvements ✅
(secondary)
-0.1% [-0.1%, -0.1%] 1
All ❌✅ (primary) -0.0% [-1.1%, 0.6%] 27

Bootstrap: 509.701s -> 512.229s (0.50%)
Artifact size: 400.67 MiB -> 398.49 MiB (-0.55%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jun 3, 2026
Comment thread compiler/rustc_mir_transform/src/gvn.rs Outdated
Comment on lines 837 to 839
// DO NOT reason the pointer value that has references.
// We cannot unify two pointers that dereference same local, because they may
// have different lifetimes.
Copy link
Copy Markdown
Member

@RalfJung RalfJung Jun 3, 2026

Choose a reason for hiding this comment

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

This isn't quite grammatical. Maybe you mean "do not reason about ..."? But even then I'm a bit confused about what the comment is trying to say.

This should definitely mention that nested shared references are not read-only and have a link to the issue.

View changes since the review

// let c: &T = *a;
// ```
if projection_ty.ty.is_ref() {
// Unifying them can violate Stacked Borrows or Tree Borrows.
Copy link
Copy Markdown
Member

@RalfJung RalfJung Jun 3, 2026

Choose a reason for hiding this comment

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

Suggested change
// Unifying them can violate Stacked Borrows or Tree Borrows.
// Furthermore, unifying them can also violate Stacked Borrows or Tree Borrows.

View changes since the review

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

Labels

perf-regression Performance regression. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GVN assumes nested shared references are read-only

5 participants