Skip to content

fix(aot): register generated formatters for array elements - #474

Open
Mr444-dev wants to merge 1 commit into
Cysharp:mainfrom
Mr444-dev:fix/nativeaot-array-element-registration-467
Open

Mr444-dev wants to merge 1 commit into
Cysharp:mainfrom
Mr444-dev:fix/nativeaot-array-element-registration-467

Conversation

@Mr444-dev

Copy link
Copy Markdown

What changed

  • Emit a module initializer for accessible, non-generic [MemoryPackable] models.
  • On runtimes without dynamic code, register the generated formatter directly. This keeps the model's own static constructor lazy.
  • Extend the NativeAOT sandbox with the reported Item[] payload and add source-generator tests.

Why

NativeAOT can trim the generated static interface registration method when a model is first reached as an array element. Formatter lookup then fails even though the element formatter was generated.

Scope and tradeoff

This initializer is limited to non-generic model types because open generic models need concrete type arguments. In NativeAOT, generated registrations for accessible non-generic models in the assembly are rooted and registered during module initialization.

How tested

  • dotnet test tests/MemoryPack.Tests/MemoryPack.Tests.csproj -c Release — 159 passed.
  • dotnet run --project sandbox/NativeAot/NativeAot.csproj -c Release — printed A.
  • dotnet publish sandbox/NativeAot/NativeAot.csproj -c Release -r win-x64, then ran the native executable — printed A.

The NativeAOT publish still reports the existing generic formatter trim/AOT analysis warnings from MemoryPackFormatterProvider.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant