@@ -5,7 +5,6 @@ use rustc_middle::mir;
55use rustc_middle:: mir:: interpret:: { ConstValue , ErrorHandled } ;
66use rustc_middle:: ty:: layout:: HasTyCtxt ;
77use rustc_middle:: ty:: { self , Ty } ;
8- use rustc_span:: source_map:: Span ;
98use rustc_target:: abi:: Abi ;
109
1110use super :: FunctionCx ;
@@ -59,15 +58,34 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
5958 } )
6059 }
6160
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+
6280 /// process constant containing SIMD shuffle indices
6381 pub fn simd_shuffle_indices (
6482 & mut self ,
6583 bx : & Bx ,
66- span : Span ,
67- ty : Ty < ' tcx > ,
68- constant : Result < Option < ty:: ValTree < ' tcx > > , ErrorHandled > ,
84+ constant : & mir:: Constant < ' tcx > ,
6985 ) -> ( 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)
7189 . ok ( )
7290 . flatten ( )
7391 . map ( |val| {
@@ -90,9 +108,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
90108 bx. const_struct ( & values, false )
91109 } )
92110 . unwrap_or_else ( || {
93- bx. tcx ( ) . sess . emit_err ( errors:: ShuffleIndicesEvaluation { span } ) ;
111+ bx. tcx ( ) . sess . emit_err ( errors:: ShuffleIndicesEvaluation { span : constant . span } ) ;
94112 // We've errored, so we don't have to produce working code.
95- let ty = self . monomorphize ( ty) ;
96113 let llty = bx. backend_type ( bx. layout_of ( ty) ) ;
97114 bx. const_undef ( llty)
98115 } ) ;
0 commit comments