Skip to content

Replace PolyKit.Embedded with PolySharp in Buildvana.Sdk.SourceGenerators - #307

Merged
rdeago merged 1 commit into
Tenacom:mainfrom
rdeago:issue/305-polysharp
Jul 29, 2026
Merged

Replace PolyKit.Embedded with PolySharp in Buildvana.Sdk.SourceGenerators#307
rdeago merged 1 commit into
Tenacom:mainfrom
rdeago:issue/305-polysharp

Conversation

@rdeago

@rdeago rdeago commented Jul 29, 2026

Copy link
Copy Markdown
Member

Proposed changes

WHY#305: PolyKit.Embedded is effectively unmaintained and injects far more polyfills than the repository's only netstandard2.0 project needs. The excess internals leaked into the test project through InternalsVisibleTo, colliding with the same types in System.Runtime (CS0433) and forcing an extern-alias reference — a construct rare enough to be overlooked by maintainers, and one that had already triggered an in-IDE ReSharper false positive.

WHEREBuildvana.Sdk.SourceGenerators (project file and one expression in ConstantValueParser), Directory.Packages.props, Buildvana.Sdk.SourceGenerators.Tests.

WHATPolyKit.Embedded is gone. PolySharp 1.16.0 (PrivateAssets="all", central version under development dependencies) provides polyfills, restricted via PolySharpIncludeGeneratedTypes to a single type: IsExternalInit, required by the project's one readonly record struct. The test project now references the generators project without Aliases="Generators", and the two test files lose their extern alias directives. No consumer-visible changes; no CHANGELOG entry.

HOW#305 prescribed polyfilling System.Index too, for the project's single str[^1] expression — but PolySharp's Index polyfill references [NotNullWhen] and [DoesNotReturn], and PolySharp does not generate dependencies transitively. Polyfilling those attributes would have reintroduced, through InternalsVisibleTo, exactly the BCL collision that forced the extern alias (the test project itself uses [NotNullWhen]). Writing str[str.Length - 1] instead shrinks the injected surface to one type never named in source and lets the alias go for good. A comment on PolySharpIncludeGeneratedTypes warns future polyfill additions about this dependency fan-out.

Sanity check: dotnet bv pack clean (both packages produced), 51/51 source-generator tests green, dotnet build with zero warnings and zero errors; ReSharper inspectcode reports nothing in changed code (its single result is a pre-existing false positive in Buildvana.Core.JsonSchema, unrelated to this PR).

Checklist of related issues / discussions

Types of changes

This pull request introduces the following types of changes:

  • Bug fix
  • New feature
  • Test addition / update (no changes to non-test code)
  • Refactor (no changes in public API syntax or semantics)
  • Performance improvement (no changes in public API syntax or semantics)
  • Documentation (docs directory) update
  • Dependency addition / update
  • Changes to the build scripts
  • Changes to CI (workflows, bot / app configurations)
  • Other

Breaking changes

This pull request introduces breaking changes:

  • Yes
  • No

Checklist

  • For all types of changes:
  • For code changes only:
    • The project builds on my machine, via the provided build script, with zero warnings
    • I have added tests that prove my feature works / my fix is effective
    • I have added / modified XML documentation according to changes in code
    • I have checked that all the links I added or modified in XML documentation point to their intended destination
  • For documentation changes (docs directory) only:
    • I have built and tested documentation locally
    • I have checked that all the links I added or modified point to their intended destination

🤖 Generated with Claude Code

PolyKit is effectively unmaintained and injects far more polyfills than
the only netstandard2.0 project needs; the excess internals leaked into
the test project through InternalsVisibleTo, forcing an extern-alias
reference. PolySharp is restricted via PolySharpIncludeGeneratedTypes to
IsExternalInit alone: polyfilling System.Index (for a single str[^1])
would drag in the nullable attributes, which are precisely the types
that collided with the BCL's — so that expression becomes
str[str.Length - 1] and the extern alias goes away entirely.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@rdeago rdeago added the refactor [issue/PR] requests / implements a refactor of existing code without affecting functionality. label Jul 29, 2026
@github-actions github-actions Bot added area:code [issue/PR] affects project code (excluding tests). area:deps [issue/PR] adds, updates, or removes dependencies. labels Jul 29, 2026
@rdeago

