Updates reference tracking to properly find num keyed alists (#95066)

## About The Pull Request

This is the most efficent way of doing it (I think), typeid checking is
actually worse (it's 55 btw). I've also added alists to all the find
reference unit tests.

This is a good step in making these things actually work in our
codebase. The next thing to look into will be VV (or SDQL though I
suspect that's just a matter of being able to use a stable version)
which is gonna require playing around with IS_NORMAL_LIST's uses a good
bit
This commit is contained in:
LemonInTheDark
2026-02-03 22:19:42 -05:00
committed by GitHub
parent fc89975a71
commit 2f87da7532
2 changed files with 40 additions and 6 deletions
@@ -126,6 +126,7 @@
else if(islist(potential_container))
var/list/potential_cache = potential_container
var/is_alist = istype(potential_cache, /alist)
for(var/element_in_list in potential_cache)
//Check normal sublists
if(islist(element_in_list))
@@ -162,7 +163,7 @@
log_reftracker("All references to [type] [text_ref(src)] found, exiting.")
return
if(!isnum(element_in_list) && !is_special_list)
if((!isnum(element_in_list) || is_alist) && !is_special_list)
// This exists to catch an error that throws when we access a special list
// is_special_list is a hint, it can be wrong
try
@@ -6,12 +6,14 @@
var/atom/movable/ref_test/test
var/list/test_list = list()
var/list/test_assoc_list = list()
var/alist/test_alist = alist()
/atom/movable/ref_holder/Destroy()
test = null
static_test = null
test_list.Cut()
test_assoc_list.Cut()
test_alist.Cut()
return ..()
/atom/movable/ref_test
@@ -45,14 +47,16 @@
testbed.test = victim
testbed.test_list += victim
testbed.test_assoc_list["baseline"] = victim
testbed.test_alist["baseline"] = victim
var/refcount = refcount(victim)
TEST_ASSERT_EQUAL(refcount, 6, "Should be: test references: 3 + baseline references: 3 (victim var,loc,allocated list)")
TEST_ASSERT_EQUAL(refcount, 7, "Should be: test references: 4 + baseline references: 3 (victim var,loc,allocated list)")
victim.DoSearchVar(testbed, "First Run")
TEST_ASSERT(LAZYACCESS(victim.found_refs, "test"), "The ref-tracking tool failed to find a regular value")
TEST_ASSERT(LAZYACCESS(victim.found_refs, testbed.test_list), "The ref-tracking tool failed to find a list entry")
TEST_ASSERT(LAZYACCESS(victim.found_refs, testbed.test_assoc_list), "The ref-tracking tool failed to find an assoc list value")
TEST_ASSERT(LAZYACCESS(victim.found_refs, testbed.test_alist), "The ref-tracking tool failed to find an alist value")
SSgarbage.should_save_refs = FALSE
/datum/unit_test/find_reference_exotic/Run()
@@ -64,15 +68,17 @@
testbed.overlays += victim
testbed.vis_contents += victim
testbed.test_assoc_list[victim] = TRUE
testbed.test_alist[victim] = TRUE
var/refcount = refcount(victim)
TEST_ASSERT_EQUAL(refcount, 6, "Should be: test references: 3 + baseline references: 3 (victim var,loc,allocated list)")
TEST_ASSERT_EQUAL(refcount, 7, "Should be: test references: 4 + baseline references: 3 (victim var,loc,allocated list)")
victim.DoSearchVar(testbed, "Second Run")
//This is another sanity check
TEST_ASSERT(!LAZYACCESS(victim.found_refs, testbed.overlays), "The ref-tracking tool found an overlays entry? That shouldn't be possible")
TEST_ASSERT(LAZYACCESS(victim.found_refs, testbed.vis_contents), "The ref-tracking tool failed to find a vis_contents entry")
TEST_ASSERT(LAZYACCESS(victim.found_refs, testbed.test_assoc_list), "The ref-tracking tool failed to find an assoc list key")
TEST_ASSERT(LAZYACCESS(victim.found_refs, testbed.test_alist), "The ref-tracking tool failed to find an alist key")
SSgarbage.should_save_refs = FALSE
/datum/unit_test/find_reference_esoteric/Run()
@@ -86,15 +92,18 @@
testbed.test_list += list(to_find)
var/list/to_find_assoc = list(victim)
testbed.test_assoc_list["Nesting"] = to_find_assoc
var/list/to_find_alist = list(victim)
testbed.test_alist["Nesting"] = to_find_alist
var/refcount = refcount(victim)
TEST_ASSERT_EQUAL(refcount, 6, "Should be: test references: 3 + baseline references: 3 (victim var,loc,allocated list)")
TEST_ASSERT_EQUAL(refcount, 7, "Should be: test references: 4 + baseline references: 3 (victim var,loc,allocated list)")
victim.DoSearchVar(victim, "Third Run Self")
victim.DoSearchVar(testbed, "Third Run Testbed")
TEST_ASSERT(LAZYACCESS(victim.found_refs, "self_ref"), "The ref-tracking tool failed to find a self reference")
TEST_ASSERT(LAZYACCESS(victim.found_refs, to_find), "The ref-tracking tool failed to find a nested list entry")
TEST_ASSERT(LAZYACCESS(victim.found_refs, to_find_assoc), "The ref-tracking tool failed to find a nested assoc list entry")
TEST_ASSERT(LAZYACCESS(victim.found_refs, to_find_alist), "The ref-tracking tool failed to find a nested alist entry")
SSgarbage.should_save_refs = FALSE
/datum/unit_test/find_reference_null_key_entry/Run()
@@ -104,11 +113,13 @@
//Calm before the storm
testbed.test_assoc_list = list(null = victim)
testbed.test_alist = alist(null = victim)
var/refcount = refcount(victim)
TEST_ASSERT_EQUAL(refcount, 4, "Should be: test references: 1 + baseline references: 3 (victim var,loc,allocated list)")
TEST_ASSERT_EQUAL(refcount, 5, "Should be: test references: 2 + baseline references: 3 (victim var,loc,allocated list)")
victim.DoSearchVar(testbed, "Fourth Run")
TEST_ASSERT(LAZYACCESS(victim.found_refs, testbed.test_assoc_list), "The ref-tracking tool failed to find a null key'd assoc list entry")
TEST_ASSERT(LAZYACCESS(victim.found_refs, testbed.test_alist), "The ref-tracking tool failed to find a null key'd alist entry")
/datum/unit_test/find_reference_assoc_investigation/Run()
var/atom/movable/ref_test/victim = allocate(/atom/movable/ref_test)
@@ -129,6 +140,28 @@
TEST_ASSERT(LAZYACCESS(victim.found_refs, to_find_null_assoc_nested), "The ref-tracking tool failed to find a null key'd nested assoc list entry")
SSgarbage.should_save_refs = FALSE
/datum/unit_test/find_reference_alist_investigation/Run()
var/atom/movable/ref_test/victim = allocate(/atom/movable/ref_test)
var/atom/movable/ref_holder/testbed = allocate(/atom/movable/ref_holder)
SSgarbage.should_save_refs = TRUE
//Alists are evil let's fuck em up a little
var/list/to_find_in_key = list(victim)
testbed.test_alist[to_find_in_key] = list("memes")
var/list/to_find_null_assoc_nested = list(victim)
testbed.test_alist[null] = to_find_null_assoc_nested
var/list/to_find_number_assoc_nested = list(victim)
testbed.test_alist[0] = to_find_number_assoc_nested
var/refcount = refcount(victim)
TEST_ASSERT_EQUAL(refcount, 6, "Should be: test references: 3 + baseline references: 3 (victim var,loc,allocated list)")
victim.DoSearchVar(testbed, "Sixth Run")
TEST_ASSERT(LAZYACCESS(victim.found_refs, to_find_in_key), "The ref-tracking tool failed to find a nested assoc list key")
TEST_ASSERT(LAZYACCESS(victim.found_refs, to_find_null_assoc_nested), "The ref-tracking tool failed to find a null key'd nested assoc list entry")
TEST_ASSERT(LAZYACCESS(victim.found_refs, to_find_number_assoc_nested), "The ref-tracking tool failed to find a number key'd alist entry")
SSgarbage.should_save_refs = FALSE
/datum/unit_test/find_reference_static_investigation/Run()
var/atom/movable/ref_test/victim = allocate(/atom/movable/ref_test)
var/atom/movable/ref_holder/testbed = allocate(/atom/movable/ref_holder)
@@ -146,7 +179,7 @@
var/refcount = refcount(victim)
TEST_ASSERT_EQUAL(refcount, 5, "Should be: test references: 2 + baseline references: 3 (victim var,loc,allocated list)")
victim.DoSearchVar(global_vars, "Sixth Run")
victim.DoSearchVar(global_vars, "Seventh Run")
TEST_ASSERT(LAZYACCESS(victim.found_refs, global_vars), "The ref-tracking tool failed to find a natively global variable")
SSgarbage.should_save_refs = FALSE