13
13
14
14
use std:: convert:: TryInto ;
15
15
16
- use rustc:: { mir, ty } ;
16
+ use rustc:: mir;
17
17
use rustc:: ty:: layout:: { self , Size , LayoutOf , TyLayout , HasDataLayout , IntegerExt , VariantIdx } ;
18
18
19
19
use rustc:: mir:: interpret:: {
@@ -535,20 +535,21 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
535
535
. collect ( )
536
536
}
537
537
538
- // Also used e.g. when miri runs into a constant.
539
- // FIXME: Can we avoid converting with ConstValue and Const? We should be using RawConst.
540
- fn const_value_to_op (
538
+ // Used when miri runs into a constant, and by CTFE.
539
+ // FIXME: CTFE should use allocations, then we can make this private (embed it into
540
+ // `eval_operand`, ideally).
541
+ pub ( crate ) fn const_value_to_op (
541
542
& self ,
542
543
val : ConstValue < ' tcx > ,
543
544
) -> EvalResult < ' tcx , Operand < M :: PointerTag > > {
544
545
trace ! ( "const_value_to_op: {:?}" , val) ;
545
546
match val {
546
547
ConstValue :: Unevaluated ( def_id, substs) => {
547
548
let instance = self . resolve ( def_id, substs) ?;
548
- self . global_to_op ( GlobalId {
549
+ Ok ( * OpTy :: from ( self . const_eval_raw ( GlobalId {
549
550
instance,
550
551
promoted : None ,
551
- } )
552
+ } ) ? ) )
552
553
}
553
554
ConstValue :: ByRef ( id, alloc, offset) => {
554
555
// We rely on mutability being set correctly in that allocation to prevent writes
@@ -566,21 +567,6 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
566
567
Ok ( Operand :: Immediate ( Immediate :: Scalar ( x. into ( ) ) ) . with_default_tag ( ) ) ,
567
568
}
568
569
}
569
- pub fn const_to_op (
570
- & self ,
571
- cnst : & ty:: Const < ' tcx > ,
572
- ) -> EvalResult < ' tcx , OpTy < ' tcx , M :: PointerTag > > {
573
- let op = self . const_value_to_op ( cnst. val ) ?;
574
- Ok ( OpTy { op, layout : self . layout_of ( cnst. ty ) ? } )
575
- }
576
-
577
- pub ( super ) fn global_to_op (
578
- & self ,
579
- gid : GlobalId < ' tcx >
580
- ) -> EvalResult < ' tcx , Operand < M :: PointerTag > > {
581
- let cv = self . const_eval ( gid) ?;
582
- self . const_value_to_op ( cv. val )
583
- }
584
570
585
571
/// Read discriminant, return the runtime value as well as the variant index.
586
572
pub fn read_discriminant (
0 commit comments