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

Fix issue with frozen-partial snapshots having incomplete references. #73205

Merged
merged 1 commit into from
Apr 24, 2024

Conversation

CyrusNajmabadi
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi commented Apr 24, 2024

Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2035575

Core issue is that when producing a frozen partial snapshot, we had uniform logic for producing P2P references, regardless of whether the P2P reference was to the same language or a different language.

For frozen partial, we don't want to produce the reference to a different language, as that would involve generating skeleton assemblies. This is enormously expensive as it is effectively running the compiler and emitting the metadata to an in-memory object we then read in as a reference.

However, for the same language, making a normal P2P reference is fine (and cheap). In that case, we can just point directly at the compilation object directly, as the compilers support direct (same lang) p2p refs.

In the case of frozen-partial, because we already forked all compilation-trackers to not run generators or produce skeletons, asking for the compilation for the reference will not incur those costs (transitively). So frozen partial will still be fast for the mainline case, while avoiding the massive expensvie of SGs and Skeletons at all levels.

--

This was breaking a cross project winforms case when the project config was changed. Namely, after changing the project config, we would try to determine which were the designable types in the solution. Finding a type X in P1, we would then try to walk its inheritance chain. If that type X inherited from a type Y in P2, and we hadn't produced a viable P2P ref for that, we'd end up with error types, breaking the designable type detection rules.

In the case here, while we had a P2P ref, because we simply snapped that P2P ref at the point it was at, we never did things like properly add all the metadata-references that project had, leading to a referenced compilation with sources in it, but no metadata.

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner April 24, 2024 00:53
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 24, 2024
{
// if we have a compilation and its the correct language, use a simple compilation reference in any
// state it happens to be in right now
if (ReadState() is CompilationTrackerState compilationState)
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 was the crux of the bug. the CompilationTrackerState we fetched here would have the compilations containing the source-documents, but not the referenced metadata (either PE references, or P2P references).

I considered updating this logic to add that in. But that would then effectively be doing what FinalizeCompilation already does. So i uniformly handled it at that layer.

@@ -1046,6 +1028,9 @@ public Task<bool> HasSuccessfullyLoadedAsync(ProjectState project, CancellationT
return compilation.ToMetadataReference(projectReference.Aliases, projectReference.EmbedInteropTypes);
}
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 now always succeed when it's from teh same language. the call to tracker.GetCompilationAsync above will ensure that you get back a compilation with all the references properly added (modulo respecting the 'generate skeletons' flag).

@CyrusNajmabadi CyrusNajmabadi requested a review from dibarbet April 24, 2024 00:58
Copy link
Contributor

@ToddGrun ToddGrun left a comment

Choose a reason for hiding this comment

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

:shipit:

@CyrusNajmabadi CyrusNajmabadi merged commit 90d27e0 into dotnet:main Apr 24, 2024
25 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the partialCompilations branch April 24, 2024 04:46
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Apr 24, 2024
@CyrusNajmabadi
Copy link
Member Author

@jasonmalinowski For review when you get back.

@dibarbet dibarbet modified the milestones: Next, 17.11 P1 Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants