Skip to content

Add arg splat experiment initial tuple impl#153697

Open
teor2345 wants to merge 12 commits into
rust-lang:mainfrom
teor2345:fn-arg-splat-experiment
Open

Add arg splat experiment initial tuple impl#153697
teor2345 wants to merge 12 commits into
rust-lang:mainfrom
teor2345:fn-arg-splat-experiment

Conversation

@teor2345

@teor2345 teor2345 commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

Description

View all comments

This PR is part of the argument splatting lang experiment, and FFI overloading / C++ interop project goals:

Example code using existing unstable features:

Discussion of implementation strategy:

The PR is the initial implementation of the feature:

  • splat incomplete feature gate
  • #[splat] attribute on function arguments
  • Splatted function argument TypeInfo
  • #[splat] function parameter check at THIR level
  • splatted MIR lowering (as tupled arguments)
  • feature gate and UI tests for item type filtering, non-splattable arguments, splattable tuples, generics, and the "overloading at home" example
    • about half the diff (1100 lines) is tests and test output

Once this PR merges, we can add further functionality, then test it out in interop tools.

Perf Impact

We expect a 0.1% regression on 5 primary and 0.2% regression on 4 secondary benchmarks in this PR, based on this perf run.

We tried a number of different ways to improve perf. Limiting splat to the 255th or lower argument is a simple hack that gives good perf, and is good enough for an experiment.

This PR series already has significant perf wins in #155223 - 0.3% perf improvement across 45 primary benchmarks. We're spending a small amount of that perf for the new feature in this PR.

Out of Scope for this PR

  • Change codegen to de-tuple caller and callee
  • Better diagnostics
  • Full support for splatted function pointer arguments

@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. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 11, 2026
@rustbot

rustbot commented Mar 11, 2026

Copy link
Copy Markdown
Collaborator

r? @JohnTitor

rustbot has assigned @JohnTitor.
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: compiler
  • compiler expanded to 69 candidates
  • Random selection from 16 candidates

@rust-log-analyzer

This comment has been minimized.

Comment thread compiler/rustc_builtin_macros/src/splat.rs Outdated
@JohnTitor

Copy link
Copy Markdown
Member

It should be better for someone on https://rust-lang.zulipchat.com/#narrow/channel/213817-t-lang/topic/On.20overloading/with/573924937 to review this, @oli-obk could you take over?

@oli-obk oli-obk assigned oli-obk and unassigned JohnTitor Mar 11, 2026
@oli-obk oli-obk added the S-blocked Status: Blocked on something else such as an RFC or other implementation work. label Mar 12, 2026
@oli-obk

oli-obk commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

Let's wait for the ongoing discussion on Zulip to figure out whether we need to have a proc macro, an AST manipulating attribute (like define_opaque), or just a normal attribute

@teor2345 teor2345 marked this pull request as draft March 13, 2026 06:49
@rustbot rustbot 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 Mar 13, 2026
@teor2345 teor2345 force-pushed the fn-arg-splat-experiment branch from 89102bf to c784a57 Compare March 16, 2026 07:35
@rustbot rustbot added the A-attributes Area: Attributes (`#[…]`, `#![…]`) label Mar 16, 2026
Comment thread compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs Outdated
Comment thread compiler/rustc_hir/src/target.rs
Comment thread tests/ui/splat/splat-non-function.rs Outdated
@teor2345 teor2345 force-pushed the fn-arg-splat-experiment branch from c784a57 to 2d9e563 Compare March 20, 2026 01:37
@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) labels Mar 20, 2026
@teor2345

This comment was marked as outdated.

@rust-log-analyzer

This comment has been minimized.

teor2345

This comment was marked as resolved.

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added the T-clippy Relevant to the Clippy team. label Mar 20, 2026
@rustbot

This comment has been minimized.

@JonathanBrouwer

Copy link
Copy Markdown
Contributor

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rust-bors

