Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GC] Ignore public types in SignatureRefining #7022

Merged
merged 1 commit into from
Oct 18, 2024
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
17 changes: 5 additions & 12 deletions src/passes/SignatureRefining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,11 @@ struct SignatureRefining : public Pass {
}
}

// We cannot alter the signature of an exported function, as the outside may
// notice us doing so. For example, if we turn a parameter from nullable
// into non-nullable then callers sending a null will break. Put another
// way, we need to see all callers to refine types, and for exports we
// cannot do so.
// TODO If a function type is passed we should also mark the types used
// there, etc., recursively. For now this code just handles the top-
// level type, which is enough to keep the fuzzer from erroring. More
// generally, we need to decide about adding a "closed-world" flag of
// some kind.
for (auto* exportedFunc : ExportUtils::getExportedFunctions(*module)) {
allInfo[exportedFunc->type].canModify = false;
// Find the public types, which we must not modify.
for (auto type : ModuleUtils::getPublicHeapTypes(*module)) {
if (type.isFunction()) {
allInfo[type].canModify = false;
}
}

// For now, do not optimize types that have subtypes. When we modify such a
Expand Down
40 changes: 40 additions & 0 deletions test/lit/passes/signature-refining.wast
Original file line number Diff line number Diff line change
Expand Up @@ -1119,3 +1119,43 @@
;; (see tests above for how we handle refining of return values).
)
)

;; Visibility: The type we'd like to refine, $sig, is in a rec group with a
;; public type, so do not optimize.
(module
(rec
;; CHECK: (rec
;; CHECK-NEXT: (type $sig (sub (func (param anyref))))
(type $sig (sub (func (param anyref))))

;; CHECK: (type $struct (struct))
(type $struct (struct))
)

;; Export a global with $struct to make it public.
;; CHECK: (type $2 (func))

;; CHECK: (global $struct (ref $struct) (struct.new_default $struct))
(global $struct (ref $struct) (struct.new $struct))

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

;; CHECK: (func $func (type $sig) (param $x anyref)
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: )
(func $func (type $sig) (param $x anyref)
)

;; CHECK: (func $caller (type $2)
;; CHECK-NEXT: (call $func
;; CHECK-NEXT: (struct.new_default $struct)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $caller
(call $func
(struct.new $struct)
)
)
)

Loading