Skip to content
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: Type is not pre-initialized #83043

Open
EgorBo opened this issue Mar 6, 2023 · 4 comments
Open

NativeAOT: Type is not pre-initialized #83043

EgorBo opened this issue Mar 6, 2023 · 4 comments

Comments

@EgorBo
Copy link
Member

EgorBo commented Mar 6, 2023

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: 18

It 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.

cc @MichalStrehovsky

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Mar 6, 2023
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Mar 6, 2023
@ghost
Copy link

ghost commented Mar 6, 2023

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch, @kunalspathak
See info in area-owners.md if you want to be subscribed.

Issue Details
internal class Program
{
    struct MyStruct
    {
        public string Name;
    }

    static readonly MyStruct MyStr = new() { Name = "Hey!" };

    [MethodImpl(MethodImplOptions.NoInlining)]
    static MyStruct Test() => MyStr;
}

Codegen for Test():

; Method Program:Test():Program+MyStruct
G_M41189_IG01:              ;; offset=0000H
       4883EC28             sub      rsp, 40
G_M41189_IG02:              ;; offset=0004H
       E800000000           call     CORINFO_HELP_READYTORUN_GCSTATIC_BASE
       488B4010             mov      rax, gword ptr [rax+10H]
G_M41189_IG03:              ;; offset=000DH
       4883C428             add      rsp, 40
       C3                   ret      
; Total bytes of code: 18

It seems that _compilation.HasLazyStaticConstructor(field.OwningType) returns true for Program

cc @MichalStrehovsky

Author: EgorBo
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@EgorBo EgorBo added area-NativeAOT-coreclr and removed area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI labels Mar 6, 2023
@ghost
Copy link

ghost commented Mar 6, 2023

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Issue Details
internal class Program
{
    struct MyStruct
    {
        public string Name;
    }

    static readonly MyStruct MyStr = new() { Name = "Hey!" };

    [MethodImpl(MethodImplOptions.NoInlining)]
    static MyStruct Test() => MyStr;
}

Codegen for Test():

; Method Program:Test():Program+MyStruct
G_M41189_IG01:              ;; offset=0000H
       4883EC28             sub      rsp, 40
G_M41189_IG02:              ;; offset=0004H
       E800000000           call     CORINFO_HELP_READYTORUN_GCSTATIC_BASE
       488B4010             mov      rax, gword ptr [rax+10H]
G_M41189_IG03:              ;; offset=000DH
       4883C428             add      rsp, 40
       C3                   ret      
; Total bytes of code: 18

It seems that _compilation.HasLazyStaticConstructor(field.OwningType) returns true for Program

cc @MichalStrehovsky

Author: EgorBo
Assignees: -
Labels:

untriaged, area-NativeAOT-coreclr

Milestone: -

@MichalStrehovsky MichalStrehovsky added this to the Future milestone Mar 6, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Mar 6, 2023
@MichalStrehovsky
Copy link
Member

Value types are represented as byte arrays within the interpreter. It's hard to add object references to it.

The features the interpreter supports follow the pareto principle.

@jkotas
Copy link
Member

jkotas commented Mar 7, 2023

Similar issue for initialization of reference types: #82993

@agocke agocke added this to AppModel Mar 27, 2023
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label May 7, 2023
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

3 participants