Skip to content
New issue

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

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

Already on GitHub? # to your account

Validate the Kept attribute against the presence of EEType in NativeAOT #81830

Merged
merged 3 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
Expand Up @@ -691,6 +691,8 @@ public IEnumerable<TypeDesc> ConstructedEETypes
}
}
}

public DependencyAnalyzerBase<NodeFactory> Graph => _graph;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you expose this on CompilationResults instead? If the whole graph is public, there's no point to have CompilationResults.

I kind of like that IEETypeNode and IMethodBodyNode are implementation details. Going over the graph exposes e.g. the duality of Constructed/Unconstructed types (some types will appear twice).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I mean expose a way to get to the list of all method tables constructed or not. I don't mean a way to get to every marked node.)

}

public sealed class ConstrainedCallInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ public static void Main ()
TestArrayInAttributeParameter_ViaReflection ();
}

// NativeAOT: No need to preserve the element type if it's never instantiated
// There will be a reflection record about it, but we don't validate that yet
[Kept (By = ProducedBy.Trimmer)]
[Kept]
class ArrayElementType
{
public ArrayElementType () { }
Expand Down Expand Up @@ -58,9 +56,7 @@ static void RequirePublicMethodsOnArrayOfGeneric<T> ()
RequirePublicMethods (typeof (T[]));
}

// NativeAOT: No need to preserve the element type if it's never instantiated
// There will be a reflection record about it, but we don't validate that yet
[Kept (By = ProducedBy.Trimmer)]
[Kept]
class ArrayElementInGenericType
{
public ArrayElementInGenericType () { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,7 @@ class MyReflect : IReflect
public object InvokeMember (string name, BindingFlags invokeAttr, Binder binder, object target, object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] namedParameters) => throw new NotImplementedException ();
}

// NativeAOT: Doesn't preserve this type because there's no need. The type itself is never instantiated
// there's only a field of that type and accessed to that field can be made without knowing it's type (just memory address access)
[Kept (By = ProducedBy.Trimmer)]
[Kept]
[KeptBaseType (typeof (MyReflect), By = ProducedBy.Trimmer)]
class MyReflectDerived : MyReflect
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,11 @@ static Nested ()

class Complex
{
// NativeAOT currently only validates runtime type information, in this case ilc only keeps metadata, but no runtime info
// since the type is never instantiated or used anywhere else, just in the method signature.
[Kept (By = ProducedBy.Trimmer)]
[Kept]
public struct S<T> { }
[Kept]
public class A { }
[Kept (By = ProducedBy.Trimmer)]
[Kept]
public class G<T, U> { }

[Kept]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ interface IFoo3<T, K, J>
int Bar3 { get; set; }
}

// Cat class should be Kept https://github.com/dotnet/runtime/issues/80408
[Kept (By = ProducedBy.NativeAot)]
class Cat
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Text;
using FluentAssertions;
using ILCompiler;
using ILCompiler.DependencyAnalysis;
using Internal.IL.Stubs;
using Internal.TypeSystem;
using Internal.TypeSystem.Ecma;
Expand Down Expand Up @@ -159,12 +160,12 @@ public void Verify ()

private void PopulateLinkedMembers ()
{
foreach (TypeDesc? constructedType in testResult.TrimmingResults.ConstructedEETypes) {
AddType (constructedType);
foreach (TypeDesc type in testResult.TrimmingResults.Graph.MarkedNodeList.OfType<IEETypeNode> ().Select (node => node.Type)) {
AddType (type);
}

foreach (MethodDesc? compiledMethod in testResult.TrimmingResults.CompiledMethodBodies) {
AddMethod (compiledMethod);
foreach (MethodDesc method in testResult.TrimmingResults.Graph.MarkedNodeList.OfType<IMethodBodyNode> ().Select (node => node.Method)) {
AddMethod (method);
}

void AddMethod (MethodDesc method)
Expand Down