@@ -5,7 +5,7 @@ use std::assert_matches::assert_matches;
55
66use either:: { Either , Left , Right } ;
77use rustc_abi as abi;
8- use rustc_abi:: { Abi , HasDataLayout , Size } ;
8+ use rustc_abi:: { HasDataLayout , IrForm , Size } ;
99use rustc_hir:: def:: Namespace ;
1010use rustc_middle:: mir:: interpret:: ScalarSizeMismatch ;
1111use rustc_middle:: ty:: layout:: { HasParamEnv , HasTyCtxt , LayoutOf , TyAndLayout } ;
@@ -114,9 +114,9 @@ impl<Prov: Provenance> Immediate<Prov> {
114114 }
115115
116116 /// Assert that this immediate is a valid value for the given ABI.
117- pub fn assert_matches_abi ( self , abi : Abi , msg : & str , cx : & impl HasDataLayout ) {
117+ pub fn assert_matches_abi ( self , abi : IrForm , msg : & str , cx : & impl HasDataLayout ) {
118118 match ( self , abi) {
119- ( Immediate :: Scalar ( scalar) , Abi :: Scalar ( s) ) => {
119+ ( Immediate :: Scalar ( scalar) , IrForm :: Scalar ( s) ) => {
120120 assert_eq ! ( scalar. size( ) , s. size( cx) , "{msg}: scalar value has wrong size" ) ;
121121 if !matches ! ( s. primitive( ) , abi:: Primitive :: Pointer ( ..) ) {
122122 // This is not a pointer, it should not carry provenance.
@@ -126,7 +126,7 @@ impl<Prov: Provenance> Immediate<Prov> {
126126 ) ;
127127 }
128128 }
129- ( Immediate :: ScalarPair ( a_val, b_val) , Abi :: ScalarPair ( a, b) ) => {
129+ ( Immediate :: ScalarPair ( a_val, b_val) , IrForm :: ScalarPair ( a, b) ) => {
130130 assert_eq ! (
131131 a_val. size( ) ,
132132 a. size( cx) ,
@@ -244,15 +244,15 @@ impl<'tcx, Prov: Provenance> std::ops::Deref for ImmTy<'tcx, Prov> {
244244impl < ' tcx , Prov : Provenance > ImmTy < ' tcx , Prov > {
245245 #[ inline]
246246 pub fn from_scalar ( val : Scalar < Prov > , layout : TyAndLayout < ' tcx > ) -> Self {
247- debug_assert ! ( layout. abi . is_scalar( ) , "`ImmTy::from_scalar` on non-scalar layout" ) ;
247+ debug_assert ! ( layout. ir_form . is_scalar( ) , "`ImmTy::from_scalar` on non-scalar layout" ) ;
248248 debug_assert_eq ! ( val. size( ) , layout. size) ;
249249 ImmTy { imm : val. into ( ) , layout }
250250 }
251251
252252 #[ inline]
253253 pub fn from_scalar_pair ( a : Scalar < Prov > , b : Scalar < Prov > , layout : TyAndLayout < ' tcx > ) -> Self {
254254 debug_assert ! (
255- matches!( layout. abi , Abi :: ScalarPair ( ..) ) ,
255+ matches!( layout. ir_form , IrForm :: ScalarPair ( ..) ) ,
256256 "`ImmTy::from_scalar_pair` on non-scalar-pair layout"
257257 ) ;
258258 let imm = Immediate :: ScalarPair ( a, b) ;
@@ -263,9 +263,9 @@ impl<'tcx, Prov: Provenance> ImmTy<'tcx, Prov> {
263263 pub fn from_immediate ( imm : Immediate < Prov > , layout : TyAndLayout < ' tcx > ) -> Self {
264264 // Without a `cx` we cannot call `assert_matches_abi`.
265265 debug_assert ! (
266- match ( imm, layout. abi ) {
267- ( Immediate :: Scalar ( ..) , Abi :: Scalar ( ..) ) => true ,
268- ( Immediate :: ScalarPair ( ..) , Abi :: ScalarPair ( ..) ) => true ,
266+ match ( imm, layout. ir_form ) {
267+ ( Immediate :: Scalar ( ..) , IrForm :: Scalar ( ..) ) => true ,
268+ ( Immediate :: ScalarPair ( ..) , IrForm :: ScalarPair ( ..) ) => true ,
269269 ( Immediate :: Uninit , _) if layout. is_sized( ) => true ,
270270 _ => false ,
271271 } ,
@@ -356,7 +356,7 @@ impl<'tcx, Prov: Provenance> ImmTy<'tcx, Prov> {
356356 fn offset_ ( & self , offset : Size , layout : TyAndLayout < ' tcx > , cx : & impl HasDataLayout ) -> Self {
357357 // Verify that the input matches its type.
358358 if cfg ! ( debug_assertions) {
359- self . assert_matches_abi ( self . layout . abi , "invalid input to Immediate::offset" , cx) ;
359+ self . assert_matches_abi ( self . layout . ir_form , "invalid input to Immediate::offset" , cx) ;
360360 }
361361 // `ImmTy` have already been checked to be in-bounds, so we can just check directly if this
362362 // remains in-bounds. This cannot actually be violated since projections are type-checked
@@ -370,19 +370,19 @@ impl<'tcx, Prov: Provenance> ImmTy<'tcx, Prov> {
370370 ) ;
371371 // This makes several assumptions about what layouts we will encounter; we match what
372372 // codegen does as good as we can (see `extract_field` in `rustc_codegen_ssa/src/mir/operand.rs`).
373- let inner_val: Immediate < _ > = match ( * * self , self . layout . abi ) {
373+ let inner_val: Immediate < _ > = match ( * * self , self . layout . ir_form ) {
374374 // If the entire value is uninit, then so is the field (can happen in ConstProp).
375375 ( Immediate :: Uninit , _) => Immediate :: Uninit ,
376376 // If the field is uninhabited, we can forget the data (can happen in ConstProp).
377377 // `enum S { A(!), B, C }` is an example of an enum with Scalar layout that
378378 // has an `Uninhabited` variant, which means this case is possible.
379- _ if layout. abi . is_uninhabited ( ) => Immediate :: Uninit ,
379+ _ if layout. is_uninhabited ( ) => Immediate :: Uninit ,
380380 // the field contains no information, can be left uninit
381381 // (Scalar/ScalarPair can contain even aligned ZST, not just 1-ZST)
382382 _ if layout. is_zst ( ) => Immediate :: Uninit ,
383383 // some fieldless enum variants can have non-zero size but still `Aggregate` ABI... try
384384 // to detect those here and also give them no data
385- _ if matches ! ( layout. abi , Abi :: Aggregate { .. } )
385+ _ if matches ! ( layout. ir_form , IrForm :: Memory { .. } )
386386 && matches ! ( layout. variants, abi:: Variants :: Single { .. } )
387387 && matches ! ( & layout. fields, abi:: FieldsShape :: Arbitrary { offsets, .. } if offsets. len( ) == 0 ) =>
388388 {
@@ -394,7 +394,7 @@ impl<'tcx, Prov: Provenance> ImmTy<'tcx, Prov> {
394394 * * self
395395 }
396396 // extract fields from types with `ScalarPair` ABI
397- ( Immediate :: ScalarPair ( a_val, b_val) , Abi :: ScalarPair ( a, b) ) => {
397+ ( Immediate :: ScalarPair ( a_val, b_val) , IrForm :: ScalarPair ( a, b) ) => {
398398 Immediate :: from ( if offset. bytes ( ) == 0 {
399399 a_val
400400 } else {
@@ -411,7 +411,7 @@ impl<'tcx, Prov: Provenance> ImmTy<'tcx, Prov> {
411411 ) ,
412412 } ;
413413 // Ensure the new layout matches the new value.
414- inner_val. assert_matches_abi ( layout. abi , "invalid field type in Immediate::offset" , cx) ;
414+ inner_val. assert_matches_abi ( layout. ir_form , "invalid field type in Immediate::offset" , cx) ;
415415
416416 ImmTy :: from_immediate ( inner_val, layout)
417417 }
@@ -567,8 +567,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
567567 // case where some of the bytes are initialized and others are not. So, we need an extra
568568 // check that walks over the type of `mplace` to make sure it is truly correct to treat this
569569 // like a `Scalar` (or `ScalarPair`).
570- interp_ok ( match mplace. layout . abi {
571- Abi :: Scalar ( abi:: Scalar :: Initialized { value : s, .. } ) => {
570+ interp_ok ( match mplace. layout . ir_form {
571+ IrForm :: Scalar ( abi:: Scalar :: Initialized { value : s, .. } ) => {
572572 let size = s. size ( self ) ;
573573 assert_eq ! ( size, mplace. layout. size, "abi::Scalar size does not match layout size" ) ;
574574 let scalar = alloc. read_scalar (
@@ -577,7 +577,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
577577 ) ?;
578578 Some ( ImmTy :: from_scalar ( scalar, mplace. layout ) )
579579 }
580- Abi :: ScalarPair (
580+ IrForm :: ScalarPair (
581581 abi:: Scalar :: Initialized { value : a, .. } ,
582582 abi:: Scalar :: Initialized { value : b, .. } ,
583583 ) => {
@@ -637,9 +637,12 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
637637 op : & impl Projectable < ' tcx , M :: Provenance > ,
638638 ) -> InterpResult < ' tcx , ImmTy < ' tcx , M :: Provenance > > {
639639 if !matches ! (
640- op. layout( ) . abi,
641- Abi :: Scalar ( abi:: Scalar :: Initialized { .. } )
642- | Abi :: ScalarPair ( abi:: Scalar :: Initialized { .. } , abi:: Scalar :: Initialized { .. } )
640+ op. layout( ) . ir_form,
641+ IrForm :: Scalar ( abi:: Scalar :: Initialized { .. } )
642+ | IrForm :: ScalarPair (
643+ abi:: Scalar :: Initialized { .. } ,
644+ abi:: Scalar :: Initialized { .. }
645+ )
643646 ) {
644647 span_bug ! ( self . cur_span( ) , "primitive read not possible for type: {}" , op. layout( ) . ty) ;
645648 }
0 commit comments