You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 278ba42
Browse filesBrowse the repository at this point in the historyBrowse files
Follow-up to #126330, which migrated CLR->COM stubs to IL stubs. This
moves them the rest of the way to *transient IL*, the same technology
#126509 (plus the regression fixes in #127400) used for P/Invokes.
Before this change, every `[ComImport]` interface method allocated a
separate IL stub `DynamicMethodDesc` plus an `ILStubResolver`, and
dispatched through it using a secret `MethodDesc` context argument. With
transient IL the marshalling IL is generated directly onto the
`CLRToCOMCallMethodDesc` and discarded after JIT, so there is no second
`MethodDesc`, no secret argument, and no extra frame.
## What changed
**Transient IL generation.** `CLRToCOMCall::CreateCLRToCOMCallMethodIL`
and `PInvoke::CreateCLRToCOMMarshallingIL` build IL into a resolver
owned by the COM method itself, hooked up through
`MethodDesc::TryGenerateTransientILImplementation`. `DoPrestub` now
routes CLR->COM through the normal `PrepareInitialCode` path; the
late-bound `IDispatch` predefined stub is the only remaining special
case. `mcComInterop` gains `MayHaveNativeCode` and a native code slot,
and is excluded from tiering and ELT profiling.
**No secret argument.** Because the IL is per-method rather than shared,
everything the stub used to read out of the secret `MethodDesc` is baked
in at generation time instead: the HRESULT-swap error path takes the
interface type as an `ldtoken`, and `GetCOMIPFromRCW` takes the
interface `MethodTable*` and COM slot as constants. That let
`PInvokeStubLinker::m_pStubContextMD` and the
`StubHelpers.GetComInterfaceFromMethodDesc` FCall go away entirely.
**Debugger.** A new `CLRToCOMStubManager`, modelled on the
`PInvokeStubManager` added in #123411, handles stepping into
early-bound, late-bound, and event calls, replacing the `ILStubManager`
paths that no longer see a stub `MethodDesc`. `DebuggerWalkStackProc`
skips frameless CLR->COM methods.
**Cleanup.** `DynamicMethodDesc::StubCLRToCOMInterop` and
`StubCLRToCOMEvent` can no longer be set on anything, so the VM code
that produced and consumed them is removed and the enum values are
commented out. The unreachable delegate path in
`CLRToCOMCallInfo::FromMethodDesc` is removed as well (see below).
## Things worth a careful look
- **The retired `ILStubType` values are reserved, not reused.** The cDAC
still interprets value `6` when reading older runtimes, so
`RuntimeTypeSystem_1.cs` and
`docs/design/datacontracts/RuntimeTypeSystem.md` are intentionally
untouched. As we're near the end of .NET 11, I wanted to make this
change such that it can go in as part of .NET 12.
- **Drive-by bug fix.** `corelib.h` declared `VALIDATE_OBJECT` and
`VALIDATE_BYREF` with 3-argument binder signatures while the managed
methods take 2. Any P/Invoke with a pinned local asserted `"EE expects
method to exist"` under `DOTNET_InteropValidatePinnedObjects=1`. This
reproduces on `main` and is fixed here because the same file was already
being modified.
- **Pre-existing dead code removed.** `CLRToCOMCallInfo::FromMethodDesc`
had an `IsEEImpl()` branch reading
`DelegateEEClass::m_pCLRToCOMCallInfo`. That field's only writer,
`COMDelegate::PopulateCLRToCOMCallInfo`, has no callers (it is already
dead on `main`), so the branch was unreachable and all four callers pass
a `CLRToCOMCallMethodDesc`. The branch, the field, and the populator are
all deleted. Nothing in the DAC, cDAC, or data descriptors referenced
the `DelegateEEClass` field, and every removed piece was inside `#ifdef
FEATURE_COMINTEROP`.
## New test
`src/tests/Interop/COM/ComImportUnimplementedMethod` guards a subtlety
that this area makes easy to get wrong: every abstract instance method
on an interface is a `CLRToCOMCallMethodDesc`, so a plain managed class
that claims to implement a `[ComImport]` interface must not silently
pick the interface method up as an implementation. Only RCWs should
dispatch through those. The test asserts the same `TypeLoadException` as
a non-COM control case. The runtime already behaved correctly here, so
this is purely a regression guard.
## Validation
- x64 and x86 checked builds, including the DAC: 0 warnings, 0 errors.
- `src/tests/Interop` 73/73, including `NETClientEvents`,
`NETClientDispatch`, `NETClientPrimitives` (its `ErrorTests` covers the
HRESULT-swap path across 10 HRESULTs plus the IID-sensitive `HelpLink`
case), and `NETClientPrimitivesInALC` for the collectible-ALC lifetime
scenario.
- `src/tests/Interop` under `DOTNET_InteropValidatePinnedObjects=1`: all
passing, verified when the binder signature fix landed.
- `profiler/transitions` 1/1.
- `src/tests/Loader` 64/65; `PlatformNativeR2R` fails for an unrelated
local environment reason.
There is no COM profiler-transition test in the repo, so that one branch
is compile-verified only.
> [!NOTE]
> This pull request description was drafted with GitHub Copilot.
---------
Co-authored-by: Copilot App <[email protected]>
0 commit comments