Skip to content

Use frozen partial semantics for syntax classification#60122

Merged
sharwell merged 3 commits intodotnet:mainfrom
sharwell:partial-semantics
Mar 17, 2022
Merged

Use frozen partial semantics for syntax classification#60122
sharwell merged 3 commits intodotnet:mainfrom
sharwell:partial-semantics

Conversation

@sharwell
Copy link
Copy Markdown
Contributor

@sharwell sharwell commented Mar 11, 2022

  • Update OOP classification to use frozen partial semantics when in-process request uses it
  • Update OOP navigation bars to use frozen partial semantics when in-process request uses it

Fixes AB#1488520

@sharwell sharwell requested a review from a team as a code owner March 11, 2022 20:45
@ghost ghost added the Area-IDE label Mar 11, 2022
var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false);
var (_, semanticModel) = await document.GetPartialSemanticModelAsync(cancellationToken).ConfigureAwait(false);
semanticModel ??= await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false);
AddSemanticClassifications(semanticModel, textSpan, getNodeClassifiers, getTokenClassifiers, result, options, cancellationToken);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i am wildly curious why SyntaxClassification is using semantic models at all...................................................

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, I do not have enough thumbs to thumbs-up @CyrusNajmabadi's comment here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh, or is this just confusing naming? This "syntax classification service" is doing both actual syntax classification and also semantic classification?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

oh right. it's 'Syntax' in that it's C#/VB classification, not for other languages. bleaghhhhhhhhh why is my naming so bad.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, this type handles each of the various types of classification. This change is on the semantic classification path.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@sharwell: ah, interesting. It would seem this should be either:

  1. Freezing on the OOP side then when that service is called before it makes it here.
  2. Somehow passing the frozen state across.

The latter is a strange concept in this case: even if you ignore source generators for a moment, the idea of frozen semantics is you are getting a compilation and snapshot that doesn't require any further effort to produce a Compilation. But if we remote that frozen snapshot over, we'll potentially have to spend more time syncing that snapshot on the OOP side than if we simply froze whatever OOP had in the first place.

Unless there was a reason to not freeze? @CyrusNajmabadi?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Converted to draft. I believe this needs to be rewritten with the following characteristics:

  1. OOP needs to use frozen partial semantics when in-process does
  2. OOP may use the same solution data from in-process, but the only hard requirement is we need to make sure that if the in-process solution was frozen with a specific document guaranteed, that document also exists in the frozen OOP solution

Given the weird timing approach for frozen partial semantics in process, I don't believe it's critical to force an exact match of all frozen state when making an OOP call. It's arguably more correct, but doesn't seem likely to produce visible discrepancies if/when we deviate.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How does LSP communicate that the semantics are stale and they can be refreshed?

Currently this happens via polling in VS, though there are some ongoing discussions on if we want to switch to the workspace/semanticTokens/refresh event

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, so "frozen" isn't really a persisted concept in the way that we can remote it to OOP and then have that follow a different set of semantics. If the in-proc and out-of-proc don't require the exact same semantics, then there's no reason to get fancy here: just have the out-of-proc service call the method to freeze before doing the rest of the work. Easy.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

note: i'm always worried about oop/in-proc being out of sync. but i agree if we're very careful (And at least ensure the doc we're callign on is in sync) it's likely to be a non-issue for classification.

however, we have other features using frozen-partial, where i think not-being in total sync could be a big issue. for example, nav bars use frozen partial and have results that refer to other documents. So if we did frozen-partial on both ends, but somehow were in disagreement with things like positions and wahtnot, we could have a potential race/crash.

@sharwell sharwell marked this pull request as draft March 14, 2022 16:42
@sharwell sharwell force-pushed the partial-semantics branch from b7df2bc to 16df1c7 Compare March 15, 2022 20:50
@sharwell sharwell marked this pull request as ready for review March 15, 2022 20:50
@sharwell sharwell requested a review from a team as a code owner March 15, 2022 20:50
@sharwell sharwell enabled auto-merge March 15, 2022 20:50
@genlu
Copy link
Copy Markdown
Member

genlu commented Mar 15, 2022

If I understand the discussion correctly, we'd probably need to use FrozenPartial document for import completion as well (since all completion providers are getting a frozen partial document from CompeltionService)?
RemoteExtensionMethodImportCompletionService

If so, I wonder if this is the cause of random delays we saw when calling into RemoteExtensionMethodImportCompletionService

@sharwell sharwell force-pushed the partial-semantics branch from 16df1c7 to 53c02cd Compare March 17, 2022 14:25
@sharwell sharwell merged commit 2f113a1 into dotnet:main Mar 17, 2022
@ghost ghost added this to the Next milestone Mar 17, 2022
@sharwell sharwell deleted the partial-semantics branch March 21, 2022 16:15
@allisonchou allisonchou modified the milestones: Next, 17.2.P3 Mar 28, 2022
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.

6 participants