[TrimmableTypeMap] Compute generated IL maxstack#11260
[TrimmableTypeMap] Compute generated IL maxstack#11260simonrozsival wants to merge 2 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the TrimmableTypeMap PE/IL emitter to compute per-method maxstack by tracking evaluation stack usage during IL generation, replacing the previous fixed maxstack approach.
Changes:
- Introduces a
TrackedInstructionEncoderinPEAssemblyBuilderto track IL stack depth, detect underflow, and feed computedmaxstackinto method body emission. - Updates IL emission sites to route stack-affecting instructions through tracked helper methods (e.g.,
Call,Callvirt,NewObject,NewArray,LoadToken,Return), including explicit catch-handler stack seeding. - Adds tests that assert generated methods now use computed
MaxStackvalues.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator/TypeMapAssemblyGeneratorTests.cs | Adds assertions for emitted MaxStack and updates one IL emission call to use the new tracked Return() helper. |
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator/RootTypeMapAssemblyGeneratorTests.cs | Adds a helper to find methods by name and tests that Initialize uses computed MaxStack. |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/TypeMapAssemblyEmitter.cs | Switches method-body emission callbacks to use TrackedInstructionEncoder and updates many IL sequences to tracked helpers. |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/RootTypeMapAssemblyGenerator.cs | Updates emitted IL for Initialize to use tracked Call/NewArray/Return helpers. |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/PEAssemblyBuilder.cs | Replaces fixed maxstack with tracked stack accounting and passes computed maxstack into MethodBodyStreamEncoder.AddMethodBody. |
simonrozsival
left a comment
There was a problem hiding this comment.
@copilot address code review
Addressed all four review items in commit
All 434 tests still pass. |
|
@copilot try again |
All four code-review changes are ready in local commit The To unblock the push, someone with admin access would need to either:
The pending changes are:
|
Track emitted IL stack depth in PEAssemblyBuilder instead of using a fixed maxstack of 32, and emit max(computed + 4, 8). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use less brittle maxstack test assertions and reject unsupported unconditional branches in the tracked IL encoder. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
d714d55 to
11318c1
Compare
Summary
Moves the generated typemap PE emitter from a fixed
DefaultMaxStack = 32to per-method IL evaluation-stack tracking.This PR is based on #11252 /
trimmable-typemap-startup-fixes.InstructionEncoderwith a tracked emitter inPEAssemblyBuildercall,callvirt,newobj,newarr,ldtoken,stobj,ret, etc.) through explicit helpersmax(computed + 4, 8)so generated fat bodies get a computed value with safety padding and the ECMA-335 tiny-method floorValidation
dotnet test tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests.csproj -v minimaldotnet new maui) built as Releasenet11.0-androidforandroid-arm64with CoreCLR/trimmable typemapsemulator-5554com.companyname.mauimaxstacksmoke/crc64d3fac713b535959c.MainActivityStatus: ok,LaunchState: COLD,TotalTime: 1610ms