@@ -9,12 +9,20 @@ import '../ir/ir.dart' as ir;
99import 'builder.dart' ;
1010
1111/// The available field values that can be used in brand type StructTypes.
12- const List <ir.ValueType > _brandTypeFieldValues = [
12+ const List <ir.StorageType > _brandTypeFieldValues = [
1313 ir.NumType .i32,
1414 ir.NumType .i64,
1515 ir.NumType .f32,
1616 ir.NumType .f64,
1717 ir.NumType .v128,
18+ ir.PackedType .i8,
19+ ir.PackedType .i16,
20+ ir.RefType .i31 (nullable: false ),
21+ ir.RefType .i31 (nullable: true ),
22+ ir.RefType .struct (nullable: false ),
23+ ir.RefType .struct (nullable: true ),
24+ ir.RefType .array (nullable: false ),
25+ ir.RefType .array (nullable: true ),
1826 ir.RefType .extern (nullable: false ),
1927 ir.RefType .extern (nullable: true ),
2028 ir.RefType .any (nullable: false ),
@@ -35,22 +43,17 @@ const List<ir.ValueType> _brandTypeFieldValues = [
3543/// The produced brand type can be added to rec groups that would otherwise be
3644/// considered equal by the wasm type system. The brand types break the unwanted
3745/// equivalence relation between the groups.
38- ///
39- /// The brand type must contain at least one field because every struct is a
40- /// subtype of the empty struct.
4146 ir.StructType _getBrandType (int index) {
4247 final brandName = 'brand$index ' ;
4348 final List <ir.FieldType > fields = [];
4449 final numDigits = _brandTypeFieldValues.length;
45- do {
46- final modValue = index % numDigits;
47- // It's important that the fields are mutable. This ensures that the
48- // contained StorageTypes must be mutual subtypes (i.e. they must be equal)
49- // in order for them to match. Some of our brand digit options are subtypes
50- // of others so to avoid them matching we need the mutual subtyping.
51- fields.add (ir.FieldType (_brandTypeFieldValues[modValue], mutable: true ));
52- index = index ~ / numDigits;
53- } while (index > 0 );
50+ while (index > 0 ) {
51+ final useMutable = index & 1 == 1 ;
52+ final digitIndex = (index >> 1 ) % numDigits;
53+ fields.add (
54+ ir.FieldType (_brandTypeFieldValues[digitIndex], mutable: useMutable));
55+ index = index ~ / (numDigits * 2 );
56+ }
5457 return ir.StructType (brandName, fields: fields);
5558}
5659
0 commit comments