-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Unreadable documents no longer exist in the Compilation #41190
Comments
Yeah... the part that worries me the most is that this seems like making major inconsistencies between things that used to be consistent.
|
Yes. I would probably model this as a SyntaxTree either with a bit saying "i'm borked" or some critical diagnostic on it saying "i'm borked". |
So if you can't read a file, the Document's text is empty. Previously you had no good way to figure that out, but @tmat's change does add a sane API to ask that which is fantastic. It's more the "what does this mean for the Compilation?" that's the question. |
I don't imagine it's hugely widespread. That said, this sort of inconsistency is pretty awful thing to absorb. Primarily because it's just so trivial for people to hold this expectation in their head and not have a landmind waiting to go off. |
Representing an unreadable Document as having 'empty text' seems totally sensible to me. You'll get an empty tree, and you'll have a compilation that contains that empty tree. |
IMO, the right level of abstraction here is all at the Document level (and the tools tha tprocess that). The compiler layer should be blissfully unaware of this and should just expose a model where all its constituent parts still make sense together. |
The IDE reports diagnostic for the unreadable document. Running analyzers on the empty syntax tree might result in errors that are confusing to the user. We can re-establish the invariant, which was not documented or tested anywhere BTW, by marking the tree as "generated" or in some other way making the analyzer driver to skip it. |
Definitely a pity. I think that likely fell into the: if this changes, we're screwed camp. We should be better about actually ensuring there is some sort of test for that sort of thing. Several people who worked on these designs aren't around anymore. So it's hard to tell what actually has testing and what does not but just became a baked in assumption over time. |
That seems a worthwhile place to go for me. |
Moving to 16.5.P3 now that we also have internal crashes that may be related. |
The design review on Monday concluded that we should keep the tree there, and mark it as generated (which, in a very pedantic sense, the fake empty file is generated). |
#40044 made a change to our API behavior. Previously, if a Document could not be read, a syntax tree would still be placed in the Compilation that was empty. Now, simply no syntax tree exists anymore. This means that this assertion is no longer valid:
I did have some unit tests that implicitly depended on this which were broken by the change, which is what alerted me to the break. @tmat's motivation for the change was to prevent an analyzer (say "you need a file header") from running on files that couldn't be loaded, but I'm wondering if that's better achieved by leaving the syntax tree there and just not running diagnostics (i.e. treat it as a generated file, since yes, the fake empty file is "generated!").
There is other code out there that is doing ContainsSyntaxTree() and in some cases asserting if the tree doesn't exist in the compilation, for example here:
roslyn/src/Features/Core/Portable/LanguageServices/SymbolDisplayService/AbstractSymbolDisplayService.AbstractSymbolDescriptionBuilder.cs
Lines 122 to 141 in 6cb854a
Other code making similar assumptions is now broken if there's an unreadable file. I'm not sure how widespread that might be, but I'm not sure if we need to do a different approach to prevent the breaks being seen.
As a background, the original motivation for stubbing in the empty file was to ensure that the exceptional case doesn't result in Compilation inconsistencies: anybody processing a single snapshot might not be processing "real" source but won't see some inconsistency which results in crashes.
The text was updated successfully, but these errors were encountered: