Skip to content
This repository was archived by the owner on Nov 1, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
34 changes: 29 additions & 5 deletions src/Common/src/TypeSystem/Common/TypeSystemHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,16 @@ public static MethodDesc FindVirtualFunctionTargetMethodOnObjectType(this TypeDe
}

/// <summary>
/// Given Foo&lt;T&gt;, returns Foo&lt;!0&gt;.
/// Creates an open instantiation of a type. Given Foo&lt;T&gt;, returns Foo&lt;!0&gt;.
/// If the type is not generic, returns the <paramref name="type"/>.
/// </summary>
private static InstantiatedType InstantiateAsOpen(this MetadataType type)
public static TypeDesc InstantiateAsOpen(this TypeDesc type)
Copy link
Member

Choose a reason for hiding this comment

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

I believe this terminology for Open is quite confusing. It really means instantiate such that if the type parameters from an open instantiation were substituted in, the result would be the same as the type definition. Which is really bizarre. (The open instantiation is used to refer to the uninstantiated form in a number of documents, and is the same thing as the typical instantiation.)

{
Debug.Assert(type.IsGenericDefinition);
if (!type.IsGenericDefinition)
{
Debug.Assert(!type.HasInstantiation);
return type;
}

TypeSystemContext context = type.Context;

Expand All @@ -280,7 +285,26 @@ private static InstantiatedType InstantiateAsOpen(this MetadataType type)
inst[i] = context.GetSignatureVariable(i, false);
}

return context.GetInstantiatedType(type, new Instantiation(inst));
return context.GetInstantiatedType((MetadataType)type, new Instantiation(inst));
}

/// <summary>
/// Creates an open instantiation of a field. Given Foo&lt;T&gt;.Field, returns
/// Foo&lt;!0&gt;.Field. If the owning type is not generic, returns the <paramref name="field"/>.
/// </summary>
public static FieldDesc InstantiateAsOpen(this FieldDesc field)
Copy link
Member

Choose a reason for hiding this comment

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

Same naming issue as above. I don't have a good name, but I don't like Open.

{
Debug.Assert(field.GetTypicalFieldDefinition() == field);

TypeDesc owner = field.OwningType;

if (owner.HasInstantiation)
{
var instantiatedOwner = (InstantiatedType)owner.InstantiateAsOpen();
return field.Context.GetFieldForInstantiatedType(field, instantiatedOwner);
}

return field;
}

/// <summary>
Expand All @@ -295,7 +319,7 @@ public static MethodDesc InstantiateAsOpen(this MethodDesc method)

if (owner.HasInstantiation)
{
MetadataType instantiatedOwner = ((MetadataType)owner).InstantiateAsOpen();
MetadataType instantiatedOwner = (MetadataType)owner.InstantiateAsOpen();
return method.Context.GetMethodForInstantiatedType(method, (InstantiatedType)instantiatedOwner);
}

Expand Down
Loading