@@ -25,8 +25,6 @@ use rustc_target::abi::{
25
25
} ;
26
26
use rustc_target:: spec:: abi:: Abi ;
27
27
use std:: collections:: BTreeMap ;
28
- use std:: convert:: TryInto ;
29
- use std:: fmt:: Debug ;
30
28
use std:: iter;
31
29
use std:: iter:: FromIterator ;
32
30
use tracing:: { debug, trace, warn} ;
@@ -717,24 +715,18 @@ impl<'tcx> GotocCtx<'tcx> {
717
715
self . codegen_ty_tuple_like ( t, tys. to_vec ( ) )
718
716
}
719
717
720
- fn codegen_struct_padding < T > (
718
+ fn codegen_struct_padding (
721
719
& self ,
722
- current_offset_in_bits : T ,
723
- next_offset_in_bits : T ,
720
+ current_offset : Size ,
721
+ next_offset : Size ,
724
722
idx : usize ,
725
- ) -> Option < DatatypeComponent >
726
- where
727
- T : TryInto < u64 > ,
728
- T :: Error : Debug ,
729
- {
730
- let current_offset: u64 = current_offset_in_bits. try_into ( ) . unwrap ( ) ;
731
- let next_offset: u64 = next_offset_in_bits. try_into ( ) . unwrap ( ) ;
723
+ ) -> Option < DatatypeComponent > {
732
724
assert ! ( current_offset <= next_offset) ;
733
725
if current_offset < next_offset {
734
726
// We need to pad to the next offset
735
- let bits = next_offset - current_offset;
727
+ let padding_size = next_offset - current_offset;
736
728
let name = format ! ( "$pad{}" , idx) ;
737
- Some ( DatatypeComponent :: padding ( & name, bits) )
729
+ Some ( DatatypeComponent :: padding ( & name, padding_size . bits ( ) ) )
738
730
} else {
739
731
None
740
732
}
@@ -747,10 +739,10 @@ impl<'tcx> GotocCtx<'tcx> {
747
739
layout : & Layout ,
748
740
idx : usize ,
749
741
) -> Option < DatatypeComponent > {
750
- let align = layout. align ( ) . abi . bits ( ) ;
751
- let overhang = size. bits ( ) % align;
752
- if overhang != 0 {
753
- self . codegen_struct_padding ( size. bits ( ) , size. bits ( ) + align - overhang, idx)
742
+ let align = Size :: from_bits ( layout. align ( ) . abi . bits ( ) ) ;
743
+ let overhang = Size :: from_bits ( size. bits ( ) % align. bits ( ) ) ;
744
+ if overhang != Size :: ZERO {
745
+ self . codegen_struct_padding ( size, size + align - overhang, idx)
754
746
} else {
755
747
None
756
748
}
@@ -770,16 +762,16 @@ impl<'tcx> GotocCtx<'tcx> {
770
762
& mut self ,
771
763
flds : Vec < ( String , Ty < ' tcx > ) > ,
772
764
layout : & Layout ,
773
- initial_offset : usize ,
765
+ initial_offset : Size ,
774
766
) -> Vec < DatatypeComponent > {
775
767
match & layout. fields ( ) {
776
768
FieldsShape :: Arbitrary { offsets, memory_index } => {
777
769
assert_eq ! ( flds. len( ) , offsets. len( ) ) ;
778
770
assert_eq ! ( offsets. len( ) , memory_index. len( ) ) ;
779
771
let mut final_fields = Vec :: with_capacity ( flds. len ( ) ) ;
780
- let mut offset: u64 = initial_offset. try_into ( ) . unwrap ( ) ;
772
+ let mut offset = initial_offset;
781
773
for idx in layout. fields ( ) . index_by_increasing_offset ( ) {
782
- let fld_offset = offsets[ idx] . bits ( ) ;
774
+ let fld_offset = offsets[ idx] ;
783
775
let ( fld_name, fld_ty) = & flds[ idx] ;
784
776
if let Some ( padding) =
785
777
self . codegen_struct_padding ( offset, fld_offset, final_fields. len ( ) )
@@ -790,10 +782,10 @@ impl<'tcx> GotocCtx<'tcx> {
790
782
final_fields. push ( DatatypeComponent :: field ( fld_name, self . codegen_ty ( * fld_ty) ) ) ;
791
783
let layout = self . layout_of ( * fld_ty) ;
792
784
// we compute the overall offset of the end of the current struct
793
- offset = fld_offset + layout. size . bits ( ) ;
785
+ offset = fld_offset + layout. size ;
794
786
}
795
787
final_fields. extend ( self . codegen_alignment_padding (
796
- Size :: from_bits ( offset) ,
788
+ offset,
797
789
& layout,
798
790
final_fields. len ( ) ,
799
791
) ) ;
@@ -810,7 +802,7 @@ impl<'tcx> GotocCtx<'tcx> {
810
802
let flds: Vec < _ > =
811
803
tys. iter ( ) . enumerate ( ) . map ( |( i, t) | ( GotocCtx :: tuple_fld_name ( i) , * t) ) . collect ( ) ;
812
804
// tuple cannot have other initial offset
813
- self . codegen_struct_fields ( flds, & layout. layout , 0 )
805
+ self . codegen_struct_fields ( flds, & layout. layout , Size :: ZERO )
814
806
}
815
807
816
808
/// A closure in Rust MIR takes two arguments:
@@ -1004,9 +996,7 @@ impl<'tcx> GotocCtx<'tcx> {
1004
996
let field_ty = type_and_layout. field ( ctx, idx) . ty ;
1005
997
let field_offset = type_and_layout. fields . offset ( idx) ;
1006
998
let field_size = type_and_layout. field ( ctx, idx) . size ;
1007
- if let Some ( padding) =
1008
- ctx. codegen_struct_padding ( offset. bits ( ) , field_offset. bits ( ) , idx)
1009
- {
999
+ if let Some ( padding) = ctx. codegen_struct_padding ( offset, field_offset, idx) {
1010
1000
fields. push ( padding) ;
1011
1001
}
1012
1002
fields. push ( DatatypeComponent :: Field {
@@ -1215,7 +1205,7 @@ impl<'tcx> GotocCtx<'tcx> {
1215
1205
self . ensure_struct ( self . ty_mangled_name ( ty) , self . ty_pretty_name ( ty) , |ctx, _| {
1216
1206
let variant = & def. variants ( ) . raw [ 0 ] ;
1217
1207
let layout = ctx. layout_of ( ty) ;
1218
- ctx. codegen_variant_struct_fields ( variant, subst, & layout. layout , 0 )
1208
+ ctx. codegen_variant_struct_fields ( variant, subst, & layout. layout , Size :: ZERO )
1219
1209
} )
1220
1210
}
1221
1211
@@ -1225,7 +1215,7 @@ impl<'tcx> GotocCtx<'tcx> {
1225
1215
variant : & VariantDef ,
1226
1216
subst : & ' tcx InternalSubsts < ' tcx > ,
1227
1217
layout : & Layout ,
1228
- initial_offset : usize ,
1218
+ initial_offset : Size ,
1229
1219
) -> Vec < DatatypeComponent > {
1230
1220
let flds: Vec < _ > =
1231
1221
variant. fields . iter ( ) . map ( |f| ( f. name . to_string ( ) , f. ty ( self . tcx , subst) ) ) . collect ( ) ;
@@ -1307,7 +1297,7 @@ impl<'tcx> GotocCtx<'tcx> {
1307
1297
Some ( variant) => {
1308
1298
// a single enum is pretty much like a struct
1309
1299
let layout = ctx. layout_of ( ty) . layout ;
1310
- ctx. codegen_variant_struct_fields ( variant, subst, & layout, 0 )
1300
+ ctx. codegen_variant_struct_fields ( variant, subst, & layout, Size :: ZERO )
1311
1301
}
1312
1302
}
1313
1303
}
@@ -1331,7 +1321,7 @@ impl<'tcx> GotocCtx<'tcx> {
1331
1321
// of each union field is the name of the corresponding discriminant.
1332
1322
let discr_t = ctx. codegen_enum_discr_typ ( ty) ;
1333
1323
let int = ctx. codegen_ty ( discr_t) ;
1334
- let discr_offset = ctx. layout_of ( discr_t) . size . bits_usize ( ) ;
1324
+ let discr_offset = ctx. layout_of ( discr_t) . size ;
1335
1325
let initial_offset =
1336
1326
ctx. variant_min_offset ( variants) . unwrap_or ( discr_offset) ;
1337
1327
let mut fields = vec ! [ DatatypeComponent :: field( "case" , int) ] ;
@@ -1382,7 +1372,14 @@ impl<'tcx> GotocCtx<'tcx> {
1382
1372
?subst,
1383
1373
"codegen_enum: Niche"
1384
1374
) ;
1385
- ctx. codegen_enum_cases ( name, pretty_name, adtdef, subst, variants, 0 )
1375
+ ctx. codegen_enum_cases (
1376
+ name,
1377
+ pretty_name,
1378
+ adtdef,
1379
+ subst,
1380
+ variants,
1381
+ Size :: ZERO ,
1382
+ )
1386
1383
}
1387
1384
}
1388
1385
}
@@ -1393,7 +1390,7 @@ impl<'tcx> GotocCtx<'tcx> {
1393
1390
pub ( crate ) fn variant_min_offset (
1394
1391
& self ,
1395
1392
variants : & IndexVec < VariantIdx , Layout > ,
1396
- ) -> Option < usize > {
1393
+ ) -> Option < Size > {
1397
1394
variants
1398
1395
. iter ( )
1399
1396
. filter_map ( |lo| {
@@ -1407,8 +1404,7 @@ impl<'tcx> GotocCtx<'tcx> {
1407
1404
// fields.
1408
1405
Some (
1409
1406
lo. fields ( )
1410
- . offset ( lo. fields ( ) . index_by_increasing_offset ( ) . nth ( 0 ) . unwrap ( ) )
1411
- . bits_usize ( ) ,
1407
+ . offset ( lo. fields ( ) . index_by_increasing_offset ( ) . nth ( 0 ) . unwrap ( ) ) ,
1412
1408
)
1413
1409
}
1414
1410
} )
@@ -1481,7 +1477,7 @@ impl<'tcx> GotocCtx<'tcx> {
1481
1477
def : & ' tcx AdtDef ,
1482
1478
subst : & ' tcx InternalSubsts < ' tcx > ,
1483
1479
layouts : & IndexVec < VariantIdx , Layout > ,
1484
- initial_offset : usize ,
1480
+ initial_offset : Size ,
1485
1481
) -> Vec < DatatypeComponent > {
1486
1482
def. variants ( )
1487
1483
. iter_enumerated ( )
@@ -1513,7 +1509,7 @@ impl<'tcx> GotocCtx<'tcx> {
1513
1509
case : & VariantDef ,
1514
1510
subst : & ' tcx InternalSubsts < ' tcx > ,
1515
1511
variant : & Layout ,
1516
- initial_offset : usize ,
1512
+ initial_offset : Size ,
1517
1513
) -> Type {
1518
1514
let case_name = format ! ( "{}::{}" , name, case. name) ;
1519
1515
let pretty_name = format ! ( "{}::{}" , pretty_name, case. name) ;
0 commit comments