Skip to content

Split the largest generator methods into dedicated partial files#716

Merged
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-refactor-decompose-visitrecorddecl
Jul 13, 2026
Merged

Split the largest generator methods into dedicated partial files#716
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-refactor-decompose-visitrecorddecl

Conversation

@tannergooding

Copy link
Copy Markdown
Member

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:

Method Lines New file
VisitRecordDecl ~1963 PInvokeGenerator.VisitRecordDecl.cs
VisitVarDecl ~290 PInvokeGenerator.VisitVarDecl.cs
Close ~1444 PInvokeGenerator.Close.cs

Net effect on the host files:

  • PInvokeGenerator.VisitDecl.cs: 4146 -> 1891 lines
  • PInvokeGenerator.cs: 3917 -> 2472 lines

The 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.UnitTests pass.

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

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
tannergooding merged commit d4089a1 into dotnet:main Jul 13, 2026
14 checks passed
@tannergooding
tannergooding deleted the tannergooding-refactor-decompose-visitrecorddecl branch July 13, 2026 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant