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

Implement compiler /warnversion flag and one "wave" warning #45750

Merged
10 commits merged into from
Jul 16, 2020

Conversation

gafter
Copy link
Member

@gafter gafter commented Jul 7, 2020

Fixes #45702
Fixes #45744
Related to #45701 and #45704

@gafter gafter requested a review from a team as a code owner July 7, 2020 17:19
@gafter gafter self-assigned this Jul 7, 2020
@gafter gafter added this to the 16.8 milestone Jul 7, 2020
@jaredpar
Copy link
Member

jaredpar commented Jul 7, 2020

Looks like you're missing the MSBuild hookup to the switch here. #Resolved

@gafter
Copy link
Member Author

gafter commented Jul 7, 2020

Looks like you're missing the MSBuild hookup to the switch here.

See #45701 for the work breakdown. This is the compiler portion only. The MSBuild hookup is tracked by dotnet/roslyn-analyzers#3823 and @jmarolf plans to implement it. #Resolved

@jmarolf
Copy link
Contributor

jmarolf commented Jul 9, 2020

@jaredpar yep I am going to build on top of this #Resolved

CreateCompilation(source, options: TestOptions.ReleaseDll.WithWarningVersion(4.9m)).VerifyDiagnostics();
CreateCompilation(source, options: TestOptions.ReleaseDll.WithWarningVersion(5m)).VerifyDiagnostics(whenWave5);
CreateCompilation(source, options: TestOptions.ReleaseDll.WithWarningVersion(5.0m)).VerifyDiagnostics(whenWave5);
CreateCompilation(source, options: TestOptions.ReleaseDll.WithWarningVersion(5.1m)).VerifyDiagnostics(whenWave5);
Copy link
Contributor

@RikkiGibson RikkiGibson Jul 9, 2020

Choose a reason for hiding this comment

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

Is there a possibility of a platform version like "dotnet 5.10", which is later than dotnet 5.2? #ByDesign

Copy link
Member Author

@gafter gafter Jul 10, 2020

Choose a reason for hiding this comment

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

I don't think we are planning to use minor versions for .net core at all (though the current version is 3.1). It seems unlikely we would have so many minor versions without a major version bump. Also, many people would be confused if we did that.


In reply to: 452460481 [](ancestors = 452460481)

@@ -4617,7 +4620,9 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
-warnaserror[+|-] Report all warnings as errors
-warnaserror[+|-]:<warn list> Report specific warnings as errors
(use "nullable" for all nullability warnings)
-warn:<n> Set warning level (0-4) (Short form: -w)
Copy link
Member

@jcouv jcouv Jul 9, 2020

Choose a reason for hiding this comment

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

Should we keep the old setting, since still works? #Closed

Copy link
Member Author

Choose a reason for hiding this comment

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

No, since we do not want to encourage people to use it. The UI for setting this is also being removed from VS.


