Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ILLink: Add EventDefinitionNode to dependency analysis #102578

Closed
wants to merge 5 commits into from
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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.Collections.Generic;
using ILCompiler.DependencyAnalysisFramework;
using Mono.Cecil;

namespace Mono.Linker.Steps
{
public partial class MarkStep
{
internal sealed class EventDefinitionNode : DependencyNodeCore<NodeFactory>
{
EventDefinition _event;
public EventDefinitionNode (EventDefinition @event) => _event = @event;

public override bool InterestingForDynamicDependencyAnalysis => false;

public override bool HasDynamicDependencies => false;

public override bool HasConditionalStaticDependencies => false;

public override bool StaticDependenciesAreComputed => true;

public override IEnumerable<CombinedDependencyListEntry>? GetConditionalStaticDependencies (NodeFactory context) => null;

public override IEnumerable<DependencyListEntry>? GetStaticDependencies (NodeFactory context)
{
var eventOrigin = new MessageOrigin (_event);
context.MarkStep.MarkCustomAttributes (_event, new DependencyInfo (DependencyKind.CustomAttribute, _event), eventOrigin);
context.MarkStep.DoAdditionalEventProcessing (_event);
context.MarkStep.Annotations.MarkProcessed (_event);

return null;
}

public override IEnumerable<CombinedDependencyListEntry>? SearchDynamicDependencies (List<DependencyNodeCore<NodeFactory>> markedNodes, int firstNode, NodeFactory context) => null;

protected override string GetName (NodeFactory context) => _event.GetDisplayName ();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ internal sealed class NodeFactory (MarkStep markStep)
public MarkStep MarkStep { get; } = markStep;
readonly NodeCache<TypeDefinition, TypeDefinitionNode> _typeNodes = new (static t => new TypeDefinitionNode(t));
readonly NodeCache<MethodDefinition, MethodDefinitionNode> _methodNodes = new (static _ => throw new InvalidOperationException ("Creation of node requires more than the key."));
readonly NodeCache<EventDefinition, EventDefinitionNode> _eventNodes = new (static e => new EventDefinitionNode (e));
readonly NodeCache<PropertyDefinition, PropertyDefinitionNode> _propertyNodes = new (static p => new PropertyDefinitionNode(p));
readonly NodeCache<TypeDefinition, TypeIsRelevantToVariantCastingNode> _typeIsRelevantToVariantCastingNodes = new (static (t) => new TypeIsRelevantToVariantCastingNode (t));

Expand All @@ -33,6 +34,11 @@ internal TypeIsRelevantToVariantCastingNode GetTypeIsRelevantToVariantCastingNod
return _typeIsRelevantToVariantCastingNodes.GetOrAdd (type);
}

internal EventDefinitionNode GetEventDefinitionNode (EventDefinition evt)
{
return _eventNodes.GetOrAdd (evt);
}

internal PropertyDefinitionNode GetPropertyNode (PropertyDefinition prop)
{
return _propertyNodes.GetOrAdd (prop);
Expand Down
8 changes: 2 additions & 6 deletions src/tools/illink/src/linker/Linker.Steps/MarkStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3517,12 +3517,8 @@ protected internal virtual void MarkEvent (EventDefinition evt, in DependencyInf
MarkMethodIfNotNull (evt.InvokeMethod, new DependencyInfo (dependencyKind, evt), origin);
MarkMethodIfNotNull (evt.RemoveMethod, new DependencyInfo (dependencyKind, evt), origin);

if (!Annotations.MarkProcessed (evt, reason))
return;

var eventOrigin = new MessageOrigin (evt);
MarkCustomAttributes (evt, new DependencyInfo (DependencyKind.CustomAttribute, evt), eventOrigin);
DoAdditionalEventProcessing (evt);
Tracer.AddDirectDependency (evt, reason, true);
_dependencyGraph.AddRoot (_nodeFactory.GetEventDefinitionNode (evt), Enum.GetName (reason.Kind));
}

internal void MarkMethodIfNotNull (MethodReference method, in DependencyInfo reason, in MessageOrigin origin)
Expand Down
6 changes: 6 additions & 0 deletions src/tools/illink/src/linker/Linker/Annotations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,12 @@ public bool MarkProcessed (IMetadataTokenProvider provider, in DependencyInfo re
return processed.Add (provider);
}

internal bool MarkProcessed (IMetadataTokenProvider provider)
{
marked_pending.Remove (provider);
return processed.Add (provider);
}

public TypeDefinition[] GetPendingPreserve ()
{
return pending_preserve.ToArray ();
Expand Down