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

Run analyzer consistency checks on .NET Core #70517

Merged
merged 6 commits into from
Oct 27, 2023
Merged

Conversation

jaredpar
Copy link
Member

The job of AnalyzerConsistencyChecker is to determine when the compiler server has loaded analyzers in a bad state and force a restart. One of the bad states it detects is when the analyzers on disk change. That is not handled by AnalyzerAssemblyLoader because it has an invariant that the file system is unchanged. This was not running for .NET Core so this particular scenario was missed. This change updates AnalyzerConsistencyChecker to run on .NET Core too to catch these issues.

closes #70053

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Analyzers untriaged Issues and PRs which have not yet been triaged by a lead labels Oct 23, 2023
@@ -13,6 +13,15 @@

namespace Microsoft.CodeAnalysis
{
internal interface IAnalyzerAssemblyLoaderInternal : IAnalyzerAssemblyLoader
Copy link
Member Author

Choose a reason for hiding this comment

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

IAnalyzerAssemblyLoader is a public API and did not want to create new public API for this hence went with an internal API instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

We don't expect external users (at least those who lack IVT) to implement IAnalyzerAssemblyLoader, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct. This is only used in the compiler server where external teams cannot provide implementations.


private class InMemoryAssemblyLoader : IAnalyzerAssemblyLoader
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 type muddied the waters a bit on how analyzer loading reacts in consistency checks because it doesn't load analyzers the same way as the actual implementations. So removed this and flipped to using the real implementations in order to make sure the tests are accurate.

@jaredpar jaredpar marked this pull request as ready for review October 23, 2023 15:34
@jaredpar jaredpar requested a review from a team as a code owner October 23, 2023 15:34
@jaredpar
Copy link
Member Author

@dotnet/roslyn-compiler PTAL

@RikkiGibson RikkiGibson self-assigned this Oct 23, 2023
@jaredpar
Copy link
Member Author

@RikkiGibson, @jjonescz PTAL

Copy link
Contributor

@RikkiGibson RikkiGibson left a comment

Choose a reason for hiding this comment

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

LGTM, just had minor comments/questions

@@ -13,6 +13,15 @@

namespace Microsoft.CodeAnalysis
{
internal interface IAnalyzerAssemblyLoaderInternal : IAnalyzerAssemblyLoader
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't expect external users (at least those who lack IVT) to implement IAnalyzerAssemblyLoader, right?

@@ -21,7 +30,7 @@ namespace Microsoft.CodeAnalysis
/// This type generally assumes that files on disk aren't changing, since it ensure that two calls to <see cref="LoadFromPath(string)"/>
/// will always return the same thing, per that interface's contract.
/// </remarks>
internal abstract partial class AnalyzerAssemblyLoader : IAnalyzerAssemblyLoader
internal abstract partial class AnalyzerAssemblyLoader : IAnalyzerAssemblyLoaderInternal
Copy link
Contributor

Choose a reason for hiding this comment

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

I was a little surprised I didn't see any changes which type-test or cast to IAnalyzerAssemblyLoaderInternal. I thought we had public API which permits users to pass in instances of IAnalyzerAssemblyLoader in order to use a common analyzer loader across compilations.

Copy link
Member Author

Choose a reason for hiding this comment

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

You're correct that we have end points that provide IAnalyzerAssemblyLoader parameters. This particular API is only used in the compiler server where we do not provide a public API end point. It's not a re-hostable component but one where we provide all the implementations.

Pretty much the only reason that the compiler server takes IAnalyzerAssemblyLoader and not AnalyzerAssemblyLoader is that it limits the API surface area and it's easier to provide throwing implementations in unit tests so we can validate behavior better.

@@ -91,27 +111,15 @@ internal static class AnalyzerConsistencyChecker
loadedAssemblies.Add(loader.LoadFromPath(resolvedPath));
}

// Third, check that the MVIDs of the files on disk match the MVIDs of the loaded assemblies.
Copy link
Member

@jjonescz jjonescz Oct 26, 2023

Choose a reason for hiding this comment

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

Looks like this comment applies to the whole for loop below and should not be removed.

{
// When an assembly is loaded from the GAC then the load result would be the same if
// this ran on command line compiler. So there is no consistency issue here, this
// is just runtime rules expressing themselves.
Copy link
Member

Choose a reason for hiding this comment

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

It's a bit weird that the API is named IsHostAssembly but the comments are talking about "consistency" - they made sense when inside the consistency checker but here are bit out of context. But I guess it's fine since it's an internal API (and has just one caller - the consistency checker).

@jaredpar jaredpar merged commit a12cd3b into dotnet:main Oct 27, 2023
24 of 27 checks passed
@jaredpar jaredpar deleted the mvid branch October 27, 2023 04:32
@ghost ghost added this to the Next milestone Oct 27, 2023
@jjonescz jjonescz modified the milestones: Next, 17.9 P1 Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Analyzers 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.

VBCSCompiler doesn't load changed dll referenced as analyzer reference
3 participants