-
Notifications
You must be signed in to change notification settings - Fork 5.3k
ILC: track concrete dependencies of open generic methods #122012
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
Open
sbomer
wants to merge
18
commits into
dotnet:main
Choose a base branch
from
sbomer:vtableScannerFix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+559
−150
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
dc8058b
Create MethodGenericDictionary for calls to GVMs
sbomer 036aded
Revert "Create MethodGenericDictionary for calls to GVMs"
sbomer 74c0072
Create ShadowConcreteMethod for GVMs
sbomer bfc47f2
Revert "Create ShadowConcreteMethod for GVMs"
sbomer 9141892
Add ShadowGenericMethod for partially instantiated methods
sbomer b0923a9
Add testcase
sbomer 5d9b2bc
Use existing InstantiateDependencies for generic lookups to create sh…
sbomer 3a67c7f
More tests
sbomer 34787ec
Track ShadowGenericMethod for direct call
sbomer 2add96c
Merge remote-tracking branch 'origin/main' into vtableScannerFix
sbomer f2a2fcc
Revert normalization change
sbomer 4d6fbdc
Cleanup
sbomer 9911cf5
Update src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyA…
sbomer 7b51934
Feedback
sbomer 7316f1c
Merge branch 'main' into vtableScannerFix
sbomer 438c801
Handle null GetTarget and non-concrete MakeGeneric
sbomer 9dd909e
Revert MakeGeneric logic
sbomer 2f39adc
Update src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/Ha…
sbomer 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 hidden or 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 hidden or 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
128 changes: 128 additions & 0 deletions
128
src/coreclr/tools/Common/Compiler/DependencyAnalysis/ShadowMethodNode.cs
This file contains hidden or 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,128 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Collections.Generic; | ||
|
|
||
| using ILCompiler.DependencyAnalysisFramework; | ||
|
|
||
| using Internal.Text; | ||
| using Internal.TypeSystem; | ||
|
|
||
| using Debug = System.Diagnostics.Debug; | ||
|
|
||
| namespace ILCompiler.DependencyAnalysis | ||
| { | ||
| /// <summary> | ||
| /// Represents a method on a generic type (or a generic method) that doesn't | ||
| /// have code emitted in the executable because it's physically backed by a canonical | ||
| /// method body. The purpose of this node is to track the dependencies of the generic | ||
| /// method body, as if it was generated. The node acts as a symbol for the canonical | ||
| /// method for convenience. | ||
| /// </summary> | ||
| public abstract class ShadowMethodNode : DependencyNodeCore<NodeFactory>, IMethodNode, ISymbolNodeWithLinkage | ||
| { | ||
| /// <summary> | ||
| /// Gets the canonical method body that defines the dependencies of this node. | ||
| /// </summary> | ||
| public IMethodNode CanonicalMethodNode { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the generic method represented by this node. | ||
| /// </summary> | ||
| public MethodDesc Method { get; } | ||
|
|
||
| // Implementation of ISymbolNode that makes this node act as a symbol for the canonical body | ||
| public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb) | ||
| { | ||
| CanonicalMethodNode.AppendMangledName(nameMangler, sb); | ||
| } | ||
| public int Offset => CanonicalMethodNode.Offset; | ||
| public bool RepresentsIndirectionCell => CanonicalMethodNode.RepresentsIndirectionCell; | ||
|
|
||
| public override bool StaticDependenciesAreComputed | ||
| => CanonicalMethodNode.StaticDependenciesAreComputed; | ||
|
|
||
| public ShadowMethodNode(MethodDesc method, IMethodNode canonicalMethod) | ||
| { | ||
| Debug.Assert(!method.IsRuntimeDeterminedExactMethod); | ||
| Debug.Assert(canonicalMethod.Method == method.GetCanonMethodTarget(CanonicalFormKind.Specific)); | ||
| Debug.Assert(canonicalMethod.Method.IsSharedByGenericInstantiations); | ||
| Method = method; | ||
| CanonicalMethodNode = canonicalMethod; | ||
| } | ||
|
|
||
| public ISymbolNode NodeForLinkage(NodeFactory factory) | ||
| { | ||
| return CanonicalMethodNode; | ||
| } | ||
|
|
||
| public override IEnumerable<DependencyListEntry> GetStaticDependencies(NodeFactory factory) | ||
| { | ||
| DependencyList dependencies = new DependencyList(); | ||
|
|
||
| // Make sure the canonical body gets generated | ||
| dependencies.Add(new DependencyListEntry(CanonicalMethodNode, "Canonical body")); | ||
|
|
||
| // Instantiate the runtime determined dependencies of the canonical method body | ||
| // with the concrete instantiation of the method to get concrete dependencies. | ||
| Instantiation typeInst = Method.OwningType.Instantiation; | ||
| Instantiation methodInst = Method.Instantiation; | ||
| IEnumerable<DependencyListEntry> staticDependencies = CanonicalMethodNode.GetStaticDependencies(factory); | ||
|
|
||
| if (staticDependencies != null) | ||
| { | ||
| foreach (DependencyListEntry canonDep in staticDependencies) | ||
| { | ||
| var runtimeDep = canonDep.Node as INodeWithRuntimeDeterminedDependencies; | ||
| if (runtimeDep != null) | ||
| { | ||
| dependencies.AddRange(runtimeDep.InstantiateDependencies(factory, typeInst, methodInst, isConcreteInstantiation: !Method.IsSharedByGenericInstantiations)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return dependencies; | ||
| } | ||
|
|
||
| public sealed override IEnumerable<CombinedDependencyListEntry> GetConditionalStaticDependencies(NodeFactory factory) | ||
| { | ||
| // Instantiate the runtime determined dependencies of the canonical method body | ||
| // with the concrete instantiation of the method to get concrete dependencies. | ||
| Instantiation typeInst = Method.OwningType.Instantiation; | ||
| Instantiation methodInst = Method.Instantiation; | ||
| IEnumerable<CombinedDependencyListEntry> staticDependencies = CanonicalMethodNode.GetConditionalStaticDependencies(factory); | ||
|
|
||
| if (staticDependencies != null) | ||
| { | ||
| foreach (CombinedDependencyListEntry canonDep in staticDependencies) | ||
| { | ||
| Debug.Assert(canonDep.OtherReasonNode is not INodeWithRuntimeDeterminedDependencies); | ||
|
|
||
| var node = canonDep.Node; | ||
| if (node is INodeWithRuntimeDeterminedDependencies runtimeDeterminedNode) | ||
| { | ||
| foreach (var nodeInner in runtimeDeterminedNode.InstantiateDependencies(factory, typeInst, methodInst, isConcreteInstantiation: !Method.IsSharedByGenericInstantiations)) | ||
| yield return new CombinedDependencyListEntry(nodeInner.Node, canonDep.OtherReasonNode, nodeInner.Reason); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| protected override string GetName(NodeFactory factory) => $"{Method} backed by {CanonicalMethodNode.GetMangledName(factory.NameMangler)}"; | ||
|
|
||
| public sealed override bool HasConditionalStaticDependencies => CanonicalMethodNode.HasConditionalStaticDependencies; | ||
| public sealed override bool HasDynamicDependencies => false; | ||
| public sealed override bool InterestingForDynamicDependencyAnalysis => false; | ||
|
|
||
| public sealed override IEnumerable<CombinedDependencyListEntry> SearchDynamicDependencies(List<DependencyNodeCore<NodeFactory>> markedNodes, int firstNode, NodeFactory factory) => null; | ||
|
|
||
| int ISortableNode.ClassCode => ClassCode; | ||
|
|
||
| protected abstract int ClassCode { get; } | ||
|
|
||
| int ISortableNode.CompareToImpl(ISortableNode other, CompilerComparer comparer) => CompareToImpl(other, comparer); | ||
|
|
||
| protected abstract int CompareToImpl(ISortableNode other, CompilerComparer comparer); | ||
| } | ||
| } |
38 changes: 38 additions & 0 deletions
38
src/coreclr/tools/Common/Compiler/DependencyAnalysis/ShadowNonConcreteMethodNode.cs
This file contains hidden or 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,38 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Collections.Generic; | ||
|
|
||
| using ILCompiler.DependencyAnalysisFramework; | ||
|
|
||
| using Internal.Text; | ||
| using Internal.TypeSystem; | ||
|
|
||
| using Debug = System.Diagnostics.Debug; | ||
|
|
||
| namespace ILCompiler.DependencyAnalysis | ||
| { | ||
| /// <summary> | ||
| /// Represents a non-concrete method (not fully instantiated) for the purpose of | ||
| /// tracking dependencies. | ||
| /// </summary> | ||
| public class ShadowNonConcreteMethodNode : ShadowMethodNode, IMethodNode, ISymbolNodeWithLinkage | ||
| { | ||
| public ShadowNonConcreteMethodNode(MethodDesc method, IMethodNode canonicalMethod) | ||
| : base(method, canonicalMethod) | ||
| { | ||
| Debug.Assert(method.IsSharedByGenericInstantiations); | ||
| } | ||
|
|
||
| protected override int ClassCode => 2120942405; | ||
|
|
||
| protected override int CompareToImpl(ISortableNode other, CompilerComparer comparer) | ||
| { | ||
| var compare = comparer.Compare(Method, ((ShadowNonConcreteMethodNode)other).Method); | ||
| if (compare != 0) | ||
| return compare; | ||
|
|
||
| return comparer.Compare(CanonicalMethodNode, ((ShadowNonConcreteMethodNode)other).CanonicalMethodNode); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
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.
I would want to keep these assert - they prevent nonsensical graphs.
I think we should split this class into multiple classes - one that tracks fully instantiated things (can keep calling it
ShadowConcreteMethod) - this one can still assert all these things. And add one that is not fully specialized. There may be a common base type. I think separate node would also result in more readable dependency graphs.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.
Split into ShadowConcreteMethodNode and ShadowNonConcreteMethodNode (with shared base ShadowMethodNode)