Skip to content

Commit 202b1be

Browse files
authored
ILLink: Add PropertyNode for dependency analysis (#102026)
Adds a node for PropertyDefinitions to the trimmers dependency analysis, and moves the body of MarkProperty to the node's GetStaticDependencies.
1 parent 839dac9 commit 202b1be

File tree

3 files changed

+54
-5
lines changed

3 files changed

+54
-5
lines changed

src/tools/illink/src/linker/Linker.Steps/MarkStep.NodeFactory.cs

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ internal sealed class NodeFactory (MarkStep markStep)
1515
public MarkStep MarkStep { get; } = markStep;
1616
readonly NodeCache<TypeDefinition, TypeDefinitionNode> _typeNodes = new (static t => new TypeDefinitionNode(t));
1717
readonly NodeCache<MethodDefinition, MethodDefinitionNode> _methodNodes = new (static _ => throw new InvalidOperationException ("Creation of node requires more than the key."));
18+
readonly NodeCache<PropertyDefinition, PropertyDefinitionNode> _propertyNodes = new (static p => new PropertyDefinitionNode(p));
1819
readonly NodeCache<TypeDefinition, TypeIsRelevantToVariantCastingNode> _typeIsRelevantToVariantCastingNodes = new (static (t) => new TypeIsRelevantToVariantCastingNode (t));
1920

2021
internal TypeDefinitionNode GetTypeNode (TypeDefinition definition)
@@ -32,6 +33,11 @@ internal TypeIsRelevantToVariantCastingNode GetTypeIsRelevantToVariantCastingNod
3233
return _typeIsRelevantToVariantCastingNodes.GetOrAdd (type);
3334
}
3435

36+
internal PropertyDefinitionNode GetPropertyNode (PropertyDefinition prop)
37+
{
38+
return _propertyNodes.GetOrAdd (prop);
39+
}
40+
3541
struct NodeCache<TKey, TValue> where TKey : notnull
3642
{
3743
// Change to concurrent dictionary if/when multithreaded marking is enabled
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System.Collections.Generic;
5+
using ILCompiler.DependencyAnalysisFramework;
6+
using Mono.Cecil;
7+
8+
namespace Mono.Linker.Steps
9+
{
10+
11+
public partial class MarkStep
12+
{
13+
internal sealed class PropertyDefinitionNode : DependencyNodeCore<NodeFactory>
14+
{
15+
PropertyDefinition _property;
16+
public PropertyDefinitionNode(PropertyDefinition property)
17+
{
18+
_property = property;
19+
}
20+
21+
public override bool InterestingForDynamicDependencyAnalysis => false;
22+
23+
public override bool HasDynamicDependencies => false;
24+
25+
public override bool HasConditionalStaticDependencies => false;
26+
27+
public override bool StaticDependenciesAreComputed => true;
28+
29+
public override IEnumerable<CombinedDependencyListEntry>? GetConditionalStaticDependencies (NodeFactory context) => null;
30+
31+
public override IEnumerable<DependencyListEntry>? GetStaticDependencies (NodeFactory context)
32+
{
33+
var propertyOrigin = new MessageOrigin (_property);
34+
35+
// Consider making this more similar to MarkEvent method?
36+
context.MarkStep.MarkCustomAttributes (_property, new DependencyInfo (DependencyKind.CustomAttribute, _property), propertyOrigin);
37+
context.MarkStep.DoAdditionalPropertyProcessing (_property);
38+
return null;
39+
}
40+
41+
public override IEnumerable<CombinedDependencyListEntry>? SearchDynamicDependencies (List<DependencyNodeCore<NodeFactory>> markedNodes, int firstNode, NodeFactory context) => null;
42+
43+
protected override string GetName (NodeFactory context) => _property.GetDisplayName ();
44+
}
45+
}
46+
}

src/tools/illink/src/linker/Linker.Steps/MarkStep.cs

+2-5
Original file line numberDiff line numberDiff line change
@@ -3498,11 +3498,8 @@ protected internal void MarkProperty (PropertyDefinition prop, in DependencyInfo
34983498
if (!Annotations.MarkProcessed (prop, reason))
34993499
return;
35003500

3501-
var propertyOrigin = new MessageOrigin (prop);
3502-
3503-
// Consider making this more similar to MarkEvent method?
3504-
MarkCustomAttributes (prop, new DependencyInfo (DependencyKind.CustomAttribute, prop), propertyOrigin);
3505-
DoAdditionalPropertyProcessing (prop);
3501+
PropertyDefinitionNode propertyNode = _nodeFactory.GetPropertyNode (prop);
3502+
_dependencyGraph.AddRoot (propertyNode, reason.Kind.ToString ());
35063503
}
35073504

35083505
protected internal virtual void MarkEvent (EventDefinition evt, in DependencyInfo reason, MessageOrigin origin)

0 commit comments

Comments
 (0)