Skip to content

Conversation

@dibarbet
Copy link
Member

@dibarbet dibarbet commented Jul 22, 2025

… balanced mode

Resolves #75586

Support for this was originally added in #77271
However it seems like Project.GetDependentVersionAsync changed to no longer increment when the sg execution version changed, and due to a test issue, the problem was not caught.

Now:
sg_refresh

clean val - https://dev.azure.com/devdiv/DevDiv/_git/VS/pullrequest/656041

public override async Task<(int globalStateVersion, VersionStamp? dependentVersion, Checksum? executionVersion)> ComputeCheapVersionAsync(DiagnosticsRequestState state, CancellationToken cancellationToken)
{
return (state.GlobalStateVersion, await state.Project.GetDependentVersionAsync(cancellationToken).ConfigureAwait(false));
Checksum? executionVersion = state.Project.Solution.CompilationState.SourceGeneratorExecutionVersionMap.Map.TryGetValue(state.Project.Id, out var sourceGeneratorExecutionVersion) ?
Copy link
Member Author

@dibarbet dibarbet Jul 22, 2025

Choose a reason for hiding this comment

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

This was the problem - the cheap version is not incrementing when the sg execution version changed (the expensive one did and does, that was added in #77271).

A couple of alternatives to this, not sure if they are better

  1. Project.GetDependentVersionAsync could include the execution version (may have downstream impacts on other callers)
  2. Remove the cheap version check entirely in favor of Project.GetDiagnosticChecksumAsync which checks execution version. Downside is potentially more computation of the checksums

Copy link
Member

Choose a reason for hiding this comment

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

1 seems possible. Though I'm not actually sure how it would work. Wouls the sg execution map also map to a Version that changed whenever the value charged?

That actually seems somewhat reasonable...

I do like 2 though. It just removes complexity here. I'm not concerned about checksum cost. We're constantly computing (and caching those values), so I don't think this fast path is generally that helpful.

So let's do 2.

Copy link
Member Author

Choose a reason for hiding this comment

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

  1. works for me, and the same checksums are also getting computed for code actions quite frequently anyway already.

@dibarbet dibarbet marked this pull request as ready for review July 22, 2025 01:14
@dibarbet dibarbet requested a review from a team as a code owner July 22, 2025 01:14
@CyrusNajmabadi
Copy link
Member

CyrusNajmabadi commented Jul 22, 2025 via email

@dibarbet
Copy link
Member Author

Also, I realize I'm not understanding something. The point of the two
checks is so that we could fast path knowing if something changed. So if
the version check says "it changed" then we recompute. That's cheap and
let's us easily recompute for many ops. But if the version says it is the
same, then we need to do the full and accurate checksum check.

Not quite that - if the cheap check matches, that is supposed to mean that definitely nothing changed (because its essentially the versionstamp which almost always increments on anything changed). Then if the cheap check does not match, we do the more expensive checksum check to see if anything is different that might affect diagnostics.

@CyrusNajmabadi
Copy link
Member

if the cheap check matches, that is supposed to mean that definitely nothing changed (
oh.

well in that case, we def need executionmap info to roll into the 'version' info for a project. that's morally fine.

--

but, i would love to get us onto checksums entirely. versionstamps are just... bleagh :)

@dibarbet dibarbet merged commit c510ecf into dotnet:main Jul 28, 2025
25 checks passed
@dibarbet dibarbet deleted the sg_refresh_save branch July 28, 2025 18:11
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Jul 28, 2025
@RikkiGibson RikkiGibson modified the milestones: Next, 18.0 P1 Aug 19, 2025
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.

Balanced Source Generator mode does not work on saving

3 participants