In reply to: 452492523 [](ancestors = 452492523)

Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions.CSharpCompilationOptions(Microsoft.CodeAnalysis.OutputKind outputKind, bool reportSuppressedDiagnostics = false, string moduleName = null, string mainTypeName = null, string scriptClassName = null, System.Collections.Generic.IEnumerable<string> usings = null, Microsoft.CodeAnalysis.OptimizationLevel optimizationLevel = Microsoft.CodeAnalysis.OptimizationLevel.Debug, bool checkOverflow = false, bool allowUnsafe = false, string cryptoKeyContainer = null, string cryptoKeyFile = null, System.Collections.Immutable.ImmutableArray<byte> cryptoPublicKey = default(System.Collections.Immutable.ImmutableArray<byte>), bool? delaySign = null, Microsoft.CodeAnalysis.Platform platform = Microsoft.CodeAnalysis.Platform.AnyCpu, Microsoft.CodeAnalysis.ReportDiagnostic generalDiagnosticOption = Microsoft.CodeAnalysis.ReportDiagnostic.Default, int warningLevel = 4, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, Microsoft.CodeAnalysis.ReportDiagnostic>> specificDiagnosticOptions = null, bool concurrentBuild = true, bool deterministic = false, Microsoft.CodeAnalysis.XmlReferenceResolver xmlReferenceResolver = null, Microsoft.CodeAnalysis.SourceReferenceResolver sourceReferenceResolver = null, Microsoft.CodeAnalysis.MetadataReferenceResolver metadataReferenceResolver = null, Microsoft.CodeAnalysis.AssemblyIdentityComparer assemblyIdentityComparer = null, Microsoft.CodeAnalysis.StrongNameProvider strongNameProvider = null, bool publicSign = false, Microsoft.CodeAnalysis.MetadataImportOptions metadataImportOptions = Microsoft.CodeAnalysis.MetadataImportOptions.Public, Microsoft.CodeAnalysis.NullableContextOptions nullableContextOptions = Microsoft.CodeAnalysis.NullableContextOptions.Disable, decimal warningVersion = 0) -> void
Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions.CSharpCompilationOptions(Microsoft.CodeAnalysis.OutputKind outputKind, bool reportSuppressedDiagnostics, string moduleName, string mainTypeName, string scriptClassName, System.Collections.Generic.IEnumerable<string> usings, Microsoft.CodeAnalysis.OptimizationLevel optimizationLevel, bool checkOverflow, bool allowUnsafe, string cryptoKeyContainer, string cryptoKeyFile, System.Collections.Immutable.ImmutableArray<byte> cryptoPublicKey, bool? delaySign, Microsoft.CodeAnalysis.Platform platform, Microsoft.CodeAnalysis.ReportDiagnostic generalDiagnosticOption, int warningLevel, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, Microsoft.CodeAnalysis.ReportDiagnostic>> specificDiagnosticOptions, bool concurrentBuild, bool deterministic, Microsoft.CodeAnalysis.XmlReferenceResolver xmlReferenceResolver, Microsoft.CodeAnalysis.SourceReferenceResolver sourceReferenceResolver, Microsoft.CodeAnalysis.MetadataReferenceResolver metadataReferenceResolver, Microsoft.CodeAnalysis.AssemblyIdentityComparer assemblyIdentityComparer, Microsoft.CodeAnalysis.StrongNameProvider strongNameProvider, bool publicSign, Microsoft.CodeAnalysis.MetadataImportOptions metadataImportOptions, Microsoft.CodeAnalysis.NullableContextOptions nullableContextOptions) -> void
Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions.WarningVersion.get -> decimal
Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions.WithWarningVersion(decimal warningVersion) -> Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions
Copy link
Member

@jcouv jcouv Jul 9, 2020

Choose a reason for hiding this comment

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

decimal [](start = 74, length = 7)

Should we use an enum (like we do for WithLanguageVersion)? #ByDesign

Copy link
Member Author

Choose a reason for hiding this comment

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

No, as there is not a fixed set of values you can specify.


In reply to: 452493235 [](ancestors = 452493235)

@@ -4617,7 +4620,9 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
-warnaserror[+|-] Report all warnings as errors
-warnaserror[+|-]:&lt;warn list&gt; Report specific warnings as errors
(use "nullable" for all nullability warnings)
-warn:&lt;n&gt; Set warning level (0-4) (Short form: -w)
-warnversion:&lt;n&gt; Enable recently introduced warnings. Default '0'.
Copy link
Member

@jcouv jcouv Jul 9, 2020

Choose a reason for hiding this comment

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

Should we support -warnversion:? as we do for -langversion:? #ByDesign

Copy link
Member Author

Choose a reason for hiding this comment

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

No plans to do so, since there is not a fixed set of values you can specify.


In reply to: 452493597 [](ancestors = 452493597)

/// the warning wave in which it was introduced.
/// </summary>
/// <param name="code"></param>
/// <returns></returns>
Copy link
Member

@jcouv jcouv Jul 9, 2020

Choose a reason for hiding this comment

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

nit: xml can be cleaned up #Closed

`k` or later is used to compile the code.

The default warning version is `0` (produce no optional warnings).
Our first warning under control of `/warnversion` was introduced in version `5`.
Copy link
Member

@jcouv jcouv Jul 9, 2020

Choose a reason for hiding this comment

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

nit: may be good to mention this corresponds to .NET 5 #Closed

@@ -792,7 +792,7 @@ private void CheckLiftedBinOp(BoundBinaryOperator node)

