`nickel doc` overflows the stack with recursive schemas
yannham opened this issue · 2 comments
Describe the bug
nickel doc
aborts with a stack overflow on a real-world 1MB Nickel schema, which doesn't look very deep (nickel doc
does use recursive calls, but the stack space should be linear in the depth of the schema, roughly).
To Reproduce
I unfortunately can't provide the test case, which has been provided as a courtesy but isn't public. This issue is mostly a reminder to investigate it.
We do have a MRE, and it seems it doesn't have anything to do with schema size, but everything to do with recursive contracts:
{
Recursive = {
foo | Number,
bar | Recursive | optional
}
}
I think we had the exact same problem in the LSP (not for documentation, but for elaborating e.g. completion information). One simple and stupid solution was to set a recursion limit there.
However, I don't think that would work very well for documentation, because that will result in unrolling the definition of Recursive
max_depth
times, which is not what one's want. So we need a way to keep track of things that we've already processed (or are processing), and decide to not unfold those definitions. I wonder if we can reuse the logistics of thunks to do so.
cc @Quantum64