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

RequiresAssemblyFilesAttribute resource manager changes #1790

Merged
merged 12 commits into from
Feb 4, 2021

Conversation

tlakollo
Copy link
Contributor

PR for #1786
-Change resource file to have a default message and accept arguments
-Add test for RequiresAssemblyFilesAttribute with Url named argument only

-Add test for RequiresAssemblyFilesAttribute with Url named argument
only
@tlakollo tlakollo requested a review from agocke January 29, 2021 01:41
@tlakollo tlakollo self-assigned this Jan 29, 2021
@tlakollo tlakollo requested a review from marek-safar as a code owner January 29, 2021 01:41
<value>RequiresAssemblyFilesAnalyzer</value>
</data>
<data name="RequiresAssemblyFilesMessage" xml:space="preserve">
<value>Calling '{0}' which has `RequiresAssemblyFilesAttribute` can break functionality when bundling the application code. {1}. {2}</value>
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure bundling the application code is a well-understood term. The above terminology uses "embedded in a single-file app," which seems understandable for things like Xamarin or Blazor.

<data name="RequiresAssemblyFilesTitle" xml:space="preserve">
<value />
<value>RequiresAssemblyFilesAnalyzer</value>
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is supposed to be the title of the analyzer, it's the title of the warning, which is like a short description of what the warning is supposed to prevent.

Something like, "Avoid calling members marked with RequiresAssemblyFilesAttribute when publishing as a single file"?

@@ -48,7 +48,7 @@ void M()
}
}";
return VerifyRequiresAssemblyFilesAnalyzer (TestRequiresAssemblyFieldsOnEvent,
Copy link
Member

Choose a reason for hiding this comment

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

These tests should print out a comment with the message when the test fails. If you include the comment, you can see if it looks right in the message and make the code easier to review.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are we sure we want the comments? they got deleted from the RequiresUnreferencedCodeAnalyzerTests too. I'm fine with or without them just want to homologate things between the analyzers code.

<data name="RequiresAssemblyFilesTitle" xml:space="preserve">
<value />
<value>Avoid calling members marked with `RequiresAssemblyFilesAttribute` when publishing as a single-file</value>
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Is calling the right terminology here?. Are we going to add a new message for each bundle like format?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is calling the right terminology here?

I'm changing the message to match something similar to #1778 (comment)

Are we going to add a new message for each bundle like format?

Since they all will use the same custom attribute I would expect to print the same message independent of the kind of bundle

<data name="RequiresUnreferencedCodeAnalyzerTitle" xml:space="preserve">
<value>RequiresUnreferencedCodeAnalyzer</value>
<data name="RequiresUnreferencedCodeTitle" xml:space="preserve">
<value>Avoid calling members marked with `RequiresUnreferencedCodeAttribute` when trimming application code</value>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<value>Avoid calling members marked with `RequiresUnreferencedCodeAttribute` when trimming application code</value>
<value>Avoid calling methods marked with 'RequiresUnreferencedCodeAttribute' when trimming application code</value>

Also I'm not sure that something marked with this attribute is something that the user should avoid calling, it's just a method that requires dynamic access, which is dangerous when linking the application (but I really don't have a good suggestion for framing this title).

Copy link
Member

Choose a reason for hiding this comment

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

We could rephrase by saying something like "Members annotated with RequiresUnreferencedCodeAttribute may behave differently or fail if the unreferenced code is removed by trimming"

I think that's a decent description of the problem, but it doesn't really give a call to action, like "don't call this when trimming." I don't have a strong opinion either way, but I think we should decide on what kind of title we want to present.

The context for this resource is that when you're looking at a list of the warnings, this will be the description of what the warning is about. The message is what's actually printed when the warning fires.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In a previous commit, I changed the message to:
Methods marked with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code

</data>
<data name="RequiresUnreferencedCodeAnalyzerMessage" xml:space="preserve">
<data name="RequiresUnreferencedCodeMessage" xml:space="preserve">
<value>Calling '{0}' which has `RequiresUnreferencedCodeAttribute` can break functionality when trimming application code. {1}. {2}</value>
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you're editing things here, I think we should update this message to match the one we produce from within the linker: #1778 (comment)

Tlakollo added 3 commits January 29, 2021 11:58
-Change terminology of analyzers warnings messages to match linker
-Change title description of analyzer RequiresUnreferenceCodeTitle
-Change RequireUnreferencedCodeCapability Expected warnings
@tlakollo tlakollo requested review from mateoatr and agocke January 30, 2021 00:02
break;
expectedMessageContains.RemoveAt (0);
var expectedMessages = expectedMessagesContains[1];
Copy link
Member

Choose a reason for hiding this comment

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

It looks like this no longer handles params arrays properly, namely it only looks at the second argument, instead of all the arguments.

Tlakollo added 4 commits February 3, 2021 11:32
…leResourceChange

Update error messages
Update ExpectedWarning usage
Throw whenever a named argument is passed in ExpectedWarning
@@ -56,7 +56,7 @@ public static void Main ()
TestRequiresInDynamicDependency ();
}

[ExpectedWarning ("IL2026", "--RequiresWithMessageOnly--")]
[ExpectedWarning ("IL2026", new string[] { "'Mono.Linker.Tests.Cases.RequiresCapability.RequiresUnreferencedCodeCapability.RequiresWithMessageOnly()'", "Message for --RequiresWithMessageOnly--." })]
Copy link
Member

Choose a reason for hiding this comment

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

Why add new string[]?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I changed the code to not support array creation, the code will throw in GetStringFromExpr if it ever tries to be used

Copy link
Member

@agocke agocke left a comment

Choose a reason for hiding this comment

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

LGTM, although I'd prefer if we settle on one style for params array invocations in ExpectedWarning: either use new string[] everywhere, or don't use it anywhere.

Copy link
Contributor

@mateoatr mateoatr left a comment

Choose a reason for hiding this comment

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

Can we remove the new string[] usage in the tests? Why do we need it? Looks to me that it is enough to just look for the warning code and look for the message that was specified in the Message parameter of the method that we think is the origin of the warning.

@@ -108,7 +108,7 @@ static void TestRequiresOnPropertyGetterAndSetter ()
set { }
}

