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

Add nowarn option #1324

Merged
merged 12 commits into from
Jul 9, 2020
Merged

Add nowarn option #1324

merged 12 commits into from
Jul 9, 2020

Conversation

mateoatr
Copy link
Contributor

@mateoatr mateoatr commented Jul 8, 2020

This PR adds the new --nowarn option that behaves similarly to the Roslyn option of the same name. The user can turn off warning messages by specifying an ILLinker warning code. Some examples:

--nowarn IL2001
--nowarn IL2002;IL2003;IL2004
--nowarn IL2005,IL2006;IL2007
--nowarn IL2008,IL2009;IL2010
--nowarn "IL2011 IL2012,IL2013"

It also adds a new warning subcategory, TrimCorrectness, and a new ILLinkTask property, NoWarn.

This is the set of warnings that will be turned off whenever TrimmerAnalysisWarnings is set to true:

Code Message Subcategory
2006 - TrimCorrectness
2026 Calling method annotated with RequiresUnreferencedCodeAttribute TrimCorrectness
2043 Trying to propagate DynamicallyAccessedMemberAttribute from property 'property' to its getter 'method', but it already has such attribute. TrimCorrectness

/cc @agocke @eerhardt

@mateoatr mateoatr added this to the .NET5.0 milestone Jul 8, 2020
@mateoatr mateoatr self-assigned this Jul 8, 2020
src/ILLink.Tasks/LinkTask.cs Outdated Show resolved Hide resolved
src/ILLink.Tasks/LinkTask.cs Outdated Show resolved Hide resolved
/// Turns off trim correctness analysis warnings.
/// Maps to '--nowarn 2006;2026;2037;2043'.
/// </summary>
public bool TrimmerAnalysisWarnings { set => _trimmerAnalysisWarnings = value; }
Copy link
Member

Choose a reason for hiding this comment

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

Regardless of where this should live the name needs to change.
Currently we have "Trim correctness" analysis. In the future I anticipate "Single-file correctness", "AOT correctness" and potentially more. The name must reflect this.

I would probably call it EnableTrimCorrectnessAnalysis or TrimCorrectnessAnalysis (whichever fits the current style in SDK better). It would be "false" by default for now.

Copy link
Member

Choose a reason for hiding this comment

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

My understanding is that this should live in the SDK only for now, not in the task. For naming, I personally find correctness a little redundant. What do you think of TrimAnalysis?

Maybe it would make sense to preemptively open an SDK PR that introduces the option to discuss naming there, and avoid getting caught up in it here? I'm happy to do that if you think it makes sense @vitek-karas @mateoatr

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe it would make sense to preemptively open an SDK PR that introduces the option to discuss naming there, and avoid getting caught up in it here? I'm happy to do that if you think it makes sense @vitek-karas @mateoatr

This sounds good. I'm dropping this property from here then. I think EnableTrimAnalysis would be a good name, but we can follow up on this conversation in the SDK.

Copy link
Member

Choose a reason for hiding this comment

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

@sbomer Please prepare the SDK change (you can do that fastest)... EnableTrimAnalysis sounds good - please include Sam in the discussion on the SDK side.

Copy link
Member

Choose a reason for hiding this comment

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

dotnet/sdk#12388 to get the discussion started. I will add tests and such as we go.

