Extract STJ UnsafeAccessor emitter into a shared SourceGenerators helper - #133360
Draft
svick wants to merge 1 commit into
Draft
Extract STJ UnsafeAccessor emitter into a shared SourceGenerators helper#133360svick wants to merge 1 commit into
svick wants to merge 1 commit into
Conversation
Move the System.Text.Json source generator's accessor-emission machinery (UnsafeAccessor-based get/set/field accessors, constructor accessors, generic wrappers, and the reflection fallback) into a new shared helper, Common/src/SourceGenerators/UnsafeAccessorEmitter.cs, so other source generators (e.g. the Microsoft.Extensions.Configuration.Binder generator) can reuse it. The helper works over neutral, primitive-only spec types (UnsafeAccessorMemberSpec, UnsafeAccessorConstructorSpec, UnsafeAccessorParameterSpec) and owns accessor naming using STJ's existing scheme, parameterized by a type-friendly name. STJ's GenerateMemberAccessors and GenerateConstructorAccessor become thin adapters that build the neutral specs and delegate to the helper. This is a pure refactoring with no behavior change: the generated output is byte-identical, as verified by the SourceGeneratedOutputTests baselines for both the netcoreapp (UnsafeAccessor) and net462 (reflection) code paths. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 1a0d7ac2-f2a3-4526-93ab-36bf1a23933f
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-text-json |
This was referenced Sep 7, 2026
Member
|
Is this change a precondition for a #133369 fix? If the answer is yes, it may complicate the backporting process to .NET 11. I would suggest making a minimal fix for the regression first that can be backported to 11 before branching off to new infra. |
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.
Summary
Extracts the System.Text.Json source generator's accessor-emission machinery into a new shared helper,
src/libraries/Common/src/SourceGenerators/UnsafeAccessorEmitter.cs, so that other source generators can reuse it.This is a pure refactoring with no behavior change — it is a preparatory step for giving the
Microsoft.Extensions.Configuration.Bindersource generator the same[UnsafeAccessor]-based accessor support (including generic-type support), which will come in a follow-up PR stacked on top of this one.What moved
The shared helper now owns:
net462), including the cachedMemberInfo/ConstructorInfowrappers.The helper works over neutral, primitive-only spec types (
UnsafeAccessorMemberSpec,UnsafeAccessorConstructorSpec,UnsafeAccessorParameterSpec) rather than STJ's own model types.STJ's
GenerateMemberAccessorsandGenerateConstructorAccessorare now thin adapters that build the neutral specs and delegate to the helper. The value-type-setter/reflection-fallback contract (theValueTypeSetter<,>delegate andBindingFlagsconst the emitted code references) is documented on the helper and remains emitted by the consuming generator, exactly as STJ already does.Note
This PR description was generated by GitHub Copilot.