Skip to content

delegation: support Self mapping adjustments for non-first arguments#158945

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
aerooneqq:delegation-adjustments-for-mapped-arguments
Jul 11, 2026
Merged

delegation: support Self mapping adjustments for non-first arguments#158945
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
aerooneqq:delegation-adjustments-for-mapped-arguments

Conversation

@aerooneqq

@aerooneqq aerooneqq commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

View all comments

This PR implements initial version of Self mapping adjustments of all arguments that are needed to be mapped. The method probing routine is reused in order to find adjustments for each mapped argument, then they are processed in the same way the receiver is processed in delegation. The current solution is a bit hacky, explained in the comment:

/// Hack for applying method probing routine for arbitrary types
/// in order to get adjustments as if they were at receiver position.
/// Used only for delegation's `Self` arguments mapping.
/// FIXME(fn_delegation): now this hack is used, however in perfect world
/// we would like to separate adjustments finding logic from probe context,
/// if we do so we will be able to find wanted adjustments given only two
/// types without reusing the whole method probing routine

The next part of Self mapping is to support heuristics to map complex return types: Self -> Box<Arc<Self>>.

Part of #118212.
r? @petrochenkov

@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 Jul 8, 2026
@aerooneqq

Copy link
Copy Markdown
Contributor Author

Maybe need to run perf, as non-delegation code was modified.

@aerooneqq aerooneqq changed the title delegation: support Self mapping for non-receiver arguments delegation: support Self mapping for non-receiver arguments Jul 8, 2026
@aerooneqq
aerooneqq force-pushed the delegation-adjustments-for-mapped-arguments branch from 88b00af to 78083a0 Compare July 8, 2026 06:48
@aerooneqq aerooneqq changed the title delegation: support Self mapping for non-receiver arguments delegation: support Self mapping adjustments for non-receiver arguments Jul 8, 2026
@petrochenkov petrochenkov added the F-fn_delegation `#![feature(fn_delegation)]` label Jul 9, 2026
Comment thread compiler/rustc_hir/src/hir.rs Outdated
Comment thread compiler/rustc_ast_lowering/src/delegation/resolution.rs Outdated
Comment thread compiler/rustc_hir_typeck/src/method/probe.rs Outdated
Comment thread compiler/rustc_hir_typeck/src/callee.rs
Comment thread compiler/rustc_hir_typeck/src/callee.rs Outdated
@petrochenkov

Copy link
Copy Markdown
Contributor

Maybe need to run perf, as non-delegation code was modified.

All the extra logic that I see happens only for delegation (i.e. after get_info_for_method_call_adjustments succeeds), but let's do the perf run anyway.
@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 Jul 9, 2026
rust-bors Bot pushed a commit that referenced this pull request Jul 9, 2026
…rguments, r=<try>

delegation: support `Self` mapping adjustments for non-receiver arguments
@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 9, 2026
@rust-bors

rust-bors Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: f318c88 (f318c880dcc1b70824f62b9d6963ecc60c301024)
Base parent: 561ea2b (561ea2bfa3022226082e2db39d6ccb241e9e34bc)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (f318c88): comparison URL.

Overall result: ❌ regressions - 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.2% [0.2%, 0.3%] 2
Regressions ❌
(secondary)
0.4% [0.2%, 1.5%] 8
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.2% [0.2%, 0.3%] 2

Max RSS (memory usage)

Results (primary 2.7%, secondary 5.9%)

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

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

Cycles

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

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.6% [3.6%, 3.6%] 1
Improvements ✅
(primary)
-2.3% [-2.4%, -2.1%] 2
Improvements ✅
(secondary)
-2.5% [-2.8%, -2.2%] 2
All ❌✅ (primary) -2.3% [-2.4%, -2.1%] 2

Binary size

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

Bootstrap: 489.147s -> 488.401s (-0.15%)
Artifact size: 388.47 MiB -> 388.91 MiB (0.11%)

@petrochenkov

Copy link
Copy Markdown
Contributor

The perf changes are acceptable, if we couldn't add a single option.is_some() condition, then we wouldn't be able to do anything.

@petrochenkov petrochenkov removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 10, 2026
@petrochenkov

Copy link
Copy Markdown
Contributor

@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 Jul 10, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jul 10, 2026
…rguments, r=<try>

delegation: support `Self` mapping adjustments for non-receiver arguments
@aerooneqq aerooneqq changed the title delegation: support Self mapping adjustments for non-receiver arguments delegation: support Self mapping adjustments for non-first arguments Jul 10, 2026
@rust-bors

rust-bors Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 2d30a6e (2d30a6e17fcf4158ee8a77580f3eb0d83ad1967c)
Base parent: cb014fc (cb014fcb149e44d8aa16a8f66c9f2b1762f034f8)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (2d30a6e): comparison URL.

