-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NativeAOT] don't generate __GetFieldHelper if struct is never boxed? #111544
Comments
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas |
This is the repro, not great. var action = (Struct _) => { };
struct Struct; |
This is from two things:
Making it so that 1 or 2 doesn't apply would fix this. I don't know if it's really possible. We had reasons for both behaviors. |
When we make a method reflection-callable, we have to make sure the reflection stack can get type handles of types within the method signature. The type handles are used as part of reflection activation to do castability checks (is it valid to call the method with this parameter?) and to do boxing of return values. In the past, what we did: * If the type has a canonical form, generate type loader template for it. * Otherwise, generate a constructed MethodTable. This was too much, so we restricted it in #92994 into: * If the type is a GC pointer, don't generate anything. Update reflection stack to be able to deal with a null type handle if and only if this is a reference type and nobody actually allocated such reference type. * Otherwise do what we did above. This is still a bit too much, as demonstrated in #111544 (comment). In this PR, I'm restricting this further to: * If the type is in the canonical form (not just "has canonical form" - "_is_ canonical form"), generate type loader template. * If the type is an out valuetype parameter, generate constructed method table (since reflection stack is going to end up boxing) * Generate necessary (unconstructed) method table otherwise (since we're only going to do castability checks and necessary method tables are exactly for that) I'm deleting the "GC pointer could have null methodtable" complication since it doesn't help much in practice once we downgraded to necessary method tables (that revert is in dc34018 and rt-sz measurements show it really doesn't affect much). Cc @dotnet/ilc-contrib
Broke the pattern by addressing 2 in #111610. The TodosApi is an app that use Npgsql. Size statisticsPull request #111610
|
I'm unsure how feasible this is but it would be helpful if the helper isn't emitted if the struct is never boxed (and never gets a constrained call on Equals/GetHashCode either).
I understand the difficulty of tracking whether a struct is 'boxed', as generics (and
(T)(object)value
casts etc) significantly complicate the analysis. Though with struct types forcing specialization it should not be impossible to get some certainty?The text was updated successfully, but these errors were encountered: