Fix splat ICEs and ban it in closures#158645
Conversation
|
r? @folkertdev rustbot has assigned @folkertdev. Use Why was this reviewer chosen?The reviewer was selected based on:
|
| (*fn_ptr)(1u32, 2i8); | ||
| let fn_pp: *const fn(#[splat] (u32, i8)) = tuple_args as *const fn(#[splat] (u32, i8)); | ||
| (*fn_pp)(1, 2); | ||
| (*fn_pp)(1u32, 2i8); |
There was a problem hiding this comment.
I'd expect this to need unsafe, you are reading from a raw pointer.
There was a problem hiding this comment.
I think it ICEs before the unsafe check, due to the lines above panicking. I can split the test to make that clearer.
| } | ||
|
|
||
| if !splatted_arg_indexes.is_empty() { | ||
| if let SplatSemantic::NoClosures(closure_span) = splat_semantic { |
There was a problem hiding this comment.
why is this not a match (together with the other if let below)?
| Extern::Explicit(abi_str, span) | ||
| if abi_str.symbol_unescaped.as_str() == "rust-call" => | ||
| { | ||
| SplatSemantic::NoRustCall(span) | ||
| } | ||
| Extern::Explicit(_abi_str, _span) => SplatSemantic::Yes, |
There was a problem hiding this comment.
| Extern::Explicit(abi_str, span) | |
| if abi_str.symbol_unescaped.as_str() == "rust-call" => | |
| { | |
| SplatSemantic::NoRustCall(span) | |
| } | |
| Extern::Explicit(_abi_str, _span) => SplatSemantic::Yes, | |
| Extern::Explicit(abi_str, span) => match abi_str.symbol_unescaped { | |
| sym::rust_dash_call => SplatSemantic::NoRustCall(span), | |
| _ => SplatSemantic::Yes, | |
| }, |
There was a problem hiding this comment.
and add a comment on why here too perhaps?
| // FIXME(splat): should splatting extern "C" fns be allowed? | ||
| Extern::Implicit(_) => SplatSemantic::Yes, |
There was a problem hiding this comment.
well extern "C" probably yes? but for most other extern "CC"s probably not actually? Anyhow, not for this PR.
There was a problem hiding this comment.
I'll add this to the tracking issue as an unresolved questiom
|
Reminder, once the PR becomes ready for a review, use |
This comment has been minimized.
This comment has been minimized.
| LL | dyn_asref_splat(&s); | ||
| | ^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| error[E0277]: cannot use splat attribute; the splatted argument type must be a tuple or unit, not a Trait(std::convert::AsRef<(u8 |
There was a problem hiding this comment.
The tuple case (AsRef<(u8, f32)>) renders truncated Trait(std::convert::AsRef<(u8 with no closing , f32)>). Is this expected, or a bug in how the diagnostic formats tuple types?
There was a problem hiding this comment.
That's a bug in my normalisation regex, which stops at the first comma, rather than looking for the next field name or balanced brackets
https://github.com/rust-lang/rust/pull/158645/changes#diff-1ba06a0d11ba6d51fa60caa4eb9589af26fe6e4abc458b03ff1d96d40d444c06R8
|
The job Click to see the possible cause of the failure (guessed by this bot) |
There was a problem hiding this comment.
A first pass. Overall this PR seems kind of large, it would be easier to review if split up into smaller chunks.
Yeah I wondered about that, I'll split it up today, now I know which parts actually fail in CI.
@rustbot label +F-splat +I-ICE +T-compiler +C-bug
| // FIXME(splat): should splatting extern "C" fns be allowed? | ||
| Extern::Implicit(_) => SplatSemantic::Yes, |
There was a problem hiding this comment.
I'll add this to the tracking issue as an unresolved questiom
| (*fn_ptr)(1u32, 2i8); | ||
| let fn_pp: *const fn(#[splat] (u32, i8)) = tuple_args as *const fn(#[splat] (u32, i8)); | ||
| (*fn_pp)(1, 2); | ||
| (*fn_pp)(1u32, 2i8); |
There was a problem hiding this comment.
I think it ICEs before the unsafe check, due to the lines above panicking. I can split the test to make that clearer.
| LL | dyn_asref_splat(&s); | ||
| | ^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| error[E0277]: cannot use splat attribute; the splatted argument type must be a tuple or unit, not a Trait(std::convert::AsRef<(u8 |
There was a problem hiding this comment.
That's a bug in my normalisation regex, which stops at the first comma, rather than looking for the next field name or balanced brackets
https://github.com/rust-lang/rust/pull/158645/changes#diff-1ba06a0d11ba6d51fa60caa4eb9589af26fe6e4abc458b03ff1d96d40d444c06R8
This PR is part of the splat lang experiment #153629.
It fixes one ICE, and cleans up the surrounding error handling to avoid future ICEs:
Close #158482
Improves the message and error handling in another ICE (but doesn't fix it):
cc #158603
And bans splat on closures and rust-call, because they already de-tuple arguments:
Close #158605
In the process I discovered another symbol mangling bug with splatting, which I added a test for (but didn't fix yet):
cc #158644
This test might be flaky, I'll drop it from this PR if it fails in CI.