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>
111 lines
2.7 KiB
Plaintext
111 lines
2.7 KiB
Plaintext
-- main.mcl --
|
|
# state machine that previously experienced unusable slow type unification
|
|
import "world"
|
|
|
|
$ns = "estate"
|
|
$exchanged = world.kvlookup($ns)
|
|
$state = $exchanged[$hostname] || "default"
|
|
|
|
if $state == "one" or $state == "default" {
|
|
|
|
file "/tmp/mgmt/state" {
|
|
content => "state: one\n",
|
|
}
|
|
|
|
exec "timer" {
|
|
cmd => "/usr/bin/sleep 1s",
|
|
}
|
|
kv "${ns}" {
|
|
key => $ns,
|
|
value => "two",
|
|
}
|
|
Exec["timer"] -> Kv["${ns}"]
|
|
}
|
|
if $state == "two" {
|
|
|
|
file "/tmp/mgmt/state" {
|
|
content => "state: two\n",
|
|
}
|
|
|
|
exec "timer" {
|
|
cmd => "/usr/bin/sleep 1s",
|
|
}
|
|
kv "${ns}" {
|
|
key => $ns,
|
|
value => "three",
|
|
}
|
|
Exec["timer"] -> Kv["${ns}"]
|
|
}
|
|
if $state == "three" {
|
|
|
|
file "/tmp/mgmt/state" {
|
|
content => "state: three\n",
|
|
}
|
|
|
|
exec "timer" {
|
|
cmd => "/usr/bin/sleep 1s",
|
|
}
|
|
kv "${ns}" {
|
|
key => $ns,
|
|
value => "one",
|
|
}
|
|
Exec["timer"] -> Kv["${ns}"]
|
|
}
|
|
-- OUTPUT --
|
|
Edge: _lookup_default -> _operator # a
|
|
Edge: _lookup_default -> _operator # a
|
|
Edge: _lookup_default -> _operator # a
|
|
Edge: _lookup_default -> _operator # a
|
|
Edge: _operator -> _operator # a
|
|
Edge: _operator -> _operator # b
|
|
Edge: const: str("") -> _lookup_default # indexorkey
|
|
Edge: const: str("==") -> _operator # op
|
|
Edge: const: str("==") -> _operator # op
|
|
Edge: const: str("==") -> _operator # op
|
|
Edge: const: str("==") -> _operator # op
|
|
Edge: const: str("default") -> _lookup_default # default
|
|
Edge: const: str("default") -> _operator # b
|
|
Edge: const: str("estate") -> kvlookup # namespace
|
|
Edge: const: str("one") -> _operator # b
|
|
Edge: const: str("or") -> _operator # op
|
|
Edge: const: str("three") -> _operator # b
|
|
Edge: const: str("two") -> _operator # b
|
|
Edge: kvlookup -> _lookup_default # listormap
|
|
Vertex: _lookup_default
|
|
Vertex: _operator
|
|
Vertex: _operator
|
|
Vertex: _operator
|
|
Vertex: _operator
|
|
Vertex: _operator
|
|
Vertex: const: str("")
|
|
Vertex: const: str("/tmp/mgmt/state")
|
|
Vertex: const: str("/tmp/mgmt/state")
|
|
Vertex: const: str("/tmp/mgmt/state")
|
|
Vertex: const: str("/usr/bin/sleep 1s")
|
|
Vertex: const: str("/usr/bin/sleep 1s")
|
|
Vertex: const: str("/usr/bin/sleep 1s")
|
|
Vertex: const: str("==")
|
|
Vertex: const: str("==")
|
|
Vertex: const: str("==")
|
|
Vertex: const: str("==")
|
|
Vertex: const: str("default")
|
|
Vertex: const: str("default")
|
|
Vertex: const: str("estate")
|
|
Vertex: const: str("one")
|
|
Vertex: const: str("one")
|
|
Vertex: const: str("or")
|
|
Vertex: const: str("state: one\n")
|
|
Vertex: const: str("state: three\n")
|
|
Vertex: const: str("state: two\n")
|
|
Vertex: const: str("three")
|
|
Vertex: const: str("three")
|
|
Vertex: const: str("timer")
|
|
Vertex: const: str("timer")
|
|
Vertex: const: str("timer")
|
|
Vertex: const: str("timer")
|
|
Vertex: const: str("timer")
|
|
Vertex: const: str("timer")
|
|
Vertex: const: str("two")
|
|
Vertex: const: str("two")
|
|
Vertex: kvlookup
|