Skip to content

Commit 482a548

Browse files
authored
[Custom Descriptors] Support in Precompute (#7678)
Now that we support interpretation of ref.get_desc and the descriptor casts, test that Precompute handles them properly.
1 parent 7dbb670 commit 482a548

File tree

3 files changed

+86
-6
lines changed

3 files changed

+86
-6
lines changed

scripts/test/fuzzing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
'type-merging-desc.wast',
124124
'heap2local-desc.wast',
125125
'minimize-rec-groups-desc.wast',
126+
'precompute-desc.wast',
126127
# TODO: fix split_wast() on tricky escaping situations like a string ending
127128
# in \\" (the " is not escaped - there is an escaped \ before it)
128129
'string-lifting-section.wast',

src/passes/Precompute.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,6 @@ class PrecomputingExpressionRunner
240240
// string.encode_wtf16_array anyhow.)
241241
return Flow(NONCONSTANT_FLOW);
242242
}
243-
244-
Flow visitRefGetDesc(RefGetDesc* curr) {
245-
// TODO: Implement this. For now, return nonconstant so that we skip it and
246-
// do not error.
247-
return Flow(NONCONSTANT_FLOW);
248-
}
249243
};
250244

251245
struct Precompute

test/lit/passes/precompute-desc.wast

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
2+
3+
;; RUN: wasm-opt %s --remove-unused-names --precompute-propagate --fuzz-exec -all -S -o - \
4+
;; RUN: | filecheck %s
5+
6+
(module
7+
(rec
8+
;; CHECK: (rec
9+
;; CHECK-NEXT: (type $struct (descriptor $desc (struct)))
10+
(type $struct (descriptor $desc (struct)))
11+
;; CHECK: (type $desc (describes $struct (struct)))
12+
(type $desc (describes $struct (struct)))
13+
)
14+
15+
;; CHECK: (global $desc (ref (exact $desc)) (struct.new_default $desc))
16+
(global $desc (ref (exact $desc)) (struct.new $desc))
17+
;; CHECK: (global $struct (ref $struct) (struct.new_default $struct
18+
;; CHECK-NEXT: (global.get $desc)
19+
;; CHECK-NEXT: ))
20+
(global $struct (ref $struct) (struct.new $struct (global.get $desc)))
21+
22+
;; CHECK: (func $eq-descs (type $0) (result i32)
23+
;; CHECK-NEXT: (i32.const 1)
24+
;; CHECK-NEXT: )
25+
(func $eq-descs (result i32)
26+
(ref.eq
27+
(ref.get_desc $struct
28+
(struct.new $struct
29+
(global.get $desc)
30+
)
31+
)
32+
(global.get $desc)
33+
)
34+
)
35+
36+
;; CHECK: (func $different-descs (type $0) (result i32)
37+
;; CHECK-NEXT: (i32.const 0)
38+
;; CHECK-NEXT: )
39+
(func $different-descs (result i32)
40+
(ref.eq
41+
(ref.get_desc $struct
42+
(struct.new $struct
43+
(struct.new $desc)
44+
)
45+
)
46+
(global.get $desc)
47+
)
48+
)
49+
50+
;; CHECK: (func $br-on-cast-desc (type $0) (result i32)
51+
;; CHECK-NEXT: (i32.const 1)
52+
;; CHECK-NEXT: )
53+
(func $br-on-cast-desc (result i32)
54+
(ref.eq
55+
(block $l (result eqref)
56+
(drop
57+
(br_on_cast_desc $l eqref (ref $struct)
58+
(global.get $struct)
59+
(global.get $desc)
60+
)
61+
)
62+
(ref.null none)
63+
)
64+
(global.get $struct)
65+
)
66+
)
67+
68+
;; CHECK: (func $br-on-cast-desc-fail (type $0) (result i32)
69+
;; CHECK-NEXT: (i32.const 0)
70+
;; CHECK-NEXT: )
71+
(func $br-on-cast-desc-fail (result i32)
72+
(ref.eq
73+
(block $l (result eqref)
74+
(drop
75+
(br_on_cast_desc_fail $l eqref (ref $struct)
76+
(global.get $struct)
77+
(global.get $desc)
78+
)
79+
)
80+
(ref.null none)
81+
)
82+
(global.get $struct)
83+
)
84+
)
85+
)

0 commit comments

Comments
 (0)