Commit 182e808
interpreter: accept folded GC allocator global initializers in the WAT decoder
The global-decl parser detected GC heap-allocating initializers
(struct.new / array.new*) by scanning only the top-level atoms of the
initializer sexpr, so the folded leaf form
(struct.new $s (i32.const 100)) slipped past the check, fell through to
the literal-folding shape match, and was rejected with 'global init
expression must be i32.const or i64.const'. The same allocation wrapped
in extended-const arithmetic was accepted, because the extended-const
scan does recurse into folded operands.
Generalize the recursive sexpr scan into initExprMentions and use it for
both the extended-const detection and a new initExprAllocates predicate,
so GC allocators are detected in both the flat form emitted by
wasm-tools print and the folded form.
Adds regression theorems in Examples/GlobalInitExpr exercising the exact
repro from the issue: the leaf and arithmetic-wrapped struct.new
initializers both decode and evaluate to a struct whose field reads back
as 100.
Fixes #109
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>1 parent 3b2e07d commit 182e808
2 files changed
Lines changed: 78 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2189 | 2189 | | |
2190 | 2190 | | |
2191 | 2191 | | |
2192 | | - | |
2193 | | - | |
2194 | | - | |
2195 | | - | |
2196 | | - | |
2197 | | - | |
| 2192 | + | |
| 2193 | + | |
| 2194 | + | |
| 2195 | + | |
| 2196 | + | |
| 2197 | + | |
2198 | 2198 | | |
2199 | | - | |
| 2199 | + | |
2200 | 2200 | | |
2201 | | - | |
| 2201 | + | |
2202 | 2202 | | |
2203 | 2203 | | |
| 2204 | + | |
| 2205 | + | |
| 2206 | + | |
| 2207 | + | |
| 2208 | + | |
| 2209 | + | |
| 2210 | + | |
| 2211 | + | |
| 2212 | + | |
| 2213 | + | |
| 2214 | + | |
| 2215 | + | |
| 2216 | + | |
| 2217 | + | |
| 2218 | + | |
2204 | 2219 | | |
2205 | 2220 | | |
2206 | 2221 | | |
| |||
2228 | 2243 | | |
2229 | 2244 | | |
2230 | 2245 | | |
2231 | | - | |
2232 | | - | |
2233 | | - | |
2234 | | - | |
2235 | | - | |
2236 | | - | |
| 2246 | + | |
2237 | 2247 | | |
2238 | 2248 | | |
2239 | 2249 | | |
| |||
Lines changed: 54 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
58 | 112 | | |
59 | 113 | | |
0 commit comments