Use similar types for self-referential generics instead of the exact canonical type...
authorDavid Wrighton <davidwr@microsoft.com>
Tue, 4 Apr 2023 20:16:00 +0000 (13:16 -0700)
committerGitHub <noreply@github.com>
Tue, 4 Apr 2023 20:16:00 +0000 (13:16 -0700)
commitbc887b38db30f11d7fd35619c35e3043d3b3a6f9
treea7d00592461a94a024bec85e4018a81083c7f48c
parent735ddeaf8cbc2a2be89ba292bd405bcce615ee60
Use similar types for self-referential generics instead of the exact canonical type (#83995)

- Take advantage of work done a few years ago to simplify the interaction with the interop subsystem
- In the problematic case, simulate loads with two different types as instantiations which are unrelated in field layout, and see if they match up. Only enable this code in a few very small isolated parts of the runtime
- Filter more of the type loader logic through the byvalue class cache which should improve performance a bit
- Similarly when considering blittability, tweak the logic to use the special load path

- Support for self-recursive generics is not enabled for static fields, as that requires a somewhat different tweak, and there is less apparent demand. (For that scenario self-referential generics really should support having fields of type T.)
- Support for indirect self-recursive generics is also not enabled. The approach taken here is not practical for that, and there does not appear to be significant demand for that either.

Fixes #6924
17 files changed:
src/coreclr/debug/daccess/dacdbiimpl.cpp
src/coreclr/dlls/mscorrc/mscorrc.rc
src/coreclr/dlls/mscorrc/resource.h
src/coreclr/vm/class.h
src/coreclr/vm/classlayoutinfo.cpp
src/coreclr/vm/field.cpp
src/coreclr/vm/field.h
src/coreclr/vm/fieldmarshaler.cpp
src/coreclr/vm/fieldmarshaler.h
src/coreclr/vm/methodtable.cpp
src/coreclr/vm/methodtable.h
src/coreclr/vm/methodtablebuilder.cpp
src/coreclr/vm/methodtablebuilder.h
src/coreclr/vm/siginfo.cpp
src/coreclr/vm/siginfo.hpp
src/tests/Loader/classloader/generics/Layout/Specific/SelfRecursiveGenerics.cs [new file with mode: 0644]
src/tests/Loader/classloader/generics/Layout/Specific/SelfRecursiveGenerics.csproj [new file with mode: 0644]