Skip to content

Fix TypeSpec discovery and listing #194

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

Merged
merged 1 commit into from
Jun 3, 2025
Merged
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
71 changes: 63 additions & 8 deletions MetadataProcessor.Shared/Tables/nanoTypeSpecificationsTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,26 @@ private void FillTypeSpecsFromMemberReferences()
}
}
}

// make sure we pick up *all* GenericInstanceType that we know
// about via MethodSpecificationTable as well as TypeReferencesTable
IEnumerable<TypeReference> allGenericInstances =
_context.MethodSpecificationTable.Items
.OfType<GenericInstanceMethod>()
.Select(ms => ms.DeclaringType as GenericInstanceType)
.Concat(_context.TypeReferencesTable.Items.OfType<GenericInstanceType>())
.Where(git => git != null)
.Distinct(new TypeReferenceEqualityComparer(_context));

foreach (TypeReference typeRefItem in allGenericInstances)
{
if (!_idByTypeSpecifications.ContainsKey(typeRefItem))
{
ushort sigId = _context.SignaturesTable.GetOrCreateSignatureId(typeRefItem);
_idByTypeSpecifications.Add(typeRefItem, sigId);
ExpandNestedTypeSpecs(typeRefItem);
}
}
}

private void FillTypeSpecsFromTypes()
Expand All @@ -271,10 +291,39 @@ private void FillTypeSpecsFromTypes()
{
AddIfNew(gp, _context.SignaturesTable.GetOrCreateSignatureId(gp));
}
else if (instr.Operand is MethodReference mr)
{
// register return‐type...
ExpandNestedTypeSpecs(mr.ReturnType);

// ... and parameters
foreach (ParameterDefinition p in mr.Parameters)
{
ExpandNestedTypeSpecs(p.ParameterType);
}
}

// catch field‐refs too
else if (instr.Operand is FieldReference fieldRef)
{
ExpandNestedTypeSpecs(fieldRef.DeclaringType);
ExpandNestedTypeSpecs(fieldRef.FieldType);
}
else if (instr.Operand is GenericInstanceMethod genericInstanceMethod)
{
GenericInstanceType genericInstanceType = genericInstanceMethod.DeclaringType as GenericInstanceType;
if (genericInstanceType != null && !_idByTypeSpecifications.ContainsKey(genericInstanceType))
{
ushort sigId = _context.SignaturesTable.GetOrCreateSignatureId(genericInstanceType);
_idByTypeSpecifications.Add(genericInstanceType, sigId);

// also pull in its element‐type and args
ExpandNestedTypeSpecs(genericInstanceType);
}
}
else if (instr.Operand is TypeReference tr)
{
// refuse multi-dimensional arrays
// we only support jagged arrays
// refuse multi-dimensional arrays (we only support jagged arrays)
if (tr.IsArray)
{
var at = (ArrayType)tr;
Expand All @@ -286,12 +335,15 @@ private void FillTypeSpecsFromTypes()
}
}

// register the type reference itself...
ushort sigId = _context.SignaturesTable.GetOrCreateSignatureId(tr);
AddIfNew(tr, sigId);
// register the type reference itself, if it is a TypeSpec
if (tr is TypeSpecification)
{
ushort sigId = _context.SignaturesTable.GetOrCreateSignatureId(tr);
AddIfNew(tr, sigId);

// ... then walk *into* any nested TypeSpecifications it might contain
ExpandNestedTypeSpecs(tr);
// also walk into any nested TypeSpecifications it might contain
ExpandNestedTypeSpecs(tr);
}
}
}
}
Expand All @@ -316,7 +368,10 @@ private void ExpandNestedTypeSpecs(TypeReference t)
case GenericInstanceType git:
inner = git.ElementType;
foreach (var arg in git.GenericArguments)
{
ExpandNestedTypeSpecs(arg);
}

break;

case ArrayType at:
Expand All @@ -340,7 +395,7 @@ private void ExpandNestedTypeSpecs(TypeReference t)
break;
}

if (inner != null)
if (inner is TypeSpecification)
{
ushort innerId = _context.SignaturesTable.GetOrCreateSignatureId(inner);
AddIfNew(inner, innerId);
Expand Down
Loading