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:
committed by
James Shubin
parent
aae0e16350
commit
16dfb7b5f5
17
lang/interpret_test/TestAstFunc2/constant-sub-graph.txtar
Normal file
17
lang/interpret_test/TestAstFunc2/constant-sub-graph.txtar
Normal 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]
|
||||
11
lang/interpret_test/TestAstFunc2/speculative-call1.txtar
Normal file
11
lang/interpret_test/TestAstFunc2/speculative-call1.txtar
Normal 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]
|
||||
12
lang/interpret_test/TestAstFunc2/speculative-call2.txtar
Normal file
12
lang/interpret_test/TestAstFunc2/speculative-call2.txtar
Normal 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]
|
||||
Reference in New Issue
Block a user