@@ -2458,8 +2458,13 @@ pub struct TypeList {
24582458 core_type_to_rec_group : SnapshotList < RecGroupId > ,
24592459 // The supertype of each core type.
24602460 //
2461- // A secondary map from `coreTypeId ` to `Option<CoreTypeId>`.
2461+ // A secondary map from `CoreTypeId ` to `Option<CoreTypeId>`.
24622462 core_type_to_supertype : SnapshotList < Option < CoreTypeId > > ,
2463+ // The subtyping depth of each core type. We use `u8::MAX` as a sentinel for
2464+ // an uninitialized entry.
2465+ //
2466+ // A secondary map from `CoreTypeId` to `u8`.
2467+ core_type_to_depth : Option < IndexMap < CoreTypeId , u8 > > ,
24632468 // A primary map from `RecGroupId` to the range of the rec group's elements
24642469 // within `core_types`.
24652470 rec_group_elements : SnapshotList < Range < CoreTypeId > > ,
@@ -2499,6 +2504,7 @@ struct TypeListCheckpoint {
24992504 core_instances : usize ,
25002505 core_type_to_rec_group : usize ,
25012506 core_type_to_supertype : usize ,
2507+ core_type_to_depth : usize ,
25022508 rec_group_elements : usize ,
25032509 canonical_rec_groups : usize ,
25042510}
@@ -2614,6 +2620,29 @@ impl TypeList {
26142620 self . core_type_to_supertype [ id. index ( ) ]
26152621 }
26162622
2623+ /// Get the subtyping depth of the given type. A type without any supertype
2624+ /// has depth 0.
2625+ pub fn get_subtyping_depth ( & self , id : CoreTypeId ) -> u8 {
2626+ let depth = self
2627+ . core_type_to_depth
2628+ . as_ref ( )
2629+ . expect ( "cannot get subtype depth from a committed list" ) [ id. index ( ) ] ;
2630+ debug_assert ! ( usize :: from( depth) <= crate :: limits:: MAX_WASM_SUBTYPING_DEPTH ) ;
2631+ depth
2632+ }
2633+
2634+ /// Set the subtyping depth of the given type. This may only be done once
2635+ /// per type.
2636+ pub fn set_subtyping_depth ( & mut self , id : CoreTypeId , depth : u8 ) {
2637+ debug_assert ! ( usize :: from( depth) <= crate :: limits:: MAX_WASM_SUBTYPING_DEPTH ) ;
2638+ let map = self
2639+ . core_type_to_depth
2640+ . as_mut ( )
2641+ . expect ( "cannot set a subtype depth in a committed list" ) ;
2642+ debug_assert ! ( !map. contains_key( & id) ) ;
2643+ map. insert ( id, depth) ;
2644+ }
2645+
26172646 /// Get the `CoreTypeId` for a canonicalized `PackedIndex`.
26182647 ///
26192648 /// Panics when given a non-canonicalized `PackedIndex`.
@@ -2827,6 +2856,7 @@ impl TypeList {
28272856 core_instances,
28282857 core_type_to_rec_group,
28292858 core_type_to_supertype,
2859+ core_type_to_depth,
28302860 rec_group_elements,
28312861 canonical_rec_groups,
28322862 } = self ;
@@ -2842,6 +2872,7 @@ impl TypeList {
28422872 core_instances : core_instances. len ( ) ,
28432873 core_type_to_rec_group : core_type_to_rec_group. len ( ) ,
28442874 core_type_to_supertype : core_type_to_supertype. len ( ) ,
2875+ core_type_to_depth : core_type_to_depth. as_ref ( ) . map ( |m| m. len ( ) ) . unwrap_or ( 0 ) ,
28452876 rec_group_elements : rec_group_elements. len ( ) ,
28462877 canonical_rec_groups : canonical_rec_groups. as_ref ( ) . map ( |m| m. len ( ) ) . unwrap_or ( 0 ) ,
28472878 }
@@ -2862,6 +2893,7 @@ impl TypeList {
28622893 core_instances,
28632894 core_type_to_rec_group,
28642895 core_type_to_supertype,
2896+ core_type_to_depth,
28652897 rec_group_elements,
28662898 canonical_rec_groups,
28672899 } = self ;
@@ -2878,6 +2910,14 @@ impl TypeList {
28782910 core_type_to_supertype. truncate ( checkpoint. core_type_to_supertype ) ;
28792911 rec_group_elements. truncate ( checkpoint. rec_group_elements ) ;
28802912
2913+ if let Some ( core_type_to_depth) = core_type_to_depth {
2914+ assert_eq ! (
2915+ core_type_to_depth. len( ) ,
2916+ checkpoint. core_type_to_depth,
2917+ "checkpointing does not support resetting `core_type_to_depth` (it would require a \
2918+ proper immutable and persistent hash map) so adding new groups is disallowed"
2919+ ) ;
2920+ }
28812921 if let Some ( canonical_rec_groups) = canonical_rec_groups {
28822922 assert_eq ! (
28832923 canonical_rec_groups. len( ) ,
@@ -2914,6 +2954,7 @@ impl TypeList {
29142954 core_instances : self . core_instances . commit ( ) ,
29152955 core_type_to_rec_group : self . core_type_to_rec_group . commit ( ) ,
29162956 core_type_to_supertype : self . core_type_to_supertype . commit ( ) ,
2957+ core_type_to_depth : None ,
29172958 rec_group_elements : self . rec_group_elements . commit ( ) ,
29182959 canonical_rec_groups : None ,
29192960 }
@@ -3006,6 +3047,7 @@ impl Default for TypeAlloc {
30063047 } ,
30073048 next_resource_id : 0 ,
30083049 } ;
3050+ ret. list . core_type_to_depth = Some ( Default :: default ( ) ) ;
30093051 ret. list . canonical_rec_groups = Some ( Default :: default ( ) ) ;
30103052 ret
30113053 }
0 commit comments