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

Always make sure we have the right comparer for DocumentIds #53603

Conversation

jasonmalinowski
Copy link
Member

I believe this fixes #52698, although I don't have a dump for that issue so I'm having to deduce what I think happened based on the stack alone. Unfortunately the stack also has some frames inlined so there's a bit more guessing than usual:

The stack shows that we ended up in Comparer.Compare and it threw; the only exception that it throws directly if the thing being compared isn't IComparable. There aren't many uses of ImmutableSortedDictionary in Roslyn, but the one specific one that makes sense to be under GetDocumentState is the one we have inside our TextDocumentStates type. And that one is one where we normally pass in a custom comparer to pass in DocumentIds, so it seems logical that we somehow ended up with a map that didn't have our comparer.

It turns out the Empty member we had didn't specify one, so if we started with the Empty member and then added stuff from there, we'd end up with such a map without a comparer. Why didn't we see this right away? Because it turns out we only have a few uses of .Empty, most of which are with source generated files. And even then we often are creating the source generated collections with something else.

I believe this fixes dotnet#52698,
although I don't have a dump for that issue so I'm having to deduce
what I think happened based on the stack alone. Unfortunately the stack
also has some frames inlined so there's a bit more guessing than usual:

The stack shows that we ended up in Comparer.Compare and it threw; the
only exception that it throws directly if the thing being compared
isn't IComparable. There aren't many uses of ImmutableSortedDictionary
in Roslyn, but the one specific one that makes sense to be under
GetDocumentState is the one we have inside our TextDocumentStates type.
And that one is one where we normally pass in a custom comparer to pass
in DocumentIds, so it seems logical that we somehow ended up with
a map that didn't have our comparer.

It turns out the Empty member we had didn't specify one, so if we
started with the Empty member and then added stuff from there, we'd end
up with such a map without a comparer. Why didn't we see this right
away? Because it turns out we only have a few uses of .Empty, most
of which are with source generated files. And even then we often are
creating the source generated collections with something else.
@jasonmalinowski jasonmalinowski requested a review from tmat May 21, 2021 22:06
@jasonmalinowski jasonmalinowski self-assigned this May 21, 2021
@jasonmalinowski jasonmalinowski requested a review from a team as a code owner May 21, 2021 22:06
@jasonmalinowski
Copy link
Member Author

@jinujoseph Low risk fix for 16.11. Should fix a very peculiar crash @CyrusNajmabadi saw in 16.10, although we haven't seen many hits since.

@jasonmalinowski jasonmalinowski merged commit e9c506c into dotnet:release/dev16.11 May 25, 2021
@jasonmalinowski jasonmalinowski deleted the fix-textdocumentstates-potentially-having-no-comparer branch May 25, 2021 14:34
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.

4 participants