rust-bors Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 2bd9dab (2bd9dab3bd10849e2abc3a5cc97c04adf523e7da)
Base parent: 9639eef (9639eefc07db282b25e9c83cdfebb10688ed5114)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (2bd9dab): 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.1%, 0.2%] 14
Regressions ❌
(secondary)
0.3% [0.2%, 0.4%] 26
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.2% [0.1%, 0.2%] 14

Max RSS (memory usage)

Results (primary 4.1%, secondary 3.0%)

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

mean range count
Regressions ❌
(primary)
4.1% [2.1%, 7.4%] 3
Regressions ❌
(secondary)
3.0% [2.4%, 3.9%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 4.1% [2.1%, 7.4%] 3

Cycles

Results (secondary 5.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)
5.6% [3.1%, 7.1%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

Results (primary 0.1%, 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.2%] 80
Regressions ❌
(secondary)
0.1% [0.0%, 0.7%] 62
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.1% [0.0%, 0.2%] 80

Bootstrap: 482.613s -> 483.026s (0.09%)
Artifact size: 390.75 MiB -> 390.78 MiB (0.01%)

@rustbot

This comment has been minimized.

@teor2345

Copy link
Copy Markdown
Contributor Author

Perf Update

We expect a 0.1% regression on 5 primary and 0.2% regression on 4 secondary benchmarks in this PR, based on this perf run.

We tried a number of different ways to improve perf. Limiting splat to the 255th or lower argument is a simple hack that gives good perf, and is good enough for an experiment.

This PR series already has significant perf wins in #155223 - 0.3% perf improvement across 45 primary benchmarks. We're spending a small amount of that perf for the new feature in this PR.

@rustbot ready

@teor2345

Copy link
Copy Markdown
Contributor Author

Umm?

@rustbot reviewer

@rust-log-analyzer

This comment has been minimized.

And remove redundant const fn
@rustbot

rustbot commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Comment thread compiler/rustc_symbol_mangling/src/v0.rs Outdated
Comment thread compiler/rustc_hir/src/hir.rs
Comment thread compiler/rustc_hir/src/hir.rs
Comment thread compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
Comment thread compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs Outdated
Comment thread compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs Outdated
Comment thread compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs Outdated
None => {
if !tuple_arguments.is_splatted() {
// FIXME(splat): when the arg is splatted, adjust its index
use_splat_fallback = true;

@oli-obk oli-obk Jun 23, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

how does this case happen?

View changes since the review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

does it only happen in error cases?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I expanded these comments to clarify it's only for better error handling

Comment thread compiler/rustc_type_ir/src/ty_kind.rs Outdated

let tupled_args = Expr {
ty: Ty::new_tup_from_iter(tcx, tupled_arg_tys),
temp_scope_id: method.temp_scope_id,

@oli-obk oli-obk Jun 23, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

except for this line, everything leading up to it is 100% equivalent to the function call logic, pull everything into a method and add a flag/enum to make the differences clear (and pass in the receiver as an option, then you can just chain all the pieces together and collect them)

View changes since the review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

wait actually even this is equivalent, just loading the same id via different means. so yea, it should just be the receiver that's the difference?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah the receiver is optional, and it determines:

  • the temp_scope_id
  • the start of the args list (receiver or just function args)
  • the generated call span

The segment was only used for debugging in a span bug, so I removed it.

@teor2345 teor2345 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review, I'll try to make this changes later today

View changes since this review

Comment thread compiler/rustc_hir/src/hir.rs
Comment thread compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
Comment thread compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs Outdated
Comment thread compiler/rustc_type_ir/src/ty_kind.rs Outdated
@teor2345

Copy link
Copy Markdown
Contributor Author

I pushed some fixups for each comment, and resolved the comments that seemed trivial or straightforward.
Each fixup commit message has a second line explaining what it fixes, they're roughly in review comment order.

@rustbot ready

@oli-obk oli-obk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

r=me with history fixed up

View changes since this review

@teor2345

Copy link
Copy Markdown
Contributor Author

Fixups squashed, including an extra fix that deletes a redundant UI test comment and some whitespace:
d9a9b94

@rustbot ready

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

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) perf-regression Performance regression. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.