rdeago commented Jul 29, 2026

Copy link
Copy Markdown
Member Author

@claude please review this PR.

@claude

claude Bot commented Jul 29, 2026

Copy link
Copy Markdown

Claude finished @rdeago's task in 1m 33s —— View job


Review: Replace PolyKit.Embedded with PolySharp in Buildvana.Sdk.SourceGenerators

  • Gather context (diff, changed files)
  • Understand the request
  • Review code changes
  • Post review feedback

Summary

Clean, well-scoped refactor. I reviewed the full diff against origin/main (6 files, +11/-12) plus the surrounding code to check for anything the diff might have missed.

Findings

Correctness — all good:

  • Directory.Packages.props: PolyKit.Embedded removed from run-time deps, PolySharp added under "Development dependencies" — correct placement per the central-package-management convention in dependency-management.md.
  • Buildvana.Sdk.SourceGenerators.csproj: PolySharpIncludeGeneratedTypes correctly restricts generation to IsExternalInit, which is genuinely needed — I confirmed the project's only record type, AdditionalAssemblyInfoValues (Internal/AdditionalAssemblyInfoValues.cs:7), is a readonly record struct with a primary constructor, which requires init accessors under netstandard2.0. The explanatory comment about System.Index's transitive dependency on [NotNullWhen]/[DoesNotReturn] (and the resulting InternalsVisibleTo collision) matches the reasoning in the PR description and will save the next contributor from rediscovering it.
  • ConstantValueParser.cs:46: str[^1]str[str.Length - 1] is a correct, semantically-identical rewrite — str is already proven non-empty by the preceding str!.Length > 1 check, so no off-by-one risk.
  • I grepped the whole source-generators project for other C# 9+/10+ constructs that might implicitly need a polyfill (init;, required, nint, Half, additional ^/range usages) and found none — the IsExternalInit-only restriction isn't going to silently break on a spot the PR didn't touch.
  • Test project: Aliases="Generators" removed from the ProjectReference, and both extern alias Generators; / Generators:: usages removed from ConstantValueParserTests.cs and ThisAssemblyClassGeneratorTests.cs. I confirmed via grep that no extern alias or Generators:: references remain anywhere in the test project, and no other test file needed the same treatment.
  • Remaining PolyKit mentions in the repo (README.md:140, CHANGELOG.md:384) are unrelated — one is a "built with Buildvana" shout-out to a different Tenacom project, the other is a historical changelog entry — neither should be touched by this PR.
  • No CHANGELOG entry, consistent with the PR's claim of no consumer-visible change (this project isn't packaged as a NuGet API surface consumers see; it only affects the SDK's internal source-generator build).

Nothing to flag — I don't have inline suggestions here. The one thing I'd normally double-check per .claude/rules/nuget-version-lookup.md — that PolySharp 1.16.0 is actually the current target version (latest stable, since the old PolyKit.Embedded reference was itself a preview and this is a straight replacement rather than an update-in-place) — I wasn't able to verify against the live NuGet feed in this session (no network tool access), so it's worth a quick manual check before merge if you want that fully confirmed.

Types of changes / checklist

Matches: pure internal refactor, PrivateAssets="all" on the new package (no consumer-visible impact), no breaking changes, no test behavior changes (51/51 as reported).

@rdeago
rdeago merged commit c224ce6 into Tenacom:main Jul 29, 2026
6 checks passed
@rdeago
rdeago deleted the issue/305-polysharp branch July 29, 2026 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:code [issue/PR] affects project code (excluding tests). area:deps [issue/PR] adds, updates, or removes dependencies. refactor [issue/PR] requests / implements a refactor of existing code without affecting functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace PolyKit.Embedded with PolySharp in Buildvana.Sdk.SourceGenerators

1 participant