From 5b5c7726eb32eeaedc0eafe7d79452b5f2e2eaa6 Mon Sep 17 00:00:00 2001 From: vitek-karas <10670590+vitek-karas@users.noreply.github.com> Date: Thu, 12 May 2022 02:28:11 -0700 Subject: [PATCH 1/9] Explicit nullable on shared code due to AOT --- src/ILLink.Shared/Annotations.cs | 3 +++ src/ILLink.Shared/DataFlow/DefaultValueDictionary.cs | 3 +++ src/ILLink.Shared/DataFlow/DictionaryLattice.cs | 3 +++ src/ILLink.Shared/DataFlow/ForwardDataFlowAnalysis.cs | 3 +++ src/ILLink.Shared/DataFlow/IControlFlowGraph.cs | 3 +++ src/ILLink.Shared/DataFlow/IDataFlowState.cs | 3 +++ src/ILLink.Shared/DataFlow/IDeepCopyValue.cs | 3 +++ src/ILLink.Shared/DataFlow/ILattice.cs | 3 +++ src/ILLink.Shared/DataFlow/ITransfer.cs | 3 +++ src/ILLink.Shared/DataFlow/SingleValue.cs | 3 +++ src/ILLink.Shared/DataFlow/ValueSet.cs | 3 +++ src/ILLink.Shared/DataFlow/ValueSetLattice.cs | 3 +++ src/ILLink.Shared/DiagnosticCategory.cs | 3 +++ src/ILLink.Shared/DiagnosticId.cs | 3 +++ src/ILLink.Shared/DiagnosticString.cs | 3 +++ src/ILLink.Shared/HashUtils.cs | 3 +++ src/ILLink.Shared/IsExternalInit.cs | 3 +++ src/ILLink.Shared/MessageFormat.cs | 3 +++ src/ILLink.Shared/MessageSubCategory.cs | 3 +++ src/ILLink.Shared/TrimAnalysis/ArrayValue.cs | 3 +++ src/ILLink.Shared/TrimAnalysis/ConstIntValue.cs | 3 +++ src/ILLink.Shared/TrimAnalysis/DiagnosticContext.cs | 3 +++ src/ILLink.Shared/TrimAnalysis/FieldValue.cs | 3 +++ src/ILLink.Shared/TrimAnalysis/FlowAnnotations.cs | 3 +++ src/ILLink.Shared/TrimAnalysis/GenericParameterValue.cs | 3 +++ src/ILLink.Shared/TrimAnalysis/HandleCallAction.cs | 3 +++ src/ILLink.Shared/TrimAnalysis/IntrinsicId.cs | 3 +++ src/ILLink.Shared/TrimAnalysis/Intrinsics.cs | 3 +++ src/ILLink.Shared/TrimAnalysis/KnownStringValue.cs | 3 +++ src/ILLink.Shared/TrimAnalysis/MethodParameterValue.cs | 3 +++ src/ILLink.Shared/TrimAnalysis/MethodReturnValue.cs | 3 +++ src/ILLink.Shared/TrimAnalysis/MethodThisParameterValue.cs | 3 +++ src/ILLink.Shared/TrimAnalysis/NullValue.cs | 3 +++ src/ILLink.Shared/TrimAnalysis/NullableSystemTypeValue.cs | 3 +++ .../NullableValueWithDynamicallyAccessedMembers.cs | 3 +++ .../TrimAnalysis/RequireDynamicallyAccessedMembersAction.cs | 3 +++ src/ILLink.Shared/TrimAnalysis/RuntimeMethodHandleValue.cs | 3 +++ .../TrimAnalysis/RuntimeTypeHandleForGenericParameterValue.cs | 3 +++ .../RuntimeTypeHandleForNullableSystemTypeValue.cs | 3 +++ ...TypeHandleForNullableValueWithDynamicallyAccessedMembers.cs | 3 +++ src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleValue.cs | 3 +++ .../TrimAnalysis/SystemReflectionMethodBaseValue.cs | 3 +++ src/ILLink.Shared/TrimAnalysis/SystemTypeValue.cs | 3 +++ src/ILLink.Shared/TrimAnalysis/UnknownValue.cs | 3 +++ src/ILLink.Shared/TrimAnalysis/ValueExtensions.cs | 3 +++ .../TrimAnalysis/ValueWithDynamicallyAccessedMembers.cs | 3 +++ src/ILLink.Shared/TypeSystemProxy/GenericParameterProxy.cs | 3 +++ src/ILLink.Shared/TypeSystemProxy/IMemberProxy.cs | 3 +++ src/ILLink.Shared/TypeSystemProxy/MethodProxy.cs | 3 +++ src/ILLink.Shared/TypeSystemProxy/TypeProxy.cs | 3 +++ src/ILLink.Shared/TypeSystemProxy/WellKnownType.cs | 3 +++ 51 files changed, 153 insertions(+) diff --git a/src/ILLink.Shared/Annotations.cs b/src/ILLink.Shared/Annotations.cs index d0e8a2799cbc..ca09218c0cc9 100644 --- a/src/ILLink.Shared/Annotations.cs +++ b/src/ILLink.Shared/Annotations.cs @@ -8,6 +8,9 @@ using System.Linq; using ILLink.Shared.TrimAnalysis; +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared { // Temporary workaround - should be removed once linker can be upgraded to build against diff --git a/src/ILLink.Shared/DataFlow/DefaultValueDictionary.cs b/src/ILLink.Shared/DataFlow/DefaultValueDictionary.cs index fad9daf26615..679f70ca621e 100644 --- a/src/ILLink.Shared/DataFlow/DefaultValueDictionary.cs +++ b/src/ILLink.Shared/DataFlow/DefaultValueDictionary.cs @@ -7,6 +7,9 @@ using System.Linq; using System.Text; +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.DataFlow { // This is a dictionary along with a default value, where every possible key either maps to diff --git a/src/ILLink.Shared/DataFlow/DictionaryLattice.cs b/src/ILLink.Shared/DataFlow/DictionaryLattice.cs index aef1e1ba7df3..77732b28f4c7 100644 --- a/src/ILLink.Shared/DataFlow/DictionaryLattice.cs +++ b/src/ILLink.Shared/DataFlow/DictionaryLattice.cs @@ -3,6 +3,9 @@ using System; +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.DataFlow { // A lattice over dictionaries where the stored values are also from a lattice. diff --git a/src/ILLink.Shared/DataFlow/ForwardDataFlowAnalysis.cs b/src/ILLink.Shared/DataFlow/ForwardDataFlowAnalysis.cs index 4c6b72fca6c0..345fbe8680a5 100644 --- a/src/ILLink.Shared/DataFlow/ForwardDataFlowAnalysis.cs +++ b/src/ILLink.Shared/DataFlow/ForwardDataFlowAnalysis.cs @@ -5,6 +5,9 @@ using System.Collections.Generic; using System.Diagnostics; +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.DataFlow { // A generic implementation of a forward dataflow analysis. Forward means that it flows facts diff --git a/src/ILLink.Shared/DataFlow/IControlFlowGraph.cs b/src/ILLink.Shared/DataFlow/IControlFlowGraph.cs index 356ec43a5a82..eb1b492aa308 100644 --- a/src/ILLink.Shared/DataFlow/IControlFlowGraph.cs +++ b/src/ILLink.Shared/DataFlow/IControlFlowGraph.cs @@ -6,6 +6,9 @@ using System.Collections.Immutable; using System.Diagnostics.CodeAnalysis; +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.DataFlow { public enum RegionKind diff --git a/src/ILLink.Shared/DataFlow/IDataFlowState.cs b/src/ILLink.Shared/DataFlow/IDataFlowState.cs index 69c368b1844a..26f056be835e 100644 --- a/src/ILLink.Shared/DataFlow/IDataFlowState.cs +++ b/src/ILLink.Shared/DataFlow/IDataFlowState.cs @@ -3,6 +3,9 @@ using System; +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.DataFlow { public sealed class Box where T : struct diff --git a/src/ILLink.Shared/DataFlow/IDeepCopyValue.cs b/src/ILLink.Shared/DataFlow/IDeepCopyValue.cs index c9630d530b0a..da1278094952 100644 --- a/src/ILLink.Shared/DataFlow/IDeepCopyValue.cs +++ b/src/ILLink.Shared/DataFlow/IDeepCopyValue.cs @@ -1,6 +1,9 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.DataFlow { // Adds ability to deep copy a value diff --git a/src/ILLink.Shared/DataFlow/ILattice.cs b/src/ILLink.Shared/DataFlow/ILattice.cs index 30990c5ff505..07f31c4e5ed3 100644 --- a/src/ILLink.Shared/DataFlow/ILattice.cs +++ b/src/ILLink.Shared/DataFlow/ILattice.cs @@ -3,6 +3,9 @@ using System; +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.DataFlow { // ILattice represents a lattice (technically a semilattice) of values. diff --git a/src/ILLink.Shared/DataFlow/ITransfer.cs b/src/ILLink.Shared/DataFlow/ITransfer.cs index 60da4e3305e9..74c35c8613d5 100644 --- a/src/ILLink.Shared/DataFlow/ITransfer.cs +++ b/src/ILLink.Shared/DataFlow/ITransfer.cs @@ -3,6 +3,9 @@ using System; +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.DataFlow { // ITransfer represents the transfer functions for a dataflow analysis. diff --git a/src/ILLink.Shared/DataFlow/SingleValue.cs b/src/ILLink.Shared/DataFlow/SingleValue.cs index 03fb4907f63f..79963757b934 100644 --- a/src/ILLink.Shared/DataFlow/SingleValue.cs +++ b/src/ILLink.Shared/DataFlow/SingleValue.cs @@ -1,6 +1,9 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.DataFlow { // This is a sum type over the various kinds of values we track: diff --git a/src/ILLink.Shared/DataFlow/ValueSet.cs b/src/ILLink.Shared/DataFlow/ValueSet.cs index 2466255d121f..120e9116eaf3 100644 --- a/src/ILLink.Shared/DataFlow/ValueSet.cs +++ b/src/ILLink.Shared/DataFlow/ValueSet.cs @@ -7,6 +7,9 @@ using System.Linq; using System.Text; +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.DataFlow { public readonly struct ValueSet : IEquatable>, IEnumerable diff --git a/src/ILLink.Shared/DataFlow/ValueSetLattice.cs b/src/ILLink.Shared/DataFlow/ValueSetLattice.cs index 2fed57e3ebba..1acca955ce04 100644 --- a/src/ILLink.Shared/DataFlow/ValueSetLattice.cs +++ b/src/ILLink.Shared/DataFlow/ValueSetLattice.cs @@ -3,6 +3,9 @@ using System; +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.DataFlow { // A lattice over ValueSets where the Meet operation is just set union. diff --git a/src/ILLink.Shared/DiagnosticCategory.cs b/src/ILLink.Shared/DiagnosticCategory.cs index e2e7f3e72e88..a1d1e116f773 100644 --- a/src/ILLink.Shared/DiagnosticCategory.cs +++ b/src/ILLink.Shared/DiagnosticCategory.cs @@ -1,6 +1,9 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared { internal static class DiagnosticCategory diff --git a/src/ILLink.Shared/DiagnosticId.cs b/src/ILLink.Shared/DiagnosticId.cs index a069fe5bba6f..ac417f4ee58e 100644 --- a/src/ILLink.Shared/DiagnosticId.cs +++ b/src/ILLink.Shared/DiagnosticId.cs @@ -1,6 +1,9 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared { public enum DiagnosticId diff --git a/src/ILLink.Shared/DiagnosticString.cs b/src/ILLink.Shared/DiagnosticString.cs index d2a3076e4f5a..0102ae90c22c 100644 --- a/src/ILLink.Shared/DiagnosticString.cs +++ b/src/ILLink.Shared/DiagnosticString.cs @@ -3,6 +3,9 @@ using System; +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared { public readonly struct DiagnosticString diff --git a/src/ILLink.Shared/HashUtils.cs b/src/ILLink.Shared/HashUtils.cs index e794ef780255..cc9b259bedb9 100644 --- a/src/ILLink.Shared/HashUtils.cs +++ b/src/ILLink.Shared/HashUtils.cs @@ -5,6 +5,9 @@ using System; #endif +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared { static class HashUtils diff --git a/src/ILLink.Shared/IsExternalInit.cs b/src/ILLink.Shared/IsExternalInit.cs index 00001f8f9642..f2b081a032f4 100644 --- a/src/ILLink.Shared/IsExternalInit.cs +++ b/src/ILLink.Shared/IsExternalInit.cs @@ -1,6 +1,9 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + #if NETSTANDARD // Allow use of init setters on downlevel frameworks. namespace System.Runtime.CompilerServices diff --git a/src/ILLink.Shared/MessageFormat.cs b/src/ILLink.Shared/MessageFormat.cs index cf7636ba0b9c..0e67c71b676e 100644 --- a/src/ILLink.Shared/MessageFormat.cs +++ b/src/ILLink.Shared/MessageFormat.cs @@ -1,6 +1,9 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared { internal static class MessageFormat diff --git a/src/ILLink.Shared/MessageSubCategory.cs b/src/ILLink.Shared/MessageSubCategory.cs index 04bc7642fdfe..b571f3c95ee0 100644 --- a/src/ILLink.Shared/MessageSubCategory.cs +++ b/src/ILLink.Shared/MessageSubCategory.cs @@ -1,6 +1,9 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared { internal static class MessageSubCategory diff --git a/src/ILLink.Shared/TrimAnalysis/ArrayValue.cs b/src/ILLink.Shared/TrimAnalysis/ArrayValue.cs index d043998b80f7..d8c399878374 100644 --- a/src/ILLink.Shared/TrimAnalysis/ArrayValue.cs +++ b/src/ILLink.Shared/TrimAnalysis/ArrayValue.cs @@ -4,6 +4,9 @@ using ILLink.Shared.DataFlow; using MultiValue = ILLink.Shared.DataFlow.ValueSet; +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.TrimAnalysis { sealed partial record ArrayValue : SingleValue diff --git a/src/ILLink.Shared/TrimAnalysis/ConstIntValue.cs b/src/ILLink.Shared/TrimAnalysis/ConstIntValue.cs index 725034ec3f2f..e83a7cd5d378 100644 --- a/src/ILLink.Shared/TrimAnalysis/ConstIntValue.cs +++ b/src/ILLink.Shared/TrimAnalysis/ConstIntValue.cs @@ -3,6 +3,9 @@ using ILLink.Shared.DataFlow; +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.TrimAnalysis { /// diff --git a/src/ILLink.Shared/TrimAnalysis/DiagnosticContext.cs b/src/ILLink.Shared/TrimAnalysis/DiagnosticContext.cs index f10953413059..06353c222852 100644 --- a/src/ILLink.Shared/TrimAnalysis/DiagnosticContext.cs +++ b/src/ILLink.Shared/TrimAnalysis/DiagnosticContext.cs @@ -1,6 +1,9 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.TrimAnalysis { readonly partial struct DiagnosticContext diff --git a/src/ILLink.Shared/TrimAnalysis/FieldValue.cs b/src/ILLink.Shared/TrimAnalysis/FieldValue.cs index 2974ed4eb36d..0041e436313f 100644 --- a/src/ILLink.Shared/TrimAnalysis/FieldValue.cs +++ b/src/ILLink.Shared/TrimAnalysis/FieldValue.cs @@ -1,6 +1,9 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.TrimAnalysis { sealed partial record FieldValue : ValueWithDynamicallyAccessedMembers; diff --git a/src/ILLink.Shared/TrimAnalysis/FlowAnnotations.cs b/src/ILLink.Shared/TrimAnalysis/FlowAnnotations.cs index e58ef82abae0..cf114978c02e 100644 --- a/src/ILLink.Shared/TrimAnalysis/FlowAnnotations.cs +++ b/src/ILLink.Shared/TrimAnalysis/FlowAnnotations.cs @@ -4,6 +4,9 @@ using System.Diagnostics.CodeAnalysis; using ILLink.Shared.TypeSystemProxy; +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.TrimAnalysis { // Shared helpers to go from MethodProxy to dataflow values. diff --git a/src/ILLink.Shared/TrimAnalysis/GenericParameterValue.cs b/src/ILLink.Shared/TrimAnalysis/GenericParameterValue.cs index 75055cd680b1..18bfa5fbbdef 100644 --- a/src/ILLink.Shared/TrimAnalysis/GenericParameterValue.cs +++ b/src/ILLink.Shared/TrimAnalysis/GenericParameterValue.cs @@ -3,6 +3,9 @@ using ILLink.Shared.TypeSystemProxy; +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.TrimAnalysis { /// diff --git a/src/ILLink.Shared/TrimAnalysis/HandleCallAction.cs b/src/ILLink.Shared/TrimAnalysis/HandleCallAction.cs index 60b41e750c99..34e55100459a 100644 --- a/src/ILLink.Shared/TrimAnalysis/HandleCallAction.cs +++ b/src/ILLink.Shared/TrimAnalysis/HandleCallAction.cs @@ -13,6 +13,9 @@ using ILLink.Shared.TypeSystemProxy; using MultiValue = ILLink.Shared.DataFlow.ValueSet; +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.TrimAnalysis { [StructLayout (LayoutKind.Auto)] // A good way to avoid CS0282, we don't really care about field order diff --git a/src/ILLink.Shared/TrimAnalysis/IntrinsicId.cs b/src/ILLink.Shared/TrimAnalysis/IntrinsicId.cs index 898a5a09e57b..a4548bc64110 100644 --- a/src/ILLink.Shared/TrimAnalysis/IntrinsicId.cs +++ b/src/ILLink.Shared/TrimAnalysis/IntrinsicId.cs @@ -1,6 +1,9 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.TrimAnalysis { enum IntrinsicId diff --git a/src/ILLink.Shared/TrimAnalysis/Intrinsics.cs b/src/ILLink.Shared/TrimAnalysis/Intrinsics.cs index 36f9189f6dde..3dbcaa96f643 100644 --- a/src/ILLink.Shared/TrimAnalysis/Intrinsics.cs +++ b/src/ILLink.Shared/TrimAnalysis/Intrinsics.cs @@ -3,6 +3,9 @@ using ILLink.Shared.TypeSystemProxy; +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.TrimAnalysis { static class Intrinsics diff --git a/src/ILLink.Shared/TrimAnalysis/KnownStringValue.cs b/src/ILLink.Shared/TrimAnalysis/KnownStringValue.cs index 10fe1c2f44b9..bbdedf5bf02d 100644 --- a/src/ILLink.Shared/TrimAnalysis/KnownStringValue.cs +++ b/src/ILLink.Shared/TrimAnalysis/KnownStringValue.cs @@ -3,6 +3,9 @@ using ILLink.Shared.DataFlow; +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.TrimAnalysis { /// diff --git a/src/ILLink.Shared/TrimAnalysis/MethodParameterValue.cs b/src/ILLink.Shared/TrimAnalysis/MethodParameterValue.cs index c8a021938d2f..8d2b4a6a64b4 100644 --- a/src/ILLink.Shared/TrimAnalysis/MethodParameterValue.cs +++ b/src/ILLink.Shared/TrimAnalysis/MethodParameterValue.cs @@ -1,6 +1,9 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.TrimAnalysis { sealed partial record MethodParameterValue : ValueWithDynamicallyAccessedMembers; diff --git a/src/ILLink.Shared/TrimAnalysis/MethodReturnValue.cs b/src/ILLink.Shared/TrimAnalysis/MethodReturnValue.cs index 7a318509efb4..708b5f469c39 100644 --- a/src/ILLink.Shared/TrimAnalysis/MethodReturnValue.cs +++ b/src/ILLink.Shared/TrimAnalysis/MethodReturnValue.cs @@ -1,6 +1,9 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.TrimAnalysis { sealed partial record class MethodReturnValue : ValueWithDynamicallyAccessedMembers; diff --git a/src/ILLink.Shared/TrimAnalysis/MethodThisParameterValue.cs b/src/ILLink.Shared/TrimAnalysis/MethodThisParameterValue.cs index 9b0626eee867..baf12d256d8f 100644 --- a/src/ILLink.Shared/TrimAnalysis/MethodThisParameterValue.cs +++ b/src/ILLink.Shared/TrimAnalysis/MethodThisParameterValue.cs @@ -1,6 +1,9 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.TrimAnalysis { sealed partial record MethodThisParameterValue : ValueWithDynamicallyAccessedMembers; diff --git a/src/ILLink.Shared/TrimAnalysis/NullValue.cs b/src/ILLink.Shared/TrimAnalysis/NullValue.cs index f548058ecdcb..90afd5a87929 100644 --- a/src/ILLink.Shared/TrimAnalysis/NullValue.cs +++ b/src/ILLink.Shared/TrimAnalysis/NullValue.cs @@ -3,6 +3,9 @@ using ILLink.Shared.DataFlow; +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.TrimAnalysis { sealed record NullValue : SingleValue diff --git a/src/ILLink.Shared/TrimAnalysis/NullableSystemTypeValue.cs b/src/ILLink.Shared/TrimAnalysis/NullableSystemTypeValue.cs index 6c7a30575304..1f54cc2779bf 100644 --- a/src/ILLink.Shared/TrimAnalysis/NullableSystemTypeValue.cs +++ b/src/ILLink.Shared/TrimAnalysis/NullableSystemTypeValue.cs @@ -5,6 +5,9 @@ using ILLink.Shared.DataFlow; using ILLink.Shared.TypeSystemProxy; +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.TrimAnalysis { /// diff --git a/src/ILLink.Shared/TrimAnalysis/NullableValueWithDynamicallyAccessedMembers.cs b/src/ILLink.Shared/TrimAnalysis/NullableValueWithDynamicallyAccessedMembers.cs index 886cff678e52..4c09d6f7f173 100644 --- a/src/ILLink.Shared/TrimAnalysis/NullableValueWithDynamicallyAccessedMembers.cs +++ b/src/ILLink.Shared/TrimAnalysis/NullableValueWithDynamicallyAccessedMembers.cs @@ -7,6 +7,9 @@ using ILLink.Shared.DataFlow; using ILLink.Shared.TypeSystemProxy; +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.TrimAnalysis { /// diff --git a/src/ILLink.Shared/TrimAnalysis/RequireDynamicallyAccessedMembersAction.cs b/src/ILLink.Shared/TrimAnalysis/RequireDynamicallyAccessedMembersAction.cs index d8a4a2c84c91..9eb5db78804f 100644 --- a/src/ILLink.Shared/TrimAnalysis/RequireDynamicallyAccessedMembersAction.cs +++ b/src/ILLink.Shared/TrimAnalysis/RequireDynamicallyAccessedMembersAction.cs @@ -8,6 +8,9 @@ using ILLink.Shared.TypeSystemProxy; using MultiValue = ILLink.Shared.DataFlow.ValueSet; +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.TrimAnalysis { [StructLayout (LayoutKind.Auto)] diff --git a/src/ILLink.Shared/TrimAnalysis/RuntimeMethodHandleValue.cs b/src/ILLink.Shared/TrimAnalysis/RuntimeMethodHandleValue.cs index 2843fd929e9d..7ef048f224b5 100644 --- a/src/ILLink.Shared/TrimAnalysis/RuntimeMethodHandleValue.cs +++ b/src/ILLink.Shared/TrimAnalysis/RuntimeMethodHandleValue.cs @@ -4,6 +4,9 @@ using ILLink.Shared.DataFlow; using ILLink.Shared.TypeSystemProxy; +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.TrimAnalysis { /// diff --git a/src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleForGenericParameterValue.cs b/src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleForGenericParameterValue.cs index 579857a95762..1eb108e5faea 100644 --- a/src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleForGenericParameterValue.cs +++ b/src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleForGenericParameterValue.cs @@ -4,6 +4,9 @@ using ILLink.Shared.DataFlow; using ILLink.Shared.TypeSystemProxy; +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.TrimAnalysis { /// diff --git a/src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleForNullableSystemTypeValue.cs b/src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleForNullableSystemTypeValue.cs index 0f6e73d2ca7d..c92d4274b2d9 100644 --- a/src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleForNullableSystemTypeValue.cs +++ b/src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleForNullableSystemTypeValue.cs @@ -5,6 +5,9 @@ using ILLink.Shared.DataFlow; using ILLink.Shared.TypeSystemProxy; +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.TrimAnalysis { /// diff --git a/src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleForNullableValueWithDynamicallyAccessedMembers.cs b/src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleForNullableValueWithDynamicallyAccessedMembers.cs index acd9d886bc68..b4b0653931d0 100644 --- a/src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleForNullableValueWithDynamicallyAccessedMembers.cs +++ b/src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleForNullableValueWithDynamicallyAccessedMembers.cs @@ -5,6 +5,9 @@ using ILLink.Shared.DataFlow; using ILLink.Shared.TypeSystemProxy; +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.TrimAnalysis { /// diff --git a/src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleValue.cs b/src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleValue.cs index 48e08399ff58..c508c1f784dc 100644 --- a/src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleValue.cs +++ b/src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleValue.cs @@ -4,6 +4,9 @@ using ILLink.Shared.DataFlow; using ILLink.Shared.TypeSystemProxy; +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.TrimAnalysis { /// diff --git a/src/ILLink.Shared/TrimAnalysis/SystemReflectionMethodBaseValue.cs b/src/ILLink.Shared/TrimAnalysis/SystemReflectionMethodBaseValue.cs index 005ad98ca5d5..3ef755cb7aae 100644 --- a/src/ILLink.Shared/TrimAnalysis/SystemReflectionMethodBaseValue.cs +++ b/src/ILLink.Shared/TrimAnalysis/SystemReflectionMethodBaseValue.cs @@ -4,6 +4,9 @@ using ILLink.Shared.DataFlow; using ILLink.Shared.TypeSystemProxy; +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.TrimAnalysis { /// diff --git a/src/ILLink.Shared/TrimAnalysis/SystemTypeValue.cs b/src/ILLink.Shared/TrimAnalysis/SystemTypeValue.cs index b3b41e275814..71af91c4e56d 100644 --- a/src/ILLink.Shared/TrimAnalysis/SystemTypeValue.cs +++ b/src/ILLink.Shared/TrimAnalysis/SystemTypeValue.cs @@ -4,6 +4,9 @@ using ILLink.Shared.DataFlow; using ILLink.Shared.TypeSystemProxy; +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.TrimAnalysis { /// diff --git a/src/ILLink.Shared/TrimAnalysis/UnknownValue.cs b/src/ILLink.Shared/TrimAnalysis/UnknownValue.cs index e764cd1474f9..7dc49dc66627 100644 --- a/src/ILLink.Shared/TrimAnalysis/UnknownValue.cs +++ b/src/ILLink.Shared/TrimAnalysis/UnknownValue.cs @@ -3,6 +3,9 @@ using ILLink.Shared.DataFlow; +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.TrimAnalysis { sealed record UnknownValue : SingleValue diff --git a/src/ILLink.Shared/TrimAnalysis/ValueExtensions.cs b/src/ILLink.Shared/TrimAnalysis/ValueExtensions.cs index 6bfd1cfb76c7..d9358f2910f1 100644 --- a/src/ILLink.Shared/TrimAnalysis/ValueExtensions.cs +++ b/src/ILLink.Shared/TrimAnalysis/ValueExtensions.cs @@ -6,6 +6,9 @@ using ILLink.Shared.DataFlow; using MultiValue = ILLink.Shared.DataFlow.ValueSet; +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.TrimAnalysis { static partial class ValueExtensions diff --git a/src/ILLink.Shared/TrimAnalysis/ValueWithDynamicallyAccessedMembers.cs b/src/ILLink.Shared/TrimAnalysis/ValueWithDynamicallyAccessedMembers.cs index a2b62e33cdb5..c67d30040d2a 100644 --- a/src/ILLink.Shared/TrimAnalysis/ValueWithDynamicallyAccessedMembers.cs +++ b/src/ILLink.Shared/TrimAnalysis/ValueWithDynamicallyAccessedMembers.cs @@ -5,6 +5,9 @@ using System.Diagnostics.CodeAnalysis; using ILLink.Shared.DataFlow; +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.TrimAnalysis { public abstract record ValueWithDynamicallyAccessedMembers : SingleValue diff --git a/src/ILLink.Shared/TypeSystemProxy/GenericParameterProxy.cs b/src/ILLink.Shared/TypeSystemProxy/GenericParameterProxy.cs index cefd3a93b912..09ddbc4ae052 100644 --- a/src/ILLink.Shared/TypeSystemProxy/GenericParameterProxy.cs +++ b/src/ILLink.Shared/TypeSystemProxy/GenericParameterProxy.cs @@ -1,6 +1,9 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.TypeSystemProxy { internal readonly partial struct GenericParameterProxy diff --git a/src/ILLink.Shared/TypeSystemProxy/IMemberProxy.cs b/src/ILLink.Shared/TypeSystemProxy/IMemberProxy.cs index fe216b005404..3e358b9a5b85 100644 --- a/src/ILLink.Shared/TypeSystemProxy/IMemberProxy.cs +++ b/src/ILLink.Shared/TypeSystemProxy/IMemberProxy.cs @@ -1,6 +1,9 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.TypeSystemProxy { interface IMemberProxy diff --git a/src/ILLink.Shared/TypeSystemProxy/MethodProxy.cs b/src/ILLink.Shared/TypeSystemProxy/MethodProxy.cs index cc4d0954c9cb..a30ce2200e3e 100644 --- a/src/ILLink.Shared/TypeSystemProxy/MethodProxy.cs +++ b/src/ILLink.Shared/TypeSystemProxy/MethodProxy.cs @@ -3,6 +3,9 @@ using System.Collections.Immutable; +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.TypeSystemProxy { internal readonly partial struct MethodProxy : IMemberProxy diff --git a/src/ILLink.Shared/TypeSystemProxy/TypeProxy.cs b/src/ILLink.Shared/TypeSystemProxy/TypeProxy.cs index 078bf58114bb..0c459f05df29 100644 --- a/src/ILLink.Shared/TypeSystemProxy/TypeProxy.cs +++ b/src/ILLink.Shared/TypeSystemProxy/TypeProxy.cs @@ -3,6 +3,9 @@ using System.Collections.Immutable; +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.TypeSystemProxy { internal readonly partial struct TypeProxy : IMemberProxy diff --git a/src/ILLink.Shared/TypeSystemProxy/WellKnownType.cs b/src/ILLink.Shared/TypeSystemProxy/WellKnownType.cs index d187bf0fbef7..9d6f580c06d2 100644 --- a/src/ILLink.Shared/TypeSystemProxy/WellKnownType.cs +++ b/src/ILLink.Shared/TypeSystemProxy/WellKnownType.cs @@ -3,6 +3,9 @@ using System; +// This is needed due to NativeAOT which doesn't enable nullable globally yet +#nullable enable + namespace ILLink.Shared.TypeSystemProxy { public enum WellKnownType From 345b72717a0537cac7f18da1de019a585387f067 Mon Sep 17 00:00:00 2001 From: vitek-karas <10670590+vitek-karas@users.noreply.github.com> Date: Thu, 12 May 2022 03:40:06 -0700 Subject: [PATCH 2/9] Change FlowAnnotations to a class --- .../TrimAnalysis/FlowAnnotations.cs | 18 ++++++++++++++---- .../TrimAnalysis/HandleCallAction.cs | 2 +- .../TrimAnalysis/FlowAnnotations.cs | 2 +- src/linker/Linker.Dataflow/FlowAnnotations.cs | 2 +- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/ILLink.RoslynAnalyzer/TrimAnalysis/FlowAnnotations.cs b/src/ILLink.RoslynAnalyzer/TrimAnalysis/FlowAnnotations.cs index 95f20604755d..1c66633a2155 100644 --- a/src/ILLink.RoslynAnalyzer/TrimAnalysis/FlowAnnotations.cs +++ b/src/ILLink.RoslynAnalyzer/TrimAnalysis/FlowAnnotations.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using ILLink.RoslynAnalyzer; @@ -9,8 +10,17 @@ namespace ILLink.Shared.TrimAnalysis { - readonly partial struct FlowAnnotations + partial class FlowAnnotations { + // In the analyzer there's no stateful data the flow annotations need to store + // so we just create a singleton on demand. + static readonly Lazy _instance = new (() => new FlowAnnotations (), isThreadSafe: true); + + public static FlowAnnotations Instance { get => _instance.Value; } + + // Hide the default .ctor so that only the one singleton instance can be created + private FlowAnnotations () { } + public static bool RequiresDataFlowAnalysis (IMethodSymbol method) { if (method.GetDynamicallyAccessedMemberTypes () != DynamicallyAccessedMemberTypes.None) @@ -72,13 +82,13 @@ public static DynamicallyAccessedMemberTypes GetMethodReturnValueAnnotation (IMe // In linker this is an optimization to avoid the heavy lifting of analysis if there's no point // it's unclear if the same optimization makes sense for the analyzer. internal partial bool MethodRequiresDataFlowAnalysis (MethodProxy method) - => FlowAnnotations.RequiresDataFlowAnalysis (method.Method); + => RequiresDataFlowAnalysis (method.Method); internal partial MethodReturnValue GetMethodReturnValue (MethodProxy method, DynamicallyAccessedMemberTypes dynamicallyAccessedMemberTypes) => new MethodReturnValue (method.Method, dynamicallyAccessedMemberTypes); internal partial MethodReturnValue GetMethodReturnValue (MethodProxy method) - => GetMethodReturnValue (method, FlowAnnotations.GetMethodReturnValueAnnotation (method.Method)); + => GetMethodReturnValue (method, GetMethodReturnValueAnnotation (method.Method)); internal partial GenericParameterValue GetGenericParameterValue (GenericParameterProxy genericParameter) => new GenericParameterValue (genericParameter.TypeParameterSymbol); @@ -94,7 +104,7 @@ internal partial MethodParameterValue GetMethodParameterValue (MethodProxy metho internal partial MethodParameterValue GetMethodParameterValue (MethodProxy method, int parameterIndex) { - var annotation = FlowAnnotations.GetMethodParameterAnnotation (method.Method.Parameters[parameterIndex]); + var annotation = GetMethodParameterAnnotation (method.Method.Parameters[parameterIndex]); return GetMethodParameterValue (method, parameterIndex, annotation); } #pragma warning restore CA1822 diff --git a/src/ILLink.RoslynAnalyzer/TrimAnalysis/HandleCallAction.cs b/src/ILLink.RoslynAnalyzer/TrimAnalysis/HandleCallAction.cs index 5b36514de3fd..3f220a97b0a0 100644 --- a/src/ILLink.RoslynAnalyzer/TrimAnalysis/HandleCallAction.cs +++ b/src/ILLink.RoslynAnalyzer/TrimAnalysis/HandleCallAction.cs @@ -26,7 +26,7 @@ public HandleCallAction (in DiagnosticContext diagnosticContext, ISymbol owningS _owningSymbol = owningSymbol; _operation = operation; _diagnosticContext = diagnosticContext; - _annotations = new FlowAnnotations (); + _annotations = FlowAnnotations.Instance; _reflectionAccessAnalyzer = new ReflectionAccessAnalyzer (); _requireDynamicallyAccessedMembersAction = new (diagnosticContext, _reflectionAccessAnalyzer); } diff --git a/src/ILLink.Shared/TrimAnalysis/FlowAnnotations.cs b/src/ILLink.Shared/TrimAnalysis/FlowAnnotations.cs index cf114978c02e..7d3912e971e2 100644 --- a/src/ILLink.Shared/TrimAnalysis/FlowAnnotations.cs +++ b/src/ILLink.Shared/TrimAnalysis/FlowAnnotations.cs @@ -10,7 +10,7 @@ namespace ILLink.Shared.TrimAnalysis { // Shared helpers to go from MethodProxy to dataflow values. - readonly partial struct FlowAnnotations + partial class FlowAnnotations { internal partial bool MethodRequiresDataFlowAnalysis (MethodProxy method); diff --git a/src/linker/Linker.Dataflow/FlowAnnotations.cs b/src/linker/Linker.Dataflow/FlowAnnotations.cs index f7435ccea4c2..32e148acd97a 100644 --- a/src/linker/Linker.Dataflow/FlowAnnotations.cs +++ b/src/linker/Linker.Dataflow/FlowAnnotations.cs @@ -15,7 +15,7 @@ namespace ILLink.Shared.TrimAnalysis { - readonly partial struct FlowAnnotations + partial class FlowAnnotations { readonly LinkContext _context; readonly Dictionary _annotations = new Dictionary (); From c448dd1af033577470a2c4669d8106e3db1e2fd6 Mon Sep 17 00:00:00 2001 From: vitek-karas <10670590+vitek-karas@users.noreply.github.com> Date: Tue, 17 May 2022 08:16:28 -0700 Subject: [PATCH 3/9] Add intrinsics only recognized in Native AOT --- src/ILLink.Shared/TrimAnalysis/IntrinsicId.cs | 6 ++++ src/ILLink.Shared/TrimAnalysis/Intrinsics.cs | 36 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/ILLink.Shared/TrimAnalysis/IntrinsicId.cs b/src/ILLink.Shared/TrimAnalysis/IntrinsicId.cs index a4548bc64110..7a2a40b068ac 100644 --- a/src/ILLink.Shared/TrimAnalysis/IntrinsicId.cs +++ b/src/ILLink.Shared/TrimAnalysis/IntrinsicId.cs @@ -46,6 +46,12 @@ enum IntrinsicId Expression_Field, Expression_Property, Expression_New, + Enum_GetValues, + Marshal_SizeOf, + Marshal_OffsetOf, + Marshal_PtrToStructure, + Marshal_DestroyStructure, + Marshal_GetDelegateForFunctionPointer, Activator_CreateInstance_Type, Activator_CreateInstance_AssemblyName_TypeName, Activator_CreateInstanceFrom, diff --git a/src/ILLink.Shared/TrimAnalysis/Intrinsics.cs b/src/ILLink.Shared/TrimAnalysis/Intrinsics.cs index 3dbcaa96f643..872f943e9fad 100644 --- a/src/ILLink.Shared/TrimAnalysis/Intrinsics.cs +++ b/src/ILLink.Shared/TrimAnalysis/Intrinsics.cs @@ -87,6 +87,42 @@ public static IntrinsicId GetIntrinsicIdForMethod (MethodProxy calledMethod) && calledMethod.HasParametersCount (1) => IntrinsicId.Expression_New, + // static Array System.Enum.GetValues (Type) + "GetValues" when calledMethod.IsDeclaredOnType ("System.Enum") + && calledMethod.HasParameterOfType (0, "System.Type") + && calledMethod.HasParametersCount (1) + => IntrinsicId.Enum_GetValues, + + // static int System.Runtime.InteropServices.Marshal.SizeOf (Type) + "SizeOf" when calledMethod.IsDeclaredOnType ("System.Runtime.InteropServices.Marshal") + && calledMethod.HasParameterOfType (0, "System.Type") + && calledMethod.HasParametersCount (1) + => IntrinsicId.Marshal_SizeOf, + + // static int System.Runtime.InteropServices.Marshal.OffsetOf (Type, string) + "OffsetOf" when calledMethod.IsDeclaredOnType ("System.Runtime.InteropServices.Marshal") + && calledMethod.HasParameterOfType (0, "System.Type") + && calledMethod.HasParametersCount (2) + => IntrinsicId.Marshal_OffsetOf, + + // static object System.Runtime.InteropServices.Marshal.PtrToStructure (IntPtr, Type) + "PtrToStructure" when calledMethod.IsDeclaredOnType ("System.Runtime.InteropServices.Marshal") + && calledMethod.HasParameterOfType (1, "System.Type") + && calledMethod.HasParametersCount (2) + => IntrinsicId.Marshal_PtrToStructure, + + // static void System.Runtime.InteropServices.Marshal.DestroyStructure (IntPtr, Type) + "DestroyStructure" when calledMethod.IsDeclaredOnType ("System.Runtime.InteropServices.Marshal") + && calledMethod.HasParameterOfType (1, "System.Type") + && calledMethod.HasParametersCount (2) + => IntrinsicId.Marshal_DestroyStructure, + + // static Delegate System.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointer (IntPtr, Type) + "GetDelegateForFunctionPointer" when calledMethod.IsDeclaredOnType ("System.Runtime.InteropServices.Marshal") + && calledMethod.HasParameterOfType (1, "System.Type") + && calledMethod.HasParametersCount (2) + => IntrinsicId.Marshal_GetDelegateForFunctionPointer, + // static System.Type.GetType (string) // static System.Type.GetType (string, Boolean) // static System.Type.GetType (string, Boolean, Boolean) From 338ff78a0e8c5f083adcba8fc0007c8a0afc700b Mon Sep 17 00:00:00 2001 From: vitek-karas <10670590+vitek-karas@users.noreply.github.com> Date: Wed, 18 May 2022 04:47:11 -0700 Subject: [PATCH 4/9] Formatting --- src/ILLink.Shared/TrimAnalysis/Intrinsics.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ILLink.Shared/TrimAnalysis/Intrinsics.cs b/src/ILLink.Shared/TrimAnalysis/Intrinsics.cs index 872f943e9fad..654e851513cd 100644 --- a/src/ILLink.Shared/TrimAnalysis/Intrinsics.cs +++ b/src/ILLink.Shared/TrimAnalysis/Intrinsics.cs @@ -371,6 +371,7 @@ public static IntrinsicId GetIntrinsicIdForMethod (MethodProxy calledMethod) && calledMethod.HasParameterOfType (0, "System.Type") && calledMethod.IsStatic () => IntrinsicId.Nullable_GetUnderlyingType, + _ => IntrinsicId.None, }; } From e69f03697eb3dcea880a12801689aa0fccf755b9 Mon Sep 17 00:00:00 2001 From: vitek-karas <10670590+vitek-karas@users.noreply.github.com> Date: Wed, 18 May 2022 04:58:01 -0700 Subject: [PATCH 5/9] Improve comments --- src/ILLink.Shared/TrimAnalysis/HandleCallAction.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ILLink.Shared/TrimAnalysis/HandleCallAction.cs b/src/ILLink.Shared/TrimAnalysis/HandleCallAction.cs index 34e55100459a..b9ad6f85f4d4 100644 --- a/src/ILLink.Shared/TrimAnalysis/HandleCallAction.cs +++ b/src/ILLink.Shared/TrimAnalysis/HandleCallAction.cs @@ -1164,6 +1164,10 @@ GenericParameterValue genericParam // Disable warnings for all unimplemented intrinsics. Some intrinsic methods have annotations, but analyzing them // would produce unnecessary warnings even for cases that are intrinsically handled. So we disable handling these calls // until a proper intrinsic handling is made + // NOTE: Currently this is done "for the analyzer" and it relies on linker/NativeAOT to not call HandleCallAction + // for intrinsics which linker/NativeAOT need special handling for or those which are not implemented here and only there. + // Ideally we would run everything through HandleCallAction and it would return "false" for intrinsics it doesn't handle + // like it already does for Activator.CreateInstance for example. default: methodReturnValue = MultiValueLattice.Top; return true; From 52cdc203848d66e7e8012e03bafdd0adb9c80886 Mon Sep 17 00:00:00 2001 From: vitek-karas <10670590+vitek-karas@users.noreply.github.com> Date: Mon, 23 May 2022 05:42:45 -0700 Subject: [PATCH 6/9] Make constants public as required by AOT --- src/ILLink.Shared/MessageSubCategory.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ILLink.Shared/MessageSubCategory.cs b/src/ILLink.Shared/MessageSubCategory.cs index b571f3c95ee0..4b47d2666811 100644 --- a/src/ILLink.Shared/MessageSubCategory.cs +++ b/src/ILLink.Shared/MessageSubCategory.cs @@ -6,7 +6,7 @@ namespace ILLink.Shared { - internal static class MessageSubCategory + public static class MessageSubCategory { public const string None = ""; public const string TrimAnalysis = "Trim analysis"; From a9ecd590061e9bbe6678cad0a56ca44f41b20c70 Mon Sep 17 00:00:00 2001 From: vitek-karas <10670590+vitek-karas@users.noreply.github.com> Date: Thu, 2 Jun 2022 09:27:09 -0700 Subject: [PATCH 7/9] Add tes for RUC on type and attribute induced warnings --- .../RequiresCapability/RequiresOnClass.cs | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresOnClass.cs b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresOnClass.cs index c5979bc34135..8b8b1defe830 100644 --- a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresOnClass.cs +++ b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresOnClass.cs @@ -36,6 +36,7 @@ public static void Main () ReflectionAccessOnEvents.Test (); ReflectionAccessOnProperties.Test (); KeepFieldOnAttribute (); + AttributeParametersAndProperties.Test (); } [RequiresUnreferencedCode ("Message for --ClassWithRequires--")] @@ -83,6 +84,10 @@ public static void TestSuppressions (Type[] types) void LocalFunction (int a) { } LocalFunction (2); } + + // The attribute would generate warning, but it is suppressed due to the Requires on the type + [AttributeWithRequires()] + public static void AttributedMethod () { } } class RequiresOnMethod @@ -901,5 +906,51 @@ public int PropertyOnAttribute { [ExpectedWarning ("IL2026", "AttributeWithRequires.AttributeWithRequires()")] [ExpectedWarning ("IL3050", "AttributeWithRequires.AttributeWithRequires()", ProducedBy = ProducedBy.Analyzer)] static void KeepFieldOnAttribute () { } + + public class AttributeParametersAndProperties + { + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] + public static Type AnnotatedField; + + [AttributeUsage (AttributeTargets.Method, AllowMultiple = true)] + public class AttributeWithRequirementsOnParameters : Attribute + { + public AttributeWithRequirementsOnParameters () + { + } + + public AttributeWithRequirementsOnParameters ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] Type type) + { + } + + public int PropertyWithRequires { + get => 0; + + [RequiresUnreferencedCode ("--PropertyWithRequires--")] + [RequiresDynamicCode ("--PropertyWithRequires--")] + set { } + } + + [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] + public Type AnnotatedField; + } + + [RequiresUnreferencedCode ("--AttributeParametersAndProperties--")] + [RequiresDynamicCode ("--AttributeParametersAndProperties--")] + class TestClass + { + [AttributeWithRequirementsOnParameters (typeof (AttributeParametersAndProperties))] + [AttributeWithRequirementsOnParameters (PropertyWithRequires = 1)] + [AttributeWithRequirementsOnParameters (AnnotatedField = typeof (AttributeParametersAndProperties))] + public static void Test () { } + } + + [ExpectedWarning ("IL2026")] + [ExpectedWarning ("IL3050", ProducedBy = ProducedBy.Analyzer)] + public static void Test () + { + TestClass.Test (); + } + } } } From 6fc42f5516d735c821bc6d647d924b20ccf613d5 Mon Sep 17 00:00:00 2001 From: vitek-karas <10670590+vitek-karas@users.noreply.github.com> Date: Thu, 2 Jun 2022 09:33:17 -0700 Subject: [PATCH 8/9] Formatting --- .../RequiresCapability/RequiresOnClass.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresOnClass.cs b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresOnClass.cs index 8b8b1defe830..9cb6e8a5030b 100644 --- a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresOnClass.cs +++ b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresOnClass.cs @@ -86,7 +86,7 @@ void LocalFunction (int a) { } } // The attribute would generate warning, but it is suppressed due to the Requires on the type - [AttributeWithRequires()] + [AttributeWithRequires ()] public static void AttributedMethod () { } } @@ -909,7 +909,7 @@ static void KeepFieldOnAttribute () { } public class AttributeParametersAndProperties { - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] + [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicProperties)] public static Type AnnotatedField; [AttributeUsage (AttributeTargets.Method, AllowMultiple = true)] From 21cbdc5f916a18b7e26a4208392fa22f47789d95 Mon Sep 17 00:00:00 2001 From: vitek-karas <10670590+vitek-karas@users.noreply.github.com> Date: Fri, 3 Jun 2022 03:57:34 -0700 Subject: [PATCH 9/9] Fix a bug --- .../Linker.Dataflow/ReflectionMethodBodyScanner.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/linker/Linker.Dataflow/ReflectionMethodBodyScanner.cs b/src/linker/Linker.Dataflow/ReflectionMethodBodyScanner.cs index 052b0d69d8bf..8ab26982c9d1 100644 --- a/src/linker/Linker.Dataflow/ReflectionMethodBodyScanner.cs +++ b/src/linker/Linker.Dataflow/ReflectionMethodBodyScanner.cs @@ -275,6 +275,15 @@ public static bool HandleCall ( } break; + case IntrinsicId.Enum_GetValues: + case IntrinsicId.Marshal_SizeOf: + case IntrinsicId.Marshal_OffsetOf: + case IntrinsicId.Marshal_PtrToStructure: + case IntrinsicId.Marshal_DestroyStructure: + case IntrinsicId.Marshal_GetDelegateForFunctionPointer: + // These intrinsics are not interesting for trimmer (they are interesting for AOT and that's why they are recognized) + break; + // // System.Object //