Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/linker.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorVitek Karas <vitek.karas@microsoft.com>2021-06-17 15:04:44 +0300
committerGitHub <noreply@github.com>2021-06-17 15:04:44 +0300
commitbee7f73564e495e6ab8627e7c595dacc32a4b096 (patch)
treeefa4d4c7116898b736223e24b431843f124bb668 /docs
parent4f68312aeb4b8b906bee4e06438020ad6721c522 (diff)
Warning suppressions in compiler generated code (#2075)
This change implements the following high-level functionality: * `UnconditionalSuppressMessage` applies to the entire method body even for iterators, async methods * `RequiresUnreferencedCode` automatically suppresses trim analysis warnings from entire method body for iterators, async methods Solution approach: * Detect compiler generated code by using the `IteratorStateMachineAttribute`, `AsyncStateMachineAttribute` and `AyncIteratorStateMachineAttribute`. * When a method which is compiler generated (detected by looing for `<` in its name) is processed the original "user method" is determined by looking for a method with the "state machine" attribute pointing to the compiler generated type. * This information is cached to avoid duplication of relatively expensive detection logic. * Looks for `UnconditionalSuppressMessage` and `RequriesUnreferencedCode` in: * If the warning origin is not a compiler generated code - simply use the warning origin (method) - existing behavior * If the warning origin is compiler generated use both the origin as well as the user defined method (non-compiler-generated) which is the source of the code for the compiler generated origin This is done by storing additional `SuppressionContextMember` on `MessageOrigin` which should always point to non-compiler-generated item. Added lot of new tests for these scenarios. This implements warning suppression part of https://github.com/mono/linker/issues/2001 for state machines.
Diffstat (limited to 'docs')
-rw-r--r--docs/error-codes.md76
1 files changed, 54 insertions, 22 deletions
diff --git a/docs/error-codes.md b/docs/error-codes.md
index c28da8a99..3f59b374d 100644
--- a/docs/error-codes.md
+++ b/docs/error-codes.md
@@ -1561,36 +1561,36 @@ class Test
#### `IL2103`: Trim analysis: Value passed to the 'propertyAccessor' parameter of method 'System.Linq.Expressions.Expression.Property(Expression, MethodInfo)' cannot be statically determined as a property accessor
-The value passed to the `propertyAccessor` parameter of `Expression.Property(expression, propertyAccessor)` was not recognized as a property accessor method. Trimmer can't guarantee the presence of the property.
+- The value passed to the `propertyAccessor` parameter of `Expression.Property(expression, propertyAccessor)` was not recognized as a property accessor method. Trimmer can't guarantee the presence of the property.
-```C#
-void TestMethod(MethodInfo methodInfo)
-{
- // IL2103: Value passed to the 'propertyAccessor' parameter of method 'System.Linq.Expressions.Expression.Property(Expression, MethodInfo)' cannot be statically determined as a property accessor.
- Expression.Property(null, methodInfo);
-}
-```
+ ```C#
+ void TestMethod(MethodInfo methodInfo)
+ {
+ // IL2103: Value passed to the 'propertyAccessor' parameter of method 'System.Linq.Expressions.Expression.Property(Expression, MethodInfo)' cannot be statically determined as a property accessor.
+ Expression.Property(null, methodInfo);
+ }
+ ```
#### `IL2104`: Assembly 'assembly' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries
-The assembly 'assembly' produced trim analysis warnings in the context of the app. This means the assembly has not been fully annotated for trimming. Consider contacting the library author to request they add trim annotations to the library. To see detailed warnings for this assembly, turn off grouped warnings by passing either `--singlewarn-` to show detailed warnings for all assemblies, or `--singlewarn- "assembly"` to show detailed warnings for that assembly. https://aka.ms/dotnet-illink/libraries has more information on annotating libraries for trimming.
+- The assembly 'assembly' produced trim analysis warnings in the context of the app. This means the assembly has not been fully annotated for trimming. Consider contacting the library author to request they add trim annotations to the library. To see detailed warnings for this assembly, turn off grouped warnings by passing either `--singlewarn-` to show detailed warnings for all assemblies, or `--singlewarn- "assembly"` to show detailed warnings for that assembly. https://aka.ms/dotnet-illink/libraries has more information on annotating libraries for trimming.
#### `IL2105`: Type 'type' was not found in the caller assembly nor in the base library. Type name strings used for dynamically accessing a type should be assembly qualified.
-Type name strings representing dynamically accessed types must be assembly qualified, otherwise linker will first search for the type name in the caller's assembly and then in System.Private.CoreLib.
-If the linker fails to resolve the type name, null will be returned.
+- Type name strings representing dynamically accessed types must be assembly qualified, otherwise linker will first search for the type name in the caller's assembly and then in System.Private.CoreLib.
+ If the linker fails to resolve the type name, null will be returned.
-```C#
-void TestInvalidTypeName()
-{
- RequirePublicMethodOnAType("Foo.Unqualified.TypeName");
-}
-void RequirePublicMethodOnAType(
- [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
- string typeName)
-{
-}
-```
+ ```C#
+ void TestInvalidTypeName()
+ {
+ RequirePublicMethodOnAType("Foo.Unqualified.TypeName");
+ }
+ void RequirePublicMethodOnAType(
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
+ string typeName)
+ {
+ }
+ ```
#### `IL2106`: Trim analysis: Return type of method 'method' has 'DynamicallyAccessedMembersAttribute', but that attribute can only be applied to properties of type 'System.Type' or 'System.String'
@@ -1604,6 +1604,38 @@ void RequirePublicMethodOnAType(
}
```
+#### `IL2107`: Trim analysis: Methods 'method1' and 'method2' are both associated with state machine type 'type'. This is currently unsupported and may lead to incorrectly reported warnings.
+
+- Trimmer currently can't correctly handle if the same compiler generated state machine type is associated (via the state machine attributes) with two different methods.
+ Since the trimmer currently derives warning suppressions from the method which produced the state machine and currently doesn't support reprocessing the same method/type more than once.
+
+ Only a meta-sample:
+
+ ```C#
+ class <compiler_generated_state_machine>_type {
+ void MoveNext()
+ {
+ // This should normally produce IL2026
+ CallSomethingWhichRequiresUnreferencedCode ();
+ }
+ }
+
+ [RequiresUnreferencedCode ("")] // This should suppress all warnings from the method
+ [IteratorStateMachine(typeof(<compiler_generated_state_machine>_type))]
+ IEnumerable<int> UserDefinedMethod()
+ {
+ // Uses the state machine type
+ // The IL2026 from the state machine should be suppressed in this case
+ }
+
+ // IL2107: Methods 'UserDefinedMethod' and 'SecondUserDefinedMethod' are both associated with state machine type '<compiler_generated_state_machine>_type'.
+ [IteratorStateMachine(typeof(<compiler_generated_state_machine>_type))]
+ IEnumerable<int> SecondUserDefinedMethod()
+ {
+ // Uses the state machine type
+ // The IL2026 from the state should be reported in this case
+ }
+ ```
## Single-File Warning Codes