Most of the time, we don't need to have a dynamic call sub graph, since the actual function call could be represented statically as it originally was before lambda functions were implemented. Simplifying the graph shape has important performance benefits in terms of both keep the graph smaller (memory, etc) and in avoiding the need to run transactions at runtime (speed) to reshape the graph. Co-authored-by: Samuel Gélineau <gelisam@gmail.com>
42 lines
691 B
Plaintext
42 lines
691 B
Plaintext
-- main.mcl --
|
|
# this can return changing functions, and could be optimized, too
|
|
func funcgen($b) {
|
|
if $b {
|
|
func() {
|
|
"hello"
|
|
}
|
|
} else {
|
|
func() {
|
|
"world"
|
|
}
|
|
}
|
|
}
|
|
|
|
$fn1 = funcgen(true)
|
|
$fn2 = funcgen(false)
|
|
|
|
$out1 = $fn1()
|
|
$out2 = $fn2()
|
|
|
|
test "${out1}" {}
|
|
test "${out2}" {}
|
|
-- OUTPUT --
|
|
Edge: FuncValue -> if # a
|
|
Edge: FuncValue -> if # a
|
|
Edge: FuncValue -> if # b
|
|
Edge: FuncValue -> if # b
|
|
Edge: const: bool(false) -> if # c
|
|
Edge: const: bool(true) -> if # c
|
|
Edge: if -> call # fn
|
|
Edge: if -> call # fn
|
|
Vertex: FuncValue
|
|
Vertex: FuncValue
|
|
Vertex: FuncValue
|
|
Vertex: FuncValue
|
|
Vertex: call
|
|
Vertex: call
|
|
Vertex: const: bool(false)
|
|
Vertex: const: bool(true)
|
|
Vertex: if
|
|
Vertex: if
|