Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/ILLink.RoslynAnalyzer/TrimAnalysis/FlowAnnotations.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<FlowAnnotations> _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)
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/ILLink.RoslynAnalyzer/TrimAnalysis/HandleCallAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 3 additions & 0 deletions src/ILLink.Shared/Annotations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/ILLink.Shared/DataFlow/DefaultValueDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/ILLink.Shared/DataFlow/DictionaryLattice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions src/ILLink.Shared/DataFlow/ForwardDataFlowAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/ILLink.Shared/DataFlow/IControlFlowGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/ILLink.Shared/DataFlow/IDataFlowState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> where T : struct
Expand Down
3 changes: 3 additions & 0 deletions src/ILLink.Shared/DataFlow/IDeepCopyValue.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/ILLink.Shared/DataFlow/ILattice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions src/ILLink.Shared/DataFlow/ITransfer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions src/ILLink.Shared/DataFlow/SingleValue.cs
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
3 changes: 3 additions & 0 deletions src/ILLink.Shared/DataFlow/ValueSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TValue> : IEquatable<ValueSet<TValue>>, IEnumerable<TValue>
Expand Down
3 changes: 3 additions & 0 deletions src/ILLink.Shared/DataFlow/ValueSetLattice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions src/ILLink.Shared/DiagnosticCategory.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/ILLink.Shared/DiagnosticId.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/ILLink.Shared/DiagnosticString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/ILLink.Shared/HashUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/ILLink.Shared/IsExternalInit.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/ILLink.Shared/MessageFormat.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/ILLink.Shared/MessageSubCategory.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// 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
public static class MessageSubCategory
{
public const string None = "";
public const string TrimAnalysis = "Trim analysis";
Expand Down
3 changes: 3 additions & 0 deletions src/ILLink.Shared/TrimAnalysis/ArrayValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
using ILLink.Shared.DataFlow;
using MultiValue = ILLink.Shared.DataFlow.ValueSet<ILLink.Shared.DataFlow.SingleValue>;

// This is needed due to NativeAOT which doesn't enable nullable globally yet
#nullable enable

namespace ILLink.Shared.TrimAnalysis
{
sealed partial record ArrayValue : SingleValue
Expand Down
3 changes: 3 additions & 0 deletions src/ILLink.Shared/TrimAnalysis/ConstIntValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions src/ILLink.Shared/TrimAnalysis/DiagnosticContext.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/ILLink.Shared/TrimAnalysis/FieldValue.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
5 changes: 4 additions & 1 deletion src/ILLink.Shared/TrimAnalysis/FlowAnnotations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
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.
readonly partial struct FlowAnnotations
partial class FlowAnnotations
{
internal partial bool MethodRequiresDataFlowAnalysis (MethodProxy method);

Expand Down
3 changes: 3 additions & 0 deletions src/ILLink.Shared/TrimAnalysis/GenericParameterValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/// <summary>
Expand Down
7 changes: 7 additions & 0 deletions src/ILLink.Shared/TrimAnalysis/HandleCallAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
using ILLink.Shared.TypeSystemProxy;
using MultiValue = ILLink.Shared.DataFlow.ValueSet<ILLink.Shared.DataFlow.SingleValue>;

// 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
Expand Down Expand Up @@ -1161,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<T> for example.
default:
methodReturnValue = MultiValueLattice.Top;
return true;
Expand Down
9 changes: 9 additions & 0 deletions src/ILLink.Shared/TrimAnalysis/IntrinsicId.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -43,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,
Expand Down
Loading