Skip to content

Do not shallow resolve to root var while fudging#153869

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
ShoyuVanilla:issue-153816
Mar 19, 2026
Merged

Do not shallow resolve to root var while fudging#153869
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
ShoyuVanilla:issue-153816

Conversation

@ShoyuVanilla
Copy link
Copy Markdown
Member

@ShoyuVanilla ShoyuVanilla commented Mar 14, 2026

View all comments

Fixes #153816 and fixes #153849

In #151380, I thought that whether shallow resolve to root var or not wouldn't affect the actual type inferencing, but it isn't true for the fudge, in which we discard all newly created relationships between unresolved inference variables 😅

r? lcnr

@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 Mar 14, 2026
@ShoyuVanilla
Copy link
Copy Markdown
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Mar 14, 2026
Do not shallow resolve to root var while fudging
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 14, 2026
@ShoyuVanilla
Copy link
Copy Markdown
Member Author

@bors try cancel

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Mar 14, 2026

@ShoyuVanilla
Copy link
Copy Markdown
Member Author

@bors try

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Mar 14, 2026
Do not shallow resolve to root var while fudging
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Mar 14, 2026

☀️ Try build successful (CI)
Build commit: 1edb863 (1edb863e6d15a3bd38cd1bfc3f124a3de6878c25, parent: fd2649988fdc91e056ddd316865d33e812f48a0e)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (1edb863): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

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.

Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

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

Max RSS (memory usage)

Results (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)
- - 0
Regressions ❌
(secondary)
1.9% [1.0%, 2.8%] 5
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.9% [-0.9%, -0.9%] 1
All ❌✅ (primary) - - 0

Cycles

Results (secondary 3.9%)

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

Binary size

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

