Skip to content

Handle Mono AOT typeload recovery for missing fields#129657

Draft
vitek-karas wants to merge 4 commits into
dotnet:mainfrom
vitek-karas:copilot/issue-129613-best-fix
Draft

Handle Mono AOT typeload recovery for missing fields#129657
vitek-karas wants to merge 4 commits into
dotnet:mainfrom
vitek-karas:copilot/issue-129613-best-fix

Conversation

@vitek-karas

@vitek-karas vitek-karas commented Jun 20, 2026

Copy link
Copy Markdown
Member

Summary

  • clear stale metadata errors after lowering Mono AOT field-resolution typeload failures into runtime throw IR
  • add an iOS simulator functional test that exercises the typeload recovery scenarios in one compile-and-run app
  • keep the helper project outputs under artifacts while separating contract and stub assemblies to avoid collisions

Testing

  • dotnet build --nologo src/tests/FunctionalTests/iOS/Simulator/AotTypeLoadRecovery/ReproCore/ReproCore.csproj
  • dotnet build --nologo src/tests/FunctionalTests/iOS/Simulator/AotTypeLoadRecovery/Contracts/ReproContracts/ReproContracts.Contract.csproj
  • dotnet build --nologo src/tests/FunctionalTests/iOS/Simulator/AotTypeLoadRecovery/Stubs/ReproContracts/ReproContracts.Stub.csproj

Add an iOS functional test that covers typeload recovery scenarios during AOT compilation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @akoeplinger, @matouskozak, @simonrozsival
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Mono’s IL->IR pipeline to better recover from AOT field-resolution typeload failures by clearing lingering MonoError state after the failure is lowered into runtime-throw IR. It also introduces a new iOS simulator functional test app (plus helper “contract/stub” assemblies) intended to exercise the missing-field recovery scenarios.

Changes:

  • Mono AOT: clear pending cfg->error after field-resolution typeload recovery is emitted during ldfld/ldsfld/... handling.
  • Add an iOS simulator functional test app plus helper projects (contract + stub assemblies, and a repro core library) to reproduce the scenarios.
  • Add MSBuild logic in the test project to build the stub and swap ReproContracts.dll in the linked/published inputs before AOT compilation.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/mono/mono/mini/method-to-ir.c Clears cfg->error after lowering AOT field-resolution failures into runtime throw IR.
src/tests/FunctionalTests/iOS/Simulator/AotTypeLoadRecovery/iOS.Simulator.AotTypeLoadRecovery.Test.csproj New iOS simulator functional test project; builds & swaps stub contract assembly before AOT.
src/tests/FunctionalTests/iOS/Simulator/AotTypeLoadRecovery/Program.cs Test app entrypoint; runs the probe and exits with the expected code.
src/tests/FunctionalTests/iOS/Simulator/AotTypeLoadRecovery/AotTypeLoadRecoveryProbe.cs Calls into the repro harness (separated from Program).
src/tests/FunctionalTests/iOS/Simulator/AotTypeLoadRecovery/ReproCore/ReproCore.csproj Helper library containing the IL patterns used to exercise typeload recovery.
src/tests/FunctionalTests/iOS/Simulator/AotTypeLoadRecovery/ReproCore/AotTypeLoadRecoveryHarness.cs Aggregates the scenario harnesses.
src/tests/FunctionalTests/iOS/Simulator/AotTypeLoadRecovery/ReproCore/StorePathVariant.cs One scenario variant producing specific IL patterns (store path).
src/tests/FunctionalTests/iOS/Simulator/AotTypeLoadRecovery/ReproCore/InitObjTypeLoadVariant.cs One scenario variant producing initobj-related IL patterns.
src/tests/FunctionalTests/iOS/Simulator/AotTypeLoadRecovery/ReproCore/LoadSideInlineVariant.cs One scenario variant focused on inline/load-side field access patterns.
src/tests/FunctionalTests/iOS/Simulator/AotTypeLoadRecovery/Contracts/ReproContracts/ReproContracts.Contract.csproj Contract assembly project used by the repro.
src/tests/FunctionalTests/iOS/Simulator/AotTypeLoadRecovery/Contracts/ReproContracts/Contract.cs Contract surface (types/fields) referenced by the repro code.
src/tests/FunctionalTests/iOS/Simulator/AotTypeLoadRecovery/Stubs/ReproContracts/ReproContracts.Stub.csproj Stub assembly project used for swapping during AOT compilation.
src/tests/FunctionalTests/iOS/Simulator/AotTypeLoadRecovery/Stubs/ReproContracts/Placeholder.cs Stub type definitions (currently incomplete vs contract).

Comment thread src/mono/mono/mini/method-to-ir.c
vitek-karas and others added 2 commits June 20, 2026 21:06
Keep the store-path probe's contract types in the stub assembly so the shared test app still reaches the intended missing-field scenarios while leaving the initobj case as the missing-type probe.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Only clear the expected recoverable field-resolution metadata errors after lowering the failure into runtime throw IR.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 20, 2026 21:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.

Keep the original store-path trigger shape while letting each scenario run to its expected runtime failure without aborting the app.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants