Skip to content

Commit a1e8b7c

Browse files
authored
Classify public tag types as public (#7232)
Tags previously preserved only their signatures and not their heap types in the IR, so there was no need or opportunity to classify their types as public, even for tags that were imported or exported. When we updated tags to preserve their heap types, we did not update the visibility classification code to handle them. Update that code now.
1 parent c7fdc01 commit a1e8b7c

File tree

2 files changed

+86
-3
lines changed

2 files changed

+86
-3
lines changed

src/ir/module-utils.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -605,8 +605,7 @@ void classifyTypeVisibility(Module& wasm,
605605
}
606606
};
607607

608-
// TODO: Consider Tags as well, but they should store HeapTypes instead of
609-
// Signatures first.
608+
ModuleUtils::iterImportedTags(wasm, [&](Tag* tag) { notePublic(tag->type); });
610609
ModuleUtils::iterImportedTables(wasm, [&](Table* table) {
611610
assert(table->type.isRef());
612611
notePublic(table->type.getHeapType());
@@ -647,7 +646,7 @@ void classifyTypeVisibility(Module& wasm,
647646
continue;
648647
}
649648
case ExternalKind::Tag:
650-
// TODO
649+
notePublic(wasm.getTag(ex->value)->type);
651650
continue;
652651
case ExternalKind::Invalid:
653652
break;
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
2+
3+
;; Check that public tag types are correctly considered public and do not become
4+
;; part of the single, large rec group.
5+
6+
;; RUN: foreach %s %t wasm-opt --remove-unused-types --closed-world -all -S -o - | filecheck %s
7+
8+
;; Neither imported nor exported tag. The tag type is private.
9+
(module
10+
;; CHECK: (rec
11+
;; CHECK-NEXT: (type $other-2 (struct (field i8)))
12+
13+
;; CHECK: (type $other-1 (struct))
14+
15+
;; CHECK: (type $tag-type (func))
16+
(type $tag-type (func))
17+
(type $other-1 (struct))
18+
(type $other-2 (struct (field i8)))
19+
20+
;; CHECK: (global $tag-type (ref null $tag-type) (ref.null nofunc))
21+
22+
;; CHECK: (global $other-1 (ref null $other-1) (ref.null none))
23+
24+
;; CHECK: (global $other-2 (ref null $other-2) (ref.null none))
25+
26+
;; CHECK: (tag $exported (type $tag-type))
27+
(tag $exported (type $tag-type))
28+
29+
;; Use all the types.
30+
(global $tag-type (ref null $tag-type) (ref.null nofunc))
31+
(global $other-1 (ref null $other-1) (ref.null none))
32+
(global $other-2 (ref null $other-2) (ref.null none))
33+
)
34+
35+
;; Imported tag.
36+
(module
37+
;; CHECK: (type $tag-type (func))
38+
(type $tag-type (func))
39+
;; CHECK: (rec
40+
;; CHECK-NEXT: (type $other-2 (struct (field i8)))
41+
42+
;; CHECK: (type $other-1 (struct))
43+
(type $other-1 (struct))
44+
(type $other-2 (struct (field i8)))
45+
46+
(tag $imported (import "" "") (type $tag-type))
47+
48+
;; Use all the types.
49+
;; CHECK: (import "" "" (tag $imported (type $tag-type)))
50+
51+
;; CHECK: (global $tag-type (ref null $tag-type) (ref.null nofunc))
52+
(global $tag-type (ref null $tag-type) (ref.null nofunc))
53+
;; CHECK: (global $other-1 (ref null $other-1) (ref.null none))
54+
(global $other-1 (ref null $other-1) (ref.null none))
55+
;; CHECK: (global $other-2 (ref null $other-2) (ref.null none))
56+
(global $other-2 (ref null $other-2) (ref.null none))
57+
)
58+
59+
;; Exported tag.
60+
(module
61+
;; CHECK: (type $tag-type (func))
62+
(type $tag-type (func))
63+
;; CHECK: (rec
64+
;; CHECK-NEXT: (type $other-2 (struct (field i8)))
65+
66+
;; CHECK: (type $other-1 (struct))
67+
(type $other-1 (struct))
68+
(type $other-2 (struct (field i8)))
69+
70+
;; CHECK: (global $tag-type (ref null $tag-type) (ref.null nofunc))
71+
72+
;; CHECK: (global $other-1 (ref null $other-1) (ref.null none))
73+
74+
;; CHECK: (global $other-2 (ref null $other-2) (ref.null none))
75+
76+
;; CHECK: (tag $exported (type $tag-type))
77+
(tag $exported (export "") (type $tag-type))
78+
79+
;; Use all the types.
80+
(global $tag-type (ref null $tag-type) (ref.null nofunc))
81+
(global $other-1 (ref null $other-1) (ref.null none))
82+
(global $other-2 (ref null $other-2) (ref.null none))
83+
)
84+
;; CHECK: (export "" (tag $exported))

0 commit comments

Comments
 (0)