Bootstrap: 481.843s -> 481.051s (-0.16%)
Artifact size: 396.85 MiB -> 394.81 MiB (-0.51%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Mar 14, 2026
Copy link
Copy Markdown
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

I dislike these changes to shallow_resolve as worry that it's easy for this to have unintended sideeffects/weirdness, e.g. it also affects canonicalization in the fudging scope.

My understanding of the two regressions is as follows:

tests/ui/coercion/fudge-inference/input-ty-higher-ranked-fn-trait.rs: We have the expectation Server<?n> and the ret type of the function Server<?m> with n < m. We have an ?m: Fn obligation, so if we don't relate ?n with ?m, but have fudging return ?n, we lose that knowledge

tests/ui/coercion/fudge-inference/input-ty-closure-param-fn-trait-bounds.rs: not actually minimal, this is enough

struct Inv<T, U>(*mut (T, U));
fn pass_through<F>(_: F) -> Inv<F, F> { todo!() }
fn map(_: Inv<impl FnOnce(), impl Fn()>) {}
pub fn traverse() {
    map(pass_through(|| ()))
}

We have the same issue on stable already, if we partially constrain F

struct Inv<T, U>(*mut (T, U));
fn pass_through<F>(_: F) -> Inv<F, F> { todo!() }
fn map(_: Inv<(impl FnOnce(),), (impl Fn(),)>) {}
pub fn traverse() {
    map(pass_through((|| (),)))
}

I don't get why we'd actually limit the closure to only impl FnOnce instead of properly inferring the closure kind as we do normally. That feels like a separate issue here, would be happy for you to look into what happens if we never eagerly infer the closure kind in deduce_closure_signature

Could you instead add a fn resolve_vars_for_fudging which has this special behavior by just ignoring the output of shallow_resolve if its an infer var?

I really dislike this problem :x I feel like there should be a better way to handle this sort of thing, but can't think of anything right away

View changes since this review

@ShoyuVanilla
Copy link
Copy Markdown
Member Author

Yeah, this doesn't feel to me the right way to do the things, either. I think I should look into the problem more deeply and make some correct fix in a long term, but since the problemtaic issues are stable to beta regression, I ended up in somewhat makeshift 😅

Could you instead add a fn resolve_vars_for_fudging which has this special behavior by just ignoring the output of shallow_resolve if its an infer var?

Yeah, this feels better

I don't get why we'd actually limit the closure to only impl FnOnce instead of properly inferring the closure kind as we do normally. That feels like a separate issue here, would be happy for you to look into what happens if we never eagerly infer the closure kind in deduce_closure_signature

I'm already a bit familiar with this closure kind deduction. Gonna be a bit verbose, so I'll continue in a new comment

@ShoyuVanilla
Copy link
Copy Markdown
Member Author

ShoyuVanilla commented Mar 15, 2026

In the beta,

struct Inv<T, U>(*mut (T, U));
fn pass_through<F>(_: F) -> Inv<F, F> { todo!() }
fn map(_: Inv<impl FnOnce(), impl Fn()>) {}
pub fn traverse() {
    map(pass_through(|| ()))
}

When we fudge the input expectations in map(pass_through(|| ())), we make Inv<?impl FnOnce(), ?impl FnOnce> :> Inv<?F, ?F>, which results into eq relations ?impl FnOnce() = ?F and ?impl Fn() = ?F.

Since the ty vars aren't fully resolved yet, their root variable becomes something feels quite random, the one with the minimal vid index, ?impl FnOnce(). This is somewhat implementation dependent thing here:

fn order_roots(a: Self, _: &Self::Value, b: Self, _: &Self::Value) -> Option<(Self, Self)> {
if a.vid.as_u32() < b.vid.as_u32() { Some((a, b)) } else { Some((b, a)) }
}

With my resolve to root var PR, the pass_through's input type expectation ?F ends up to its root var ?impl FnOnce() from the fudge and therefore, the only predicate we have for the pass_through's input ty is ?impl FnOnce(): impl FnOnce()

This makes us to deduce the closure kind as FnOnce, becase we deduce closure kind from predicates, which leads to {closure}: Fn() -> NoSolution.

fn deduce_closure_signature_from_predicates(

But in stable, we do not shallow resolve to root var, so the expectation becomes ?F, which has no Fn trait related predicate.
Thus we infer the closure's kind without any predicates, but modulo upvars, which leads to Fn as || () doesn't have any move or borrow.

For the second code which has a outer concrete wraper type(unary tuple) for the expected input type, the input ty var is resolved into it ((?impl Fn(), )) instead of unresolved ty var both in the beta and the stable, so the closure has {closure}: FnOnce() predicate again, which leads to compilation error for both cases.

I've been thinking this deduce closure kind from predicates behavior somewhat weird since my first PR to rust-lang org - rust-lang/rust-analyzer#16472 😅 (it has been closed, but superseded by my another PR)

rust-analyzer was deducing the kind of a closure purely depending on its upvars, and I thought that makes more sense, but anyway, the source of truth for rust-analyzer is rustc 😄

what happens if we never eagerly infer the closure kind in deduce_closure_signature

So, I can say that the problematic regression(or breaking change) that I meant to fix with that PR will happen if we do so, at least.

struct Foo<F: std::ops::FnOnce()>(F);

fn main() {
    let mut x = String::new();
    let y = Foo(|| {
        x = String::from("foo");
    });
    (y.0)();
}

The above is compiled fine with the current rustc, but if we deduce the kind for the closure with its upvars, it would result in FnMut and the last line inside the main function would emit a mutability error.

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Mar 15, 2026
Do not shallow resolve to root var while fudging
@rust-log-analyzer

This comment has been minimized.

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Mar 15, 2026

☀️ Try build successful (CI)
Build commit: bd1c579 (bd1c579a9f06e65c30a9927c80221375e9804aab, parent: 79d2026ae87386ccbe8fc729d130e5e298959a48)

@ShoyuVanilla ShoyuVanilla force-pushed the issue-153816 branch 2 times, most recently from 7884c7c to 5c95952 Compare March 15, 2026 18:01
@ShoyuVanilla
Copy link
Copy Markdown
Member Author

@bors r=lcnr

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Mar 18, 2026

📌 Commit b77739a has been approved by lcnr

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 18, 2026
@theemathas theemathas added the beta-nominated Nominated for backporting to the compiler in the beta channel. label Mar 18, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Mar 18, 2026
Do not shallow resolve to root var while fudging



Fixes #153816 and fixes #153849

In #151380, I thought that whether shallow resolve to root var or not wouldn't affect the actual type inferencing, but it isn't true for the fudge, in which we discard all newly created relationships between unresolved inference variables 😅

r? lcnr
@jhpratt
Copy link
Copy Markdown
Member

jhpratt commented Mar 19, 2026

CI has been stuck at the same line of output for at least half an hour.

@bors yield

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Mar 19, 2026

Auto build was cancelled. Cancelled workflows:

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

@Zalathar
Copy link
Copy Markdown
Member

Scheduling: Run a mixture of rollup and non-rollup PRs.

@bors p=5

@rust-bors

This comment has been minimized.

@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 19, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Mar 19, 2026

☀️ Test successful - CI
Approved by: lcnr
Duration: 3h 18m 57s
Pushing 1f7f8ea to main...

@rust-bors rust-bors Bot merged commit 1f7f8ea into rust-lang:main Mar 19, 2026
12 checks passed
@rustbot rustbot added this to the 1.96.0 milestone Mar 19, 2026
@github-actions
Copy link
Copy Markdown
Contributor

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 8b86f48 (parent) -> 1f7f8ea (this PR)

Test differences

Show 8 test diffs

Stage 1

  • [ui] tests/ui/coercion/fudge-inference/input-ty-closure-param-fn-trait-bounds.rs: [missing] -> pass (J1)
  • [ui] tests/ui/coercion/fudge-inference/input-ty-higher-ranked-fn-trait.rs: [missing] -> pass (J1)

Stage 2

  • [ui] tests/ui/coercion/fudge-inference/input-ty-closure-param-fn-trait-bounds.rs: [missing] -> pass (J0)
  • [ui] tests/ui/coercion/fudge-inference/input-ty-higher-ranked-fn-trait.rs: [missing] -> pass (J0)

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

Job group index

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 1f7f8ea0721a3b1eb73e6c6d25cccb371434b320 --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. dist-x86_64-apple: 1h 39m -> 2h 2m (+23.5%)
  2. x86_64-gnu-stable: 2h 37m -> 2h 13m (-15.4%)
  3. aarch64-apple: 2h 53m -> 2h 27m (-14.9%)
  4. x86_64-msvc-ext3: 1h 40m -> 1h 54m (+14.4%)
  5. test-various: 2h 8m -> 1h 52m (-11.9%)
  6. dist-x86_64-illumos: 1h 38m -> 1h 50m (+11.8%)
  7. dist-x86_64-llvm-mingw: 1h 56m -> 1h 43m (-11.7%)
  8. i686-gnu-nopt-1: 2h 23m -> 2h 7m (-11.3%)
  9. dist-aarch64-apple: 1h 48m -> 2h (+10.6%)
  10. i686-gnu-2: 1h 44m -> 1h 33m (-10.4%)
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.

@ShoyuVanilla ShoyuVanilla deleted the issue-153816 branch March 19, 2026 15:43
@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (1f7f8ea): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Our benchmarks found a performance regression caused by this PR.
This might be an actual regression, but it can also be just noise.

Next Steps:

  • If the regression was expected or you think it can be justified,
    please write a comment with sufficient written justification, and add
    @rustbot label: +perf-regression-triaged to it, to mark the regression as triaged.
  • If you think that you know of a way to resolve the regression, try to create
    a new PR with a fix for the regression.
  • If you do not understand the regression or you think that it is just noise,
    you can ask the @rust-lang/wg-compiler-performance working group for help (members of this group
    were already notified of this PR).

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

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.3% [0.2%, 0.4%] 7
Improvements ✅
(primary)
-0.1% [-0.1%, -0.1%] 2
Improvements ✅
(secondary)
-0.3% [-0.3%, -0.2%] 4
All ❌✅ (primary) -0.1% [-0.1%, -0.1%] 2

Max RSS (memory usage)

Results (secondary -3.1%)

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)
-3.1% [-3.1%, -3.1%] 1
All ❌✅ (primary) - - 0

Cycles

Results (secondary 10.8%)

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

Binary size

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

Bootstrap: 480.842s -> 481.515s (0.14%)
Artifact size: 395.02 MiB -> 394.79 MiB (-0.06%)

@apiraino
Copy link
Copy Markdown
Contributor

apiraino commented Mar 23, 2026

@ShoyuVanilla @lcnr just for my understanding: the preferred fix here in the end was merging this patch instead of reverting #151380, correct?

(a revert was discussed on Zulip)

thanks

@panstromek
Copy link
Copy Markdown
Contributor

panstromek commented Mar 24, 2026

perf triage:

Improvements mostly outweigh regressions. Secondary regressions in projection-caching and regression-31157 seem to just undo part of the wins from #151380, so this still seems like a net improvement overall.

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Mar 24, 2026
ShoyuVanilla added a commit to ShoyuVanilla/rust that referenced this pull request Mar 24, 2026
…=lcnr"

This reverts commit 1f7f8ea, reversing
changes made to 8b86f48.
ShoyuVanilla added a commit to ShoyuVanilla/rust that referenced this pull request Mar 24, 2026
…=lcnr"

This reverts commit 1f7f8ea, reversing
changes made to 8b86f48.
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 24, 2026

beta backport declined as per compiler team on Zulip.

@rustbot rustbot removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Mar 24, 2026
erickt pushed a commit to erickt/rust that referenced this pull request Apr 14, 2026
…=lcnr"

This reverts commit 1f7f8ea, reversing
changes made to 8b86f48.
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. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

10 participants