Skip to content

Split method cloning from the async to sync rules - #168

Merged
virzak merged 2 commits into
masterfrom
refactor/method-cloner
Sep 12, 2026
Merged

virzak merged 2 commits into
masterfrom
refactor/method-cloner

Conversation

@virzak

@virzak virzak commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Separates copying a method into its own file from the async to sync rules, so a second transformation would not have to untangle them. No change to generated output; every snapshot is unchanged.

  • Cloning/ now holds target discovery (CloneTarget), namespaces/usings/containing types (MethodLocation), collision detection and file naming (MethodSignature, ClonedMethodOutput), and file emission (ClonedMethodSource).
  • CloningRewriter is a new base class that fully qualifies types and static members. AsyncToSyncRewriter derives from it and keeps only the async rules; its type substitutions go through the MapSymbol and MapTypeName hooks.

Namespaces are now collected for methods with errors too, so such methods in different namespaces are no longer compared for collisions without them.

Generated with Claude Code

Separates the parts of the generator which have nothing to do with
async from the async to sync rules, so that the next transformation
does not have to start by untangling them:

- CloneTarget finds the methods an attribute marks, directly or
  through their containing type
- MethodLocation collects the namespaces, using directives and
  containing types a copy of a method needs to compile
- MethodSignature and ClonedMethodOutput detect colliding signatures,
  name the generated files and register the output
- ClonedMethodSource writes the file around the rewritten method

SyncMethodSourceGenerator keeps the attributes, the filtering and the
rewriter. Namespaces and using directives are now collected for every
method rather than only for those without errors, so a method with
errors is no longer compared for collisions without its namespace.

Generated with Claude Code
The half of the rewriter which fully qualifies the types and static
members a method names, so that its copy compiles in a file of its
own, moves into Cloning/CloningRewriter. AsyncToSyncRewriter derives
from it and keeps the async to sync rules.

Visitors which did both now call the base for the qualification and
apply the async rules to its result. Where the async rules change how
a type is named, they go through two hooks of the base: MapSymbol for
Task to void or T and the async enumerator to IEnumerator, and
MapTypeName for AsyncEnumerable to Enumerable.

A parameter whose type has no named type symbol, such as a type
parameter, now goes through the base's qualification as well, which
writes the same text for it.

AGENTS.md describes the Cloning layer and where the boundary is.

Generated with Claude Code
@codecov

codecov Bot commented Sep 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.60825% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.26%. Comparing base (34b24d4) to head (354fd2c).

Files with missing lines Patch % Lines
...omp.SyncMethodGenerator/Cloning/CloningRewriter.cs 92.85% 4 Missing and 7 partials ⚠️
...Zomp.SyncMethodGenerator/Cloning/MethodLocation.cs 89.85% 2 Missing and 5 partials ⚠️
...omp.SyncMethodGenerator/Cloning/MethodSignature.cs 73.68% 2 Missing and 3 partials ⚠️
...rc/Zomp.SyncMethodGenerator/AsyncToSyncRewriter.cs 94.64% 0 Missing and 3 partials ⚠️
...rc/Zomp.SyncMethodGenerator/Cloning/CloneTarget.cs 90.47% 1 Missing and 1 partial ⚠️
....SyncMethodGenerator/Cloning/ClonedMethodSource.cs 97.64% 1 Missing and 1 partial ⚠️
...p.SyncMethodGenerator/SyncMethodSourceGenerator.cs 83.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #168      +/-   ##
==========================================
+ Coverage   92.19%   92.26%   +0.07%     
==========================================
  Files          11       15       +4     
  Lines        1652     1706      +54     
  Branches      381      391      +10     
==========================================
+ Hits         1523     1574      +51     
- Misses         45       48       +3     
  Partials       84       84              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@virzak
virzak merged commit ff8281b into master Sep 12, 2026
10 checks passed
@virzak
virzak deleted the refactor/method-cloner branch September 12, 2026 16:47
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