[ExpectedWarning ("IL2026", new string[] { "'Mono.Linker.Tests.Cases.RequiresCapability.RequiresUnreferencedCodeCapability.RequiresAndCallsOtherRequiresMethods<TPublicMethods>()'", "Message for --RequiresAndCallsOtherRequiresMethods--." })]
[ExpectedWarning ("IL2026", "'Mono.Linker.Tests.Cases.RequiresCapability.RequiresUnreferencedCodeCapability.RequiresAndCallsOtherRequiresMethods<TPublicMethods>()'", "Message for --RequiresAndCallsOtherRequiresMethods--.")]
Copy link
Contributor

Choose a reason for hiding this comment

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

It's enough to only validate the message that's coming from the annotated method. We explicitly removed full text validation previously: #1778 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My line of thinking was that this is not full-text validation, I only validate the method name and the message which are things that should not change in the message. The linker has code in the result checker to check for the method with the ExpectedWarning attribute. The analyzer on the other hand will match any messages that are within the span, which means that there is a chance for the analyzer to check for messages that were not produced by the method marked with ExpectedWarning. Although in this file, no message is repeated, so using the message is enough. I will change the implementation.

@tlakollo tlakollo requested a review from mateoatr February 4, 2021 22:02
@tlakollo tlakollo merged commit 9b71e7b into dotnet:master Feb 4, 2021
@tlakollo tlakollo deleted the SingleFileResourceChange branch February 4, 2021 22:07
marek-safar pushed a commit to marek-safar/linker that referenced this pull request Feb 8, 2021
* Change resource file to have a default message and accept arguments
* Add test for RequiresAssemblyFilesAttribute with Url named argument only
* Add IL3XXX warning codes to the master error code registry
* Throw whenever a named argument is passed in ExpectedWarning
agocke pushed a commit to dotnet/runtime that referenced this pull request Nov 16, 2022
…r#1790)

* Change resource file to have a default message and accept arguments
* Add test for RequiresAssemblyFilesAttribute with Url named argument only
* Add IL3XXX warning codes to the master error code registry
* Throw whenever a named argument is passed in ExpectedWarning

Commit migrated from dotnet/linker@9b71e7b
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.

4 participants