Skip to content

Commit

Permalink
Account for possible cache invalidation on a different thread in assert.
Browse files Browse the repository at this point in the history
Attempt at fixing #59395. Reviewing the codepath I don't see any other obvious points that could cause the assert to fail, so if it continues to reproduce after this change we can look at further logging to determine the root cause.
  • Loading branch information
333fred committed Feb 18, 2022
1 parent ed5caf4 commit 4570f87
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Compilers/Core/Portable/Compilation/Compilation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,9 @@ public INamedTypeSymbol CreateNativeIntegerTypeSymbol(bool signed)
{
val = CommonGetTypeByMetadataName(fullyQualifiedMetadataName);
var result = _getTypeCache.TryAdd(fullyQualifiedMetadataName, val);
Debug.Assert(result || (_getTypeCache.TryGetValue(fullyQualifiedMetadataName, out var addedType) && ReferenceEquals(addedType, val)));
Debug.Assert(result
|| !_getTypeCache.TryGetValue(fullyQualifiedMetadataName, out var addedType) // Could fail if the type was already evicted from the cache
|| ReferenceEquals(addedType, val));
}
return val;
}
Expand All @@ -1196,8 +1198,8 @@ public ImmutableArray<INamedTypeSymbol> GetTypesByMetadataName(string fullyQuali
val = getTypesByMetadataNameImpl();
var result = _getTypesCache.TryAdd(fullyQualifiedMetadataName, val);
Debug.Assert(result
|| (_getTypesCache.TryGetValue(fullyQualifiedMetadataName, out var addedArray)
&& Enumerable.SequenceEqual(addedArray, val, ReferenceEqualityComparer.Instance)));
|| !_getTypesCache.TryGetValue(fullyQualifiedMetadataName, out var addedArray) // Could fail if the type was already evicted from the cache
|| Enumerable.SequenceEqual(addedArray, val, ReferenceEqualityComparer.Instance));
}

return val;
Expand Down

0 comments on commit 4570f87

Please sign in to comment.