maybe_update_key_in_definitions = function(old_definition_name, definition_name, node)
if old_definition_name == nil or Definitions[old_definition_name] ~= node then
local pos = array.find(Definitions, node)
for i,n in ipairs(Definitions) do n.key = i end
elseif Definitions[old_definition_name] == node then
-- at this point we're sure node is no longer in Definitions
node.key = nil
Definitions[definition_name] = node
table.insert(Definitions, node)
end
node.key = #Definitions
end
--print('-- definition keys')
--for k in pairs(Definitions) do
--print(k)
--end
end
node.key = definition_name
elseif definition_name == nil or Definitions[definition_name] then
-- temporary collision; try again later
-- deleting and reinserting is inefficient, but hopefully rare
--print('moving to index', #Definitions+1)
if definition_name and Definitions[definition_name] == nil then
--print('moving to key', definition_name)
--print('found at key', old_definition_name)
Definitions[old_definition_name] = nil
end
--print('found at index', pos)
assert(pos)
table.remove(Definitions, pos)
--print(old_definition_name, definition_name)
if old_definition_name ~= definition_name then