Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/tools/wasm-merge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,10 @@ void updateTypes(Module& wasm) {
return std::make_unique<Updater>();
}

void visitGlobalGet(GlobalGet* curr) {
curr->type = getModule()->getGlobal(curr->name)->type;
}

void visitRefFunc(RefFunc* curr) {
curr->finalize(getModule()->getFunction(curr->func)->type);
}
Expand Down
42 changes: 42 additions & 0 deletions test/lit/merge/global_subtyping.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.

;; RUN: wasm-merge %s primary %s.second secondary --skip-export-conflicts -all -S -o - | filecheck %s

;; Export a global with a subtype. It is imported using the supertype, and
;; after we merge, the type must be updated, including in the global.get from
;; the second module (that goes from super to sub).
(module
;; CHECK: (type $super (sub (func)))
(type $super (sub (func)))
;; CHECK: (type $sub (sub final $super (func)))
(type $sub (sub final $super (func)))

;; CHECK: (type $2 (func))

;; CHECK: (global $sub (ref $sub) (ref.func $sub))
(global $sub (ref $sub) (ref.func $sub))

;; CHECK: (export "sub" (global $sub))
(export "sub" (global $sub))

;; CHECK: (export "second-user" (func $second-user))

;; CHECK: (func $sub (type $sub)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (global.get $sub)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $sub (type $sub)
(drop
(global.get $sub)
)
)
)

;; CHECK: (func $second-user (type $2)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (block (result (ref $sub))
;; CHECK-NEXT: (global.get $sub)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
14 changes: 14 additions & 0 deletions test/lit/merge/global_subtyping.wat.second
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(module
(type $second-super (sub (func)))

(import "primary" "sub" (global $import (ref $second-super)))

(func $second-user (export "second-user")
(drop
(block (result (ref $second-super))
(global.get $import)
)
)
)
)

Loading