File tree Expand file tree Collapse file tree 7 files changed +67
-11
lines changed Expand file tree Collapse file tree 7 files changed +67
-11
lines changed Original file line number Diff line number Diff line change 121
121
'cont_export_throw.wast' ,
122
122
'type-merging-cont.wast' ,
123
123
'remove-unused-module-elements-cont.wast' ,
124
+ 'abstract-type-refining-cont.wast' ,
124
125
# TODO: fix split_wast() on tricky escaping situations like a string ending
125
126
# in \\" (the " is not escaped - there is an escaped \ before it)
126
127
'string-lifting-section.wast' ,
Original file line number Diff line number Diff line change @@ -359,9 +359,10 @@ Type GlobalTypeRewriter::getTempType(Type type) {
359
359
}
360
360
if (type.isRef ()) {
361
361
auto heapType = type.getHeapType ();
362
- if (auto it = typeIndices.find (heapType); it != typeIndices.end ()) {
362
+ auto tempHeapType = getTempHeapType (heapType);
363
+ if (tempHeapType != heapType) {
363
364
return typeBuilder.getTempRefType (
364
- typeBuilder[it-> second ] , type.getNullability (), type.getExactness ());
365
+ tempHeapType , type.getNullability (), type.getExactness ());
365
366
}
366
367
// This type is not one that is eligible for optimizing. That is fine; just
367
368
// use it unmodified.
@@ -377,6 +378,13 @@ Type GlobalTypeRewriter::getTempType(Type type) {
377
378
WASM_UNREACHABLE (" bad type" );
378
379
}
379
380
381
+ HeapType GlobalTypeRewriter::getTempHeapType (HeapType type) {
382
+ if (auto it = typeIndices.find (type); it != typeIndices.end ()) {
383
+ return typeBuilder[it->second ];
384
+ }
385
+ return type;
386
+ }
387
+
380
388
Type GlobalTypeRewriter::getTempTupleType (Tuple tuple) {
381
389
return typeBuilder.getTempTupleType (tuple);
382
390
}
Original file line number Diff line number Diff line change @@ -404,6 +404,7 @@ class GlobalTypeRewriter {
404
404
// so that they can use a proper temp type of the TypeBuilder while modifying
405
405
// things.
406
406
Type getTempType (Type type);
407
+ HeapType getTempHeapType (HeapType type);
407
408
Type getTempTupleType (Tuple tuple);
408
409
409
410
using SignatureUpdates = std::unordered_map<HeapType, Signature>;
@@ -496,7 +497,7 @@ class TypeMapper : public GlobalTypeRewriter {
496
497
if (iter != mapping.end ()) {
497
498
return iter->second ;
498
499
}
499
- return type;
500
+ return getTempHeapType ( type) ;
500
501
}
501
502
502
503
Type getNewType (Type type) {
Original file line number Diff line number Diff line change @@ -805,9 +805,12 @@ struct TypeBuilder {
805
805
setHeapType (i, wasm::Array (elem));
806
806
return ;
807
807
}
808
- case HeapTypeKind::Cont:
809
- setHeapType (i, Continuation (map (type.getContinuation ().type )));
808
+ case HeapTypeKind::Cont: {
809
+ auto cont = type.getContinuation ();
810
+ cont.type = map (cont.type );
811
+ setHeapType (i, cont);
810
812
return ;
813
+ }
811
814
case HeapTypeKind::Basic:
812
815
WASM_UNREACHABLE (" unexpected kind" );
813
816
}
Original file line number Diff line number Diff line change @@ -1324,6 +1324,9 @@ FeatureSet HeapType::getFeatures() const {
1324
1324
1325
1325
// In addition, scan their non-ref children, to add dependencies on
1326
1326
// things like SIMD.
1327
+ // XXX This will not scan HeapType children that are not also children of
1328
+ // Type children, which happens with Continuation (has a HeapType
1329
+ // child that is not a Type).
1327
1330
for (auto child : heapType.getTypeChildren ()) {
1328
1331
if (!child.isRef ()) {
1329
1332
feats |= child.getFeatures ();
Original file line number Diff line number Diff line change
1
+ ;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
2
+
3
+ ;; RUN: foreach %s %t wasm-opt --abstract-type-refining -all --closed-world -S -o - | filecheck %s
4
+
5
+ ;; $uncreated is never created, so we optimize and rebuild types. While doing
6
+ ;; so we should not get confused as we copy the continuation type, which
7
+ ;; should end up referring properly to the corresponding func type.
8
+
9
+ (module
10
+ (rec
11
+ ;; CHECK: (rec
12
+ ;; CHECK-NEXT: (type $cont (cont $func))
13
+
14
+ ;; CHECK: (type $func (func))
15
+ (type $func (func ))
16
+ (type $cont (cont $func ))
17
+
18
+ (type $uncreated (struct ))
19
+ )
20
+
21
+ ;; CHECK: (elem declare func $func)
22
+
23
+ ;; CHECK: (func $func (type $func)
24
+ ;; CHECK-NEXT: )
25
+ (func $func (type $func )
26
+ )
27
+
28
+ ;; CHECK: (func $test (type $func)
29
+ ;; CHECK-NEXT: (drop
30
+ ;; CHECK-NEXT: (cont.new $cont
31
+ ;; CHECK-NEXT: (ref.func $func)
32
+ ;; CHECK-NEXT: )
33
+ ;; CHECK-NEXT: )
34
+ ;; CHECK-NEXT: )
35
+ (func $test (type $func )
36
+ (drop
37
+ (cont.new $cont
38
+ (ref.func $func )
39
+ )
40
+ )
41
+ )
42
+ )
43
+
Original file line number Diff line number Diff line change 10
10
;; CHECK: (rec
11
11
;; CHECK-NEXT: (type $f (func))
12
12
(type $f (func ))
13
- ;; CHECK: (type $f_0 (func))
14
-
15
- ;; CHECK: (type $k (cont $f_0))
13
+ ;; CHECK: (type $k (cont $f))
16
14
(type $k (cont $f ))
17
15
16
+ ;; CHECK: (type $f-i32 (func (result i32)))
18
17
(type $f-i32 (func (result i32 )))
19
- ;; CHECK: (type $f-i32_0 (func (result i32)))
20
-
21
- ;; CHECK: (type $k-i32 (cont $f-i32_0))
18
+ ;; CHECK: (type $k-i32 (cont $f-i32))
22
19
(type $k-i32 (cont $f-i32 ))
23
20
24
21
(rec
You can’t perform that action at this time.
0 commit comments