Repository navigation
fix(common): support value-type returns for [Idempotent] and [BatchProcessor] under Native AOT - #1371
Merged
Merged
Conversation
…ocessor] under Native AOT Build UniversalWrapperAspect handlers from generic closures instead of MakeGenericMethod over WrapSync/WrapAsync plus compiled expression trees. Plain Task is wrapped as Task<object>, and int, long, bool, double, decimal, Guid and DateTime (directly or as Task<T>) are instantiated explicitly so ILC compiles them. Other value types still fail under AOT with a clear NotSupportedException. Register the same primitives in IdempotencySerializationContext so their results are stored and replayed under AOT without user registration. Closes #1345
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1371 +/- ##
===========================================
+ Coverage 80.29% 80.36% +0.07%
===========================================
Files 303 303
Lines 12962 12990 +28
Branches 1551 1560 +9
===========================================
+ Hits 10408 10440 +32
+ Misses 2098 2095 -3
+ Partials 456 455 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.



Issue number: closes #1345
Summary
Changes
[Idempotent]and[BatchProcessor](and[Logging], which uses the same aspect) go throughUniversalWrapperAspect. It built each handler withMakeGenericMethod(WrapSync<T> / WrapAsync<T>)plus a compiled expression tree. Under Native AOT, value-type instantiations have no native code, so since #1346 these methods threw a clearNotSupportedException.The aspect now builds handlers from plain generic closures, and names the instantiations ILC needs:
Taskno longer needsTask<VoidTaskResult>, a value type we can't name in code. The wrappers seeTask<object>, and the result is a placeholderobject, which serializes as{}. That is the same valueVoidTaskResultwas stored as before, so idempotency records stay compatible in both directions.System.Linq.Expressionsis no longer used. Wrapper order is unchanged: the last wrapper runs first, which a new test covers.IdempotencySerializationContextnow registersint,long,bool,double,decimal,GuidandDateTime, so storing and replaying these results under AOT works without the user adding them to their own context. This only adds new generated properties to that public context.IL3050suppression stays on the one method that still callsMakeGenericMethod, with an updated justification.idempotency.mdandbatch-processing.mdnow list what's supported and what still throws (user structs, enums,int?,ValueTask<T>).User experience
Under Native AOT,
[Idempotent] public async Task Handler(string p)or[BatchProcessor(...)] public int Handler(SQSEvent e):NotSupportedException: 'Fns.Handler' returns 'Task', which IdempotentAttribute can't wrap when running as Native AOT...[Idempotent], the second call with the same payload returns the stored result.User-defined structs still aren't supported under AOT. They now get this message:
JIT behaviour is the same for every return type.
Evidence
Native AOT runtime (.NET 10, osx-arm64, local harness, packed
developvs this branch).[Idempotent]uses an in-memoryBasePersistenceStore, and each method is called twice with the same payload. OK means the handler ran once and the second call returned the stored value. The user'sJsonSerializerContextregisters onlyUserStruct.[BatchProcessor]uses one SQS record and anIRecordHandler.[Idempotent]develop[Idempotent]this PR[BatchProcessor]develop[BatchProcessor]this PRvoidIdempotencyConfigurationException1IdempotencyConfigurationException1string,Task<string>int,long,bool,double,decimal,Guid,DateTimeTask<T>of the types aboveTask(async, and non-asyncTask.CompletedTask){})UserStruct,Task<UserStruct>1 Idempotency rejects
voidby design, on JIT too.Under JIT,
Taskmethods store{}on bothdevelopand this PR.AOT binary size of the harness: 4,540,304 bytes on
develop, 4,092,544 bytes with this PR (noSystem.Linq.Expressions).Native AOT publish warnings (per-package harness, Powertools-owned): Idempotency 0, Idempotency usage 0, Logging 0, Logging usage 0 (all unchanged). BatchProcessing 12, the same 12 as on
develop(tracked in #1332). None of them are inUniversalWrapperAspect.Unit tests (AOT simulated with
RuntimeFeatureWrapper.SetIsDynamicCodeSupported(false)):Full Release build from
libraries/(dotnet build --configuration Release --no-restore): 0 errors, no warnings in the changed files.Merge Danger
Door: two-way
Reverting restores the expression-tree path. No public API is removed.
IdempotencySerializationContextgains generated properties for the new types, which is additive.Blast Radius: moderate
Every package that includes Common runs this code for every
[Idempotent],[BatchProcessor]and[Logging]method, on JIT and AOT. Behaviour changes to watch for:UniversalWrapperAttributesubclass now seesT = objectinstead ofVoidTaskResultfor methods that return a plainTask.VoidTaskResultis internal to the BCL, so code can't have relied on the type by name.Taskmethods, a response hook replaying a record now gets aJsonElement(deserialized asobject) instead of a boxedVoidTaskResult. The hook result is ignored forTaskanyway.Expression.Compile(), which runs interpreted under AOT. Each wrapper allocates a closure per call, similar to the nested lambdas the compiled expression created.Not covered here: JIT apps that call
WithJsonSerializationContext()lose reflection-based serialization for types that aren't in their context. For example, astringpayload fails with "JsonTypeInfo metadata for type 'System.String' was not provided". This already happens ondevelop, and this PR doesn't change it.Checklist
Is this a breaking change?
RFC issue number:
Checklist:
Acknowledgment
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.