Don't compute FnAbi for LLVM intrinsics - #160077
Conversation
|
Some changes occurred to the CTFE machinery These commits modify compiler targets. Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri |
|
|
|
I guess this finishes my quest of getting rid of
There is still cleanup that can be done, but at least this wildly wrong combination is gone. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| func: OpTy<'tcx, M::Provenance>, | ||
| callee: FnVal<'tcx, M::ExtraFnVal>, |
There was a problem hiding this comment.
This introduces redundancy (func and callee conceptually contain the same data). So I am not a fan of this.
What's the rationale for these non-trivial interpreter changes? I would understand making the fn_abi field an Option for calls that don't need an ABI, but this goes much beyond that it seems, by entirely removing fn_abi (and fn_sig).
There was a problem hiding this comment.
I could replace the func field with just the Ty. Making fn_abi optional would mean I did have to match on the instance inside eval_callee_and_args and do an unwrap outside of it. I can do it if you prefer it that way.
There was a problem hiding this comment.
I could replace the func field with just the Ty
That would be better, albeit still a bit odd.
Making fn_abi optional would mean I did have to match on the instance inside eval_callee_and_args and do an unwrap outside of it. I can do it if you prefer it that way.
Well I don't even know yet why you need to change all those other things. I could reverse engineer it from your PR but it'd be easier if you just explained it to me.
There was a problem hiding this comment.
The reason I need this change is because I made calculating the FnAbi for LLVM intrinsics panic and eval_callee_and_args is also called for LLVM intrinsics, so eval_callee_and_args must avoid computing the FnAbi for LLVM intrinsics at least.
There was a problem hiding this comment.
Making fn_abi optional would mean I did have to match on the instance inside eval_callee_and_args and do an unwrap outside of it. I can do it if you prefer it that way.
I feel like that would result in a much smaller diff?
Maybe it could even be an Either<FnAbi, T> where T is whatever information we need to invoke the intrinsic (DefId?).
There was a problem hiding this comment.
Making fn_abi optional would mean I did have to match on the instance inside eval_callee_and_args and do an unwrap outside of it. I can do it if you prefer it that way.
Wasn't too bad actually. Does it look fine to you?
This comment has been minimized.
This comment has been minimized.
| fn test_f32x2(a: f32x2); | ||
| fn test_f32x2_arr(a: f32x2); | ||
| fn test_simd(a: Simd<i32, 4>); | ||
| fn test_simd_unaligned(a: Simd<i32, 3>); |
There was a problem hiding this comment.
There is no way to test this specific case anymore it seems. LLVM doesn't accept PackedSimd on intrinsics, extern "unadjusted" requires LLVM intrinsics and any other ABI doesn't pass non-power-of-2 vectors as { [3 x i32] }.
7358ce7 to
eacedff
Compare
|
Looks like compiler-builtins still has some |
ef2938a to
e2873a0
Compare
|
cc @tgross35 |
There was a problem hiding this comment.
interpreter changes mostly LGTM.
compiler-builtins changes will need a review by @tgross35 .
| } | ||
| ty::FnDef(def_id, args) => { | ||
| let instance = self.resolve(def_id, args.no_bound_vars().unwrap())?; | ||
| // Don't compute FnAbi for LLVM intrinsics. Trying to that would panic. |
There was a problem hiding this comment.
| // Don't compute FnAbi for LLVM intrinsics. Trying to that would panic. | |
| // Don't compute FnAbi for LLVM intrinsics. Trying to do that would panic. | |
| // Rust intrinsics however *do* need a FnAbi as we may invoke the | |
| // fallback body like a regular function. |
| @ ty::Instance { def: ty::InstanceKind::LlvmIntrinsic(_), args: _ }, | ||
| ) => { | ||
| // FIXME: Should `InPlace` arguments be reset to uninit? | ||
| M::call_llvm_intrinsic( |
There was a problem hiding this comment.
init_fn_call already has an LlvmIntrinsic case, this seems to duplicate that?
You can make init_fn_call take an Option<&FnAbi> as well.
| DUMMY_SP, | ||
| ); | ||
| if let InstanceKind::LlvmIntrinsic(..) = instance.def { | ||
| return; |
There was a problem hiding this comment.
| return; | |
| // LLVM intrinsics don't have an ABI, so there is nothing to check. | |
| return; |
| abi, | ||
| ExternAbi::Unadjusted, | ||
| "fn_abi_of_instance should not be called on LLVM intrinsics" | ||
| ); |
There was a problem hiding this comment.
It's kind of annoying that this panics and hence everyone has to carefully tiptoe around it. Can't we treat this more like Rust intrinsics where we can compute an ABI but it just doesn't matter?
| @@ -1,19 +1,21 @@ | |||
| // Make sure that no 0-sized padding is inserted in structs and that | |||
| // structs are represented as expected by Neon intrinsics in LLVM. | |||
| // See #87254. | |||
| //@ only-aarch64 | |||
There was a problem hiding this comment.
This test is now impossible to run for the majority of contributors (that are on x86).
Please remove the only and add --target and minicore so everyone can run the test.
They don't have a sensible FnAbi, so the fact that we still compute an FnAbi for them requires us to make the ABI sanity check more lenient than it should be.
r? @RalfJung as all non-trivial changes are in Miri