Skip to content

Commit

Permalink
Ensure Array.CreateInstance for reference types works (dotnet#101048)
Browse files Browse the repository at this point in the history
Follow up to dotnet#100626. The original fix only worked for unoptimized builds because the list of templates doesn't survive from scanning phase (when we do dataflow) to codegen phase (when we no longer do dataflow).

The test that this was supposed to fix is still failing in dotnet#100331.
  • Loading branch information
MichalStrehovsky authored Apr 16, 2024
1 parent 5266d98 commit 5a6560a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ public static bool HandleCall(
{
// We could try to analyze if the type is known, but for now making sure this works for canonical arrays is enough.
TypeDesc canonArrayType = reflectionMarker.Factory.TypeSystemContext.CanonType.MakeArrayType();
reflectionMarker.Dependencies.Add(reflectionMarker.Factory.NativeLayout.TemplateTypeLayout(canonArrayType), "Array.CreateInstance was called");
reflectionMarker.MarkType(diagnosticContext.Origin, canonArrayType, "Array.CreateInstance was called");
goto case IntrinsicId.None;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,17 @@ public ReflectedTypeNode(TypeDesc type)

public override IEnumerable<DependencyListEntry> GetStaticDependencies(NodeFactory factory)
{
return new DependencyListEntry[]
{
new DependencyListEntry(factory.MaximallyConstructableType(_type), "Reflection target"),
};
var result = new DependencyList
{
new DependencyListEntry(factory.MaximallyConstructableType(_type), "Reflection target"),
};

if (_type.IsCanonicalSubtype(CanonicalFormKind.Any))
{
GenericTypesTemplateMap.GetTemplateTypeDependencies(ref result, factory, _type);
}

return result;
}
protected override string GetName(NodeFactory factory)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,12 @@ public bool IsReflectionBlocked(TypeDesc type)
case TypeFlags.Array:
case TypeFlags.Pointer:
case TypeFlags.ByRef:
return IsReflectionBlocked(((ParameterizedType)type).ParameterType);
TypeDesc parameterType = ((ParameterizedType)type).ParameterType;

if (parameterType.IsCanonicalDefinitionType(CanonicalFormKind.Any))
return false;

return IsReflectionBlocked(parameterType);

case TypeFlags.FunctionPointer:
MethodSignature pointerSignature = ((FunctionPointerType)type).Signature;
Expand Down

0 comments on commit 5a6560a

Please sign in to comment.