src/ILLink.Tasks/LinkTask.cs Outdated Show resolved Hide resolved
src/linker/Linker.Dataflow/FlowAnnotations.cs Outdated Show resolved Hide resolved
src/linker/Linker.Dataflow/FlowAnnotations.cs Outdated Show resolved Hide resolved
src/linker/Linker/Driver.cs Outdated Show resolved Hide resolved
src/linker/Linker/Driver.cs Show resolved Hide resolved
src/linker/Linker/LoggingReflectionPatternRecorder.cs Outdated Show resolved Hide resolved
src/linker/Linker/Driver.cs Outdated Show resolved Hide resolved
@@ -7,6 +7,7 @@ namespace Mono.Linker
public static class MessageSubCategory
{
public const string None = "";
public const string TrimCorrectness = "Trim correctness";
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this for? I don't think this term is broadly understandable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree it might not be very informative to all users, but its main purpose is to group all warnings related to trimming analysis. Going forward, if we ever allow subcategory mapping in nowarn (things like --nowarn trimcorrectness = --nowarn IL2006;IL2026;IL2043) it might come handy. What do you think could be a more informative/useful subcategory name/message?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think something like "trimalert" for the flag and "Trim alert" for subcategory printing is more readable.
--nowarn trimalert explains the purpose
Trim alert warning IL2006 : Mono.Linker.Tests....
No warn on correctness sounds like the program warns when is correct and we are disabling it. Also, since it's a broader term sounds like it should have a lot more warnings inside the subcategory.

Copy link
Member

Choose a reason for hiding this comment

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

Given the discussion on the public property - maybe "TrimAnalysis" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think TrimAnalysis is a good option given that we'll probably have an EnableTrimAnlaysis property in the SDK. Correctness is even broader than TrimCorrectness.

src/linker/Linker/Driver.cs Show resolved Hide resolved
Co-authored-by: Marek Safar <marek.safar@gmail.com>
src/linker/Linker/Driver.cs Outdated Show resolved Hide resolved
@@ -7,6 +7,7 @@ namespace Mono.Linker
public static class MessageSubCategory
{
public const string None = "";
public const string TrimCorrectness = "Trim correctness";
Copy link
Member

Choose a reason for hiding this comment

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

Given the discussion on the public property - maybe "TrimAnalysis" ?

src/ILLink.Tasks/LinkTask.cs Outdated Show resolved Hide resolved
sbomer added a commit to sbomer/sdk that referenced this pull request Jul 8, 2020
New versions of the linker will emit warnings for code that can be
broken by trimming.  dotnet/linker#1324 will
add support for --nowarn, which we will use to leave them off by default
in .NET5 to prevent noise. This change turns them off and adds a new
property to let developers opt into the warnings.
sbomer added a commit to sbomer/sdk that referenced this pull request Jul 8, 2020
New versions of the linker will emit warnings for code that can be
broken by trimming.  dotnet/linker#1324 will
add support for --nowarn, which we will use to leave them off by default
in .NET5 to prevent noise. This change turns them off and adds a new
property to let developers opt into the warnings.
src/ILLink.Tasks/LinkTask.cs Outdated Show resolved Hide resolved
mateoatr and others added 2 commits July 8, 2020 15:06
Co-authored-by: Sven Boemer <sbomer@gmail.com>
Copy link
Member

@vitek-karas vitek-karas left a comment

Choose a reason for hiding this comment

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

LGTM
We should update the category name once we agree on the public facing property name for it (so that they match), but that can be done in a separate PR.

@mateoatr mateoatr merged commit 73dd832 into dotnet:master Jul 9, 2020
sbomer added a commit to sbomer/sdk that referenced this pull request Jul 14, 2020
New versions of the linker will emit warnings for code that can be
broken by trimming.  dotnet/linker#1324 will
add support for --nowarn, which we will use to leave them off by default
in .NET5 to prevent noise. This change turns them off and adds a new
property to let developers opt into the warnings.
sbomer added a commit to sbomer/sdk that referenced this pull request Jul 15, 2020
New versions of the linker will emit warnings for code that can be
broken by trimming.  dotnet/linker#1324 will
add support for --nowarn, which we will use to leave them off by default
in .NET5 to prevent noise. This change turns them off and adds a new
property to let developers opt into the warnings.
sbomer added a commit to sbomer/sdk that referenced this pull request Aug 3, 2020
New versions of the linker will emit warnings for code that can be
broken by trimming.  dotnet/linker#1324 will
add support for --nowarn, which we will use to leave them off by default
in .NET5 to prevent noise. This change turns them off and adds a new
property to let developers opt into the warnings.
sbomer added a commit to sbomer/sdk that referenced this pull request Aug 5, 2020
New versions of the linker will emit warnings for code that can be
broken by trimming.  dotnet/linker#1324 will
add support for --nowarn, which we will use to leave them off by default
in .NET5 to prevent noise. This change turns them off and adds a new
property to let developers opt into the warnings.
sbomer added a commit to sbomer/sdk that referenced this pull request Aug 6, 2020
New versions of the linker will emit warnings for code that can be
broken by trimming.  dotnet/linker#1324 will
add support for --nowarn, which we will use to leave them off by default
in .NET5 to prevent noise. This change turns them off and adds a new
property to let developers opt into the warnings.
sbomer added a commit to sbomer/sdk that referenced this pull request Aug 6, 2020
New versions of the linker will emit warnings for code that can be
broken by trimming.  dotnet/linker#1324 will
add support for --nowarn, which we will use to leave them off by default
in .NET5 to prevent noise. This change turns them off and adds a new
property to let developers opt into the warnings.
sbomer added a commit to dotnet/sdk that referenced this pull request Aug 7, 2020
* Introduce option to enable trim analysis warnings

New versions of the linker will emit warnings for code that can be
broken by trimming.  dotnet/linker#1324 will
add support for --nowarn, which we will use to leave them off by default
in .NET5 to prevent noise. This change turns them off and adds a new
property to let developers opt into the warnings.

* Add tests

* Also disable IL2046/IL2047

* Test no warnings for helloworld app

* Print error based on exit code

* Rename option to SuppressTrimAnalysisWarnings

* Fix up tests

* Require recent MSBuild in tests

* Update warning suppressions

* Check for more specific string in tests

The full framework MSBuild verbosity was logging --nowarn arguments, causing
some of the tests to fail.

* Fix error message wording
tkapin pushed a commit to tkapin/runtime that referenced this pull request Jan 31, 2023
* Add nowarn option

* Allow multiple --nowarn

* Add `--nowarn` to docs.

* Add NoWarn test for ILLinkTask

Commit migrated from dotnet/linker@73dd832
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants