Split the largest generator methods into dedicated partial files#716
Merged
tannergooding merged 1 commit intoJul 13, 2026
Conversation
PInvokeGenerator.VisitDecl.cs and PInvokeGenerator.cs were dominated by a few very large methods: VisitRecordDecl (~1963 lines, ~47% of VisitDecl.cs), Close (~1444 lines, ~37% of PInvokeGenerator.cs), and VisitVarDecl (~290 lines). Their many nested local functions are the sole users of the enclosing method state, so a local function is the correct expression of that coupling; the readability problem is the sheer size of the host files, not the nesting. Move each method verbatim (nested locals intact) into its own partial file -- PInvokeGenerator.VisitRecordDecl.cs, PInvokeGenerator.VisitVarDecl.cs, and PInvokeGenerator.Close.cs -- using the minimal public partial class PInvokeGenerator declaration matching the other partial files. No code within the methods changed; generated output is byte-identical and all 3708 golden tests pass. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
tannergooding
deleted the
tannergooding-refactor-decompose-visitrecorddecl
branch
July 13, 2026 03:01
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.
Splits the three largest methods in the generator into their own partial files to cut the size of the two biggest source files. This is purely a code-organization change -- no method bodies were touched and the generated output is byte-identical (all 3708 golden tests pass).
The nesting itself was fine: each moved method has several nested local functions that are the sole users of the enclosing method state, so a local function is the correct expression of that coupling. The problem was the sheer size of the host files, so the fix is a dedicated partial file per method rather than un-nesting anything.
Moved verbatim (nested locals intact), each into a minimal
public partial class PInvokeGenerator:VisitRecordDeclPInvokeGenerator.VisitRecordDecl.csVisitVarDeclPInvokeGenerator.VisitVarDecl.csClosePInvokeGenerator.Close.csNet effect on the host files:
PInvokeGenerator.VisitDecl.cs: 4146 -> 1891 linesPInvokeGenerator.cs: 3917 -> 2472 linesThe two modified files show pure deletions -- no line inside any method changed, which is why the diff is large but the whitespace-ignored change is effectively zero. Build is clean (0 warnings / 0 errors) and all 3708
ClangSharp.PInvokeGenerator.UnitTestspass.The 300-500 line middle tier in
PInvokeGenerator.VisitStmt.cs(VisitInitListExpr,VisitStmt,VisitCallExpr) was intentionally left alone here to avoid over-fragmentation; it can be a follow-up if wanted.Co-authored-by: Copilot App 223556219+Copilot@users.noreply.github.com