Skip to content

[Crossgen2] Omit constrained type from imports of resolved constrained calls - #138262

Draft
jtschuster wants to merge 2 commits into
dotnet:mainfrom
jtschuster:wasm-r2r-resolved-constraint-imports
Draft

jtschuster wants to merge 2 commits into
dotnet:mainfrom
jtschuster:wasm-r2r-resolved-constraint-imports

Conversation

@jtschuster

Copy link
Copy Markdown
Member

Fixes #138199

As suggested in #138199 (comment): when Crossgen2 resolves a constrained call to a specific method body, the method-entry imports for that call no longer need the constrained type.

Before this change, MethodFixupSignature swapped the interface MemberRef for the resolved MethodDef but still encoded the exact constrained owner (e.g. Enumerator`1<Marker>). Decoding the import at runtime then eagerly loaded Marker's assembly.

Changes

  • CorInfoImpl.ReadyToRun.cs: ceeInfoGetCallInfo now reports resolvedConstraint. A new ComputeCallTargetMethodWithToken helper builds the MethodWithToken from the resolved method's own token, with no constrained type, when all of the following hold:

    • the constraint was resolved
    • the call is not unboxing and doesn't use an instantiating stub
    • the method is a primary, non-abstract method desc that versions with the method body

    Otherwise it falls back to ComputeMethodWithToken. Both CORINFO_CALL entrypoint paths in getCallInfo use it: the deferred Wasm path and the regular MethodEntrypoint path.

  • New regression test ResolvedConstrainedCallImportsOmitConstrainedType in ILCompiler.ReadyToRun.Tests. It fails without the fix.

Testing

  • ILCompiler.ReadyToRun.Tests, no failures:

    • browser-wasm: 398 passed, 43 skipped
    • linux-x64: 289 passed, 21 skipped
  • Debug Crossgen2 compiled composite CoreLib plus the repro with no asserts.

  • src/tests with --runcrossgen2tests (linux-x64) passed:

    • readytorun
    • Loader (including classloader/StaticVirtualMethods and classloader/DefaultInterfaceMethods)
    • JIT.Generics_ro

    The only two failures came from the local environment: R2RTest and hostpolicy weren't built.

When crossgen2 resolves a constrained call at compile time to a method
body in the version bubble, encode the call target import with that
method's own token and no constrained type. The runtime cannot resolve
the call differently, and decoding the constraint eagerly loaded the
exact constrained type and its instantiation arguments (for example
Enumerator<Marker> for a foreach Dispose call), which could load
application assemblies during early startup on Wasm.

Fixes dotnet#138199

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/crossgen-contrib
See info in area-owners.md if you want to be subscribed.

This branch has not been deployed

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

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[browser][CoreCLR] Key Wasm R2R method-entry imports by shared body

1 participant