greybel-vs
greybel-vs copied to clipboard
Enhancement: Detect/Warn on multilevel cycles
This doesn't affect Greybel at all, but it can completely hang a script in-game. It requires a certain amount of cyclic references - simply doing Foo = {}; Foo.__isa = Foo
doesn't affect it at all. This is a bug that's been fixed in the first 2023 release of MiniScript, but of course, GreyHack isn't using that.
From in-game testing, the hang seems to occur somewhere inside hash calculation of map keys - I suspect it's somewhere on the order of O(n^2)
(or worse) since paring down the example below will hang the game for just a few seconds.
For the purposes of the enhancement, just warning on the detection of any cycles would be a fantastic feature.
The bad code:
Foo = {}
Foo.a = "str"
Foo.b = false
Foo.c = true
Foo.d = false
Foo.id = 0
Foo[0] = new Foo
Foo[1] = new Foo
Foo[1].id = 1
Foo[1].type = "str2"
Foo[1].en_str = "str3"
Foo.x = Foo[1]
Foo[2] = new Foo
Foo[2].id = 2
Foo[2].type = "str4"
Foo[2].en_str = "str5"
Foo.y = Foo[2]
Foo[3] = new Foo
Foo.z = Foo[3]
Foo[4] = new Foo
Foo[4].id = 2
Foo[4].type = "str6"
Foo[4].en_str = "str7"
Foo.a = Foo[4]
Foo[5] = new Foo
Foo[5].id = 2
Foo[5].type = "str6"
Foo[5].en_str = "str7"
Foo.b = Foo[5]
Bar = {}
Bar[new Foo[4]] = 3 //DEAD