-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Linker dependency framework #101277
Merged
Merged
Linker dependency framework #101277
Changes from 36 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
afe8990
MarkStep runs inside dependency framework
vitek-karas 4a92aaf
Merge branch 'main' of https://github.com/dotnet/runtime into LinkerD…
jtschuster 76fe923
Put MarkType into DependencyFramework
jtschuster b3ccd66
Leave MarkType in MarkStep, use captured MarkStep to call it
jtschuster eb5e333
Format
jtschuster e1270bb
Use DF for TypeDefinition and MethodDefinition
jtschuster 2d12ade
Rename MarkTypeImpl to ProcessType and clean up code
jtschuster 1dc80db
Clean up code a bit more
jtschuster 991f7a0
Use ProjectReference for DAF, and undo method moves
jtschuster 069f47b
Merge branch 'main' of https://github.com/dotnet/runtime into LinkerD…
jtschuster c1670eb
Don't have additional virtualmethods processing
jtschuster 8382e68
Merge branch 'main' of https://github.com/dotnet/runtime into LinkerD…
jtschuster 5bf5ece
Remove old header comment copied from MarkStep
jtschuster e6edbce
Remove nullable directives from ilc files
jtschuster 10a5c57
Sign DAF instead of nowarn on trimmer
jtschuster 166d2d5
Re-add doc comment; Make types internal
jtschuster 01f3a79
Undo Queue changes, fix visibility issues
jtschuster 098f7bc
Rename TypeDefinitionDependencyNode file to match class
jtschuster 25ec8ce
PR feedback:
jtschuster 9ef1343
PR Feedback:
jtschuster d50d70c
Use static lambda for TypeDefinitionNode creation
jtschuster dfe51f2
Only warn on duplicate members within a single descriptors file
jtschuster afedfb7
Only warn on duplicate members within a single descriptors file
jtschuster a600348
Make duplicate preserve an info message
jtschuster 8d642a5
Merge branch 'main' of https://github.com/dotnet/runtime into LinkerD…
jtschuster a0ea640
Merge branch 'main' of https://github.com/dotnet/runtime into ILLinkD…
jtschuster 2bb99d7
Merge branch 'ILLinkDescriptionDuplicatePreserve' into LinkerDependen…
jtschuster b27bc04
Update expectations in xml warnings tests
jtschuster 3394758
Merge branch 'ILLinkDescriptionDuplicatePreserve' into LinkerDependen…
jtschuster 1abe4b3
Make method internal for API compat
jtschuster 8cbedd1
Merge branch 'ILLinkDescriptionDuplicatePreserve' into LinkerDependen…
jtschuster df7a522
Merge branch 'main' into LinkerDependencyFramework
jtschuster 28bf0be
Merge branch 'main' into LinkerDependencyFramework
jtschuster 3ca9f9a
PR Feedback:
jtschuster 830f23e
Merge branch 'LinkerDependencyFramework' of https://github.com/jtschu…
jtschuster 3001124
Add space before method call parentheses
jtschuster f003f74
Don't pass TargetOS and TargetArch to ILLink.Tasks when using live il…
jtschuster a0f6861
Merge branch 'main' into LinkerDependencyFramework
jtschuster d358b42
Update comment in liveILLink.targets
jtschuster 0fab4e3
Merge branch 'LinkerDependencyFramework' of https://github.com/jtschu…
jtschuster 5e124b5
Don't append platform to output dirs
jtschuster 855b109
Merge branch 'main' into LinkerDependencyFramework
jtschuster File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/tools/illink/src/linker/Linker.Steps/MarkStep.MethodDefinitionNode.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// 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 ILCompiler.DependencyAnalysisFramework; | ||
using Mono.Cecil; | ||
|
||
namespace Mono.Linker.Steps | ||
{ | ||
public partial class MarkStep | ||
{ | ||
internal sealed class MethodDefinitionNode : DependencyNodeCore<NodeFactory> | ||
{ | ||
readonly MethodDefinition method; | ||
readonly DependencyInfo reason; | ||
|
||
public MethodDefinitionNode (MethodDefinition method, DependencyInfo reason) | ||
{ | ||
this.method = method; | ||
this.reason = reason; | ||
} | ||
|
||
public override bool InterestingForDynamicDependencyAnalysis => false; | ||
|
||
public override bool HasDynamicDependencies => false; | ||
|
||
public override bool HasConditionalStaticDependencies => false; | ||
|
||
public override bool StaticDependenciesAreComputed => true; | ||
|
||
public override IEnumerable<DependencyListEntry>? GetStaticDependencies (NodeFactory context) | ||
{ | ||
context.MarkStep.ProcessMethod (method, reason); | ||
return null; | ||
} | ||
|
||
public override IEnumerable<CombinedDependencyListEntry>? GetConditionalStaticDependencies (NodeFactory context) => null; | ||
public override IEnumerable<CombinedDependencyListEntry>? SearchDynamicDependencies (List<DependencyNodeCore<NodeFactory>> markedNodes, int firstNode, NodeFactory context) => null; | ||
protected override string GetName (NodeFactory context) => method.GetDisplayName(); | ||
} | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/tools/illink/src/linker/Linker.Steps/MarkStep.NodeFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// 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.Concurrent; | ||
using System.Collections.Generic; | ||
using Mono.Cecil; | ||
|
||
namespace Mono.Linker.Steps | ||
{ | ||
public partial class MarkStep | ||
{ | ||
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<TypeDefinition, TypeIsRelevantToVariantCastingNode> _typeIsRelevantToVariantCastingNodes = new (static (t) => new TypeIsRelevantToVariantCastingNode (t)); | ||
|
||
internal TypeDefinitionNode GetTypeNode (TypeDefinition definition) | ||
{ | ||
return _typeNodes.GetOrAdd (definition); | ||
} | ||
|
||
internal MethodDefinitionNode GetMethodDefinitionNode (MethodDefinition method, DependencyInfo reason) | ||
{ | ||
return _methodNodes.GetOrAdd (method, (k) => new MethodDefinitionNode (k, reason)); | ||
} | ||
|
||
internal TypeIsRelevantToVariantCastingNode GetTypeIsRelevantToVariantCastingNode (TypeDefinition type) | ||
{ | ||
return _typeIsRelevantToVariantCastingNodes.GetOrAdd (type); | ||
} | ||
|
||
struct NodeCache<TKey, TValue> where TKey : notnull | ||
{ | ||
// Change to concurrent dictionary if/when multithreaded marking is enabled | ||
readonly Dictionary<TKey, TValue> _cache; | ||
readonly Func<TKey, TValue> _creator; | ||
|
||
public NodeCache (Func<TKey, TValue> creator, IEqualityComparer<TKey> comparer) | ||
{ | ||
_creator = creator; | ||
_cache = new (comparer); | ||
} | ||
|
||
public NodeCache (Func<TKey, TValue> creator) | ||
{ | ||
_creator = creator; | ||
_cache = new (); | ||
} | ||
|
||
public TValue GetOrAdd (TKey key) | ||
{ | ||
return _cache.GetOrAdd (key, _creator); | ||
} | ||
|
||
public TValue GetOrAdd (TKey key, Func<TKey, TValue> creator) | ||
{ | ||
return _cache.GetOrAdd (key, creator); | ||
} | ||
} | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/tools/illink/src/linker/Linker.Steps/MarkStep.ProcessCallbackNode.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
using System.Collections.Generic; | ||
using ILCompiler.DependencyAnalysisFramework; | ||
|
||
namespace Mono.Linker.Steps | ||
{ | ||
public partial class MarkStep | ||
{ | ||
sealed class ProcessCallbackNode : DependencyNodeCore<NodeFactory> | ||
{ | ||
Func<bool> _processAction; | ||
DependencyList? _dependencies; | ||
|
||
public ProcessCallbackNode (Func<bool> action) => _processAction = action; | ||
|
||
public void Process () | ||
{ | ||
_dependencies = new DependencyList (); | ||
if (_processAction ()) { | ||
_dependencies.Add (new ProcessCallbackNode (_processAction), "Some processing was done, continuation required"); | ||
} | ||
} | ||
|
||
public override bool InterestingForDynamicDependencyAnalysis => false; | ||
|
||
public override bool HasDynamicDependencies => false; | ||
|
||
public override bool HasConditionalStaticDependencies => false; | ||
|
||
public override bool StaticDependenciesAreComputed => _dependencies != null; | ||
|
||
public override IEnumerable<DependencyListEntry>? GetStaticDependencies (NodeFactory context) => _dependencies; | ||
|
||
public override IEnumerable<CombinedDependencyListEntry>? GetConditionalStaticDependencies (NodeFactory context) => null; | ||
public override IEnumerable<CombinedDependencyListEntry>? SearchDynamicDependencies (List<DependencyNodeCore<NodeFactory>> markedNodes, int firstNode, NodeFactory context) => null; | ||
protected override string GetName (NodeFactory context) => "Process"; | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/tools/illink/src/linker/Linker.Steps/MarkStep.TypeDefinitionNode.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// 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 TypeDefinitionNode : DependencyNodeCore<NodeFactory> | ||
{ | ||
readonly TypeDefinition type; | ||
|
||
public TypeDefinitionNode (TypeDefinition type) | ||
{ | ||
this.type = type; | ||
} | ||
|
||
public override bool InterestingForDynamicDependencyAnalysis => false; | ||
|
||
public override bool HasDynamicDependencies => false; | ||
|
||
public override bool HasConditionalStaticDependencies => false; | ||
|
||
public override bool StaticDependenciesAreComputed => true; | ||
|
||
public override IEnumerable<DependencyListEntry>? GetStaticDependencies (NodeFactory context) | ||
{ | ||
context.MarkStep.ProcessType (type); | ||
return null; | ||
} | ||
|
||
public override IEnumerable<CombinedDependencyListEntry>? GetConditionalStaticDependencies (NodeFactory context) => null; | ||
public override IEnumerable<CombinedDependencyListEntry>? SearchDynamicDependencies (List<DependencyNodeCore<NodeFactory>> markedNodes, int firstNode, NodeFactory context) => null; | ||
protected override string GetName (NodeFactory context) => type.GetDisplayName(); | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/tools/illink/src/linker/Linker.Steps/MarkStep.TypeIsRelevantToVariantCastingNode.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// 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 TypeIsRelevantToVariantCastingNode : DependencyNodeCore<NodeFactory> | ||
{ | ||
TypeDefinition type; | ||
public TypeIsRelevantToVariantCastingNode (TypeDefinition type) => this.type = type; | ||
|
||
public override bool InterestingForDynamicDependencyAnalysis => false; | ||
|
||
public override bool HasDynamicDependencies => false; | ||
|
||
public override bool HasConditionalStaticDependencies => false; | ||
|
||
public override bool StaticDependenciesAreComputed => true; | ||
|
||
public override IEnumerable<DependencyListEntry>? GetStaticDependencies (NodeFactory context) | ||
{ | ||
yield break; | ||
} | ||
|
||
public override IEnumerable<CombinedDependencyListEntry>? GetConditionalStaticDependencies (NodeFactory context) => null; | ||
public override IEnumerable<CombinedDependencyListEntry>? SearchDynamicDependencies (List<DependencyNodeCore<NodeFactory>> markedNodes, int firstNode, NodeFactory context) => null; | ||
protected override string GetName (NodeFactory context) => $"{type.GetDisplayName()} is relevant to variant casting"; | ||
protected override void OnMarked (NodeFactory context) | ||
{ | ||
context.MarkStep.Annotations.MarkRelevantToVariantCasting (type); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When do we use
OnMarked
vsGetStaticDependencies
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just used OnMarked arbitrarily for this since there aren't any dependencies. It looks like OnMarked will do work up front when the node is returned from another GetStaticDependencies, then it's added to a stack to later call GetStaticDependencies.