Add arg splat experiment initial tuple impl#153697
Conversation
|
r? @JohnTitor rustbot has assigned @JohnTitor. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
|
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? |
|
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 |
89102bf to
c784a57
Compare
c784a57 to
2d9e563
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
The reflection data structures are tied exactly to the implementation cc @oli-obk |
There was a problem hiding this comment.
This should be ready for another review.
I've rebased this on the latest main, trying to minimise the number of rebase changes to earlier commits. The rebase was tricky, so there are some fixes which should be squashed into earlier commits, and some code might not quite be in the nicest/clearest commit.
The last 5 commits are revisions from the latest reviews, the detailed commit message says which commit they revise.
| /// Which function argument is splatted into multiple arguments in callers, if any? | ||
| /// Splatting functions with `u16::MAX` arguments is not supported, see `FnSigKind` for | ||
| /// details. | ||
| splatted: u16, |
There was a problem hiding this comment.
It might make the compiler faster to limit it to 256 arguments, I wonder if that would break any code.
At least we test for u16::MAX arguments. It used to panic, see #88577.
| splatted: Option<u16>, | ||
| args_len: usize, | ||
| ) -> Result<Self, SplattedArgIndexError> { | ||
| if let Some(splatted_arg_index) = splatted { |
There was a problem hiding this comment.
Yeah, I wasn't sure about this either.
I felt like having the option was clearer in callers, and tried to keep the sentinel value as an internal implementation detail which never appears outside the low-level bit-packing code. That way, providing u16::MAX as the splatted argument is easy to error on.
But I don't mind dropping the option, it's unlikely this case will be encountered in practice.
What do you think?
| let ocx_error = | ||
| ocx.eq(&origin, self.param_env, calee_tuple_type, new_tupled_type); | ||
| if let Err(ocx_error) = ocx_error { | ||
| struct_span_code_err!( |
There was a problem hiding this comment.
I'm not sure if it's reachable, and I don't know how to create a test for this. It seems like other errors happen first, but there might be a way to trigger it. I left a FIXME in the code.
I made a bunch of related fixes and tests while trying to test this:
- fixed some invalid method splatted
selfargument handling which resulted in an ICE (there's a test for it now) - cleaned up some unnecessary diagnostic function arguments
- some error messages were outdated (splat is supported on any argument) so I updated them
- use the argument span in some error messages, rather than using the argument number
- add tests for generics that might be tuples, and for unresolvable/ambiguous types
This comment has been minimized.
This comment has been minimized.
|
@rustbot ready |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
6b05355 to
881fb4b
Compare
|
Just some rust-analyzer refactors, so I needed to move splat FIXME comments into the new refactored code. |
This comment has been minimized.
This comment has been minimized.
fixup! Add splat builtin attribute & feature gate
fixup! Add AST validation for #[splat]
fixup! Add HIR FnDecl for #[splat]
fixup! Impl HIR typeck for #[splat]
fixup! Impl TypeInfo for splat
881fb4b to
0e4aed3
Compare
|
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. |
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:
splatincomplete feature gate#[splat]attribute on function arguments#[splat]function parameter check at THIR levelOnce this PR merges, we can add further functionality, then test it out in interop tools.
Further Work
Out of Scope for this PR