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
diff options
context:
space:
mode:
authorVitek Karas <10670590+vitek-karas@users.noreply.github.com>2022-11-09 12:25:45 +0300
committerGitHub <noreply@github.com>2022-11-09 12:25:45 +0300
commitc196ac369f234cfbf16dd7a555db8aa3e4d14449 (patch)
treedefcfc8841384488edd3c11b46fc793c970b475d
parent3fd8e281bfdbdb35ab3d3aa301b9439dd8c0d4c4 (diff)
Sync shared code changes from NativeAOT (#3101)
Syncing back updates to the shared code from NativeAOT. Mostly formatting - runtime has enabled an analyzer which requires all members to have visibility assigned explicitly. Some cleanup.
-rw-r--r--src/ILLink.RoslynAnalyzer/TrimAnalysis/FlowAnnotations.cs2
-rw-r--r--src/ILLink.Shared/Annotations.cs4
-rw-r--r--src/ILLink.Shared/ClosedAttribute.cs2
-rw-r--r--src/ILLink.Shared/DataFlow/DefaultValueDictionary.cs9
-rw-r--r--src/ILLink.Shared/DataFlow/ForwardDataFlowAnalysis.cs15
-rw-r--r--src/ILLink.Shared/DataFlow/MaybeLattice.cs2
-rw-r--r--src/ILLink.Shared/DataFlow/ValueSet.cs16
-rw-r--r--src/ILLink.Shared/DiagnosticString.cs4
-rw-r--r--src/ILLink.Shared/HashUtils.cs2
-rw-r--r--src/ILLink.Shared/ILLink.Shared.projitems2
-rw-r--r--src/ILLink.Shared/ILLink.Shared.shproj4
-rw-r--r--src/ILLink.Shared/IsExternalInit.cs2
-rw-r--r--src/ILLink.Shared/ParameterIndex.cs11
-rw-r--r--src/ILLink.Shared/TrimAnalysis/ArrayValue.cs4
-rw-r--r--src/ILLink.Shared/TrimAnalysis/ConstIntValue.cs2
-rw-r--r--src/ILLink.Shared/TrimAnalysis/DiagnosticContext.cs2
-rw-r--r--src/ILLink.Shared/TrimAnalysis/FieldValue.cs2
-rw-r--r--src/ILLink.Shared/TrimAnalysis/FlowAnnotations.cs4
-rw-r--r--src/ILLink.Shared/TrimAnalysis/GenericParameterValue.cs2
-rw-r--r--src/ILLink.Shared/TrimAnalysis/HandleCallAction.cs20
-rw-r--r--src/ILLink.Shared/TrimAnalysis/IntrinsicId.cs22
-rw-r--r--src/ILLink.Shared/TrimAnalysis/Intrinsics.cs2
-rw-r--r--src/ILLink.Shared/TrimAnalysis/KnownStringValue.cs2
-rw-r--r--src/ILLink.Shared/TrimAnalysis/MethodParameterValue.cs4
-rw-r--r--src/ILLink.Shared/TrimAnalysis/MethodReturnValue.cs2
-rw-r--r--src/ILLink.Shared/TrimAnalysis/NullValue.cs2
-rw-r--r--src/ILLink.Shared/TrimAnalysis/NullableSystemTypeValue.cs2
-rw-r--r--src/ILLink.Shared/TrimAnalysis/NullableValueWithDynamicallyAccessedMembers.cs4
-rw-r--r--src/ILLink.Shared/TrimAnalysis/ReferenceKind.cs2
-rw-r--r--src/ILLink.Shared/TrimAnalysis/RequireDynamicallyAccessedMembersAction.cs4
-rw-r--r--src/ILLink.Shared/TrimAnalysis/RuntimeMethodHandleValue.cs2
-rw-r--r--src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleForGenericParameterValue.cs2
-rw-r--r--src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleForNullableSystemTypeValue.cs2
-rw-r--r--src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleForNullableValueWithDynamicallyAccessedMembers.cs6
-rw-r--r--src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleValue.cs2
-rw-r--r--src/ILLink.Shared/TrimAnalysis/SystemReflectionMethodBaseValue.cs2
-rw-r--r--src/ILLink.Shared/TrimAnalysis/SystemTypeValue.cs2
-rw-r--r--src/ILLink.Shared/TrimAnalysis/UnknownValue.cs2
-rw-r--r--src/ILLink.Shared/TrimAnalysis/ValueExtensions.cs8
-rw-r--r--src/ILLink.Shared/TypeSystemProxy/IMemberProxy.cs2
-rw-r--r--src/ILLink.Shared/TypeSystemProxy/ParameterCollection.cs20
-rw-r--r--src/ILLink.Shared/TypeSystemProxy/ParameterProxy.cs5
-rw-r--r--src/linker/Linker.Dataflow/DiagnosticContext.cs2
-rw-r--r--src/linker/Linker.Dataflow/FlowAnnotations.cs5
-rw-r--r--src/linker/Linker.Dataflow/HandleCallAction.cs2
-rw-r--r--src/linker/Linker.Dataflow/ParameterReferenceValue.cs2
-rw-r--r--src/linker/Linker.Dataflow/ReflectionMethodBodyScanner.cs18
-rw-r--r--src/linker/Linker.Dataflow/SingleValueExtensions.cs84
-rw-r--r--src/linker/Linker/MethodDefinitionExtensions.cs3
-rw-r--r--src/linker/Linker/MethodReferenceExtensions.cs4
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/MethodParametersDataFlow.cs2
51 files changed, 133 insertions, 201 deletions
diff --git a/src/ILLink.RoslynAnalyzer/TrimAnalysis/FlowAnnotations.cs b/src/ILLink.RoslynAnalyzer/TrimAnalysis/FlowAnnotations.cs
index 09d64065d..b918a18dc 100644
--- a/src/ILLink.RoslynAnalyzer/TrimAnalysis/FlowAnnotations.cs
+++ b/src/ILLink.RoslynAnalyzer/TrimAnalysis/FlowAnnotations.cs
@@ -35,7 +35,7 @@ namespace ILLink.Shared.TrimAnalysis
return false;
}
- public static DynamicallyAccessedMemberTypes GetMethodParameterAnnotation (ParameterProxy param)
+ internal static DynamicallyAccessedMemberTypes GetMethodParameterAnnotation (ParameterProxy param)
{
IMethodSymbol method = param.Method.Method;
if (param.IsImplicitThis)
diff --git a/src/ILLink.Shared/Annotations.cs b/src/ILLink.Shared/Annotations.cs
index cd3098d1e..e3accb135 100644
--- a/src/ILLink.Shared/Annotations.cs
+++ b/src/ILLink.Shared/Annotations.cs
@@ -79,9 +79,9 @@ namespace ILLink.Shared
}));
}
- static readonly DynamicallyAccessedMemberTypes[] AllDynamicallyAccessedMemberTypes = GetAllDynamicallyAccessedMemberTypes ();
+ private static readonly DynamicallyAccessedMemberTypes[] AllDynamicallyAccessedMemberTypes = GetAllDynamicallyAccessedMemberTypes ();
- static DynamicallyAccessedMemberTypes[] GetAllDynamicallyAccessedMemberTypes ()
+ private static DynamicallyAccessedMemberTypes[] GetAllDynamicallyAccessedMemberTypes ()
{
var values = new HashSet<DynamicallyAccessedMemberTypes> (
Enum.GetValues (typeof (DynamicallyAccessedMemberTypes))
diff --git a/src/ILLink.Shared/ClosedAttribute.cs b/src/ILLink.Shared/ClosedAttribute.cs
index 5c0260fc1..feea932ed 100644
--- a/src/ILLink.Shared/ClosedAttribute.cs
+++ b/src/ILLink.Shared/ClosedAttribute.cs
@@ -12,4 +12,4 @@ namespace StaticCs
{
public ClosedAttribute () { }
}
-} \ No newline at end of file
+}
diff --git a/src/ILLink.Shared/DataFlow/DefaultValueDictionary.cs b/src/ILLink.Shared/DataFlow/DefaultValueDictionary.cs
index 1d8221463..599e7d3b9 100644
--- a/src/ILLink.Shared/DataFlow/DefaultValueDictionary.cs
+++ b/src/ILLink.Shared/DataFlow/DefaultValueDictionary.cs
@@ -21,9 +21,8 @@ namespace ILLink.Shared.DataFlow
where TKey : IEquatable<TKey>
where TValue : IEquatable<TValue>
{
- Dictionary<TKey, TValue>? Dictionary;
-
- readonly TValue DefaultValue;
+ private Dictionary<TKey, TValue>? Dictionary;
+ private readonly TValue DefaultValue;
public DefaultValueDictionary (TValue defaultValue) => (Dictionary, DefaultValue) = (null, defaultValue);
@@ -81,13 +80,13 @@ namespace ILLink.Shared.DataFlow
public override string ToString ()
{
StringBuilder sb = new ();
- sb.Append ("{");
+ sb.Append ('{');
if (Dictionary != null) {
foreach (var kvp in Dictionary)
sb.Append (Environment.NewLine).Append ('\t').Append (kvp.Key.ToString ()).Append (" -> ").Append (kvp.Value.ToString ());
}
sb.Append (Environment.NewLine).Append ("\t_ -> ").Append (DefaultValue.ToString ());
- sb.Append (Environment.NewLine).Append ("}");
+ sb.Append (Environment.NewLine).Append ('}');
return sb.ToString ();
}
diff --git a/src/ILLink.Shared/DataFlow/ForwardDataFlowAnalysis.cs b/src/ILLink.Shared/DataFlow/ForwardDataFlowAnalysis.cs
index 345fbe868..cd65c55f4 100644
--- a/src/ILLink.Shared/DataFlow/ForwardDataFlowAnalysis.cs
+++ b/src/ILLink.Shared/DataFlow/ForwardDataFlowAnalysis.cs
@@ -25,10 +25,10 @@ namespace ILLink.Shared.DataFlow
// Data structure to store dataflow states for every basic block in the control flow graph,
// keeping the exception states shared across different basic blocks owned by the same try or catch region.
- struct ControlFlowGraphState
+ private struct ControlFlowGraphState
{
// Dataflow states for each basic block
- readonly Dictionary<TBlock, TState> blockOutput;
+ private readonly Dictionary<TBlock, TState> blockOutput;
// The control flow graph doesn't contain edges for exceptional control flow:
// - From any point in a try region to the start of any catch or finally
@@ -38,7 +38,7 @@ namespace ILLink.Shared.DataFlow
// when visiting operations inside of a try or catch region.
// Dataflow states for exceptions propagating out of try or catch regions
- readonly Dictionary<TRegion, Box<TValue>> exceptionState;
+ private readonly Dictionary<TRegion, Box<TValue>> exceptionState;
// Control may flow through a finally region when an exception is thrown from anywhere in the corresponding
// try or catch regions, or as part of non-exceptional control flow out of a try or catch.
@@ -46,15 +46,14 @@ namespace ILLink.Shared.DataFlow
// propagated out of the finally.
// Dataflow states for finally blocks when exception propagate through the finally region
- readonly Dictionary<TBlock, TValue> exceptionFinallyState;
+ private readonly Dictionary<TBlock, TValue> exceptionFinallyState;
// Finally regions may be reached (along non-exceptional paths)
// from multiple branches. This gets updated to track the normal finally input
// states from all of these branches (which aren't represented explicitly in the CFG).
- readonly Dictionary<TRegion, TValue> finallyInputState;
-
- readonly TControlFlowGraph cfg;
- readonly TLattice lattice;
+ private readonly Dictionary<TRegion, TValue> finallyInputState;
+ private readonly TControlFlowGraph cfg;
+ private readonly TLattice lattice;
public ControlFlowGraphState (TControlFlowGraph cfg, TLattice lattice)
{
diff --git a/src/ILLink.Shared/DataFlow/MaybeLattice.cs b/src/ILLink.Shared/DataFlow/MaybeLattice.cs
index f2b43d9de..4e77f9634 100644
--- a/src/ILLink.Shared/DataFlow/MaybeLattice.cs
+++ b/src/ILLink.Shared/DataFlow/MaybeLattice.cs
@@ -48,4 +48,4 @@ namespace ILLink.Shared.DataFlow
return new Maybe<T> (ValueLattice.Meet (leftValue, rightValue));
}
}
-} \ No newline at end of file
+}
diff --git a/src/ILLink.Shared/DataFlow/ValueSet.cs b/src/ILLink.Shared/DataFlow/ValueSet.cs
index 120e9116e..c47397d5a 100644
--- a/src/ILLink.Shared/DataFlow/ValueSet.cs
+++ b/src/ILLink.Shared/DataFlow/ValueSet.cs
@@ -17,7 +17,7 @@ namespace ILLink.Shared.DataFlow
{
// Since we're going to do lot of type checks for this class a lot, it is much more efficient
// if the class is sealed (as then the runtime can do a simple method table pointer comparison)
- sealed class EnumerableValues : HashSet<TValue>
+ private sealed class EnumerableValues : HashSet<TValue>
{
public EnumerableValues (IEnumerable<TValue> values) : base (values) { }
@@ -32,9 +32,9 @@ namespace ILLink.Shared.DataFlow
public struct Enumerator : IEnumerator<TValue>, IDisposable, IEnumerator
{
- readonly object? _value;
- int _state; // 0 before begining, 1 at item, 2 after end
- readonly IEnumerator<TValue>? _enumerator;
+ private readonly object? _value;
+ private int _state; // 0 before begining, 1 at item, 2 after end
+ private readonly IEnumerator<TValue>? _enumerator;
internal Enumerator (object? values)
{
@@ -87,13 +87,13 @@ namespace ILLink.Shared.DataFlow
// null - no values (empty set)
// TValue - single value itself
// EnumerableValues typed object - multiple values, stored in the hashset
- readonly object? _values;
+ private readonly object? _values;
public ValueSet (TValue value) => _values = value;
public ValueSet (IEnumerable<TValue> values) => _values = new EnumerableValues (values);
- ValueSet (EnumerableValues values) => _values = values;
+ private ValueSet (EnumerableValues values) => _values = values;
public static implicit operator ValueSet<TValue> (TValue value) => new (value);
@@ -166,9 +166,9 @@ namespace ILLink.Shared.DataFlow
public override string ToString ()
{
StringBuilder sb = new ();
- sb.Append ("{");
+ sb.Append ('{');
sb.Append (string.Join (",", this.Select (v => v.ToString ())));
- sb.Append ("}");
+ sb.Append ('}');
return sb.ToString ();
}
diff --git a/src/ILLink.Shared/DiagnosticString.cs b/src/ILLink.Shared/DiagnosticString.cs
index 0102ae90c..ce505e1c7 100644
--- a/src/ILLink.Shared/DiagnosticString.cs
+++ b/src/ILLink.Shared/DiagnosticString.cs
@@ -10,8 +10,8 @@ namespace ILLink.Shared
{
public readonly struct DiagnosticString
{
- readonly string _titleFormat;
- readonly string _messageFormat;
+ private readonly string _titleFormat;
+ private readonly string _messageFormat;
public DiagnosticString (DiagnosticId diagnosticId)
{
diff --git a/src/ILLink.Shared/HashUtils.cs b/src/ILLink.Shared/HashUtils.cs
index cc9b259be..9a265ed2f 100644
--- a/src/ILLink.Shared/HashUtils.cs
+++ b/src/ILLink.Shared/HashUtils.cs
@@ -10,7 +10,7 @@ using System;
namespace ILLink.Shared
{
- static class HashUtils
+ internal static class HashUtils
{
#if NETSTANDARD2_0
// This constant is taken from code that Roslyn generates for GetHashCode of records.
diff --git a/src/ILLink.Shared/ILLink.Shared.projitems b/src/ILLink.Shared/ILLink.Shared.projitems
index 66dd85465..8b16e3778 100644
--- a/src/ILLink.Shared/ILLink.Shared.projitems
+++ b/src/ILLink.Shared/ILLink.Shared.projitems
@@ -23,4 +23,4 @@
<SubType>Designer</SubType>
</None>
</ItemGroup>
-</Project> \ No newline at end of file
+</Project>
diff --git a/src/ILLink.Shared/ILLink.Shared.shproj b/src/ILLink.Shared/ILLink.Shared.shproj
index 9a792098e..a581f2f0b 100644
--- a/src/ILLink.Shared/ILLink.Shared.shproj
+++ b/src/ILLink.Shared/ILLink.Shared.shproj
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
- <ProjectGuid>92f5e753-2179-46dc-bdce-736858c18dc7</ProjectGuid>
+ <ProjectGuid>{FF598E93-8E9E-4091-9F50-61A7572663AE}</ProjectGuid>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
@@ -10,4 +10,4 @@
<PropertyGroup />
<Import Project="ILLink.Shared.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
-</Project>
+</Project> \ No newline at end of file
diff --git a/src/ILLink.Shared/IsExternalInit.cs b/src/ILLink.Shared/IsExternalInit.cs
index f2b081a03..c95d5f7b1 100644
--- a/src/ILLink.Shared/IsExternalInit.cs
+++ b/src/ILLink.Shared/IsExternalInit.cs
@@ -12,4 +12,4 @@ namespace System.Runtime.CompilerServices
{
}
}
-#endif \ No newline at end of file
+#endif
diff --git a/src/ILLink.Shared/ParameterIndex.cs b/src/ILLink.Shared/ParameterIndex.cs
index 84113a820..7a6ea6808 100644
--- a/src/ILLink.Shared/ParameterIndex.cs
+++ b/src/ILLink.Shared/ParameterIndex.cs
@@ -3,12 +3,14 @@
using System.Diagnostics.CodeAnalysis;
+#nullable enable
+
namespace ILLink.Shared.TypeSystemProxy
{
/// <summary>
/// Used to indicate the index of the parameter in the Parameters metadata section (i.e. the first parameter that is not the implicit 'this' is 0)
/// It is very error prone to use an int to represent the index in parameters metadata section / source code parameter index as well as for indexing into argument lists.
- /// Instead, use this struct whenever representing an index of a parameter.
+ /// Instead, use this struct whenever representing an index of a parameter.
/// </summary>
/// <example>
/// In a call to a non-static function Foo(int a, int b, int c)
@@ -25,7 +27,7 @@ namespace ILLink.Shared.TypeSystemProxy
/// 1 refers to b,
/// 2 refers to c.
/// </example>
- public struct ParameterIndex
+ public readonly struct ParameterIndex : System.IEquatable<ParameterIndex>
{
public readonly int Index;
@@ -39,7 +41,10 @@ namespace ILLink.Shared.TypeSystemProxy
public static ParameterIndex operator ++ (ParameterIndex val) => new ParameterIndex (val.Index + 1);
public override bool Equals ([NotNullWhen (true)] object? obj)
- => obj is ParameterIndex other && this == other;
+ => obj is ParameterIndex other && Index == other.Index;
+
+ public bool Equals (ParameterIndex other)
+ => Index == other.Index;
public override int GetHashCode () => Index.GetHashCode ();
diff --git a/src/ILLink.Shared/TrimAnalysis/ArrayValue.cs b/src/ILLink.Shared/TrimAnalysis/ArrayValue.cs
index d8c399878..342e3a5c5 100644
--- a/src/ILLink.Shared/TrimAnalysis/ArrayValue.cs
+++ b/src/ILLink.Shared/TrimAnalysis/ArrayValue.cs
@@ -9,9 +9,9 @@ using MultiValue = ILLink.Shared.DataFlow.ValueSet<ILLink.Shared.DataFlow.Single
namespace ILLink.Shared.TrimAnalysis
{
- sealed partial record ArrayValue : SingleValue
+ internal sealed partial record ArrayValue : SingleValue
{
- static ValueSetLattice<SingleValue> MultiValueLattice => default;
+ private static ValueSetLattice<SingleValue> MultiValueLattice => default;
public readonly SingleValue Size;
diff --git a/src/ILLink.Shared/TrimAnalysis/ConstIntValue.cs b/src/ILLink.Shared/TrimAnalysis/ConstIntValue.cs
index e83a7cd5d..b8816567f 100644
--- a/src/ILLink.Shared/TrimAnalysis/ConstIntValue.cs
+++ b/src/ILLink.Shared/TrimAnalysis/ConstIntValue.cs
@@ -11,7 +11,7 @@ namespace ILLink.Shared.TrimAnalysis
/// <summary>
/// Represents a ldc on an int32.
/// </summary>
- sealed record ConstIntValue : SingleValue
+ internal sealed record ConstIntValue : SingleValue
{
public ConstIntValue (int value) => Value = value;
diff --git a/src/ILLink.Shared/TrimAnalysis/DiagnosticContext.cs b/src/ILLink.Shared/TrimAnalysis/DiagnosticContext.cs
index ad380383c..bfb7ab5c0 100644
--- a/src/ILLink.Shared/TrimAnalysis/DiagnosticContext.cs
+++ b/src/ILLink.Shared/TrimAnalysis/DiagnosticContext.cs
@@ -15,7 +15,7 @@ namespace ILLink.Shared.TrimAnalysis
/// - Single-file warnings (suppressed by RequiresAssemblyFilesAttribute)
/// Note that not all categories are used/supported by all tools, for example the ILLink only handles trimmer warnings and ignores the rest.
/// </summary>
- readonly partial struct DiagnosticContext
+ public readonly partial struct DiagnosticContext
{
/// <param name="id">The diagnostic ID, this will be used to determine the category of diagnostic (trimmer, AOT, single-file)</param>
/// <param name="args">The arguments for diagnostic message.</param>
diff --git a/src/ILLink.Shared/TrimAnalysis/FieldValue.cs b/src/ILLink.Shared/TrimAnalysis/FieldValue.cs
index 0041e4363..2c2354723 100644
--- a/src/ILLink.Shared/TrimAnalysis/FieldValue.cs
+++ b/src/ILLink.Shared/TrimAnalysis/FieldValue.cs
@@ -6,5 +6,5 @@
namespace ILLink.Shared.TrimAnalysis
{
- sealed partial record FieldValue : ValueWithDynamicallyAccessedMembers;
+ internal sealed partial record FieldValue : ValueWithDynamicallyAccessedMembers;
}
diff --git a/src/ILLink.Shared/TrimAnalysis/FlowAnnotations.cs b/src/ILLink.Shared/TrimAnalysis/FlowAnnotations.cs
index 2a9f4d008..52006fe2f 100644
--- a/src/ILLink.Shared/TrimAnalysis/FlowAnnotations.cs
+++ b/src/ILLink.Shared/TrimAnalysis/FlowAnnotations.cs
@@ -10,7 +10,7 @@ using ILLink.Shared.TypeSystemProxy;
namespace ILLink.Shared.TrimAnalysis
{
// Shared helpers to go from MethodProxy to dataflow values.
- partial class FlowAnnotations
+ public partial class FlowAnnotations
{
internal partial bool MethodRequiresDataFlowAnalysis (MethodProxy method);
@@ -28,4 +28,4 @@ namespace ILLink.Shared.TrimAnalysis
internal partial MethodParameterValue GetMethodParameterValue (ParameterProxy param);
}
-} \ No newline at end of file
+}
diff --git a/src/ILLink.Shared/TrimAnalysis/GenericParameterValue.cs b/src/ILLink.Shared/TrimAnalysis/GenericParameterValue.cs
index 18bfa5fbb..155ab10dc 100644
--- a/src/ILLink.Shared/TrimAnalysis/GenericParameterValue.cs
+++ b/src/ILLink.Shared/TrimAnalysis/GenericParameterValue.cs
@@ -12,7 +12,7 @@ namespace ILLink.Shared.TrimAnalysis
/// This is a System.Type value which represents generic parameter (basically result of typeof(T))
/// Its actual type is unknown, but it can have annotations.
/// </summary>
- sealed partial record GenericParameterValue : ValueWithDynamicallyAccessedMembers
+ internal sealed partial record GenericParameterValue : ValueWithDynamicallyAccessedMembers
{
public readonly GenericParameterProxy GenericParameter;
}
diff --git a/src/ILLink.Shared/TrimAnalysis/HandleCallAction.cs b/src/ILLink.Shared/TrimAnalysis/HandleCallAction.cs
index 9f0ddbf45..d4d9f8972 100644
--- a/src/ILLink.Shared/TrimAnalysis/HandleCallAction.cs
+++ b/src/ILLink.Shared/TrimAnalysis/HandleCallAction.cs
@@ -19,13 +19,13 @@ using MultiValue = ILLink.Shared.DataFlow.ValueSet<ILLink.Shared.DataFlow.Single
namespace ILLink.Shared.TrimAnalysis
{
[StructLayout (LayoutKind.Auto)] // A good way to avoid CS0282, we don't really care about field order
- partial struct HandleCallAction
+ internal partial struct HandleCallAction
{
- static ValueSetLattice<SingleValue> MultiValueLattice => default;
+ private static ValueSetLattice<SingleValue> MultiValueLattice => default;
- readonly DiagnosticContext _diagnosticContext;
- readonly FlowAnnotations _annotations;
- readonly RequireDynamicallyAccessedMembersAction _requireDynamicallyAccessedMembersAction;
+ private readonly DiagnosticContext _diagnosticContext;
+ private readonly FlowAnnotations _annotations;
+ private readonly RequireDynamicallyAccessedMembersAction _requireDynamicallyAccessedMembersAction;
public bool Invoke (MethodProxy calledMethod, MultiValue instanceValue, IReadOnlyList<MultiValue> argumentValues, IntrinsicId intrinsicId, out MultiValue methodReturnValue)
{
@@ -1197,7 +1197,7 @@ namespace ILLink.Shared.TrimAnalysis
}
}
- IEnumerable<MultiValue> ProcessGetMethodByName (TypeProxy type, string methodName, BindingFlags? bindingFlags)
+ private IEnumerable<MultiValue> ProcessGetMethodByName (TypeProxy type, string methodName, BindingFlags? bindingFlags)
{
bool foundAny = false;
foreach (var method in GetMethodsOnTypeHierarchy (type, methodName, bindingFlags)) {
@@ -1214,7 +1214,7 @@ namespace ILLink.Shared.TrimAnalysis
yield return NullValue.Instance;
}
- bool AnalyzeGenericInstantiationTypeArray (in MultiValue arrayParam, in MethodProxy calledMethod, ImmutableArray<GenericParameterValue> genericParameters)
+ private bool AnalyzeGenericInstantiationTypeArray (in MultiValue arrayParam, in MethodProxy calledMethod, ImmutableArray<GenericParameterValue> genericParameters)
{
bool hasRequirements = false;
foreach (var genericParameter in genericParameters) {
@@ -1277,7 +1277,7 @@ namespace ILLink.Shared.TrimAnalysis
}
}
- void ValidateGenericMethodInstantiation (
+ private void ValidateGenericMethodInstantiation (
MethodProxy genericMethod,
in MultiValue genericParametersArray,
MethodProxy reflectionMethod)
@@ -1292,7 +1292,7 @@ namespace ILLink.Shared.TrimAnalysis
}
}
- ImmutableArray<GenericParameterValue> GetGenericParameterValues (ImmutableArray<GenericParameterProxy> genericParameters)
+ private ImmutableArray<GenericParameterValue> GetGenericParameterValues (ImmutableArray<GenericParameterProxy> genericParameters)
{
if (genericParameters.IsEmpty)
return ImmutableArray<GenericParameterValue>.Empty;
@@ -1304,7 +1304,7 @@ namespace ILLink.Shared.TrimAnalysis
return builder.ToImmutableArray ();
}
- void ProcessCreateInstanceByName (MethodProxy calledMethod, IReadOnlyList<MultiValue> argumentValues)
+ private void ProcessCreateInstanceByName (MethodProxy calledMethod, IReadOnlyList<MultiValue> argumentValues)
{
BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public;
bool parameterlessConstructor = true;
diff --git a/src/ILLink.Shared/TrimAnalysis/IntrinsicId.cs b/src/ILLink.Shared/TrimAnalysis/IntrinsicId.cs
index 47caff119..700ed6a39 100644
--- a/src/ILLink.Shared/TrimAnalysis/IntrinsicId.cs
+++ b/src/ILLink.Shared/TrimAnalysis/IntrinsicId.cs
@@ -7,7 +7,7 @@
namespace ILLink.Shared.TrimAnalysis
{
[StaticCs.Closed]
- enum IntrinsicId
+ internal enum IntrinsicId
{
None = 0,
/// <summary>
@@ -128,8 +128,8 @@ namespace ILLink.Shared.TrimAnalysis
Type_GetProperties__BindingFlags,
/// <summary>
/// <list type="table">
- /// <item><see cref="System.Type.GetEvent(string)"/></item>
- /// <item><see cref="System.Type.GetEvent(string, System.Reflection.BindingFlags)"/></item>
+ /// <item><see cref="System.Type.GetEvent(string)"/></item>
+ /// <item><see cref="System.Type.GetEvent(string, System.Reflection.BindingFlags)"/></item>
/// </list>
/// </summary>
Type_GetEvent,
@@ -139,9 +139,9 @@ namespace ILLink.Shared.TrimAnalysis
Type_GetEvents__BindingFlags,
/// <summary>
/// <list type="table">
- /// <item><see cref="System.Type.GetNestedType(string)"/></item>
- /// <item><see cref="System.Type.GetNestedType(string, System.Reflection.BindingFlags)"/></item>
- /// </list>
+ /// <item><see cref="System.Type.GetNestedType(string)"/></item>
+ /// <item><see cref="System.Type.GetNestedType(string, System.Reflection.BindingFlags)"/></item>
+ /// </list>
/// </summary>
Type_GetNestedType,
/// <summary>
@@ -150,10 +150,10 @@ namespace ILLink.Shared.TrimAnalysis
Type_GetNestedTypes__BindingFlags,
/// <summary>
/// <list type="table">
- /// <item><see cref="System.Type.GetMember(string)"/></item>
- /// <item><see cref="System.Type.GetMember(string, System.Reflection.BindingFlags)"/></item>
- /// <item><see cref="System.Type.GetMember(string, System.Reflection.MemberTypes, System.Reflection.BindingFlags)"/></item>
- /// </list>
+ /// <item><see cref="System.Type.GetMember(string)"/></item>
+ /// <item><see cref="System.Type.GetMember(string, System.Reflection.BindingFlags)"/></item>
+ /// <item><see cref="System.Type.GetMember(string, System.Reflection.MemberTypes, System.Reflection.BindingFlags)"/></item>
+ /// </list>
/// </summary>
Type_GetMember,
/// <summary>
@@ -180,7 +180,7 @@ namespace ILLink.Shared.TrimAnalysis
/// </summary>
Type_get_BaseType,
/// <summary>
- /// <see cref="System.Linq.Expressions.Expression.Call(System.Type, string, System.Type[]?, System.Linq.Expressions.Expression[]?))"/>
+ /// <see cref="System.Linq.Expressions.Expression.Call(System.Type, string, System.Type[]?, System.Linq.Expressions.Expression[]?))"/>
/// </summary>
Expression_Call,
/// <summary>
diff --git a/src/ILLink.Shared/TrimAnalysis/Intrinsics.cs b/src/ILLink.Shared/TrimAnalysis/Intrinsics.cs
index 031aa025e..fa71f7472 100644
--- a/src/ILLink.Shared/TrimAnalysis/Intrinsics.cs
+++ b/src/ILLink.Shared/TrimAnalysis/Intrinsics.cs
@@ -8,7 +8,7 @@ using ILLink.Shared.TypeSystemProxy;
namespace ILLink.Shared.TrimAnalysis
{
- static class Intrinsics
+ internal static class Intrinsics
{
public static IntrinsicId GetIntrinsicIdForMethod (MethodProxy calledMethod)
{
diff --git a/src/ILLink.Shared/TrimAnalysis/KnownStringValue.cs b/src/ILLink.Shared/TrimAnalysis/KnownStringValue.cs
index bbdedf5bf..b1cee312b 100644
--- a/src/ILLink.Shared/TrimAnalysis/KnownStringValue.cs
+++ b/src/ILLink.Shared/TrimAnalysis/KnownStringValue.cs
@@ -11,7 +11,7 @@ namespace ILLink.Shared.TrimAnalysis
/// <summary>
/// A known string - such as the result of a ldstr.
/// </summary>
- sealed partial record KnownStringValue : SingleValue
+ internal sealed partial record KnownStringValue : SingleValue
{
public KnownStringValue (string contents) => Contents = contents;
diff --git a/src/ILLink.Shared/TrimAnalysis/MethodParameterValue.cs b/src/ILLink.Shared/TrimAnalysis/MethodParameterValue.cs
index 108420326..79361582c 100644
--- a/src/ILLink.Shared/TrimAnalysis/MethodParameterValue.cs
+++ b/src/ILLink.Shared/TrimAnalysis/MethodParameterValue.cs
@@ -11,7 +11,7 @@ using ILLink.Shared.TypeSystemProxy;
namespace ILLink.Shared.TrimAnalysis
{
- sealed partial record MethodParameterValue : ValueWithDynamicallyAccessedMembers
+ internal sealed partial record MethodParameterValue : ValueWithDynamicallyAccessedMembers
{
// _overrideIsThis is needed for backwards compatibility with MakeGenericType/Method https://github.com/dotnet/linker/issues/2428
private readonly bool _overrideIsThis;
@@ -22,7 +22,7 @@ namespace ILLink.Shared.TrimAnalysis
=> Parameter.GetDiagnosticArgumentsForAnnotationMismatch ();
public override string ToString ()
- => this.ValueToString (Parameter.Method.Method, DynamicallyAccessedMemberTypes);
+ => this.ValueToString (Parameter.Method.Method, Parameter.Index, DynamicallyAccessedMemberTypes);
public bool IsThisParameter () => _overrideIsThis || Parameter.IsImplicitThis;
diff --git a/src/ILLink.Shared/TrimAnalysis/MethodReturnValue.cs b/src/ILLink.Shared/TrimAnalysis/MethodReturnValue.cs
index 708b5f469..915234337 100644
--- a/src/ILLink.Shared/TrimAnalysis/MethodReturnValue.cs
+++ b/src/ILLink.Shared/TrimAnalysis/MethodReturnValue.cs
@@ -6,5 +6,5 @@
namespace ILLink.Shared.TrimAnalysis
{
- sealed partial record class MethodReturnValue : ValueWithDynamicallyAccessedMembers;
+ internal sealed partial record class MethodReturnValue : ValueWithDynamicallyAccessedMembers;
}
diff --git a/src/ILLink.Shared/TrimAnalysis/NullValue.cs b/src/ILLink.Shared/TrimAnalysis/NullValue.cs
index 90afd5a87..0e354bf19 100644
--- a/src/ILLink.Shared/TrimAnalysis/NullValue.cs
+++ b/src/ILLink.Shared/TrimAnalysis/NullValue.cs
@@ -8,7 +8,7 @@ using ILLink.Shared.DataFlow;
namespace ILLink.Shared.TrimAnalysis
{
- sealed record NullValue : SingleValue
+ internal sealed record NullValue : SingleValue
{
private NullValue ()
{
diff --git a/src/ILLink.Shared/TrimAnalysis/NullableSystemTypeValue.cs b/src/ILLink.Shared/TrimAnalysis/NullableSystemTypeValue.cs
index 1f54cc277..f08d97baf 100644
--- a/src/ILLink.Shared/TrimAnalysis/NullableSystemTypeValue.cs
+++ b/src/ILLink.Shared/TrimAnalysis/NullableSystemTypeValue.cs
@@ -14,7 +14,7 @@ namespace ILLink.Shared.TrimAnalysis
/// This represents a Nullable<T> where T is a known SystemTypeValue.
/// It is necessary to track the underlying type to propagate DynamicallyAccessedMembers annotations to the underlying type when applied to a Nullable.
/// </summary>
- sealed record NullableSystemTypeValue : SingleValue
+ internal sealed record NullableSystemTypeValue : SingleValue
{
public NullableSystemTypeValue (in TypeProxy nullableType, in SystemTypeValue underlyingTypeValue)
{
diff --git a/src/ILLink.Shared/TrimAnalysis/NullableValueWithDynamicallyAccessedMembers.cs b/src/ILLink.Shared/TrimAnalysis/NullableValueWithDynamicallyAccessedMembers.cs
index 4c09d6f7f..38983bd9a 100644
--- a/src/ILLink.Shared/TrimAnalysis/NullableValueWithDynamicallyAccessedMembers.cs
+++ b/src/ILLink.Shared/TrimAnalysis/NullableValueWithDynamicallyAccessedMembers.cs
@@ -13,10 +13,10 @@ using ILLink.Shared.TypeSystemProxy;
namespace ILLink.Shared.TrimAnalysis
{
/// <summary>
- /// This represents a Nullable<T> where T is an unknown value with DynamicallyAccessedMembers annotations.
+ /// This represents a Nullable<T> where T is an unknown value with DynamicallyAccessedMembers annotations.
/// It is necessary to track the underlying type to ensure DynamicallyAccessedMembers annotations on the underlying type match the target parameters where the Nullable is used.
/// </summary>
- sealed record NullableValueWithDynamicallyAccessedMembers : ValueWithDynamicallyAccessedMembers
+ internal sealed record NullableValueWithDynamicallyAccessedMembers : ValueWithDynamicallyAccessedMembers
{
public NullableValueWithDynamicallyAccessedMembers (in TypeProxy nullableType, in ValueWithDynamicallyAccessedMembers underlyingTypeValue)
{
diff --git a/src/ILLink.Shared/TrimAnalysis/ReferenceKind.cs b/src/ILLink.Shared/TrimAnalysis/ReferenceKind.cs
index 1c46b2dbe..7355ef8f4 100644
--- a/src/ILLink.Shared/TrimAnalysis/ReferenceKind.cs
+++ b/src/ILLink.Shared/TrimAnalysis/ReferenceKind.cs
@@ -11,4 +11,4 @@ namespace ILLink.Shared.TypeSystemProxy
Out,
None
}
-} \ No newline at end of file
+}
diff --git a/src/ILLink.Shared/TrimAnalysis/RequireDynamicallyAccessedMembersAction.cs b/src/ILLink.Shared/TrimAnalysis/RequireDynamicallyAccessedMembersAction.cs
index 54a1c7ca1..aa24361bf 100644
--- a/src/ILLink.Shared/TrimAnalysis/RequireDynamicallyAccessedMembersAction.cs
+++ b/src/ILLink.Shared/TrimAnalysis/RequireDynamicallyAccessedMembersAction.cs
@@ -14,9 +14,9 @@ using MultiValue = ILLink.Shared.DataFlow.ValueSet<ILLink.Shared.DataFlow.Single
namespace ILLink.Shared.TrimAnalysis
{
[StructLayout (LayoutKind.Auto)]
- partial struct RequireDynamicallyAccessedMembersAction
+ internal partial struct RequireDynamicallyAccessedMembersAction
{
- readonly DiagnosticContext _diagnosticContext;
+ private readonly DiagnosticContext _diagnosticContext;
public void Invoke (in MultiValue value, ValueWithDynamicallyAccessedMembers targetValue)
{
diff --git a/src/ILLink.Shared/TrimAnalysis/RuntimeMethodHandleValue.cs b/src/ILLink.Shared/TrimAnalysis/RuntimeMethodHandleValue.cs
index 7ef048f22..f8e0029e0 100644
--- a/src/ILLink.Shared/TrimAnalysis/RuntimeMethodHandleValue.cs
+++ b/src/ILLink.Shared/TrimAnalysis/RuntimeMethodHandleValue.cs
@@ -12,7 +12,7 @@ namespace ILLink.Shared.TrimAnalysis
/// <summary>
/// This is the System.RuntimeMethodHandle equivalent to a <see cref="SystemReflectionMethodBaseValue"/> node.
/// </summary>
- sealed partial record RuntimeMethodHandleValue : SingleValue
+ internal sealed partial record RuntimeMethodHandleValue : SingleValue
{
public RuntimeMethodHandleValue (in MethodProxy representedMethod)
{
diff --git a/src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleForGenericParameterValue.cs b/src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleForGenericParameterValue.cs
index 1eb108e5f..c6b82ccc8 100644
--- a/src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleForGenericParameterValue.cs
+++ b/src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleForGenericParameterValue.cs
@@ -12,7 +12,7 @@ namespace ILLink.Shared.TrimAnalysis
/// <summary>
/// This is the System.RuntimeTypeHandle equivalent to a <see cref="GenericParameterValue"/> node.
/// </summary>
- sealed record RuntimeTypeHandleForGenericParameterValue : SingleValue
+ internal sealed record RuntimeTypeHandleForGenericParameterValue : SingleValue
{
public readonly GenericParameterProxy GenericParameter;
diff --git a/src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleForNullableSystemTypeValue.cs b/src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleForNullableSystemTypeValue.cs
index c92d4274b..f85536aeb 100644
--- a/src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleForNullableSystemTypeValue.cs
+++ b/src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleForNullableSystemTypeValue.cs
@@ -14,7 +14,7 @@ namespace ILLink.Shared.TrimAnalysis
/// This represents a type handle Nullable<T> where T is a known SystemTypeValue.
/// It is necessary to track the underlying type to propagate DynamicallyAccessedMembers annotations to the underlying type when applied to a Nullable.
/// </summary>
- sealed record RuntimeTypeHandleForNullableSystemTypeValue : SingleValue
+ internal sealed record RuntimeTypeHandleForNullableSystemTypeValue : SingleValue
{
public RuntimeTypeHandleForNullableSystemTypeValue (in TypeProxy nullableType, in SystemTypeValue underlyingTypeValue)
{
diff --git a/src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleForNullableValueWithDynamicallyAccessedMembers.cs b/src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleForNullableValueWithDynamicallyAccessedMembers.cs
index b4b065393..968e55fcd 100644
--- a/src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleForNullableValueWithDynamicallyAccessedMembers.cs
+++ b/src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleForNullableValueWithDynamicallyAccessedMembers.cs
@@ -11,10 +11,10 @@ using ILLink.Shared.TypeSystemProxy;
namespace ILLink.Shared.TrimAnalysis
{
/// <summary>
- /// This represents a type handle of a Nullable<T> where T is an unknown value with DynamicallyAccessedMembers annotations.
+ /// This represents a type handle of a Nullable<T> where T is an unknown value with DynamicallyAccessedMembers annotations.
/// It is necessary to track the underlying type to ensure DynamicallyAccessedMembers annotations on the underlying type match the target parameters where the Nullable is used.
/// </summary>
- sealed record RuntimeTypeHandleForNullableValueWithDynamicallyAccessedMembers : SingleValue
+ internal sealed record RuntimeTypeHandleForNullableValueWithDynamicallyAccessedMembers : SingleValue
{
public RuntimeTypeHandleForNullableValueWithDynamicallyAccessedMembers (in TypeProxy nullableType, in SingleValue underlyingTypeValue)
{
@@ -26,7 +26,7 @@ namespace ILLink.Shared.TrimAnalysis
public readonly TypeProxy NullableType;
public readonly SingleValue UnderlyingTypeValue;
- public override SingleValue DeepCopy () => this; // This value is immutable }
+ public override SingleValue DeepCopy () => this; // This value is immutable
public override string ToString () => this.ValueToString (UnderlyingTypeValue, NullableType);
}
diff --git a/src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleValue.cs b/src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleValue.cs
index c508c1f78..3e9cbccf7 100644
--- a/src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleValue.cs
+++ b/src/ILLink.Shared/TrimAnalysis/RuntimeTypeHandleValue.cs
@@ -12,7 +12,7 @@ namespace ILLink.Shared.TrimAnalysis
/// <summary>
/// This is the System.RuntimeTypeHandle equivalent to a <see cref="SystemTypeValue"/> node.
/// </summary>
- sealed record RuntimeTypeHandleValue : SingleValue
+ internal sealed record RuntimeTypeHandleValue : SingleValue
{
public RuntimeTypeHandleValue (in TypeProxy representedType)
{
diff --git a/src/ILLink.Shared/TrimAnalysis/SystemReflectionMethodBaseValue.cs b/src/ILLink.Shared/TrimAnalysis/SystemReflectionMethodBaseValue.cs
index 3ef755cb7..ac3d0ec89 100644
--- a/src/ILLink.Shared/TrimAnalysis/SystemReflectionMethodBaseValue.cs
+++ b/src/ILLink.Shared/TrimAnalysis/SystemReflectionMethodBaseValue.cs
@@ -12,7 +12,7 @@ namespace ILLink.Shared.TrimAnalysis
/// <summary>
/// This is a known System.Reflection.MethodBase value. MethodRepresented is the 'value' of the MethodBase.
/// </summary>
- sealed partial record SystemReflectionMethodBaseValue : SingleValue
+ internal sealed partial record SystemReflectionMethodBaseValue : SingleValue
{
public SystemReflectionMethodBaseValue (MethodProxy representedMethod) => RepresentedMethod = representedMethod;
diff --git a/src/ILLink.Shared/TrimAnalysis/SystemTypeValue.cs b/src/ILLink.Shared/TrimAnalysis/SystemTypeValue.cs
index 71af91c4e..796c4333c 100644
--- a/src/ILLink.Shared/TrimAnalysis/SystemTypeValue.cs
+++ b/src/ILLink.Shared/TrimAnalysis/SystemTypeValue.cs
@@ -12,7 +12,7 @@ namespace ILLink.Shared.TrimAnalysis
/// <summary>
/// This is a known System.Type value. TypeRepresented is the 'value' of the System.Type.
/// </summary>
- sealed record SystemTypeValue : SingleValue
+ internal sealed record SystemTypeValue : SingleValue
{
public SystemTypeValue (in TypeProxy representedType)
{
diff --git a/src/ILLink.Shared/TrimAnalysis/UnknownValue.cs b/src/ILLink.Shared/TrimAnalysis/UnknownValue.cs
index 7dc49dc66..863d757d4 100644
--- a/src/ILLink.Shared/TrimAnalysis/UnknownValue.cs
+++ b/src/ILLink.Shared/TrimAnalysis/UnknownValue.cs
@@ -8,7 +8,7 @@ using ILLink.Shared.DataFlow;
namespace ILLink.Shared.TrimAnalysis
{
- sealed record UnknownValue : SingleValue
+ internal sealed record UnknownValue : SingleValue
{
private UnknownValue ()
{
diff --git a/src/ILLink.Shared/TrimAnalysis/ValueExtensions.cs b/src/ILLink.Shared/TrimAnalysis/ValueExtensions.cs
index d9358f291..0e7643a8d 100644
--- a/src/ILLink.Shared/TrimAnalysis/ValueExtensions.cs
+++ b/src/ILLink.Shared/TrimAnalysis/ValueExtensions.cs
@@ -11,7 +11,7 @@ using MultiValue = ILLink.Shared.DataFlow.ValueSet<ILLink.Shared.DataFlow.Single
namespace ILLink.Shared.TrimAnalysis
{
- static partial class ValueExtensions
+ internal static partial class ValueExtensions
{
internal static string ValueToString (this SingleValue value, params object[] args)
{
@@ -20,15 +20,15 @@ namespace ILLink.Shared.TrimAnalysis
StringBuilder sb = new ();
sb.Append (value.GetType ().Name);
- sb.Append ("(");
+ sb.Append ('(');
if (args != null) {
for (int i = 0; i < args.Length; i++) {
if (i > 0)
- sb.Append (",");
+ sb.Append (',');
sb.Append (args[i] == null ? "<null>" : args[i].ToString ());
}
}
- sb.Append (")");
+ sb.Append (')');
return sb.ToString ();
}
diff --git a/src/ILLink.Shared/TypeSystemProxy/IMemberProxy.cs b/src/ILLink.Shared/TypeSystemProxy/IMemberProxy.cs
index 3e358b9a5..7f4882ee0 100644
--- a/src/ILLink.Shared/TypeSystemProxy/IMemberProxy.cs
+++ b/src/ILLink.Shared/TypeSystemProxy/IMemberProxy.cs
@@ -6,7 +6,7 @@
namespace ILLink.Shared.TypeSystemProxy
{
- interface IMemberProxy
+ internal interface IMemberProxy
{
public string Name { get; }
diff --git a/src/ILLink.Shared/TypeSystemProxy/ParameterCollection.cs b/src/ILLink.Shared/TypeSystemProxy/ParameterCollection.cs
index eaba6c5fd..a7a4310cd 100644
--- a/src/ILLink.Shared/TypeSystemProxy/ParameterCollection.cs
+++ b/src/ILLink.Shared/TypeSystemProxy/ParameterCollection.cs
@@ -5,18 +5,21 @@ using System;
using System.Collections;
using System.Collections.Generic;
+// This is needed due to NativeAOT which doesn't enable nullable globally yet
+#nullable enable
+
namespace ILLink.Shared.TypeSystemProxy
{
/// <summary>
/// Enumerable struct used to enumerator over a method's parameters without allocating or going through IEnumerable
/// </summary>
- internal struct ParameterProxyEnumerable : IEnumerable<ParameterProxy>
+ internal readonly struct ParameterProxyEnumerable : IEnumerable<ParameterProxy>
{
- readonly int _start;
+ private readonly int _start;
- readonly int _end;
+ private readonly int _end;
- readonly MethodProxy _method;
+ private readonly MethodProxy _method;
public ParameterProxyEnumerable (int start, int end, MethodProxy method)
{
@@ -33,10 +36,11 @@ namespace ILLink.Shared.TypeSystemProxy
public struct ParameterEnumerator : IEnumerator<ParameterProxy>
{
- readonly int _start;
- int _current;
- readonly int _end;
- readonly MethodProxy _method;
+ private readonly int _start;
+ private int _current;
+ private readonly int _end;
+ private readonly MethodProxy _method;
+
public ParameterEnumerator (int start, int end, MethodProxy method)
{
_start = start;
diff --git a/src/ILLink.Shared/TypeSystemProxy/ParameterProxy.cs b/src/ILLink.Shared/TypeSystemProxy/ParameterProxy.cs
index c31c5f383..16d3ccd08 100644
--- a/src/ILLink.Shared/TypeSystemProxy/ParameterProxy.cs
+++ b/src/ILLink.Shared/TypeSystemProxy/ParameterProxy.cs
@@ -4,9 +4,12 @@
using System;
using System.Collections.Generic;
+// This is needed due to NativeAOT which doesn't enable nullable globally yet
+#nullable enable
+
namespace ILLink.Shared.TypeSystemProxy
{
- internal partial struct ParameterProxy
+ internal readonly partial struct ParameterProxy
{
public ParameterProxy (MethodProxy method, ParameterIndex index)
{
diff --git a/src/linker/Linker.Dataflow/DiagnosticContext.cs b/src/linker/Linker.Dataflow/DiagnosticContext.cs
index 5e0f18a45..51997c92b 100644
--- a/src/linker/Linker.Dataflow/DiagnosticContext.cs
+++ b/src/linker/Linker.Dataflow/DiagnosticContext.cs
@@ -20,7 +20,7 @@ namespace ILLink.Shared.TrimAnalysis
_context.LogWarning (Origin, id, args);
}
-#pragma warning disable IDE0060, CA1822
+#pragma warning disable IDE0060, CA1822 // The details provided here are not used by illink, but they are used for example by the analyzer
public partial void AddDiagnostic (DiagnosticId id, ValueWithDynamicallyAccessedMembers actualValue, ValueWithDynamicallyAccessedMembers expectedAnnotationsValue, params string[] args)
{
AddDiagnostic (id, args);
diff --git a/src/linker/Linker.Dataflow/FlowAnnotations.cs b/src/linker/Linker.Dataflow/FlowAnnotations.cs
index 45d1bc073..777a03dad 100644
--- a/src/linker/Linker.Dataflow/FlowAnnotations.cs
+++ b/src/linker/Linker.Dataflow/FlowAnnotations.cs
@@ -40,7 +40,7 @@ namespace ILLink.Shared.TrimAnalysis
public bool RequiresGenericArgumentDataFlowAnalysis (GenericParameter genericParameter) =>
GetGenericParameterAnnotation (genericParameter) != DynamicallyAccessedMemberTypes.None;
- public DynamicallyAccessedMemberTypes GetParameterAnnotation (ParameterProxy param)
+ internal DynamicallyAccessedMemberTypes GetParameterAnnotation (ParameterProxy param)
{
if (GetAnnotations (param.Method.Method.DeclaringType).TryGetAnnotation (param.Method.Method, out var annotation) &&
annotation.ParameterAnnotations != null)
@@ -227,8 +227,6 @@ namespace ILLink.Shared.TrimAnalysis
_context.LogWarning (method, DiagnosticId.DynamicallyAccessedMembersIsNotAllowedOnMethods);
}
- // We convert indices from metadata space to IL space here.
- // IL space assigns index 0 to the `this` parameter on instance methods.
foreach (var param in method.GetParameters ()) {
DynamicallyAccessedMemberTypes pa = GetMemberTypesForDynamicallyAccessedMembersAttribute (method, param.GetCustomAttributeProvider ());
if (pa == DynamicallyAccessedMemberTypes.None)
@@ -357,7 +355,6 @@ namespace ILLink.Shared.TrimAnalysis
if (getterAnnotation?.ReturnParameterAnnotation is not (null or DynamicallyAccessedMemberTypes.None)) {
_context.LogWarning (getMethod, DiagnosticId.DynamicallyAccessedMembersConflictsBetweenPropertyAndAccessor, property.GetDisplayName (), getMethod.GetDisplayName ());
} else {
- int offset = getMethod.HasImplicitThis () ? 1 : 0;
if (getterAnnotation is not null)
annotatedMethods.Remove (getterAnnotation.Value);
diff --git a/src/linker/Linker.Dataflow/HandleCallAction.cs b/src/linker/Linker.Dataflow/HandleCallAction.cs
index 4b045a705..9a65b93fa 100644
--- a/src/linker/Linker.Dataflow/HandleCallAction.cs
+++ b/src/linker/Linker.Dataflow/HandleCallAction.cs
@@ -106,7 +106,7 @@ namespace ILLink.Shared.TrimAnalysis
=> _reflectionMarker.MarkPropertiesOnTypeHierarchy (_diagnosticContext.Origin, type.Type, p => p.Name == name, bindingFlags);
private partial void MarkPublicParameterlessConstructorOnType (TypeProxy type)
- => _reflectionMarker.MarkConstructorsOnType (_diagnosticContext.Origin, type.Type, m => m.IsPublic && m.GetMetadataParametersCount () == 0);
+ => _reflectionMarker.MarkConstructorsOnType (_diagnosticContext.Origin, type.Type, m => m.IsPublic && !m.HasMetadataParameters ());
private partial void MarkConstructorsOnType (TypeProxy type, BindingFlags? bindingFlags, int? parameterCount)
=> _reflectionMarker.MarkConstructorsOnType (_diagnosticContext.Origin, type.Type, (parameterCount == null) ? null : m => m.GetMetadataParametersCount () == parameterCount, bindingFlags);
diff --git a/src/linker/Linker.Dataflow/ParameterReferenceValue.cs b/src/linker/Linker.Dataflow/ParameterReferenceValue.cs
index c6ef6ec7e..4373e28c4 100644
--- a/src/linker/Linker.Dataflow/ParameterReferenceValue.cs
+++ b/src/linker/Linker.Dataflow/ParameterReferenceValue.cs
@@ -5,7 +5,7 @@ using ILLink.Shared.TypeSystemProxy;
namespace ILLink.Shared.TrimAnalysis
{
- internal sealed partial record ParameterReferenceValue (ParameterProxy Parameter)
+ internal sealed record ParameterReferenceValue (ParameterProxy Parameter)
: ReferenceValue (Parameter.ParameterType)
{
public override SingleValue DeepCopy ()
diff --git a/src/linker/Linker.Dataflow/ReflectionMethodBodyScanner.cs b/src/linker/Linker.Dataflow/ReflectionMethodBodyScanner.cs
index 804e5a214..530ecf25b 100644
--- a/src/linker/Linker.Dataflow/ReflectionMethodBodyScanner.cs
+++ b/src/linker/Linker.Dataflow/ReflectionMethodBodyScanner.cs
@@ -33,7 +33,7 @@ namespace Mono.Linker.Dataflow
return Intrinsics.GetIntrinsicIdForMethod (methodDefinition) > IntrinsicId.RequiresReflectionBodyScanner_Sentinel ||
context.Annotations.FlowAnnotations.RequiresDataFlowAnalysis (methodDefinition) ||
context.Annotations.DoesMethodRequireUnreferencedCode (methodDefinition, out _) ||
- methodDefinition.IsPInvokeImpl && ComDangerousMethod (methodDefinition, context);
+ IsPInvokeDangerous (methodDefinition, context, out _);
}
public static bool RequiresReflectionMethodBodyScannerForMethodBody (LinkContext context, MethodDefinition methodDefinition)
@@ -239,8 +239,10 @@ namespace Mono.Linker.Dataflow
}
case IntrinsicId.None: {
- if (calledMethodDefinition.IsPInvokeImpl && ComDangerousMethod (calledMethodDefinition, context))
+ if (IsPInvokeDangerous (calledMethodDefinition, context, out bool comDangerousMethod)) {
+ Debug.Assert (comDangerousMethod); // Currently COM dangerous is the only one we detect
diagnosticContext.AddDiagnostic (DiagnosticId.CorrectnessOfCOMCannotBeGuaranteed, calledMethodDefinition.GetDisplayName ());
+ }
if (context.Annotations.DoesMethodRequireUnreferencedCode (calledMethodDefinition, out RequiresUnreferencedCodeAttribute? requiresUnreferencedCode))
MarkStep.ReportRequiresUnreferencedCode (calledMethodDefinition.GetDisplayName (), requiresUnreferencedCode, diagnosticContext);
@@ -435,9 +437,17 @@ namespace Mono.Linker.Dataflow
TrimAnalysisPatterns.Add (new TrimAnalysisAssignmentPattern (value, targetValue, origin));
}
- private static bool ComDangerousMethod (MethodDefinition methodDefinition, LinkContext context)
+ private static bool IsPInvokeDangerous (MethodDefinition methodDefinition, LinkContext context, out bool comDangerousMethod)
{
- bool comDangerousMethod = IsComInterop (methodDefinition.MethodReturnType, methodDefinition.ReturnType, context);
+ // The method in linker only detects one condition - COM Dangerous, but it's structured like this
+ // so that the code looks very similar to AOT which has more than one condition.
+
+ if (!methodDefinition.IsPInvokeImpl) {
+ comDangerousMethod = false;
+ return false;
+ }
+
+ comDangerousMethod = IsComInterop (methodDefinition.MethodReturnType, methodDefinition.ReturnType, context);
#pragma warning disable RS0030 // MethodDefinition.Parameters is banned. Here we iterate through the parameters and don't need to worry about the 'this' parameter.
foreach (ParameterDefinition pd in methodDefinition.Parameters) {
comDangerousMethod |= IsComInterop (pd, pd.ParameterType, context);
diff --git a/src/linker/Linker.Dataflow/SingleValueExtensions.cs b/src/linker/Linker.Dataflow/SingleValueExtensions.cs
deleted file mode 100644
index 2f976cd4a..000000000
--- a/src/linker/Linker.Dataflow/SingleValueExtensions.cs
+++ /dev/null
@@ -1,84 +0,0 @@
-// 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.Collections.Generic;
-using ILLink.Shared.DataFlow;
-using Mono.Linker.Dataflow;
-
-namespace ILLink.Shared.TrimAnalysis
-{
- // These are extension methods because we want to allow the use of them on null 'this' pointers.
- internal static class SingleValueExtensions
- {
- /// <summary>
- /// Returns true if a ValueNode graph contains a cycle
- /// </summary>
- /// <param name="node">Node to evaluate</param>
- /// <param name="seenNodes">Set of nodes previously seen on the current arc. Callers may pass a non-empty set
- /// to test whether adding that set to this node would create a cycle. Contents will be modified by the walk
- /// and should not be used by the caller after returning</param>
- /// <param name="allNodesSeen">Optional. The set of all nodes encountered during a walk after DetectCycle returns</param>
- /// <returns></returns>
- public static bool DetectCycle (this SingleValue node, HashSet<SingleValue> seenNodes, HashSet<SingleValue>? allNodesSeen)
- {
- if (node == null)
- return false;
-
- if (seenNodes.Contains (node))
- return true;
-
- seenNodes.Add (node);
-
- allNodesSeen?.Add (node);
-
- bool foundCycle = false;
- switch (node) {
- //
- // Leaf nodes
- //
- case UnknownValue:
- case NullValue:
- case SystemTypeValue:
- case RuntimeTypeHandleValue:
- case KnownStringValue:
- case ConstIntValue:
- case MethodParameterValue:
- case MethodReturnValue:
- case GenericParameterValue:
- case RuntimeTypeHandleForGenericParameterValue:
- case SystemReflectionMethodBaseValue:
- case RuntimeMethodHandleValue:
- case FieldValue:
- break;
-
- //
- // Nodes with children
- //
- case ArrayValue:
- ArrayValue av = (ArrayValue) node;
- foundCycle = av.Size.DetectCycle (seenNodes, allNodesSeen);
- foreach (ValueBasicBlockPair pair in av.IndexValues.Values) {
- foreach (var v in pair.Value) {
- foundCycle |= v.DetectCycle (seenNodes, allNodesSeen);
- }
- }
- break;
-
- case RuntimeTypeHandleForNullableValueWithDynamicallyAccessedMembers value:
- foundCycle = value.UnderlyingTypeValue.DetectCycle (seenNodes, allNodesSeen);
- break;
-
- case NullableValueWithDynamicallyAccessedMembers value:
- foundCycle = value.UnderlyingTypeValue.DetectCycle (seenNodes, allNodesSeen);
- break;
-
- default:
- throw new Exception (String.Format ("Unknown node type: {0}", node.GetType ().Name));
- }
- seenNodes.Remove (node);
-
- return foundCycle;
- }
- }
-} \ No newline at end of file
diff --git a/src/linker/Linker/MethodDefinitionExtensions.cs b/src/linker/Linker/MethodDefinitionExtensions.cs
index 28ad55c65..9d3e722b0 100644
--- a/src/linker/Linker/MethodDefinitionExtensions.cs
+++ b/src/linker/Linker/MethodDefinitionExtensions.cs
@@ -102,9 +102,6 @@ namespace Mono.Linker
}
}
- public static bool HasParameterOfType (this MethodDefinition method, ParameterIndex index, string typeName)
- => method.TryGetParameter (index)?.ParameterType?.IsTypeOf (typeName) is true;
-
/// <summary>
/// Tries to get the <see cref="ParameterProxy"/> representing the parameter at index <paramref name="index"/> of method <paramref name="method"/>.
/// Returns null if <paramref name="index"/> is not a valid parameter index for <paramref name="method"/>.
diff --git a/src/linker/Linker/MethodReferenceExtensions.cs b/src/linker/Linker/MethodReferenceExtensions.cs
index 740d5bbcc..ebdb7ff3c 100644
--- a/src/linker/Linker/MethodReferenceExtensions.cs
+++ b/src/linker/Linker/MethodReferenceExtensions.cs
@@ -103,13 +103,13 @@ namespace Mono.Linker
#pragma warning restore RS0030 // Do not used banned APIs
/// <summary>
- /// Returns true if the method has any parameters in the .parameters section of the method's metadata
+ /// Returns true if the method has any parameters in the .parameters section of the method's metadata (i.e. excludes the impicit 'this')
/// </summary>
public static bool HasMetadataParameters (this MethodReference method)
=> method.GetMetadataParametersCount () != 0;
/// <summary>
- /// Returns a list of the parameters in the method's 'parameters' metadata section (i.e. excluding the implicit 'this' parameter)
+ /// Returns the number of the parameters pushed before the method's call (i.e. including the implicit 'this' if present)
/// </summary>
#pragma warning disable RS0030 // MethodReference.Parameters is banned -- this provides a wrapper
public static int GetParametersCount (this MethodReference method)
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/MethodParametersDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/MethodParametersDataFlow.cs
index 99c7e8f99..b7e43bb1e 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/MethodParametersDataFlow.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/MethodParametersDataFlow.cs
@@ -43,7 +43,9 @@ namespace Mono.Linker.Tests.Cases.DataFlow
TestParameterOverwrite (typeof (TestType));
+#if !NATIVEAOT
TestVarargsMethod (typeof (TestType), __arglist (0, 1, 2));
+#endif
WriteCapturedParameter.Test ();
}