diff --git a/lang/interpret_test/TestAstFunc2/constant-sub-graph.txtar b/lang/interpret_test/TestAstFunc2/constant-sub-graph.txtar new file mode 100644 index 00000000..6358b392 --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/constant-sub-graph.txtar @@ -0,0 +1,17 @@ +-- main.mcl -- +import "os" +$apply1 = func($f, $x) { + $f($x) +} +$apply2 = func($f, $x) { + $f($f($x)) +} +$apply = if (os.system("echo 0; echo 1") == "0") {$apply1} else {$apply2} +$id = func($y) { $y } + +# since $apply changes over time, this call needs a dynamic sub-graph. In +# theory, the $f calls above do not need a sub-graph, but does our optimization +# support this corner case yet? +test $apply($id, "foo") {} +-- OUTPUT -- +Vertex: test[foo] diff --git a/lang/interpret_test/TestAstFunc2/speculative-call1.txtar b/lang/interpret_test/TestAstFunc2/speculative-call1.txtar new file mode 100644 index 00000000..67136ca0 --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/speculative-call1.txtar @@ -0,0 +1,11 @@ +-- main.mcl -- +$f1 = func($x) { $x } +$f2 = func($x) { $x + $x } +$id = func($y) { $y } +$f = if ($id(true)) {$f1} else {$f2} + +# $f is always $f1, so in theory, this call does not need a sub-graph. +# But does our optimization support this corner case yet? +test $f("foo") {} +-- OUTPUT -- +Vertex: test[foo] diff --git a/lang/interpret_test/TestAstFunc2/speculative-call2.txtar b/lang/interpret_test/TestAstFunc2/speculative-call2.txtar new file mode 100644 index 00000000..75b2b745 --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/speculative-call2.txtar @@ -0,0 +1,12 @@ +-- main.mcl -- +$x = "not this x" +$add = func($x) { + func($y) {$x + $y} +} +$addfoo = $add("foo") + +# making sure that $x correctly refers to the lambda parameter rather than the +# top-level "not this x", even in the Value() codepath. +test $addfoo("bar") {} +-- OUTPUT -- +Vertex: test[foobar]