Unnamed repository; edit this file 'description' to name the repository.
Rollup merge of #153697 - teor2345:fn-arg-splat-experiment, r=oli-obk
Add arg splat experiment initial tuple impl
### Description
This PR is part of the argument splatting lang experiment, and FFI overloading / C++ interop project goals:
- https://github.com/rust-lang/rust/issues/153629
- https://rust-lang.github.io/rust-project-goals/2026/overloading-for-ffi.html
- https://rust-lang.github.io/rust-project-goals/2025h2/interop-problem-map.html
Example code using existing unstable features:
- https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=f42a3754a63a3d9365670e57257053d5
Discussion of implementation strategy:
- [#t-lang > On overloading @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/213817-t-lang/topic/On.20overloading/near/579590336)
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](https://github.com/rust-lang/rust/pull/158251#issuecomment-4771006751).
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 rust-lang/rust#155223 - [0.3% perf improvement across 45 primary benchmarks](https://github.com/rust-lang/rust/pull/155223#issuecomment-4257477836). 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
| -rw-r--r-- | crates/hir-ty/src/infer/callee.rs | 2 | ||||
| -rw-r--r-- | crates/hir-ty/src/lib.rs | 1 | ||||
| -rw-r--r-- | crates/hir-ty/src/lower.rs | 1 | ||||
| -rw-r--r-- | crates/hir-ty/src/next_solver/interner.rs | 1 | ||||
| -rw-r--r-- | crates/hir-ty/src/next_solver/ty.rs | 1 |
5 files changed, 6 insertions, 0 deletions
diff --git a/crates/hir-ty/src/infer/callee.rs b/crates/hir-ty/src/infer/callee.rs index 057ba7fa86..a661731e60 100644 --- a/crates/hir-ty/src/infer/callee.rs +++ b/crates/hir-ty/src/infer/callee.rs @@ -173,6 +173,8 @@ impl<'db> InferenceContext<'_, 'db> { // impl forces the closure kind to `FnOnce` i.e. `u8`. let kind_ty = autoderef.ctx().table.next_ty_var(call_expr.into()); let interner = autoderef.ctx().interner(); + + // Ignore splatting, it is unsupported on closures. let call_sig = interner.mk_fn_sig( [coroutine_closure_sig.tupled_inputs_ty], coroutine_closure_sig.to_coroutine( diff --git a/crates/hir-ty/src/lib.rs b/crates/hir-ty/src/lib.rs index cc48ba06db..1fddfc09c6 100644 --- a/crates/hir-ty/src/lib.rs +++ b/crates/hir-ty/src/lib.rs @@ -464,6 +464,7 @@ pub fn callable_sig_from_fn_trait<'db>( args.tuple_fields(), ret, false, + // FIXME(splat): handle splatted arguments Safety::Safe, ExternAbi::Rust, )); diff --git a/crates/hir-ty/src/lower.rs b/crates/hir-ty/src/lower.rs index fae63ddc2d..d63ac7f7a0 100644 --- a/crates/hir-ty/src/lower.rs +++ b/crates/hir-ty/src/lower.rs @@ -637,6 +637,7 @@ impl<'db, 'a> TyLoweringContext<'db, 'a> { fn_.abi, if fn_.is_unsafe { Safety::Unsafe } else { Safety::Safe }, fn_.is_varargs, + // FIXME(splat): handle splatted arguments ), inputs_and_output: Tys::new_from_slice(&args), }), diff --git a/crates/hir-ty/src/next_solver/interner.rs b/crates/hir-ty/src/next_solver/interner.rs index ef626fc0c8..3c2976eccd 100644 --- a/crates/hir-ty/src/next_solver/interner.rs +++ b/crates/hir-ty/src/next_solver/interner.rs @@ -2238,6 +2238,7 @@ impl<'db> DbInterner<'db> { self.replace_escaping_bound_vars_uncached(value.skip_binder(), delegate) } + // FIXME: add splat support when the experiment is complete pub fn mk_fn_sig<I>( self, inputs: I, diff --git a/crates/hir-ty/src/next_solver/ty.rs b/crates/hir-ty/src/next_solver/ty.rs index fe31d44207..d57d824e32 100644 --- a/crates/hir-ty/src/next_solver/ty.rs +++ b/crates/hir-ty/src/next_solver/ty.rs @@ -1514,6 +1514,7 @@ impl<'db> DbInterner<'db> { TyKind::Tuple(params) => params, _ => panic!(), }; + // Ignore splatting, it is unsupported on closures. self.mk_fn_sig(params, s.output(), s.c_variadic(), safety, ExternAbi::Rust) }) } |