string always = node.OperatorKind.Operator() == BinaryOperatorKind.NotEqual ? "true" : "false";

if (_compilation.FeatureStrictEnabled || !node.OperatorKind.IsUserDefined())
if (_compilation.FeatureStrictEnabled || !node.OperatorKind.IsUserDefined() || ErrorCode.WRN_NubExprIsConstBool2.GetWarningVersion() <= this._compilation.Options.WarningVersion)
Copy link
Member

@jcouv jcouv Jul 9, 2020

Choose a reason for hiding this comment

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

FeatureStrictEnabled [](start = 37, length = 20)

Should we assume that FeatureStrictEnabled is true when warn version >=5? #Closed

Copy link
Member Author

Choose a reason for hiding this comment

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

No. FeatureStrictEnabled is orthogonal and most of the diagnostics under its control are currently errors. Once we migrate something to a warning wave we can remove it from FeatureStrictEnabled after a period of time sufficient for people to start using it.


In reply to: 452495746 [](ancestors = 452495746)

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

Done with review pass (iteration 4)

@jcouv jcouv self-assigned this Jul 9, 2020
@gafter
Copy link
Member Author

gafter commented Jul 10, 2020

@jcouv I have responded to your comments. Do you have any others?

@jmarolf
Copy link
Contributor

jmarolf commented Jul 10, 2020

@gafter I do think someone needs to update the compiler MSBuild tasks to accept this new option right?

I want to be able to make this change to the msbuild targets

    <Csc Resources="@(_SatelliteAssemblyResourceInputs)"
         Sources="$(_AssemblyInfoFile)"
         OutputAssembly="$(_OutputAssembly)"
         References="@(ReferencePath)"
         KeyContainer="$(KeyContainerName)"
         KeyFile="$(KeyOriginatorFile)"
         NoConfig="true"
         NoLogo="$(NoLogo)"
         NoStandardLib="$(NoCompilerStandardLib)"
         PublicSign="$(PublicSign)"
         DelaySign="$(DelaySign)"
         Deterministic="$(Deterministic)"
         DisabledWarnings="$(DisabledWarnings)"
         WarningLevel="$(WarningLevel)"
         WarningsAsErrors="$(WarningsAsErrors)"
         WarningsNotAsErrors="$(WarningsNotAsErrors)"
+        WarnVersion="$(WarnVersion)"
         TargetType="Library"
         ToolExe="$(CscToolExe)"
         ToolPath="$(CscToolPath)"
         UseSharedCompilation="$(UseSharedCompilation)">

But I believe the Csc task needs to be updated to support this option #Resolved

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM Thanks (iteration 6)

as part of .NET 5.
If you want the compiler to produce all applicable warnings, you can specify
`/warnversion=9999`.
In the project file, the property used to specify the warning version is `AnalysisLevel`.
Copy link
Contributor

@mavasani mavasani Jul 12, 2020

Choose a reason for hiding this comment

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

Why not even call the MSBuild project property WarnVersion? #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

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

I think because it is intended it be used to specify a level of analysis for analyzers to use too.


In reply to: 453250128 [](ancestors = 453250128)

@@ -0,0 +1,25 @@
# /warnversion warning "waves"
Copy link
Contributor

@mavasani mavasani Jul 12, 2020

Choose a reason for hiding this comment

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

Will this flag be added/respected for VB as well? #Resolved

Copy link
Contributor

@jmarolf jmarolf Jul 13, 2020

Choose a reason for hiding this comment

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

my understanding is that it would not be at this time, but it could be added later if there are warnings we want to add #Resolved

/// associated with the warning. Use zero to get none of the versioned warnings, or a large number like 9999
/// to get all of the versioned warnings. The first version that enables some warnings is version 5.
/// </remarks>
public decimal WarningVersion { get; private set; }
Copy link
Contributor

@mavasani mavasani Jul 12, 2020

Choose a reason for hiding this comment

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

Why decimal and not Version, given the property itself is named version? #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

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

#45941


In reply to: 453250225 [](ancestors = 453250225)

Our first warning under control of `/warnversion` was introduced in version `5`
as part of .NET 5.
If you want the compiler to produce all applicable warnings, you can specify
`/warnversion=9999`.
Copy link
Contributor

@mavasani mavasani Jul 12, 2020

