Skip to content

Commit 69e665e

Browse files
authored
[GC] Fix order of operations in TypeRefiningGUFA: Restrictions must propagate (#7462)
We must first find global restrictions, then propagate, so that the restrictions propagate.
1 parent b0d51f5 commit 69e665e

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

src/passes/TypeRefining.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,6 @@ struct TypeRefining : public Pass {
190190
}
191191
}
192192

193-
// Propagate to supertypes, so no field is less refined than its super.
194-
propagator.propagateToSuperTypes(finalInfos);
195-
196193
// Take into account possible problems. This pass only refines struct
197194
// fields, and when we refine in a way that exceeds the wasm type system
198195
// then we fix that up with a cast (see below). However, we cannot use casts
@@ -225,6 +222,9 @@ struct TypeRefining : public Pass {
225222
}
226223
}
227224
}
225+
226+
// Propagate to supertypes, so no field is less refined than its super.
227+
propagator.propagateToSuperTypes(finalInfos);
228228
}
229229

230230
void useFinalInfos(Module* module, Propagator& propagator) {

test/lit/passes/type-refining-gufa.wast

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,3 +383,45 @@
383383
;; GUFA: (global $C (ref $struct) (struct.new_default $struct))
384384
(global $C (ref $struct) (struct.new_default $struct))
385385
)
386+
387+
;; As above, but $struct has a supertype. We must propagate restrictions on it
388+
;; to its supertype. After doing so, we can refine the field to (ref func) in
389+
;; both, but no further, because of the restriction of global.get $A, which has
390+
;; that type.
391+
(module
392+
(rec
393+
;; NRML: (rec
394+
;; NRML-NEXT: (type $super (sub (struct (field (ref func)))))
395+
;; GUFA: (rec
396+
;; GUFA-NEXT: (type $super (sub (struct (field (ref func)))))
397+
(type $super (sub (struct (field funcref))))
398+
;; NRML: (type $struct (sub $super (struct (field (ref func)))))
399+
;; GUFA: (type $struct (sub $super (struct (field (ref func)))))
400+
(type $struct (sub $super (struct (field funcref))))
401+
)
402+
403+
;; NRML: (type $func (func))
404+
;; GUFA: (type $func (func))
405+
(type $func (func))
406+
407+
;; NRML: (global $A (ref func) (ref.func $func))
408+
;; GUFA: (global $A (ref func) (ref.func $func))
409+
(global $A (ref func) (ref.func $func))
410+
411+
;; NRML: (global $B (ref $struct) (struct.new $struct
412+
;; NRML-NEXT: (global.get $A)
413+
;; NRML-NEXT: ))
414+
;; GUFA: (global $B (ref $struct) (struct.new $struct
415+
;; GUFA-NEXT: (global.get $A)
416+
;; GUFA-NEXT: ))
417+
(global $B (ref $struct) (struct.new $struct
418+
(global.get $A)
419+
))
420+
421+
;; NRML: (func $func (type $func)
422+
;; NRML-NEXT: )
423+
;; GUFA: (func $func (type $func)
424+
;; GUFA-NEXT: )
425+
(func $func (type $func)
426+
)
427+
)

0 commit comments

Comments
 (0)