summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2022-06-14 12:29:15 -0700
committerGitHub <noreply@github.com>2022-06-14 12:29:15 -0700
commit4c810e475c1a35a19fd1eec41de9c92852301ba6 (patch)
tree69fc551a352c09f690af9c5d0035010f69c7ce61
parent2a3de22a0a66ba749360bc72cf0cbb1f216bcb4f (diff)
downloadbinaryen-4c810e475c1a35a19fd1eec41de9c92852301ba6.tar.gz
binaryen-4c810e475c1a35a19fd1eec41de9c92852301ba6.tar.bz2
binaryen-4c810e475c1a35a19fd1eec41de9c92852301ba6.zip
SignatureRefining: Do not refine types of imported functions (#4727)
Spec and VM support for that is not yet stable (atm VMs do not allow complex user- defined types to be passed around).
-rw-r--r--src/passes/SignatureRefining.cpp9
-rw-r--r--test/lit/passes/signature-refining.wast25
2 files changed, 34 insertions, 0 deletions
diff --git a/src/passes/SignatureRefining.cpp b/src/passes/SignatureRefining.cpp
index bde1c4fb9..0574df434 100644
--- a/src/passes/SignatureRefining.cpp
+++ b/src/passes/SignatureRefining.cpp
@@ -81,6 +81,10 @@ struct SignatureRefining : public Pass {
ModuleUtils::ParallelFunctionAnalysis<Info, Mutable> analysis(
*module, [&](Function* func, Info& info) {
if (func->imported()) {
+ // Avoid changing the types of imported functions. Spec and VM support
+ // for that is not yet stable.
+ // TODO: optimize this when possible in the future
+ info.canModify = false;
return;
}
info.calls = std::move(FindAll<Call>(func->body).list);
@@ -111,6 +115,11 @@ struct SignatureRefining : public Pass {
// Add the function's return LUB to the one for the heap type of that
// function.
allInfo[func->type].resultsLUB.combine(info.resultsLUB);
+
+ // If one function cannot be modified, that entire type cannot be.
+ if (!info.canModify) {
+ allInfo[func->type].canModify = false;
+ }
}
// We cannot alter the signature of an exported function, as the outside may
diff --git a/test/lit/passes/signature-refining.wast b/test/lit/passes/signature-refining.wast
index 8e5d3b75e..02041c91c 100644
--- a/test/lit/passes/signature-refining.wast
+++ b/test/lit/passes/signature-refining.wast
@@ -720,3 +720,28 @@
)
)
)
+
+;; Do not modify the types used on imported functions (until the spec and VM
+;; support becomes stable).
+(module
+ ;; CHECK: (type $ref?|data|_=>_none (func_subtype (param (ref null data)) func))
+
+ ;; CHECK: (type $none_=>_none (func_subtype func))
+
+ ;; CHECK: (type $struct (struct_subtype data))
+ (type $struct (struct_subtype data))
+
+ ;; CHECK: (import "a" "b" (func $import (param (ref null data))))
+ (import "a" "b" (func $import (param (ref null data))))
+
+ ;; CHECK: (func $test (type $none_=>_none)
+ ;; CHECK-NEXT: (call $import
+ ;; CHECK-NEXT: (struct.new_default $struct)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ (func $test
+ (call $import
+ (struct.new $struct)
+ )
+ )
+)