summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xscripts/fuzz_opt.py3
-rw-r--r--src/passes/Flatten.cpp30
2 files changed, 32 insertions, 1 deletions
diff --git a/scripts/fuzz_opt.py b/scripts/fuzz_opt.py
index 94db99e05..df7ab8136 100755
--- a/scripts/fuzz_opt.py
+++ b/scripts/fuzz_opt.py
@@ -988,6 +988,9 @@ def randomize_opt_flags():
if '--disable-exception-handling' not in FEATURE_OPTS:
print('avoiding --flatten due to exception catching which does not support it yet')
continue
+ if '--disable-multivalue' not in FEATURE_OPTS and '--disable-reference-types' not in FEATURE_OPTS:
+ print('avoiding --flatten due to multivalue + reference types not supporting it (spilling of non-nullable tuples)')
+ continue
if INITIAL_CONTENTS and os.path.getsize(INITIAL_CONTENTS) > 2000:
print('avoiding --flatten due using a large amount of initial contents, which may blow up')
continue
diff --git a/src/passes/Flatten.cpp b/src/passes/Flatten.cpp
index 39c97b133..c8f731d64 100644
--- a/src/passes/Flatten.cpp
+++ b/src/passes/Flatten.cpp
@@ -17,8 +17,27 @@
//
// Flattens code into "Flat IR" form. See ir/flat.h.
//
-// TODO: handle non-nullability
+// TODO: handle non-nullability. for example:
//
+// (module
+// (type $none (func))
+// (func $foo
+// (drop
+// (block (result funcref (ref $none))
+// (tuple.make
+// (ref.null func)
+// (ref.func $foo)
+// )
+// )
+// )
+// )
+// )
+//
+// The tuple has a non-nullable type, and so it cannot be set to a local. We
+// would need to split up the tuple and reconstruct it later, but that would
+// require allowing tuple operations in more nested places than Flat IR allows
+// today. For now, error on this; eventually changes in the spec regarding
+// null-nullability may make this easier.
#include <ir/branch-utils.h>
#include <ir/effects.h>
@@ -319,6 +338,15 @@ struct Flatten
curr->body = getPreludesWithExpression(originalBody, curr->body);
// New locals we added may be non-nullable.
TypeUpdating::handleNonNullableLocals(curr, *getModule());
+ // We cannot handle non-nullable tuples currently, see the comment at the
+ // top of the file.
+ for (auto type : curr->vars) {
+ if (!type.isDefaultable()) {
+ Fatal() << "Flatten was forced to add a local of a type it cannot "
+ "handle yet: "
+ << type;
+ }
+ }
}
private: