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

Restore EETypeNode to the state before we deleted reflection blocking #94287

Merged
merged 3 commits into from
Nov 6, 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 @@ -301,9 +301,16 @@ public ISymbolNode ComputeConstantLookup(ReadyToRunHelperId lookupKind, object t
case ReadyToRunHelperId.TypeHandleForCasting:
{
var type = (TypeDesc)targetOfLookup;

// We counter-intuitively ask for a constructed type symbol. This is needed due to IDynamicInterfaceCastable.
// If this cast happens with an object that implements IDynamicIntefaceCastable, user code will
// see a RuntimeTypeHandle representing this interface.
if (type.IsInterface)
return NodeFactory.MaximallyConstructableType(type);

if (type.IsNullable)
targetOfLookup = type.Instantiation[0];
return NecessaryTypeSymbolIfPossible((TypeDesc)targetOfLookup);
type = type.Instantiation[0];
return NecessaryTypeSymbolIfPossible(type);
}
case ReadyToRunHelperId.MethodDictionary:
return NodeFactory.MethodGenericDictionary((MethodDesc)targetOfLookup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ protected override DependencyList ComputeNonRelocationBasedDependencies(NodeFact
// relocs to nodes we emit.
dependencyList.Add(factory.NecessaryTypeSymbol(_type), "NecessaryType for constructed type");

if (_type is MetadataType mdType)
ModuleUseBasedDependencyAlgorithm.AddDependenciesDueToModuleUse(ref dependencyList, factory, mdType.Module);

DefType closestDefType = _type.GetClosestDefType();

if (_type.IsArray)
Expand Down Expand Up @@ -66,6 +69,9 @@ protected override DependencyList ComputeNonRelocationBasedDependencies(NodeFact
}
}

// Ask the metadata manager if we have any dependencies due to the presence of the EEType.
factory.MetadataManager.GetDependenciesDueToEETypePresence(ref dependencyList, factory, _type);

factory.InteropStubManager.AddInterestingInteropConstructedTypeDependencies(ref dependencyList, factory, _type);

return dependencyList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,12 +633,16 @@ protected override DependencyList ComputeNonRelocationBasedDependencies(NodeFact
}
}

// Ask the metadata manager
// if we have any dependencies due to presence of the EEType.
factory.MetadataManager.GetDependenciesDueToEETypePresence(ref dependencies, factory, _type);
if (!ConstructedEETypeNode.CreationAllowed(_type))
{
// If necessary MethodTable is the highest load level for this type, ask the metadata manager
// if we have any dependencies due to presence of the EEType.
factory.MetadataManager.GetDependenciesDueToEETypePresence(ref dependencies, factory, _type);

if (_type is MetadataType mdType)
ModuleUseBasedDependencyAlgorithm.AddDependenciesDueToModuleUse(ref dependencies, factory, mdType.Module);
// If necessary MethodTable is the highest load level, consider this a module use
if (_type is MetadataType mdType)
ModuleUseBasedDependencyAlgorithm.AddDependenciesDueToModuleUse(ref dependencies, factory, mdType.Module);
}

if (_type.IsFunctionPointer)
FunctionPointerMapNode.GetHashtableDependencies(ref dependencies, factory, (FunctionPointerType)_type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ public override IEnumerable<DependencyListEntry> GetStaticDependencies(NodeFacto
result.Add(factory.ExternSymbol("RhpInitialDynamicInterfaceDispatch"), "Initial interface dispatch stub");
}

result.Add(factory.NecessaryTypeSymbol(_targetMethod.OwningType), "Interface type");
// We counter-intuitively ask for a constructed type symbol. This is needed due to IDynamicInterfaceCastable.
// If this dispatch cell is ever used with an object that implements IDynamicIntefaceCastable, user code will
// see a RuntimeTypeHandle representing this interface.
result.Add(factory.ConstructedTypeSymbol(_targetMethod.OwningType), "Interface type");

return result;
}
Expand All @@ -88,7 +91,10 @@ public override void EncodeData(ref ObjectDataBuilder objData, NodeFactory facto
objData.EmitPointerReloc(factory.ExternSymbol("RhpInitialDynamicInterfaceDispatch"));
}

IEETypeNode interfaceType = factory.NecessaryTypeSymbol(_targetMethod.OwningType);
// We counter-intuitively ask for a constructed type symbol. This is needed due to IDynamicInterfaceCastable.
// If this dispatch cell is ever used with an object that implements IDynamicIntefaceCastable, user code will
// see a RuntimeTypeHandle representing this interface.
IEETypeNode interfaceType = factory.ConstructedTypeSymbol(_targetMethod.OwningType);
if (factory.Target.SupportsRelativePointers)
{
if (interfaceType.RepresentsIndirectionCell)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ public override IEnumerable<ModuleDesc> GetCompilationModulesWithMetadata()
private IEnumerable<TypeDesc> GetTypesWithRuntimeMapping()
{
// All constructed types that are not blocked get runtime mapping
foreach (var constructedType in GetTypesWithEETypes())
foreach (var constructedType in GetTypesWithConstructedEETypes())
{
if (!IsReflectionBlocked(constructedType))
yield return constructedType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public static void Run()
Console.WriteLine(s_type == typeof(Never));

#if !DEBUG
ThrowIfPresentWithUsableMethodTable(typeof(TestTypeEquals), nameof(Never));
ThrowIfPresent(typeof(TestTypeEquals), nameof(Never));
#endif
}
}
Expand Down Expand Up @@ -371,7 +371,7 @@ public static void Run()

// We only expect to be able to get rid of it when optimizing
#if !DEBUG
ThrowIfPresentWithUsableMethodTable(typeof(TestBranchesInGenericCodeRemoval), nameof(Unused));
ThrowIfPresent(typeof(TestBranchesInGenericCodeRemoval), nameof(Unused));
#endif
ThrowIfNotPresent(typeof(TestBranchesInGenericCodeRemoval), nameof(Used));

Expand Down
Loading