Overall result: no relevant changes - 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

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

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)
3.1% [2.0%, 4.1%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Cycles

Results (primary -6.8%, secondary -2.2%)

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

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

Bootstrap: 490.017s -> 490.247s (0.05%)
Artifact size: 389.92 MiB -> 389.99 MiB (0.02%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 10, 2026
@aerooneqq

Copy link
Copy Markdown
Contributor Author

Nice.
@bors squash
@rustbot ready

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 10, 2026
@rust-bors

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 10, 2026
* delegation: support `Self` mapping for non-receiver arguments
* Review: do not allocate `FxIndexSet` on arena, remove unnecessary derives
* Review: remove ast:: prefix
* Review: `r#override` -> `self_ty_override`
* Review: rename `receiver` to `first_arg`
* Perf fix attempt
@rust-bors

rust-bors Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

🔨 6 commits were squashed into aa2eb97.

@rust-bors
rust-bors Bot force-pushed the delegation-adjustments-for-mapped-arguments branch from b5c4436 to aa2eb97 Compare July 10, 2026 16:21
@petrochenkov

Copy link
Copy Markdown
Contributor

@bors r+

@rust-bors

rust-bors Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

📌 Commit aa2eb97 has been approved by petrochenkov

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 Jul 10, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jul 10, 2026
…rguments, r=petrochenkov

delegation: support `Self` mapping adjustments for non-first arguments



This PR implements initial version of Self mapping adjustments of all arguments that are needed to be mapped. The method probing routine is reused in order to find adjustments for each mapped argument, then they are processed in the same way the receiver is processed in delegation. The current solution is a bit hacky, explained in the comment:
```rust
/// Hack for applying method probing routine for arbitrary types
/// in order to get adjustments as if they were at receiver position.
/// Used only for delegation's `Self` arguments mapping.
/// FIXME(fn_delegation): now this hack is used, however in perfect world
/// we would like to separate adjustments finding logic from probe context,
/// if we do so we will be able to find wanted adjustments given only two
/// types without reusing the whole method probing routine
```

The next part of Self mapping is to support heuristics to map complex return types: `Self` -> `Box<Arc<Self>>`.

Part of #118212.
r? @petrochenkov
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job dist-i586-gnu-i586-i686-musl failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
test [debuginfo-gdb] tests/debuginfo/zst-interferes-with-prologue.rs ... ok

failures:

---- [debuginfo-gdb] tests/debuginfo/function-call.rs stdout ----
NOTE: compiletest thinks it is using GDB version 12001000
------gdb stdout------------------------------
GNU gdb (Ubuntu 12.1-0ubuntu1~22.04.2) 12.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
Breakpoint 1 at 0x804f582: file /checkout/tests/debuginfo/function-call.rs, line 36.

Breakpoint 1, function_call::main () at /checkout/tests/debuginfo/function-call.rs:36
36     zzz(); // #break

------gdb stderr------------------------------
/checkout/obj/build/x86_64-unknown-linux-gnu/test/debuginfo/function-call.gdb/function-call.debugger.script:11: Error in sourced command file:
Couldn't write extended state status: Bad address.

------------------------------------------

error: gdb failed to execute
status: exit status: 1
command: PYTHONPATH="/checkout/src/etc" "/usr/bin/gdb" "-quiet" "-batch" "-nx" "-command=/checkout/obj/build/x86_64-unknown-linux-gnu/test/debuginfo/function-call.gdb/function-call.debugger.script"
--- stdout -------------------------------
GNU gdb (Ubuntu 12.1-0ubuntu1~22.04.2) 12.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
Breakpoint 1 at 0x804f582: file /checkout/tests/debuginfo/function-call.rs, line 36.

Breakpoint 1, function_call::main () at /checkout/tests/debuginfo/function-call.rs:36
36     zzz(); // #break
------------------------------------------
--- stderr -------------------------------
/checkout/obj/build/x86_64-unknown-linux-gnu/test/debuginfo/function-call.gdb/function-call.debugger.script:11: Error in sourced command file:
Couldn't write extended state status: Bad address.
------------------------------------------

@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 Jul 11, 2026
@rust-bors

rust-bors Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

💔 Test for f82aa26 failed: CI. Failed job:

@JonathanBrouwer

Copy link
Copy Markdown
Contributor

@bors retry

@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 Jul 11, 2026
@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 Jul 11, 2026
@rust-bors

rust-bors Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

☀️ Test successful - CI
Approved by: petrochenkov
Duration: 3h 13m 21s
Pushing acf6a00 to main...

@rust-bors
rust-bors Bot merged commit acf6a00 into rust-lang:main Jul 11, 2026
14 checks passed
@rustbot rustbot added this to the 1.99.0 milestone Jul 11, 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 3b58636 (parent) -> acf6a00 (this PR)

Test differences

Show 49 test diffs

49 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 acf6a00aff5d8aa8892aadff0b48364b50f97cf4 --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-gnu-gcc-core-tests: 8m 40s -> 14m 12s (+63.8%)
  2. dist-s390x-linux: 1h -> 1h 27m (+45.8%)
  3. i686-gnu-1: 1h 40m -> 2h 24m (+44.0%)
  4. x86_64-gnu-llvm-22-1: 42m 54s -> 1h 1m (+42.5%)
  5. dist-loongarch64-linux: 1h 46m -> 1h 10m (-33.9%)
  6. dist-x86_64-illumos: 1h 23m -> 1h 49m (+32.3%)
  7. dist-x86_64-llvm-mingw: 1h 31m -> 1h 59m (+30.7%)
  8. dist-x86_64-mingw: 1h 55m -> 2h 28m (+28.7%)
  9. pr-check-1: 28m 1s -> 35m 52s (+28.0%)
  10. arm-android: 1h 23m -> 1h 46m (+27.8%)
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
Copy Markdown
Collaborator

Finished benchmarking commit (acf6a00): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

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

Max RSS (memory usage)

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

Cycles

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

Binary size

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

Bootstrap: 490.631s -> 489.809s (-0.17%)
Artifact size: 389.34 MiB -> 389.31 MiB (-0.01%)

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

Labels

F-fn_delegation `#![feature(fn_delegation)]` 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants