@@ -5,7 +5,7 @@ use std::assert_matches::assert_matches;
5
5
6
6
use either:: { Either , Left , Right } ;
7
7
use rustc_abi as abi;
8
- use rustc_abi:: { Abi , HasDataLayout , Size } ;
8
+ use rustc_abi:: { HasDataLayout , IrForm , Size } ;
9
9
use rustc_hir:: def:: Namespace ;
10
10
use rustc_middle:: mir:: interpret:: ScalarSizeMismatch ;
11
11
use rustc_middle:: ty:: layout:: { HasParamEnv , HasTyCtxt , LayoutOf , TyAndLayout } ;
@@ -114,9 +114,9 @@ impl<Prov: Provenance> Immediate<Prov> {
114
114
}
115
115
116
116
/// 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 ) {
118
118
match ( self , abi) {
119
- ( Immediate :: Scalar ( scalar) , Abi :: Scalar ( s) ) => {
119
+ ( Immediate :: Scalar ( scalar) , IrForm :: Scalar ( s) ) => {
120
120
assert_eq ! ( scalar. size( ) , s. size( cx) , "{msg}: scalar value has wrong size" ) ;
121
121
if !matches ! ( s. primitive( ) , abi:: Primitive :: Pointer ( ..) ) {
122
122
// This is not a pointer, it should not carry provenance.
@@ -126,7 +126,7 @@ impl<Prov: Provenance> Immediate<Prov> {
126
126
) ;
127
127
}
128
128
}
129
- ( Immediate :: ScalarPair ( a_val, b_val) , Abi :: ScalarPair ( a, b) ) => {
129
+ ( Immediate :: ScalarPair ( a_val, b_val) , IrForm :: ScalarPair ( a, b) ) => {
130
130
assert_eq ! (
131
131
a_val. size( ) ,
132
132
a. size( cx) ,
@@ -244,15 +244,15 @@ impl<'tcx, Prov: Provenance> std::ops::Deref for ImmTy<'tcx, Prov> {
244
244
impl < ' tcx , Prov : Provenance > ImmTy < ' tcx , Prov > {
245
245
#[ inline]
246
246
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" ) ;
248
248
debug_assert_eq ! ( val. size( ) , layout. size) ;
249
249
ImmTy { imm : val. into ( ) , layout }
250
250
}
251
251
252
252
#[ inline]
253
253
pub fn from_scalar_pair ( a : Scalar < Prov > , b : Scalar < Prov > , layout : TyAndLayout < ' tcx > ) -> Self {
254
254
debug_assert ! (
255
- matches!( layout. abi , Abi :: ScalarPair ( ..) ) ,
255
+ matches!( layout. ir_form , IrForm :: ScalarPair ( ..) ) ,
256
256
"`ImmTy::from_scalar_pair` on non-scalar-pair layout"
257
257
) ;
258
258
let imm = Immediate :: ScalarPair ( a, b) ;
@@ -263,9 +263,9 @@ impl<'tcx, Prov: Provenance> ImmTy<'tcx, Prov> {
263
263
pub fn from_immediate ( imm : Immediate < Prov > , layout : TyAndLayout < ' tcx > ) -> Self {
264
264
// Without a `cx` we cannot call `assert_matches_abi`.
265
265
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 ,
269
269
( Immediate :: Uninit , _) if layout. is_sized( ) => true ,
270
270
_ => false ,
271
271
} ,
@@ -356,7 +356,7 @@ impl<'tcx, Prov: Provenance> ImmTy<'tcx, Prov> {
356
356
fn offset_ ( & self , offset : Size , layout : TyAndLayout < ' tcx > , cx : & impl HasDataLayout ) -> Self {
357
357
// Verify that the input matches its type.
358
358
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) ;
360
360
}
361
361
// `ImmTy` have already been checked to be in-bounds, so we can just check directly if this
362
362
// remains in-bounds. This cannot actually be violated since projections are type-checked
@@ -370,19 +370,19 @@ impl<'tcx, Prov: Provenance> ImmTy<'tcx, Prov> {
370
370
) ;
371
371
// This makes several assumptions about what layouts we will encounter; we match what
372
372
// 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 ) {
374
374
// If the entire value is uninit, then so is the field (can happen in ConstProp).
375
375
( Immediate :: Uninit , _) => Immediate :: Uninit ,
376
376
// If the field is uninhabited, we can forget the data (can happen in ConstProp).
377
377
// `enum S { A(!), B, C }` is an example of an enum with Scalar layout that
378
378
// 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 ,
380
380
// the field contains no information, can be left uninit
381
381
// (Scalar/ScalarPair can contain even aligned ZST, not just 1-ZST)
382
382
_ if layout. is_zst ( ) => Immediate :: Uninit ,
383
383
// some fieldless enum variants can have non-zero size but still `Aggregate` ABI... try
384
384
// 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 { .. } )
386
386
&& matches ! ( layout. variants, abi:: Variants :: Single { .. } )
387
387
&& matches ! ( & layout. fields, abi:: FieldsShape :: Arbitrary { offsets, .. } if offsets. len( ) == 0 ) =>
388
388
{
@@ -394,7 +394,7 @@ impl<'tcx, Prov: Provenance> ImmTy<'tcx, Prov> {
394
394
* * self
395
395
}
396
396
// 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) ) => {
398
398
Immediate :: from ( if offset. bytes ( ) == 0 {
399
399
a_val
400
400
} else {
@@ -411,7 +411,7 @@ impl<'tcx, Prov: Provenance> ImmTy<'tcx, Prov> {
411
411
) ,
412
412
} ;
413
413
// 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) ;
415
415
416
416
ImmTy :: from_immediate ( inner_val, layout)
417
417
}
@@ -567,8 +567,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
567
567
// case where some of the bytes are initialized and others are not. So, we need an extra
568
568
// check that walks over the type of `mplace` to make sure it is truly correct to treat this
569
569
// 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, .. } ) => {
572
572
let size = s. size ( self ) ;
573
573
assert_eq ! ( size, mplace. layout. size, "abi::Scalar size does not match layout size" ) ;
574
574
let scalar = alloc. read_scalar (
@@ -577,7 +577,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
577
577
) ?;
578
578
Some ( ImmTy :: from_scalar ( scalar, mplace. layout ) )
579
579
}
580
- Abi :: ScalarPair (
580
+ IrForm :: ScalarPair (
581
581
abi:: Scalar :: Initialized { value : a, .. } ,
582
582
abi:: Scalar :: Initialized { value : b, .. } ,
583
583
) => {
@@ -637,9 +637,12 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
637
637
op : & impl Projectable < ' tcx , M :: Provenance > ,
638
638
) -> InterpResult < ' tcx , ImmTy < ' tcx , M :: Provenance > > {
639
639
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
+ )
643
646
) {
644
647
span_bug ! ( self . cur_span( ) , "primitive read not possible for type: {}" , op. layout( ) . ty) ;
645
648
}
0 commit comments