Refactor FlatModule.gather from stack to heap overflow#121
Open
kshaa wants to merge 1 commit intonturley:masterfrom
Open
Refactor FlatModule.gather from stack to heap overflow#121kshaa wants to merge 1 commit intonturley:masterfrom
kshaa wants to merge 1 commit intonturley:masterfrom
Conversation
paulgeorge
pushed a commit
to paulgeorge/netlistsvg
that referenced
this pull request
Mar 16, 2026
Cherry-pick of upstream PR nturley#121. Converts recursive gather() to iterative loop to prevent stack overflow on large netlists.
This was referenced Mar 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I ran into the same error as mentioned in issue #98 and saw that there's a proposition to fix it by refactoring FlatModule.gather from a recursive function to a loop, because it seems tail recursive-ish, this PR does exactly that.
Unfortunately it seems that
gatherisn't completely tail recursive (one condition leads to a recursive call and then afterwards modifies inputs) so I just left that part recursive and refactored all the other parts. However in my use case it seemed that this condition that can't be refactored wasn't the one causing a stack overflow, so in essence the patch is worthy and does fix at least some of the badly performing use cases.TL;DR - This patch allows using more RAM on beefy netlists before everything crashes and burns. I.e. a stack overflow has been refactored into a heap overflow (or into a successful case if there's enough RAM).