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

Update Project.HasSuccessfullyLoadedAsync logic #66569

Merged
merged 4 commits into from
Feb 2, 2023

Conversation

mavasani
Copy link
Contributor

@mavasani mavasani commented Jan 27, 2023

Fixes AB#1674516
Fixes AB#1710989
Fixes AB#1665787
Fixes spurious missing corlib types errors in the error list on loading any decently large solution, such as Roslyn.sln itself. These errors stay in the error list for few seconds before metadata references get added to the project

Our current logic in the CompilationTracker to determine hasSuccessfullyLoaded for the project relies on the ProjectState.HasAllInformation flag to determine if the project has loaded successfully. Additionally, we try to convert the project references to metadata references, and failing such a conversion, we reset hasSuccessfullyLoaded to false. However, there seem to be cases during project load where ProjectState.HasAllInformation is true, but metadata references haven't yet been added to the project, leading to hundreds of spurious missing type errors for corlib types such as object, int, string, etc.

This PR updates the logic for hasSuccessfullyLoaded to also check if the project either has non-zero metadata references or is the corlib itself (defines System.Object). I confirmed that this fixes all the repro cases/bugs cited above. I no longer see any spurious errors in the error list or squiggles in the editor for all these scenarios.

return;

using var _ = PooledHashSet<Project>.GetInstance(out var seenProjects);
if (!HasSuccessfullyLoaded(document.Project, seenProjects))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We do not need this check in the tagger as this is already checked in the core executor:

// if project is not loaded successfully then, we disable semantic errors for compiler analyzers
var isCompilerAnalyzer = analyzer.IsCompilerAnalyzer();
if (kind != AnalysisKind.Syntax && isCompilerAnalyzer)
{
var isEnabled = await textDocument.Project.HasSuccessfullyLoadedAsync(cancellationToken).ConfigureAwait(false);
Logger.Log(FunctionId.Diagnostics_SemanticDiagnostic, (a, d, e) => $"{a}, ({d.Id}, {d.Project.Id}), Enabled:{e}", analyzer, textDocument, isEnabled);
if (!isEnabled)
{
return SpecializedCollections.EmptyEnumerable<DiagnosticData>();
}
}

@mavasani
Copy link
Contributor Author

Tagging @arkalyanms - if the code change gets approved, do we want to consider this for 17.5?

// For the latter, we use a heuristic if the underlying compilation defines "System.Object" type.
var hasSuccessfullyLoaded = this.ProjectState.HasAllInformation &&
(this.ProjectState.MetadataReferences.Count > 0 ||
compilationWithoutGenerators.GetTypeByMetadataName("System.Object") != null);
Copy link
Member

Choose a reason for hiding this comment

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

i don't mind this to fix the issue. but i am curious if this indicates a bug with the PS since they're the ones telling us that all info is available, even if no metadata refs are tehre. Should we be telling them there's an issue on their side? @jasonmalinowski ?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, if we're seeing HasAllInformation = true and no references, that's technically a project system bug. That all said, this might be a good tactical fix for 17.5 while we chase down the source of that problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The thing that is more concerning for me is project system is never calling the setter for “IWorkspaceProjectContext.LastDesignTimeBuildSucceeded” (neither true nor false) and we always have the default true value for HasAllInformation.

Copy link
Member

Choose a reason for hiding this comment

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

Lets open a PS bug to track for 17.6.

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.

Signing off, at least as a tactical fix for 17.5. @CyrusNajmabadi is correct that if we see this state that's really a project system bug or a bug somewhere higher up. But chasing that down to fix might be too much of trouble for 17.5 at least.

So signing off, but I won't be sad if we want to not take this and instead try to root-cause further.

Fixes [AB#1674516](https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1674516)
Fixes [AB#1710989](https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1710989)
Fixes spurious missing corlib types errors in the error list on loading any decently large solution, such as Roslyn.sln itself. These errors stay in the error list for few seconds before metadata references get added to the project

Our current logic in the CompilationTracker to determine `hasSuccessfullyLoaded` for the project relies on the `ProjectState.HasAllInformation` flag to determine if the project has loaded successfully. Additionally, we try to convert the project references to metadata references, and failing such a conversion, we reset `hasSuccessfullyLoaded` to false. However, there seem to be cases during project load where `ProjectState.HasAllInformation` is true, but metadata references haven't yet been added to the project, leading to hundreds of spurious missing type errors for corlib types such as object, int, string, etc.

This PR updates the logic for `hasSuccessfullyLoaded` to also check if the project either has non-zero metadata references or is the corlib itself (defines `System.Object`). I confirmed that this fixes all the 3 repro cases/bugs cited above. I no longer see any spurious errors in the error list or squiggles in the editor for all these scenarios.
@mavasani mavasani force-pushed the SemanticDiagnostics branch from 7f6e455 to 9cae144 Compare January 27, 2023 11:45
@mavasani mavasani changed the base branch from main to release/dev17.5 January 27, 2023 11:46
@mavasani mavasani dismissed jasonmalinowski’s stale review January 27, 2023 11:46

The base branch was changed.

@mavasani
Copy link
Contributor Author

Signing off, at least as a tactical fix for 17.5.

Thanks! Rebased the PR to release/dev17.5 @arkalyanms to make a call about whether we want to take this tactical fix for 17.5 or let Jason/ProjectSystem team to figure out a more appropriate fix.

@arunchndr
Copy link
Member

Yes let's take this for 17.5. There is a fair bit of feedback around this.

@arunchndr arunchndr merged commit 8fa912d into dotnet:release/dev17.5 Feb 2, 2023
@mavasani mavasani deleted the SemanticDiagnostics branch February 2, 2023 05:58
@CyrusNajmabadi
Copy link
Member

This needs to flow into Main. What process ensures that?

@sharwell
Copy link
Member

sharwell commented Feb 9, 2023

@CyrusNajmabadi The branch flows release/dev17.5 to release/dev17.5-vs-deps (latest PR #66766). Once that completes, it will flow to release/dev17.6. Once that completes, it will flow to main.

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.

5 participants