@@ -20,7 +20,7 @@ use rustc_middle::ty::{
20
20
use rustc_middle:: ty:: { List , TypeFoldable } ;
21
21
use rustc_span:: def_id:: DefId ;
22
22
use rustc_target:: abi:: {
23
- Abi :: Vector , FieldsShape , Integer , Layout , Primitive , Size , TagEncoding , TyAndLayout ,
23
+ Abi :: Vector , FieldsShape , Integer , LayoutS , Primitive , Size , TagEncoding , TyAndLayout ,
24
24
VariantIdx , Variants ,
25
25
} ;
26
26
use rustc_target:: spec:: abi:: Abi ;
@@ -327,10 +327,12 @@ impl<'tcx> GotocCtx<'tcx> {
327
327
self . sig_with_untupled_args ( sig)
328
328
}
329
329
330
- // Adapted from `fn_sig_for_fn_abi` in compiler/rustc_middle/src/ty/layout.rs
330
+ // Adapted from `fn_sig_for_fn_abi` in
331
+ // https://github.com/rust-lang/rust/blob/739d68a76e35b22341d9930bb6338bf202ba05ba/compiler/rustc_ty_utils/src/abi.rs#L88
331
332
// Code duplication tracked here: https://github.com/model-checking/kani/issues/1365
332
333
fn generator_sig (
333
334
& self ,
335
+ did : & DefId ,
334
336
ty : Ty < ' tcx > ,
335
337
substs : ty:: subst:: SubstsRef < ' tcx > ,
336
338
) -> ty:: PolyFnSig < ' tcx > {
@@ -352,10 +354,21 @@ impl<'tcx> GotocCtx<'tcx> {
352
354
let env_ty = self . tcx . mk_adt ( pin_adt_ref, pin_substs) ;
353
355
354
356
let sig = sig. skip_binder ( ) ;
355
- let state_did = self . tcx . require_lang_item ( LangItem :: GeneratorState , None ) ;
356
- let state_adt_ref = self . tcx . adt_def ( state_did) ;
357
- let state_substs = self . tcx . intern_substs ( & [ sig. yield_ty . into ( ) , sig. return_ty . into ( ) ] ) ;
358
- let ret_ty = self . tcx . mk_adt ( state_adt_ref, state_substs) ;
357
+ // The `FnSig` and the `ret_ty` here is for a generators main
358
+ // `Generator::resume(...) -> GeneratorState` function in case we
359
+ // have an ordinary generator, or the `Future::poll(...) -> Poll`
360
+ // function in case this is a special generator backing an async construct.
361
+ let ret_ty = if self . tcx . generator_is_async ( * did) {
362
+ let state_did = self . tcx . require_lang_item ( LangItem :: Poll , None ) ;
363
+ let state_adt_ref = self . tcx . adt_def ( state_did) ;
364
+ let state_substs = self . tcx . intern_substs ( & [ sig. return_ty . into ( ) ] ) ;
365
+ self . tcx . mk_adt ( state_adt_ref, state_substs)
366
+ } else {
367
+ let state_did = self . tcx . require_lang_item ( LangItem :: GeneratorState , None ) ;
368
+ let state_adt_ref = self . tcx . adt_def ( state_did) ;
369
+ let state_substs = self . tcx . intern_substs ( & [ sig. yield_ty . into ( ) , sig. return_ty . into ( ) ] ) ;
370
+ self . tcx . mk_adt ( state_adt_ref, state_substs)
371
+ } ;
359
372
ty:: Binder :: bind_with_vars (
360
373
self . tcx . mk_fn_sig (
361
374
[ env_ty, sig. resume_ty ] . iter ( ) ,
@@ -380,7 +393,7 @@ impl<'tcx> GotocCtx<'tcx> {
380
393
}
381
394
sig
382
395
}
383
- ty:: Generator ( _ , substs, _) => self . generator_sig ( fntyp, substs) ,
396
+ ty:: Generator ( did , substs, _) => self . generator_sig ( did , fntyp, substs) ,
384
397
_ => unreachable ! ( "Can't get function signature of type: {:?}" , fntyp) ,
385
398
} )
386
399
}
@@ -865,10 +878,10 @@ impl<'tcx> GotocCtx<'tcx> {
865
878
fn codegen_alignment_padding (
866
879
& self ,
867
880
size : Size ,
868
- layout : & Layout ,
881
+ layout : & LayoutS < VariantIdx > ,
869
882
idx : usize ,
870
883
) -> Option < DatatypeComponent > {
871
- let align = Size :: from_bits ( layout. align ( ) . abi . bits ( ) ) ;
884
+ let align = Size :: from_bits ( layout. align . abi . bits ( ) ) ;
872
885
let overhang = Size :: from_bits ( size. bits ( ) % align. bits ( ) ) ;
873
886
if overhang != Size :: ZERO {
874
887
self . codegen_struct_padding ( size, size + align - overhang, idx)
@@ -890,16 +903,16 @@ impl<'tcx> GotocCtx<'tcx> {
890
903
fn codegen_struct_fields (
891
904
& mut self ,
892
905
flds : Vec < ( String , Ty < ' tcx > ) > ,
893
- layout : & Layout ,
906
+ layout : & LayoutS < VariantIdx > ,
894
907
initial_offset : Size ,
895
908
) -> Vec < DatatypeComponent > {
896
- match & layout. fields ( ) {
909
+ match & layout. fields {
897
910
FieldsShape :: Arbitrary { offsets, memory_index } => {
898
911
assert_eq ! ( flds. len( ) , offsets. len( ) ) ;
899
912
assert_eq ! ( offsets. len( ) , memory_index. len( ) ) ;
900
913
let mut final_fields = Vec :: with_capacity ( flds. len ( ) ) ;
901
914
let mut offset = initial_offset;
902
- for idx in layout. fields ( ) . index_by_increasing_offset ( ) {
915
+ for idx in layout. fields . index_by_increasing_offset ( ) {
903
916
let fld_offset = offsets[ idx] ;
904
917
let ( fld_name, fld_ty) = & flds[ idx] ;
905
918
if let Some ( padding) =
@@ -922,7 +935,7 @@ impl<'tcx> GotocCtx<'tcx> {
922
935
}
923
936
// Primitives, such as NEVER, have no fields
924
937
FieldsShape :: Primitive => vec ! [ ] ,
925
- _ => unreachable ! ( "{}\n {:?}" , self . current_fn( ) . readable_name( ) , layout. fields( ) ) ,
938
+ _ => unreachable ! ( "{}\n {:?}" , self . current_fn( ) . readable_name( ) , layout. fields) ,
926
939
}
927
940
}
928
941
@@ -931,7 +944,7 @@ impl<'tcx> GotocCtx<'tcx> {
931
944
let flds: Vec < _ > =
932
945
tys. iter ( ) . enumerate ( ) . map ( |( i, t) | ( GotocCtx :: tuple_fld_name ( i) , * t) ) . collect ( ) ;
933
946
// tuple cannot have other initial offset
934
- self . codegen_struct_fields ( flds, & layout. layout , Size :: ZERO )
947
+ self . codegen_struct_fields ( flds, & layout. layout . 0 , Size :: ZERO )
935
948
}
936
949
937
950
/// A closure / some shims in Rust MIR takes two arguments:
@@ -1136,7 +1149,7 @@ impl<'tcx> GotocCtx<'tcx> {
1136
1149
}
1137
1150
fields. extend ( ctx. codegen_alignment_padding (
1138
1151
offset,
1139
- & type_and_layout. layout ,
1152
+ & type_and_layout. layout . 0 ,
1140
1153
fields. len ( ) ,
1141
1154
) ) ;
1142
1155
fields
@@ -1338,7 +1351,7 @@ impl<'tcx> GotocCtx<'tcx> {
1338
1351
self . ensure_struct ( self . ty_mangled_name ( ty) , self . ty_pretty_name ( ty) , |ctx, _| {
1339
1352
let variant = & def. variants ( ) . raw [ 0 ] ;
1340
1353
let layout = ctx. layout_of ( ty) ;
1341
- ctx. codegen_variant_struct_fields ( variant, subst, & layout. layout , Size :: ZERO )
1354
+ ctx. codegen_variant_struct_fields ( variant, subst, & layout. layout . 0 , Size :: ZERO )
1342
1355
} )
1343
1356
}
1344
1357
@@ -1347,7 +1360,7 @@ impl<'tcx> GotocCtx<'tcx> {
1347
1360
& mut self ,
1348
1361
variant : & VariantDef ,
1349
1362
subst : & ' tcx InternalSubsts < ' tcx > ,
1350
- layout : & Layout ,
1363
+ layout : & LayoutS < VariantIdx > ,
1351
1364
initial_offset : Size ,
1352
1365
) -> Vec < DatatypeComponent > {
1353
1366
let flds: Vec < _ > =
@@ -1430,7 +1443,7 @@ impl<'tcx> GotocCtx<'tcx> {
1430
1443
Some ( variant) => {
1431
1444
// a single enum is pretty much like a struct
1432
1445
let layout = gcx. layout_of ( ty) . layout ;
1433
- gcx. codegen_variant_struct_fields ( variant, subst, & layout, Size :: ZERO )
1446
+ gcx. codegen_variant_struct_fields ( variant, subst, & layout. 0 , Size :: ZERO )
1434
1447
}
1435
1448
}
1436
1449
} )
@@ -1516,9 +1529,9 @@ impl<'tcx> GotocCtx<'tcx> {
1516
1529
ty : Ty < ' tcx > ,
1517
1530
adtdef : & ' tcx AdtDef ,
1518
1531
subst : & ' tcx InternalSubsts < ' tcx > ,
1519
- variants : & IndexVec < VariantIdx , Layout > ,
1532
+ variants : & IndexVec < VariantIdx , LayoutS < VariantIdx > > ,
1520
1533
) -> Type {
1521
- let non_zst_count = variants. iter ( ) . filter ( |layout| layout. size ( ) . bytes ( ) > 0 ) . count ( ) ;
1534
+ let non_zst_count = variants. iter ( ) . filter ( |layout| layout. size . bytes ( ) > 0 ) . count ( ) ;
1522
1535
let mangled_name = self . ty_mangled_name ( ty) ;
1523
1536
let pretty_name = self . ty_pretty_name ( ty) ;
1524
1537
tracing:: trace!( ?pretty_name, ?variants, ?subst, ?non_zst_count, "codegen_enum: Niche" ) ;
@@ -1535,23 +1548,20 @@ impl<'tcx> GotocCtx<'tcx> {
1535
1548
1536
1549
pub ( crate ) fn variant_min_offset (
1537
1550
& self ,
1538
- variants : & IndexVec < VariantIdx , Layout > ,
1551
+ variants : & IndexVec < VariantIdx , LayoutS < VariantIdx > > ,
1539
1552
) -> Option < Size > {
1540
1553
variants
1541
1554
. iter ( )
1542
1555
. filter_map ( |lo| {
1543
- if lo. fields ( ) . count ( ) == 0 {
1556
+ if lo. fields . count ( ) == 0 {
1544
1557
None
1545
1558
} else {
1546
1559
// get the offset of the leftmost field, which is the one
1547
1560
// with the least offset since we codegen fields in a struct
1548
1561
// in the order of increasing offsets. Note that this is not
1549
1562
// necessarily the 0th field since the compiler may reorder
1550
1563
// fields.
1551
- Some (
1552
- lo. fields ( )
1553
- . offset ( lo. fields ( ) . index_by_increasing_offset ( ) . next ( ) . unwrap ( ) ) ,
1554
- )
1564
+ Some ( lo. fields . offset ( lo. fields . index_by_increasing_offset ( ) . next ( ) . unwrap ( ) ) )
1555
1565
}
1556
1566
} )
1557
1567
. min ( )
@@ -1622,7 +1632,7 @@ impl<'tcx> GotocCtx<'tcx> {
1622
1632
pretty_name : InternedString ,
1623
1633
def : & ' tcx AdtDef ,
1624
1634
subst : & ' tcx InternalSubsts < ' tcx > ,
1625
- layouts : & IndexVec < VariantIdx , Layout > ,
1635
+ layouts : & IndexVec < VariantIdx , LayoutS < VariantIdx > > ,
1626
1636
initial_offset : Size ,
1627
1637
) -> Vec < DatatypeComponent > {
1628
1638
def. variants ( )
@@ -1654,7 +1664,7 @@ impl<'tcx> GotocCtx<'tcx> {
1654
1664
pretty_name : InternedString ,
1655
1665
case : & VariantDef ,
1656
1666
subst : & ' tcx InternalSubsts < ' tcx > ,
1657
- variant : & Layout ,
1667
+ variant : & LayoutS < VariantIdx > ,
1658
1668
initial_offset : Size ,
1659
1669
) -> Type {
1660
1670
let case_name = format ! ( "{name}::{}" , case. name) ;
0 commit comments