Skip to content

Defer computing the unrooted symbol set to the point that we actually produce a final compilation to hand out.#50879

Closed
CyrusNajmabadi wants to merge 3 commits intodotnet:masterfrom
CyrusNajmabadi:deferUnrootedSet
Closed

Defer computing the unrooted symbol set to the point that we actually produce a final compilation to hand out.#50879
CyrusNajmabadi wants to merge 3 commits intodotnet:masterfrom
CyrusNajmabadi:deferUnrootedSet

Conversation

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

@CyrusNajmabadi CyrusNajmabadi commented Jan 28, 2021

Review with whitespace changes off.

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner January 28, 2021 23:44
@ghost ghost added the Area-IDE label Jan 28, 2021
@CyrusNajmabadi CyrusNajmabadi force-pushed the deferUnrootedSet branch 2 times, most recently from 4fac45d to aea9e53 Compare January 29, 2021 01:13
declarationOnlyCompilation: null,
generatedDocuments: ImmutableArray<SourceGeneratedDocumentState>.Empty,
generatedDocumentsAreFinal: false,
unrootedSymbolSet: null);
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.

i do like how all the constructors of State don't need to figure out what to pass along.

if (state.FinalCompilationWithGeneratedDocuments != null && state.FinalCompilationWithGeneratedDocuments.TryGetValue(out var compilationOpt) && compilationOpt.HasValue)
{
compilation = compilationOpt.Value;
state.InitializeUnrootedSymbolSet(compilation);
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.

i don't love that we expose compilations in effectively two separate codepaths (TryGetCompilation and GetCompilationAsync), and i need to update both. feels fragile.

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.

I'm worried there's also potentially a third place now: CompilationTracker.GetPartialMetadataReference also hands out compilations which I guess get stitched into P2P references if you're freezing some consuming project. I'm highly suspicious of that code now that I'm aware it exists because I suspect you can get compilations that hadn't called RecordAssemblySymbols on it either and that might be bad in it's own right.

I think a slightly more defensive way to write this (if this is indeed broken) is update RecordAssemblySymbols to also take a State parameter, and that method should update the the unrooted symbols for that compilation. The existing calls to RecordAssemblySymbols are updated with the states they have, and we also update GetPartialMetadataReference as well...I think.

{
return await BuildCompilationInfoAsync(solution, cancellationToken).ConfigureAwait(false);
}
}
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.

same logic as before, just extracted into helper.

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

@jasonmalinowski do you have any recommendations on how to avoid having to patch two entrypoints here. it makes me feel like this is rather fragile :(

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

@sharwell @jasonmalinowski ?

declarationOnlyCompilation: null,
generatedDocuments,
generatedDocumentsAreFinal: false, // since we have a set of transformations to make, we'll always have to run generators again
GetUnrootedSymbols(inProgressCompilation))
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.

Was there a reason we did this versus just passing null for the unrooted symbols in the first place? Because I would have imagined the only times we ever handed out a compilation was after it had been passed to a FinalState. In the case of a compilation being made for frozen partial semantics, we still create a FinalState with the in-progress compilation before handing it out, so I would have thought that would work.

The only place I can potentially imagine that invariant being broken is in GetPartialMetadataReference where it looks like we're just more or less returning a compilation directly, and it looks like there's already multiple other bugs there that we may need to fix.

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

Closing out as we prefer #51018 and #51019 instead.

@CyrusNajmabadi CyrusNajmabadi deleted the deferUnrootedSet branch May 3, 2022 23:11
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.

2 participants