diff options
| author | bors <bors@rust-lang.org> | 2023-09-12 09:02:27 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-09-12 09:02:27 +0000 |
| commit | cc7a9d69729c9710c01cb70b864e664659626674 (patch) | |
| tree | 1d987a672d6305a67f8b1ad9591286f859362af1 /compiler/rustc_const_eval/src/interpret | |
| parent | deb708af12ea5dfa10539f2d1592d289f7a92dc9 (diff) | |
| parent | 6984030f80facdda72dd81c209fa19d1e830988e (diff) | |
| download | rust-cc7a9d69729c9710c01cb70b864e664659626674.tar.gz rust-cc7a9d69729c9710c01cb70b864e664659626674.zip | |
Auto merge of #115705 - cjgillot:const-prop-aggregate, r=oli-obk
Read from non-scalar constants and statics in dataflow const-prop DataflowConstProp is designed to handle scalar values. When MIR features an assignment from a non-scalar constant, we need to manually decompose it into the custom state space. This PR tweaks interpreter callbacks to allow reusing `eval_mir_constant` without having a stack frame to get a span from. r? `@oli-obk` cc `@jachris`
Diffstat (limited to 'compiler/rustc_const_eval/src/interpret')
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/discriminant.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/intrinsics.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/step.rs | 2 |
3 files changed, 6 insertions, 5 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/discriminant.rs b/compiler/rustc_const_eval/src/interpret/discriminant.rs index 6c35fb01a93..440ee06e7fe 100644 --- a/compiler/rustc_const_eval/src/interpret/discriminant.rs +++ b/compiler/rustc_const_eval/src/interpret/discriminant.rs @@ -247,9 +247,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { &self, layout: TyAndLayout<'tcx>, variant: VariantIdx, - ) -> InterpResult<'tcx, Scalar<M::Provenance>> { + ) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>> { let discr_layout = self.layout_of(layout.ty.discriminant_ty(*self.tcx))?; - Ok(match layout.ty.discriminant_for_variant(*self.tcx, variant) { + let discr_value = match layout.ty.discriminant_for_variant(*self.tcx, variant) { Some(discr) => { // This type actually has discriminants. assert_eq!(discr.ty, discr_layout.ty); @@ -260,6 +260,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { assert_eq!(variant.as_u32(), 0); Scalar::from_uint(variant.as_u32(), discr_layout.size) } - }) + }; + Ok(ImmTy::from_scalar(discr_value, discr_layout)) } } diff --git a/compiler/rustc_const_eval/src/interpret/intrinsics.rs b/compiler/rustc_const_eval/src/interpret/intrinsics.rs index 7feed74ceae..3b58f66353b 100644 --- a/compiler/rustc_const_eval/src/interpret/intrinsics.rs +++ b/compiler/rustc_const_eval/src/interpret/intrinsics.rs @@ -222,7 +222,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let place = self.deref_pointer(&args[0])?; let variant = self.read_discriminant(&place)?; let discr = self.discriminant_for_variant(place.layout, variant)?; - self.write_scalar(discr, dest)?; + self.write_immediate(*discr, dest)?; } sym::exact_div => { let l = self.read_immediate(&args[0])?; diff --git a/compiler/rustc_const_eval/src/interpret/step.rs b/compiler/rustc_const_eval/src/interpret/step.rs index 57f99bd8f61..cf1f7ff75e1 100644 --- a/compiler/rustc_const_eval/src/interpret/step.rs +++ b/compiler/rustc_const_eval/src/interpret/step.rs @@ -301,7 +301,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let op = self.eval_place_to_op(place, None)?; let variant = self.read_discriminant(&op)?; let discr = self.discriminant_for_variant(op.layout, variant)?; - self.write_scalar(discr, &dest)?; + self.write_immediate(*discr, &dest)?; } } |
