-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Description
Tangential follow up on #116301
If we cannot prevent constructs like typeof from marking structs as boxed we should make it possible to limit what a boxed struct implies.
Given the following code I would expect there to be no record of __GetFieldHelper in the mstat:
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
_ = TypeOf<Foo>();
[MethodImpl(MethodImplOptions.NoInlining)]
static Type TypeOf<T>() => typeof(T);
struct Foo
{
public override int GetHashCode() => throw new NotSupportedException();
public override bool Equals([NotNullWhen(true)] object? obj) => throw new NotSupportedException();
}Once fixed it would be *a* mitigation for large __GetFieldHelpers being emitted.
Ideally though there would be an attribute like OmitObjectMethodImpls (or something more narrow like OmitObjectEquality) which could be applied to a type (or module even?).
Something that would make runtimes do the cheapest thing to produce a NotSupportedException in object's virtual methods for the affected types.
For NativeAOT that could be a bit flag in the type info or some __GetFieldHelper sentinel return value.
Having an intrinsic attribute would also be preferable to needing to override two or more methods (though worst case this could be handled by a source generator).
Metadata
Metadata
Assignees
Labels
Type
Projects
Status