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

Ensure we recompute top level semantic versions, even when making frozen documents #65820

Merged
merged 6 commits into from
Dec 7, 2022

Conversation

CyrusNajmabadi
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi commented Dec 6, 2022

Potential fix for an NFW we're seeing in speedometer. And, even if it doesn't help there, it certainly makes this code saner and properly in line with invariants we expect.

@@ -872,7 +872,7 @@ public ProjectState RemoveAllDocuments()
analyzerConfigSet: ComputeAnalyzerConfigOptionsValueSource(AnalyzerConfigDocumentStates));
}

public ProjectState UpdateDocument(DocumentState newDocument, bool textChanged, bool recalculateDependentVersions)
public ProjectState UpdateDocument(DocumentState newDocument, bool contentChanged)
Copy link
Member Author

Choose a reason for hiding this comment

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

merged these to one value. if hte content changed we need to recalculateDependentVersions, and if it didn't, we don't.

// We're changing the text of this document to something else entirely. So we need to pass
// `textChanged: true, recalculateDependentVersions: true` so that any interested parties that
// compute anything that is dependent on changed text get the right values.
inProgressProject = inProgressProject.UpdateDocument(docState, contentChanged: true);
Copy link
Member Author

Choose a reason for hiding this comment

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

this is the crux of the fix. it was possible to take a prior syntax tree for this doc and update ourselves with it, but then say there was no change, so top-level-versions might be incorrect. We have a supposition this is what's leading to the nfw.

@@ -1431,10 +1431,10 @@ public SolutionState UpdateAnalyzerConfigDocumentTextLoader(DocumentId documentI
return UpdateAnalyzerConfigDocumentState(oldDocument.UpdateText(loader, mode));
}

private SolutionState UpdateDocumentState(DocumentState newDocument, bool textChanged = false, bool recalculateDependentVersions = false)
Copy link
Member Author

Choose a reason for hiding this comment

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

reason 10 that optional parameters can be really bad.

Copy link
Member

@jasonmalinowski jasonmalinowski left a comment

Choose a reason for hiding this comment

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

Comments are only further places there could be some tweaking, but this could merge in this current form if needed.

return UpdateAdditionalDocumentState(oldDocument.UpdateText(loader, mode), textChanged: true, recalculateDependentVersions: true);
// Assumes that content has changed. User could have closed a doc without saving and we are loading text
// from closed file with old content.
return UpdateAdditionalDocumentState(oldDocument.UpdateText(loader, mode), contentChanged: true);
Copy link
Member

Choose a reason for hiding this comment

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

What does contentChanged control here in the case of additional files? I wouldn't have imagined it mattered, but if it does, why isn't there one in the analyzer config method right below this one?

Copy link
Member Author

Choose a reason for hiding this comment

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

so, in the end, it shouldn't matter as any attempt to get things like top-level versions will bail out immediately and return the normal text-version since these docs don't 'SupportSyntax'. But i wanted to be consistent here around the concept that is happening. There are doc changes that change contents, and doc changes that don't. We should flow that along, and have any smarts happen later.

Copy link
Member Author

Choose a reason for hiding this comment

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

Specifically, this will end up bottoming out here:

            if (_treeSource == null)
            {
                return await GetTextVersionAsync(cancellationToken).ConfigureAwait(false);
            }

So it's all ok. But, for example, if we ever stored info with these docs, we'd want to know when they actually chnaged so we could properly dump it and recompute.

src/Workspaces/CoreTest/SolutionTests/SolutionTests.cs Outdated Show resolved Hide resolved
src/Workspaces/CoreTest/SolutionTests/SolutionTests.cs Outdated Show resolved Hide resolved
src/Workspaces/CoreTest/SolutionTests/SolutionTests.cs Outdated Show resolved Hide resolved
src/Workspaces/CoreTest/SolutionTests/SolutionTests.cs Outdated Show resolved Hide resolved
@CyrusNajmabadi CyrusNajmabadi merged commit 369f361 into dotnet:main Dec 7, 2022
@ghost ghost added this to the Next milestone Dec 7, 2022
@CyrusNajmabadi CyrusNajmabadi deleted the frozenChange branch December 7, 2022 02:58
@Cosifne Cosifne modified the milestones: Next, 17.5 P3 Jan 4, 2023
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