Repository navigation
feat: reflection-free Type-based APIs through a slim source generator - #70
Merged
Blind-Striker merged 2 commits intoOct 23, 2026
Merged
Conversation
Blind-Striker
added this pull request to stack #69
October 23, 2026 13:33
This was referenced Oct 23, 2026
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
On net10.0/net11.0, the Type-based APIs (CreateClientByInterface(Type), CreateClientByImplementation, ISessionReflection) no longer use runtime reflection for clients and configs the compiler can see. The generator that ships in Core now emits direct C# for every accessible, concrete, non-generic AmazonServiceClient it finds in the consumer compilation and its references: - metadata: an UnsafeAccessor for the client's private static serviceMetadata field, read lazily - config: new TConfig() for the (credentials, clientConfig) constructor shape, with the same zero/multiple-match failures as before - client: direct constructor calls, most-derived config type first - config entries: a direct ForcePathStyle setter for the simple public bool shape, and whether RegionEndpoint is shadowed It skips shapes the compiler would reject in generated code (init-only setters, ref/out parameters, required members, Obsolete/Experimental symbols), registers each type in its own non-inlined method so a missing runtime assembly cannot abort the module initializer, and discovers clients in references that reach AWSSDK.Core only transitively. Reference discovery caches only candidate types per MetadataReference; with 121 AWS SDK packages referenced, an unrelated edit drops from ~4.2 s to ~60 ms. Types the generator does not cover (F#/VB projects, runtime-loaded assemblies, private or generic custom clients, unusual shapes) keep the previous behaviour through a reflection fallback guarded by ReflectionFallback.IsSupported, a FeatureGuard auto-property that trimmed and Native AOT apps compile away without warnings or suppressions. Core and Extensions set IsAotCompatible on net10.0/net11.0.
The test built an AmazonS3Client from a bare AmazonS3Config, which only passes on machines with an AWS default region in the shared config; CI runners have none and the SDK threw "No RegionEndpoint or ServiceURL configured". Start from us-east-1 so SetClientRegion's change to eu-west-2 is still observable.
Blind-Striker
force-pushed
the
aot/slim-generator
branch
from
October 23, 2026 20:24
b848a3a to
e0da143
Compare
This was referenced Oct 23, 2026
Blind-Striker
marked this pull request as ready for review
October 23, 2026 21:55
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.
Stack (review bottom-up, merge as one stack): #62 base, #66 the #63 fix, #67 Native AOT test lane, #68 static-factory generic path, #70 slim generator, #71 public docs, #72 internal docs and 3.0.0, #73 reflection-free test, #74 package consumer in CI, #75 convention clean-up, #76 service catalog refresh.
Goal of the stack: 3.0.0, where existing consumers upgrade without code changes, both packages support Native AOT on net10.0/net11.0, and the libraries use no runtime reflection for types the compiler can see (a JIT-only fallback covers the rest).
This PR
Makes the
Type-based APIs andISessionReflectionreflection-free on net10.0/net11.0. The rewritten generator emits direct C# for accessible, concrete, non-generic clients found in the consumer and its references: anUnsafeAccessorforserviceMetadata,new TConfig()for the(credentials, clientConfig)shape, direct constructors (most-derived config first), a directForcePathStylesetter for the simple public bool shape, and a plain-RegionEndpointflag. Generated code contains no reflection and noType.GetType.Shapes the generator does not cover (F#/VB for the
TypeAPIs, runtime-loaded assemblies, private or generic custom clients, unusual constructors or properties) keep the previous behaviour through a reflection fallback behindReflectionFallback.IsSupported. That property is aFeatureGuardauto-property, so trimmed and Native AOT apps compile the fallback away without warnings or suppressions. Core and Extensions setIsAotCompatiblefromIsLocalStackModernTarget, so it covers net10.0, net11.0 and any later modern target without a literal.Review fixes included:
MetadataReference; with 121 AWS SDK packages referenced, an unrelated edit went from about 4.2 s to about 60 ms.Verification
Build with 0 warnings. Core 106 (net10/11) and 100 (net472), Integration 244 x3, Generator 65, Extensions 62, Functional 50 x2. Native AOT lane 35/35 with 0 IL warnings. The native executable contains none of the fallback methods (checked by name), while the normal-path methods are present.