Skip to content

Conversation

@MichalStrehovsky
Copy link
Member

@MichalStrehovsky MichalStrehovsky commented Jan 9, 2024

Fixes #96655

@ghost ghost added linkable-framework Issues associated with delivering a linker friendly framework area-Tools-ILLink .NET linker development as well as trimming analyzers labels Jan 9, 2024
@ghost ghost assigned MichalStrehovsky Jan 9, 2024
@ghost
Copy link

ghost commented Jan 9, 2024

Tagging subscribers to 'linkable-framework': @eerhardt, @vitek-karas, @LakshanF, @sbomer, @joperezr, @marek-safar
See info in area-owners.md if you want to be subscribed.

Issue Details

Just want to see if the tests pass. The ILLinker SLN files seem unusable for local testing because they miss projects.

Author: MichalStrehovsky
Assignees: -
Labels:

linkable-framework

Milestone: -

@MichalStrehovsky
Copy link
Member Author

Looks like this is ready to review. I half expected worms to come out of this can but the CI looks reasonable.

sbomer

This comment was marked as resolved.

@MichalStrehovsky MichalStrehovsky merged commit 4d4c6a7 into dotnet:main Jan 9, 2024
@MichalStrehovsky MichalStrehovsky deleted the trimcctor branch January 9, 2024 23:05
@hez2010
Copy link
Contributor

hez2010 commented Jan 10, 2024

Will this also affect the behaviour of cctors without beforefieldinit?

new Foo().X = 1; // this should print "1" as the cctor of Foo is not beforefieldinit

class Foo
{
    static Foo() { } // opt-out beforefieldinit
    public static Bar bar = new();
    
    public int X;
}

class Bar
{
    public Bar()
    {
        Console.WriteLine(1);
    }
}

I believe some applications rely on this behavior to do initialization.

@jkotas
Copy link
Member

jkotas commented Jan 10, 2024

The instance constructor is responsible for triggering the cctor in your example. The instance field access (on non-null this pointer) assumes that the cctor was triggered when the instance was created.

tmds pushed a commit to tmds/runtime that referenced this pull request Jan 23, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Feb 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-Tools-ILLink .NET linker development as well as trimming analyzers linkable-framework Issues associated with delivering a linker friendly framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unnecessarily preserved cctor if an instance field is touched

4 participants