lang: Add more test cases related to future graph optimization

We are planning to implement an optimization in which some function
calls are compiled to a single static graph rather than to a CallFunc
which dynamically creates a sub-graph at runtime. These test cases
exercise corner cases for which it would be theoretically possible to
use a static graph, but which we might not be able to optimize.
This commit is contained in:
Samuel Gélineau
2023-12-18 23:35:01 -05:00
committed by James Shubin
parent aae0e16350
commit 16dfb7b5f5
3 changed files with 40 additions and 0 deletions

View File

@@ -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]

View File

@@ -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]

View File

@@ -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]