-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
CA1810 Initialize reference type static fields inline #7179
Conversation
src/Build/BackEnd/Components/RequestBuilder/IntrinsicTasks/ItemGroupLoggingHelper.cs
Show resolved
Hide resolved
Co-authored-by: Forgind <[email protected]>
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. |
There was a problem hiding this 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.
Co-authored-by: Forgind <[email protected]>
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. |
There was a problem hiding this 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.
src/Build/BackEnd/Components/RequestBuilder/IntrinsicTasks/ItemGroupLoggingHelper.cs
Show resolved
Hide resolved
There was a problem hiding this 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.
@@ -72,7 +72,7 @@ internal static class FrameworkLocationHelper | |||
internal static readonly Version visualStudioVersion170 = new Version(17, 0); | |||
|
|||
// 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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch!
There was a problem hiding this 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!
static MSBuildApp() | ||
#pragma warning restore CA1810 // Initialize reference type static fields inline |
There was a problem hiding this comment.
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.
Relates to #7174