11use std:: fmt;
22
3+ use itertools:: Either ;
34use rustc_abi as abi;
45use rustc_abi:: {
56 Align , BackendRepr , FIRST_VARIANT , FieldIdx , Primitive , Size , TagEncoding , VariantIdx , Variants ,
@@ -567,12 +568,12 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
567568
568569 /// Creates an incomplete operand containing the [`abi::Scalar`]s expected based
569570 /// on the `layout` passed. This is for use with [`OperandRef::insert_field`]
570- /// later to set the necessary immediate(s).
571+ /// later to set the necessary immediate(s), one-by-one converting all the `Right` to `Left` .
571572 ///
572573 /// Returns `None` for `layout`s which cannot be built this way.
573574 pub ( crate ) fn builder (
574575 layout : TyAndLayout < ' tcx > ,
575- ) -> Option < OperandRef < ' tcx , Result < V , abi:: Scalar > > > {
576+ ) -> Option < OperandRef < ' tcx , Either < V , abi:: Scalar > > > {
576577 // Uninhabited types are weird, because for example `Result<!, !>`
577578 // shows up as `FieldsShape::Primitive` and we need to be able to write
578579 // a field into `(u32, !)`. We'll do that in an `alloca` instead.
@@ -582,15 +583,15 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
582583
583584 let val = match layout. backend_repr {
584585 BackendRepr :: Memory { .. } if layout. is_zst ( ) => OperandValue :: ZeroSized ,
585- BackendRepr :: Scalar ( s) => OperandValue :: Immediate ( Err ( s) ) ,
586- BackendRepr :: ScalarPair ( a, b) => OperandValue :: Pair ( Err ( a) , Err ( b) ) ,
586+ BackendRepr :: Scalar ( s) => OperandValue :: Immediate ( Either :: Right ( s) ) ,
587+ BackendRepr :: ScalarPair ( a, b) => OperandValue :: Pair ( Either :: Right ( a) , Either :: Right ( b) ) ,
587588 BackendRepr :: Memory { .. } | BackendRepr :: SimdVector { .. } => return None ,
588589 } ;
589590 Some ( OperandRef { val, layout } )
590591 }
591592}
592593
593- impl < ' a , ' tcx , V : CodegenObject > OperandRef < ' tcx , Result < V , abi:: Scalar > > {
594+ impl < ' a , ' tcx , V : CodegenObject > OperandRef < ' tcx , Either < V , abi:: Scalar > > {
594595 pub ( crate ) fn insert_field < Bx : BuilderMethods < ' a , ' tcx , Value = V > > (
595596 & mut self ,
596597 bx : & mut Bx ,
@@ -614,29 +615,29 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, Result<V, abi::Scalar>> {
614615 ( field_layout. is_zst ( ) , field_offset == Size :: ZERO )
615616 } ;
616617
617- let mut update = |tgt : & mut Result < V , abi:: Scalar > , src, from_scalar| {
618- let to_scalar = tgt. unwrap_err ( ) ;
618+ let mut update = |tgt : & mut Either < V , abi:: Scalar > , src, from_scalar| {
619+ let to_scalar = tgt. unwrap_right ( ) ;
619620 let imm = transmute_scalar ( bx, src, from_scalar, to_scalar) ;
620- * tgt = Ok ( imm) ;
621+ * tgt = Either :: Left ( imm) ;
621622 } ;
622623
623624 match ( operand. val , operand. layout . backend_repr ) {
624625 ( OperandValue :: ZeroSized , _) if expect_zst => { }
625626 ( OperandValue :: Immediate ( v) , BackendRepr :: Scalar ( from_scalar) ) => match & mut self . val {
626- OperandValue :: Immediate ( val @ Err ( _) ) if is_zero_offset => {
627+ OperandValue :: Immediate ( val @ Either :: Right ( _) ) if is_zero_offset => {
627628 update ( val, v, from_scalar) ;
628629 }
629- OperandValue :: Pair ( fst @ Err ( _) , _) if is_zero_offset => {
630+ OperandValue :: Pair ( fst @ Either :: Right ( _) , _) if is_zero_offset => {
630631 update ( fst, v, from_scalar) ;
631632 }
632- OperandValue :: Pair ( _, snd @ Err ( _) ) if !is_zero_offset => {
633+ OperandValue :: Pair ( _, snd @ Either :: Right ( _) ) if !is_zero_offset => {
633634 update ( snd, v, from_scalar) ;
634635 }
635636 _ => bug ! ( "Tried to insert {operand:?} into {v:?}.{f:?} of {self:?}" ) ,
636637 } ,
637638 ( OperandValue :: Pair ( a, b) , BackendRepr :: ScalarPair ( from_sa, from_sb) ) => {
638639 match & mut self . val {
639- OperandValue :: Pair ( fst @ Err ( _) , snd @ Err ( _) ) => {
640+ OperandValue :: Pair ( fst @ Either :: Right ( _) , snd @ Either :: Right ( _) ) => {
640641 update ( fst, a, from_sa) ;
641642 update ( snd, b, from_sb) ;
642643 }
@@ -656,21 +657,21 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, Result<V, abi::Scalar>> {
656657 let field_offset = self . layout . fields . offset ( f. as_usize ( ) ) ;
657658 let is_zero_offset = field_offset == Size :: ZERO ;
658659 match & mut self . val {
659- OperandValue :: Immediate ( val @ Err ( _) ) if is_zero_offset => {
660- * val = Ok ( imm) ;
660+ OperandValue :: Immediate ( val @ Either :: Right ( _) ) if is_zero_offset => {
661+ * val = Either :: Left ( imm) ;
661662 }
662- OperandValue :: Pair ( fst @ Err ( _) , _) if is_zero_offset => {
663- * fst = Ok ( imm) ;
663+ OperandValue :: Pair ( fst @ Either :: Right ( _) , _) if is_zero_offset => {
664+ * fst = Either :: Left ( imm) ;
664665 }
665- OperandValue :: Pair ( _, snd @ Err ( _) ) if !is_zero_offset => {
666- * snd = Ok ( imm) ;
666+ OperandValue :: Pair ( _, snd @ Either :: Right ( _) ) if !is_zero_offset => {
667+ * snd = Either :: Left ( imm) ;
667668 }
668669 _ => bug ! ( "Tried to insert {imm:?} into field {f:?} of {self:?}" ) ,
669670 }
670671 }
671672
672673 /// After having set all necessary fields, this converts the
673- /// `OperandValue<Result <V, _>>` (as obtained from [`OperandRef::builder`])
674+ /// `OperandValue<Either <V, _>>` (as obtained from [`OperandRef::builder`])
674675 /// to the normal `OperandValue<V>`.
675676 ///
676677 /// ICEs if any required fields were not set.
@@ -681,13 +682,13 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, Result<V, abi::Scalar>> {
681682 // payload scalar will not actually have been set, so this converts
682683 // unset scalars to corresponding `undef` values so long as the scalar
683684 // from the layout allows uninit.
684- let unwrap = |r : Result < V , abi:: Scalar > | match r {
685- Ok ( v) => v,
686- Err ( s) if s. is_uninit_valid ( ) => {
685+ let unwrap = |r : Either < V , abi:: Scalar > | match r {
686+ Either :: Left ( v) => v,
687+ Either :: Right ( s) if s. is_uninit_valid ( ) => {
687688 let bty = cx. type_from_scalar ( s) ;
688689 cx. const_undef ( bty)
689690 }
690- Err ( _) => bug ! ( "OperandRef::build called while fields are missing {self:?}" ) ,
691+ Either :: Right ( _) => bug ! ( "OperandRef::build called while fields are missing {self:?}" ) ,
691692 } ;
692693
693694 let val = match val {
0 commit comments