Postpone marking fields on types with layout#1309
Postpone marking fields on types with layout#1309MichalStrehovsky merged 1 commit intodotnet:masterfrom
Conversation
We can postpone marking fields on types with layout until we're really sure they're needed. They're needed if they're visible to reflection, or considered instantiated (valuetypes are implicitly considered instantiated). I'm also allowing stripping fields on Auto layout structs. This is a rare sight, but there's no reason that I know of to force them to have all their fields kept.
|
This is causing regression in linker bump dotnet/runtime#38880. The problem seems to be trigger by this code https://github.com/dotnet/runtime/blob/master/src/mono/netcore/System.Private.CoreLib/src/System/Array.Mono.cs#L57 which uses StructLayout type as type argument and RawData struct no longer has all fields marked @MichalStrehovsky could please look into that or revert this change |
|
Right, linker optimizations are only valid as long as type safety is ensured (e.g. if we were to put instance methods on The fix would be to put DynamicDependency on RawData that makes RawData depend on it's ctor, but we don't support that option. The only options I see are an ILLinkTrim entry for |
|
Brainstorming some more, this particular problem could also be fixed by keeping all fields on explicit/sequential types if any field is kept. It's weird, but it would work and probably still let us optimize out junk. |
We can postpone marking fields on types with layout until we're really sure they're needed. They're needed if they're visible to reflection, or considered instantiated (valuetypes are implicitly considered instantiated). I'm also allowing stripping fields on Auto layout structs. This is a rare sight, but there's no reason that I know of to force them to have all their fields kept. Commit migrated from dotnet/linker@da2cc0f
We can postpone marking fields on types with layout until we're really sure they're needed. They're needed if they're visible to reflection, or considered instantiated (valuetypes are implicitly considered instantiated).
I'm also allowing stripping fields on Auto layout structs. This is a rare sight, but there's no reason that I know of to force them to have all their fields kept.