Skip to content

Additional text document state#54084

Closed
sharwell wants to merge 10 commits intodotnet:features/source-generatorsfrom
sharwell:additional-text-document-state
Closed

Additional text document state#54084
sharwell wants to merge 10 commits intodotnet:features/source-generatorsfrom
sharwell:additional-text-document-state

Conversation

@sharwell
Copy link
Copy Markdown
Contributor

Follow-up to #53709

jasonmalinowski and others added 10 commits June 8, 2021 16:04
This was null-returning originally because generators were a preview
feature and we didn't want to create GeneratorDrivers when the preview
feature was disabled. Then we used kept it when C# had generators but
not VB. At this point any language that creates Compilations always
creates generators, so we can simplify.
We're going to need to be managing instances more carefully, so keep a
1:1 mapping between them. A ConditionalWeakTable here isn't the best
way to be doing this, since we own the type that's the key, but our
inheritance structure is a bit odd: TextDocumentState is used as a base
type for some things (like regular files) but is also used directly as
a type for additional files. We really should introduce a new derived
type to directly represent additional files, but that's a more invasive
change.
Right now we were simply creating a new GeneratorDriver every time we
needed to run generators; now that the compiler supports an incremental
API we need to hold onto the GeneratorDriver between runs so it can
cache inputs smartly.

For the most part the change is simple: we simply hold onto the
GeneratorDriver once we're done running generators, and just give it
a new compilation when we want to incrementally run. The only real
"tricky" bit is there are some pieces of state that aren't held by
the compiler, but rather by the GeneratorDriver itself, namely:

1. The list of generators to themselves.
2. The list of additional files -- that's simply not held by a
   Compilation at all.
3. The parse options that's used for parsing generated files -- you
   can't get ParseOptions from the CompilationOptions.
4. The parsed .editorconfigs.

These are precisely the same pieces of state that are passed to
GeneratorDriver.Create when we initially create one. For these pieces
of state, if they're changing we need to also update the GeneratorDriver
itself with the APIs that exist on GeneratorDriver along when we
incrementally update a Compilation. To do this we transform the
GeneratorDriver the same way we do a Compilation through in-progress
states. Currently, there's some APIs missing on the GeneratorDriver
API, so sometimes we just drop the driver entirely which will force
a rerun from scratch after those happen.
@ghost ghost added the Area-IDE label Jun 14, 2021
@jcouv jcouv closed this Jun 17, 2021
@jcouv jcouv deleted the branch dotnet:features/source-generators June 17, 2021 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants