Skip to content

Commit 069aec9

Browse files
authored
[Wasm GC] Skip types with subtypes in SignatureRefining (#5544)
For now just skip them, to avoid problems. In the future we should look into modifying their children, when possible. Fixes #5463
1 parent c891c01 commit 069aec9

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/passes/SignatureRefining.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "ir/find_all.h"
3131
#include "ir/lubs.h"
3232
#include "ir/module-utils.h"
33+
#include "ir/subtypes.h"
3334
#include "ir/type-updating.h"
3435
#include "ir/utils.h"
3536
#include "pass.h"
@@ -139,6 +140,16 @@ struct SignatureRefining : public Pass {
139140
allInfo[exportedFunc->type].canModify = false;
140141
}
141142

143+
// For now, do not optimize types that have subtypes. When we modify such a
144+
// type we need to modify subtypes as well, similar to the analysis in
145+
// TypeRefining, and perhaps we can unify this pass with that. TODO
146+
SubTypes subTypes(*module);
147+
for (auto& [type, info] : allInfo) {
148+
if (!subTypes.getStrictSubTypes(type).empty()) {
149+
info.canModify = false;
150+
}
151+
}
152+
142153
bool refinedResults = false;
143154

144155
// Compute optimal LUBs.

test/lit/passes/signature-refining.wast

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,3 +758,25 @@
758758
)
759759
)
760760
)
761+
762+
;; If we refine a type, that may require changes to its subtypes. For now, we
763+
;; skip such optimizations. TODO
764+
(module
765+
(rec
766+
;; CHECK: (type $A (func (param (ref null $B)) (result (ref null $A))))
767+
(type $A (func (param (ref null $B)) (result (ref null $A))))
768+
;; CHECK: (type $B (func_subtype (param (ref null $A)) (result (ref null $B)) $A))
769+
(type $B (func_subtype (param (ref null $A)) (result (ref null $B)) $A))
770+
)
771+
772+
;; CHECK: (elem declare func $func)
773+
774+
;; CHECK: (func $func (type $A) (param $0 (ref null $B)) (result (ref null $A))
775+
;; CHECK-NEXT: (ref.func $func)
776+
;; CHECK-NEXT: )
777+
(func $func (type $A) (param $0 (ref null $B)) (result (ref null $A))
778+
;; This result is non-nullable, and we could refine type $A accordingly. But
779+
;; if we did that, we'd need to refine $B as well.
780+
(ref.func $func)
781+
)
782+
)

0 commit comments

Comments
 (0)