You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(stjm): source generator for reflection-free registration and generated discriminator members #211
Follow-up to #207, #210 and #209. Do not start before #207 has landed and #210 has an explicit registration API; the generator emits into that API.
What a generator buys
Analysis result (see the linked issues for the measurements): a source generator does not improve the steady-state read path. Removing the discriminator probe and the second ReadStack would require generating a complete object deserializer (naming policies, case-insensitivity, ctor binding, required/init, extension data, number handling, callbacks, unmapped members), which STJ's own generator refuses to do for the same reason. That option is rejected.
JsonMigratableConverterFactory.AddDiscriminatorProperty already early-returns when the property exists. Only attribute-declared values can be baked in; SetTypeDiscriminatorPropertyName and GetTypeDiscriminatorFrom are runtime configuration and must either be rejected when a generated member exists or take precedence with a diagnostic. Document that users can hand-write the same member today.
Shape
Incremental generator (ForAttributeWithMetadataName), netstandard2.0, same project layout and Verify snapshot testing as Egil.StronglyTypedPrimitives; packed as an analyzer asset alongside the analyzer from feat(stjm): analyzer foundation and migration diagnostics #209 (same package id).
Opt-in entry point mirroring STJ: [JsonMigrationContext] partial class AppMigrations producing AppMigrations.Default with a Configure(JsonMigrationBuilder) method; builder.AddContext(AppMigrations.Default).
Benchmarks: add a source-gen-registered variant of the existing scenarios and confirm the migratable root type serializes on the fast path with the generated member.
Follow-up to #207, #210 and #209. Do not start before #207 has landed and #210 has an explicit registration API; the generator emits into that API.
What a generator buys
Analysis result (see the linked issues for the measurements): a source generator does not improve the steady-state read path. Removing the discriminator probe and the second
ReadStackwould require generating a complete object deserializer (naming policies, case-insensitivity, ctor binding, required/init, extension data, number handling, callbacks, unmapped members), which STJ's own generator refuses to do for the same reason. That option is rejected.What it does buy:
Discovery without reflection. Emit the
AddMigratable<T>()/AddStaticMigration<,>()/AddExternalMigration<,,>()calls from docs(stjm): document trimming/NativeAOT limits, annotate reflection entry points, then add trim-safe explicit registration #210 for every[JsonMigratable]type andIMigrate<,>implementation in the compilation, replacingRegisterMigratorsFromAssembly. Cross-assembly types come through the referenced assemblies' own generated registrations (chainable), not by scanning references.Discriminator as a real member. For
partial[JsonMigratable]types, emit the discriminator property so the type'sJsonTypeInfois never modified and STJ's fast-path serialization applies to the migratable type itself (after perf(stjm): register migration through the resolver chain so source-gen fast-path serialization survives #207 only nested and unrelated types regain it):JsonMigratableConverterFactory.AddDiscriminatorPropertyalready early-returns when the property exists. Only attribute-declared values can be baked in;SetTypeDiscriminatorPropertyNameandGetTypeDiscriminatorFromare runtime configuration and must either be rejected when a generated member exists or take precedence with a diagnostic. Document that users can hand-write the same member today.Shape
ForAttributeWithMetadataName), netstandard2.0, same project layout and Verify snapshot testing asEgil.StronglyTypedPrimitives; packed as an analyzer asset alongside the analyzer from feat(stjm): analyzer foundation and migration diagnostics #209 (same package id).[JsonMigrationContext] partial class AppMigrationsproducingAppMigrations.Defaultwith aConfigure(JsonMigrationBuilder)method;builder.AddContext(AppMigrations.Default).UnionCaseRoutingreads cases fromJsonTypeClassifierContext).