|
169 | 169 | ) |
170 | 170 | ) |
171 | 171 |
|
172 | | -;; We can refine here, but as it is an export we only do so in open world. |
173 | | -(module |
174 | | - ;; CHECK: (type $0 (func)) |
175 | | - |
176 | | - ;; CHECK: (global $func-init (mut (ref $0)) (ref.func $foo)) |
177 | | - ;; CLOSD: (type $0 (func)) |
178 | | - |
179 | | - ;; CLOSD: (global $func-init (mut funcref) (ref.func $foo)) |
180 | | - (global $func-init (mut funcref) (ref.func $foo)) |
181 | | - |
182 | | - ;; CHECK: (export "global" (global $func-init)) |
183 | | - ;; CLOSD: (export "global" (global $func-init)) |
184 | | - (export "global" (global $func-init)) |
185 | | - |
186 | | - ;; CHECK: (func $foo (type $0) |
187 | | - ;; CHECK-NEXT: (nop) |
188 | | - ;; CHECK-NEXT: ) |
189 | | - ;; CLOSD: (func $foo (type $0) |
190 | | - ;; CLOSD-NEXT: (nop) |
191 | | - ;; CLOSD-NEXT: ) |
192 | | - (func $foo |
193 | | - (nop) |
194 | | - ) |
195 | | -) |
196 | | - |
197 | 172 | ;; We can refine $a, after which we should update the global.get in the other |
198 | 173 | ;; global, or else we'd error on validation. |
199 | 174 | ;; TODO: we could optimize further here and refine the type of the global $b. |
|
221 | 196 | (func $func (type $sub) |
222 | 197 | ) |
223 | 198 | ) |
| 199 | + |
| 200 | +;; Test all combinations of being exported and being mutable. |
| 201 | +;; |
| 202 | +;; Mutability limits our ability to optimize in open world: mutable globals that |
| 203 | +;; are exported cannot be refined, as they might be modified in another module |
| 204 | +;; using the old type. In closed world, however, we can optimize both globals |
| 205 | +;; here, as mutability is not a concern. As a result, we can refine the |
| 206 | +;; (ref null func) to nullfuncref only when not exported, and if exported, then |
| 207 | +;; only when immutable in open world. |
| 208 | +(module |
| 209 | + ;; CHECK: (global $mut (mut nullfuncref) (ref.null nofunc)) |
| 210 | + ;; CLOSD: (global $mut (mut nullfuncref) (ref.null nofunc)) |
| 211 | + (global $mut (mut (ref null func)) (ref.null nofunc)) |
| 212 | + ;; CHECK: (global $imm nullfuncref (ref.null nofunc)) |
| 213 | + ;; CLOSD: (global $imm nullfuncref (ref.null nofunc)) |
| 214 | + (global $imm (ref null func) (ref.null nofunc)) |
| 215 | + ;; CHECK: (global $mut-exp (mut funcref) (ref.null nofunc)) |
| 216 | + ;; CLOSD: (global $mut-exp (mut funcref) (ref.null nofunc)) |
| 217 | + (global $mut-exp (mut (ref null func)) (ref.null nofunc)) |
| 218 | + ;; CHECK: (global $imm-exp nullfuncref (ref.null nofunc)) |
| 219 | + ;; CLOSD: (global $imm-exp funcref (ref.null nofunc)) |
| 220 | + (global $imm-exp (ref null func) (ref.null nofunc)) |
| 221 | + |
| 222 | + ;; CHECK: (export "mut-exp" (global $mut-exp)) |
| 223 | + ;; CLOSD: (export "mut-exp" (global $mut-exp)) |
| 224 | + (export "mut-exp" (global $mut-exp)) |
| 225 | + ;; CHECK: (export "imm-exp" (global $imm-exp)) |
| 226 | + ;; CLOSD: (export "imm-exp" (global $imm-exp)) |
| 227 | + (export "imm-exp" (global $imm-exp)) |
| 228 | +) |
| 229 | + |
0 commit comments