Skip to content

Conversation

@elachlan
Copy link
Contributor

Relates to #7174

@elachlan
Copy link
Contributor Author

elachlan commented Jan 8, 2022

There are still 3 occurrences that I believe are false positives. I can add a suppression, but I think if this takes a while to merge it might be fixed in the analyzer by then.

@elachlan elachlan requested a review from Forgind January 18, 2022 23:31
Copy link
Contributor

@Forgind Forgind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I'm assuming the false positive problem isn't about to be resolved, though we also shouldn't be merging right now because our last insertion failed for some reason, so we have a little time.

@elachlan
Copy link
Contributor Author

Looks good! I'm assuming the false positive problem isn't about to be resolved, though we also shouldn't be merging right now because our last insertion failed for some reason, so we have a little time.

There is only one false positive and it has a suppression now. The other two were me not fully reading the analyzer article and understanding what it wanted me to do. Hence the fixes I just submitted.

Copy link
Member

@ladipro ladipro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note the tradeoffs being made when switching from an explicit static ctor to inline static field initializion. As the analyzer suggests, with beforefieldinit the JITted code may be slightly faster because it doesn't need to execute init checks. It may however lead to unwanted eager initialization. We should be especially careful when dealing with expensive initialization code. If there are scenarios where MSBuild "uses" the type but does not really call it or access its fields, then expensive initialization should be left in static ctors.

Copy link
Member

@ladipro ladipro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for making the change. I left one comment which I feel is important. Please re-request review from @Forgind after addressing.

@ladipro ladipro self-requested a review January 27, 2022 08:47
@elachlan elachlan requested a review from Forgind January 27, 2022 10:40

// keep this up-to-date; always point to the latest visual studio version.
internal static readonly Version visualStudioVersionLatest = visualStudioVersion160;
internal static readonly Version visualStudioVersionLatest = visualStudioVersion170;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

Copy link
Contributor

@Forgind Forgind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

/// </summary>
#pragma warning disable CA1810 // Initialize reference type static fields inline
static MSBuildApp()
#pragma warning restore CA1810 // Initialize reference type static fields inline
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think I'd slightly prefer putting the restore below the end of this function, but I don't care too much.

@Forgind Forgind added the merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now. label Jan 31, 2022
@AR-May AR-May merged commit 288ea72 into dotnet:main Jan 31, 2022
@elachlan elachlan deleted the CA1810 branch January 31, 2022 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants