Skip to content

Commit

Permalink
Remove from hashtable as we return from HasOnlyBlittableFields to mak…
Browse files Browse the repository at this point in the history
…e sure we're handling our recursion check correctly.
  • Loading branch information
jkoritzinsky committed May 14, 2021
1 parent 7b935da commit 070f1e7
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions DllImportGenerator/DllImportGenerator/TypeSymbolExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,30 @@ private static bool HasOnlyBlittableFields(this ITypeSymbol type, HashSet<ITypeS
seenTypes.Add(type);
foreach (var field in type.GetMembers().OfType<IFieldSymbol>())
{
bool? fieldBlittable = field switch
if (!field.IsStatic)
{
{ IsStatic: true } => null,
{ Type: { IsReferenceType: true } } => false,
{ Type: IPointerTypeSymbol ptr } => IsConsideredBlittable(ptr.PointedAtType),
{ Type: IFunctionPointerTypeSymbol } => true,
not { Type: { SpecialType: SpecialType.None } } => IsSpecialTypeBlittable(field.Type.SpecialType),
// Assume that type parameters that can be blittable are blittable.
// We'll re-evaluate blittability for generic fields of generic types at instantation time.
{ Type: ITypeParameterSymbol } => true,
{ Type: { IsValueType: false } } => false,
_ => IsConsideredBlittable(field.Type, seenTypes)
};

if (fieldBlittable is false)
{
return false;
bool fieldBlittable = field switch
{
{ Type: { IsReferenceType: true } } => false,
{ Type: IPointerTypeSymbol ptr } => IsConsideredBlittable(ptr.PointedAtType),
{ Type: IFunctionPointerTypeSymbol } => true,
not { Type: { SpecialType: SpecialType.None } } => IsSpecialTypeBlittable(field.Type.SpecialType),
// Assume that type parameters that can be blittable are blittable.
// We'll re-evaluate blittability for generic fields of generic types at instantation time.
{ Type: ITypeParameterSymbol } => true,
{ Type: { IsValueType: false } } => false,
_ => IsConsideredBlittable(field.Type, seenTypes)
};

if (!fieldBlittable)
{
seenTypes.Remove(type);
return false;
}
}
}

seenTypes.Remove(type);
return true;
}

Expand Down

0 comments on commit 070f1e7

Please sign in to comment.