Skip to content

Commit 697cd3d

Browse files
authored
Improve FillTypeSpecsFromTypes (#204)
***NO_CI***
1 parent e7a0cc4 commit 697cd3d

File tree

1 file changed

+38
-17
lines changed

1 file changed

+38
-17
lines changed

MetadataProcessor.Shared/Tables/nanoTypeSpecificationsTable.cs

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,45 @@ private void FillTypeSpecsFromTypes()
287287
{
288288
foreach (TypeDefinition td in _context.TypeDefinitionTable.Items)
289289
{
290+
// Fields of the type
291+
foreach (var field in td.Fields.Where(f => !f.IsLiteral))
292+
{
293+
if (field.FieldType is ArrayType array && array.ElementType is GenericParameter)
294+
{
295+
AddIfNew(field.FieldType, _context.SignaturesTable.GetOrCreateSignatureId(field.FieldType));
296+
}
297+
}
298+
290299
foreach (MethodDefinition m in td.Methods.Where(m => m.HasBody))
291300
{
292301
foreach (Instruction instr in m.Body.Instructions)
293302
{
294-
if (instr.Operand is GenericParameter gp)
303+
if (instr.Operand is GenericInstanceMethod genericInstanceMethod)
295304
{
296-
AddIfNew(gp, _context.SignaturesTable.GetOrCreateSignatureId(gp));
305+
GenericInstanceType genericInstanceType = genericInstanceMethod.DeclaringType as GenericInstanceType;
306+
if (genericInstanceType != null
307+
&& !_idByTypeSpecifications.ContainsKey(genericInstanceType)
308+
&& !genericInstanceType.IsToExclude())
309+
{
310+
ushort sigId = _context.SignaturesTable.GetOrCreateSignatureId(genericInstanceType);
311+
_idByTypeSpecifications.Add(genericInstanceType, sigId);
312+
313+
// also pull in its element‐type and args
314+
ExpandNestedTypeSpecs(genericInstanceType);
315+
}
316+
317+
// capture the *return‐type* of the instantiation (e.g. T[] for Array.Empty<T>())
318+
TypeReference returnType = genericInstanceMethod.ReturnType;
319+
ExpandNestedTypeSpecs(returnType);
320+
321+
if (returnType is ArrayType)
322+
{
323+
if (!_idByTypeSpecifications.ContainsKey(returnType.GetElementType())
324+
&& !returnType.GetElementType().IsToExclude())
325+
{
326+
AddIfNew(returnType.GetElementType(), _context.SignaturesTable.GetOrCreateSignatureId(returnType.GetElementType()));
327+
}
328+
}
297329
}
298330
else if (instr.Operand is MethodReference mr)
299331
{
@@ -306,27 +338,16 @@ private void FillTypeSpecsFromTypes()
306338
ExpandNestedTypeSpecs(p.ParameterType);
307339
}
308340
}
309-
341+
else if (instr.Operand is GenericParameter gp)
342+
{
343+
AddIfNew(gp, _context.SignaturesTable.GetOrCreateSignatureId(gp));
344+
}
310345
// catch field‐refs too
311346
else if (instr.Operand is FieldReference fieldRef)
312347
{
313348
ExpandNestedTypeSpecs(fieldRef.DeclaringType);
314349
ExpandNestedTypeSpecs(fieldRef.FieldType);
315350
}
316-
else if (instr.Operand is GenericInstanceMethod genericInstanceMethod)
317-
{
318-
GenericInstanceType genericInstanceType = genericInstanceMethod.DeclaringType as GenericInstanceType;
319-
if (genericInstanceType != null
320-
&& !_idByTypeSpecifications.ContainsKey(genericInstanceType)
321-
&& !genericInstanceType.IsToExclude())
322-
{
323-
ushort sigId = _context.SignaturesTable.GetOrCreateSignatureId(genericInstanceType);
324-
_idByTypeSpecifications.Add(genericInstanceType, sigId);
325-
326-
// also pull in its element‐type and args
327-
ExpandNestedTypeSpecs(genericInstanceType);
328-
}
329-
}
330351
else if (instr.Operand is TypeReference tr)
331352
{
332353
// refuse multi-dimensional arrays (we only support jagged arrays)

0 commit comments

Comments
 (0)