Skip to content
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

Account for possible cache invalidation on a different thread in assert. #59635

Closed
wants to merge 0 commits into from

Conversation

333fred
Copy link
Member

@333fred 333fred commented Feb 18, 2022

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.

@333fred 333fred requested a review from a team as a code owner February 18, 2022 01:03
@@ -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
Copy link
Contributor

@AlekseyTs AlekseyTs Feb 18, 2022

Choose a reason for hiding this comment

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

// Could fail if the type was already evicted from the cache

Technically, I think it is possible that the type got evicted and then a different instance got added by other threads. #Closed

Copy link
Contributor

Choose a reason for hiding this comment

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

Or if we add a type we should always get the same instance?

Copy link
Member Author

Choose a reason for hiding this comment

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

Or if we add a type we should always get the same instance?

I believe it should always be the same instance. This API effectively just walks through every assembly and looks for the member symbols from the assembly, and (in C#) gets the public version. Those should not be changing.

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM (commit 1)

@AlekseyTs
Copy link
Contributor

@dotnet/roslyn-compiler For the second review.

@333fred
Copy link
Member Author

333fred commented Feb 24, 2022

@dotnet/roslyn-compiler for a second review please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants