-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Open
Labels
Milestone
Description
struct MyStruct
{
public string Name;
}
class Program
{
static readonly MyStruct MyStr = new() { Name = "Hey!" };
[MethodImpl(MethodImplOptions.NoInlining)]
static MyStruct Test() => MyStr;
}Codegen for Test():
; Method Program:Test():Program+MyStruct
4883EC28 sub rsp, 40
E800000000 call CORINFO_HELP_READYTORUN_GCSTATIC_BASE
488B4010 mov rax, gword ptr [rax+10H]
4883C428 add rsp, 40
C3 ret
; Total bytes of code: 18It seems that _compilation.HasLazyStaticConstructor(field.OwningType) returns true for Program so MyStr field is not pre-computed despite being a simple struct + frozen string literal.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
No status