Skip to content

Commit

Permalink
Improve graph viz, allow dumping edge causes
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikMcClure committed Jan 17, 2025
1 parent 6a99da6 commit 63e52b2
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
26 changes: 24 additions & 2 deletions evaluator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3777,13 +3777,33 @@ function TypeCheckerState:Visualize(diff1, diff2, restrict)
}
end

local node_check = nil
if restrict ~= nil then
node_check = U.shallow_copy(restrict)

local function propagate_edges(cur_edges, prev_edges)
for i, e in ipairs(cur_edges) do
if prev_edges[i] and prev_edges[i].left == e.left and prev_edges[i].right == e.right then
if restrict[e.left] ~= nil or restrict[e.right] ~= nil then
node_check[e.left] = e.left
node_check[e.right] = e.right
end
end
end
end

propagate_edges(cur.constrain_edges, prev.constrain_edges)
propagate_edges(cur.leftcall_edges, prev.leftcall_edges)
propagate_edges(cur.rightcall_edges, prev.rightcall_edges)
end

local additions = {}
local g = "digraph State {"

for i, v in ipairs(cur.values) do
local changed = true
if prev.values[i] then
if restrict ~= nil and restrict[i] == nil then
if node_check ~= nil and node_check[i] == nil then
goto continue
end
changed = false
Expand Down Expand Up @@ -3825,13 +3845,15 @@ function TypeCheckerState:Visualize(diff1, diff2, restrict)

if v[1]:is_enum_value() and v[1]:unwrap_enum_value() == "empty" then
line = line .. "shape=doubleoctagon]"
g = g .. line
goto continue
elseif
v[1]:is_neutral()
and v[1]:unwrap_neutral():is_free()
and v[1]:unwrap_neutral():unwrap_free():is_metavariable()
then
line = line .. "shape=doublecircle]"
g = g .. line
goto continue
elseif v[1]:is_star() then
line = line .. "shape=egg, "
Expand Down Expand Up @@ -3892,7 +3914,7 @@ function TypeCheckerState:Visualize(diff1, diff2, restrict)
end

for i, e in ipairs(cur.rightcall_edges) do
local line = "\n" .. e.left .. " -> " .. e.right .. " [arrowhead=invempty"
local line = "\n" .. e.left .. " -> " .. e.right .. " [arrowhead=curve"

if
prev.rightcall_edges[i]
Expand Down
32 changes: 32 additions & 0 deletions runtest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,35 @@ end

--local graph_backtrace = 5
local internal_state

local function dump_edges(edge_list)
if internal_state == nil then
local internals_interface = require "internals-interface"

internal_state = internals_interface.evaluator.typechecker_state
end

local function dump_edge(l, r)
local function dump_edge_from(l, r, edges)
for _, v in ipairs(edges) do
if v.left == l and v.right == r then
print("EDGE FOUND: " .. l .. "->" .. r)
v.cause.track = true
print("CAUSED BY: " .. tostring(v.cause))
end
end
end
dump_edge_from(l, r, internal_state.graph.constrain_edges:all())
dump_edge_from(l, r, internal_state.graph.leftcall_edges:all())
dump_edge_from(l, r, internal_state.graph.rightcall_edges:all())
end

for i, v in ipairs(edge_list) do
print("Searching for: " .. v[1] .. "->" .. v[2])
dump_edge(v[1], v[2])
end
end

if graph_backtrace ~= nil then
local internals_interface = require "internals-interface"

Expand All @@ -359,6 +388,7 @@ if not ok then
local snapshots = internal_state.snapshot_buffer
local i = (internal_state.snapshot_count + 1) % graph_backtrace
local slice = {}
slice[55825] = 55825
for j = 2, graph_backtrace do
local f = io.open("GRAPH_STATE" .. j .. ".dot", "w")
local out, additions = internal_state:Visualize(snapshots[i + 1], snapshots[i + 2], slice)
Expand All @@ -371,8 +401,10 @@ if not ok then
end
end

--dump_edges({ { 55825, 47999 }, { 47954, 55825 } })
return
end

---@cast expr inferrable
---@cast env Environment

Expand Down

0 comments on commit 63e52b2

Please sign in to comment.