Choose a reason for hiding this comment

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

Should this instead be a special string, say latest instead of a number? This would also match the LangVersion property values. #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

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

Open issue tracked by #45941


In reply to: 453250389 [](ancestors = 453250389)

@gafter
Copy link
Member Author

gafter commented Jul 13, 2020

I (mistakenly?) thought you were planning to do that under dotnet/roslyn-analyzers#3823. Should I add that to this PR?


In reply to: 656830706 [](ancestors = 656830706)

@gafter gafter requested a review from a team as a code owner July 15, 2020 00:09
@@ -503,7 +503,7 @@ class D
public int P2 { get; set; }
}
";
await VerifyItemExistsAsync(markup, "P1");
await VerifyNoItemsExistAsync(markup);
Copy link
Member

@jasonmalinowski jasonmalinowski Jul 15, 2020

Choose a reason for hiding this comment

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

Did this sneak in from another unrelated PR? #Resolved

Copy link
Member Author

@gafter gafter Jul 15, 2020

Choose a reason for hiding this comment

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

No, just fixing a test broken in the merged branch. Probably broken in master too. See #45990 (comment) #Resolved

@jmarolf
Copy link
Contributor

jmarolf commented Jul 16, 2020

I (mistakenly?) thought you were planning to do that under dotnet/roslyn-analyzers#3823. Should I add that to this PR?

@gafter so I believe there are several phases to this:

  1. C# compiler commandline support (this PR: Implement compiler /warnversion flag and one "wave" warning #45750)
  2. C# compiler build task (add /warnversion to csc msbuild task #45940)
  3. .NET SDK passes argument to C# compiler build task (Add AnalysisLevel to configure both compiler warning wave and active analyzers sdk#12422)
  4. IDE support for new compilation option (in progress)
  5. Project property page support (in progress)
  6. Project system support? I'm still investigating

Each of these needs to go in, for the most part, in the order listed but I don't think we should block this PR on that. Once the compiler team is ok with the changes to the commandline api lets merge this and then I'll rebase the downstream PRs with whatever changes are made

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Auto-approval

@ghost ghost merged commit dbdae0b into dotnet:master Jul 16, 2020
@steveharter
Copy link
Member

steveharter commented Aug 3, 2020

It appears the latest version of the Runtime\SDK (5.0.0-rc.1.20401.1 \ 5.0.100-rc.1.20403.5) causes a simple console app project to not compile in VS. Also running VS Version 16.7.0 Preview 6.0.

Compiling gives:
Error CS1900 Warning level must be in the range 0-4

Each of these needs to go in, for the most part, in the order listed but I don't think we should block this PR on that. Once the compiler team is ok with the changes to the commandline api lets merge this and then I'll rebase the downstream PRs with whatever changes are made
...
4. IDE support for new compilation option (in progress)

Any suggestions to unblock? Using <NoWarn>$(NoWarn);1900</NoWarn> in the csproj doesn't help.

@gafter
Copy link
Member Author

gafter commented Aug 3, 2020

@steveharter Until this version of the compiler is integrated, use warning level 4.

@steveharter
Copy link
Member

@gafter the .csproj is not specifying any warning level; it's using the default. I also tried creating a new console app with the same error.

Is there an environment variable?

@jmarolf
Copy link
Contributor

jmarolf commented Aug 3, 2020

You can specify <AnalysisLevel>4</AnalysisLevel> in the project file to get the old behavior while we wait for VS to put out a new build

@jmarolf
Copy link
Contributor

jmarolf commented Aug 3, 2020

For those internal to microsoft this contains the fix on the VS side. internal vs builds will be working within a day.

@steveharter
Copy link
Member

@jmarolf the <AnalysisLevel>4</AnalysisLevel> worked; thanks.

@steveharter
Copy link
Member

steveharter commented Aug 4, 2020

@jmarolf does this also require a down-level fix in VS? (older VS, newer compiler?)

@jmarolf
Copy link
Contributor

jmarolf commented Aug 4, 2020

@steveharter .NET 5 is only going to work with VS 16.8. Moving forward you are going to need either the .NET 5 SDK to build or VS 16.8

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable CS8073 in a warning wave Implement compiler flag /warnversion
8 participants