Washi1337 / AsmResolver

A library for creating, reading and editing PE files and .NET modules.
https://docs.washi.dev/asmresolver/
MIT License
848 stars 127 forks source link

Add IsReferenceOrContainsReferences Equivalent for ITypeDescriptors #530

Closed Washi1337 closed 6 months ago

Washi1337 commented 7 months ago

Problem Description

.NET Core comes with the IsReferenceOrContainsReferences<T> JIT intrinsic which infers from the given type whether the type is a managed reference type or contains managed references in one of its fields. It is mainly used to infer whether a type needs to be GC-tracked and finalized. This value is inferred during the type layout pass when building a method table at runtime.

Currently AsmResolver does not have an equivalent way for ITypeDescriptors.

Proposal

Add a ReferenceOrContainsReferences flag to the MemoryLayoutAttributes enum.

Alternatives

We could add a property or extension method to ITypeDescriptor directly, however this would require its own full pass on the entire type.

Additional Context