@@ -5,7 +5,6 @@ use rustc_middle::mir;
5
5
use rustc_middle:: mir:: interpret:: { ConstValue , ErrorHandled } ;
6
6
use rustc_middle:: ty:: layout:: HasTyCtxt ;
7
7
use rustc_middle:: ty:: { self , Ty } ;
8
- use rustc_span:: source_map:: Span ;
9
8
use rustc_target:: abi:: Abi ;
10
9
11
10
use super :: FunctionCx ;
@@ -59,15 +58,34 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
59
58
} )
60
59
}
61
60
61
+ /// This is a convenience helper for `simd_shuffle_indices`. It has the precondition
62
+ /// that the given `constant` is an `ConstantKind::Unevaluated` and must be convertible to
63
+ /// a `ValTree`. If you want a more general version of this, talk to `wg-const-eval` on zulip.
64
+ pub fn eval_unevaluated_mir_constant_to_valtree (
65
+ & self ,
66
+ constant : & mir:: Constant < ' tcx > ,
67
+ ) -> Result < Option < ty:: ValTree < ' tcx > > , ErrorHandled > {
68
+ let uv = match constant. literal {
69
+ mir:: ConstantKind :: Unevaluated ( uv, _) => uv. shrink ( ) ,
70
+ other => span_bug ! ( constant. span, "{other:#?}" ) ,
71
+ } ;
72
+ let uv = self . monomorphize ( uv) ;
73
+ self . cx . tcx ( ) . const_eval_resolve_for_typeck (
74
+ ty:: ParamEnv :: reveal_all ( ) ,
75
+ uv,
76
+ Some ( constant. span ) ,
77
+ )
78
+ }
79
+
62
80
/// process constant containing SIMD shuffle indices
63
81
pub fn simd_shuffle_indices (
64
82
& mut self ,
65
83
bx : & Bx ,
66
- span : Span ,
67
- ty : Ty < ' tcx > ,
68
- constant : Result < Option < ty:: ValTree < ' tcx > > , ErrorHandled > ,
84
+ constant : & mir:: Constant < ' tcx > ,
69
85
) -> ( Bx :: Value , Ty < ' tcx > ) {
70
- let val = constant
86
+ let ty = self . monomorphize ( constant. ty ( ) ) ;
87
+ let val = self
88
+ . eval_unevaluated_mir_constant_to_valtree ( constant)
71
89
. ok ( )
72
90
. flatten ( )
73
91
. map ( |val| {
@@ -90,9 +108,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
90
108
bx. const_struct ( & values, false )
91
109
} )
92
110
. unwrap_or_else ( || {
93
- bx. tcx ( ) . sess . emit_err ( errors:: ShuffleIndicesEvaluation { span } ) ;
111
+ bx. tcx ( ) . sess . emit_err ( errors:: ShuffleIndicesEvaluation { span : constant . span } ) ;
94
112
// We've errored, so we don't have to produce working code.
95
- let ty = self . monomorphize ( ty) ;
96
113
let llty = bx. backend_type ( bx. layout_of ( ty) ) ;
97
114
bx. const_undef ( llty)
98
115
} ) ;
0 commit comments