-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Use directory-scoped ALCs to load analyzers in .NET Core #55098
Conversation
src/Compilers/Core/Portable/DiagnosticAnalyzer/DefaultAnalyzerAssemblyLoader.Core.cs
Outdated
Show resolved
Hide resolved
…AssemblyLoader.Core.cs
So when this gets merged will this by chance make it in .NET 6 in time? |
Yes but probably not till RC1. |
Alright, I get the daily RC1 builds so hopefully it lands on those soon. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The loader should only be loading analyzer assemblies that are explicitly passed to the compiler.
src/Compilers/Core/Portable/DiagnosticAnalyzer/DefaultAnalyzerAssemblyLoader.Core.cs
Outdated
Show resolved
Hide resolved
src/Compilers/Core/Portable/DiagnosticAnalyzer/DefaultAnalyzerAssemblyLoader.Core.cs
Outdated
Show resolved
Hide resolved
src/Compilers/Core/Portable/DiagnosticAnalyzer/DefaultAnalyzerAssemblyLoader.Core.cs
Show resolved
Hide resolved
Co-authored-by: Jared Parsons <jaredpparsons@gmail.com>
src/Compilers/Core/Portable/DiagnosticAnalyzer/DefaultAnalyzerAssemblyLoader.Core.cs
Show resolved
Hide resolved
src/Compilers/Core/CodeAnalysisTest/Analyzers/AnalyzerFileReferenceTests.cs
Show resolved
Hide resolved
src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerAssemblyLoader.cs
Outdated
Show resolved
Hide resolved
src/Compilers/Core/Portable/DiagnosticAnalyzer/DefaultAnalyzerAssemblyLoader.Core.cs
Outdated
Show resolved
Hide resolved
src/Compilers/Core/Portable/DiagnosticAnalyzer/DefaultAnalyzerAssemblyLoader.Core.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Jared Parsons <jaredpparsons@gmail.com>
src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerAssemblyLoader.cs
Outdated
Show resolved
Hide resolved
src/Compilers/Core/Portable/DiagnosticAnalyzer/DefaultAnalyzerAssemblyLoader.Core.cs
Outdated
Show resolved
Hide resolved
src/Compilers/Core/Portable/DiagnosticAnalyzer/DefaultAnalyzerAssemblyLoader.Core.cs
Show resolved
Hide resolved
src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerAssemblyLoader.cs
Outdated
Show resolved
Hide resolved
src/Compilers/Core/Portable/DiagnosticAnalyzer/DefaultAnalyzerAssemblyLoader.Core.cs
Outdated
Show resolved
Hide resolved
src/Compilers/Core/Portable/DiagnosticAnalyzer/DefaultAnalyzerAssemblyLoader.Core.cs
Outdated
Show resolved
Hide resolved
src/Compilers/Core/Portable/DiagnosticAnalyzer/DefaultAnalyzerAssemblyLoader.Core.cs
Show resolved
Hide resolved
src/Compilers/Core/CodeAnalysisTest/DefaultAnalyzerAssemblyLoaderTests.cs
Show resolved
Hide resolved
src/Compilers/Core/CodeAnalysisTest/DefaultAnalyzerAssemblyLoaderTests.cs
Show resolved
Hide resolved
analyzer.GetType().GetMethod("Method")!.Invoke(analyzer, new object[] { sb }); | ||
Assert.Equal(ExecutionConditionUtil.IsCoreClr ? "1" : "42", sb.ToString()); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One test I think is missing is firing up two different DefaultAnalyzerAssemblyLoader
and verifying they can load different assemblies that have the same simple name. That is effectively what the compiler server is going to be doing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this comment describe a different scenario than what is covered in AssemblyLoading_MultipleVersions
(where 'Delta1' and 'Delta2' have the same simple name)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. In that test you're creating one DefaultAnalyzerAssemblyLoader
and loading two different versions of Delta into it and verifying that one fails. I'm saying create two DefaultAnalyzerAssemblyLoader
instances and load Delta1
into the first and Delta2
into the second. That is effectively how long lived hosts on .NET Core will work (new loader per compilation) and want to verify that it's working and that the correct Assembly
is loaded into each context
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually one other test you need is loading Delta1
and Delta2
into the same DefaultAnalyzerAssemblyLoader
but from different directories. That should work just fine now. That is essentially our core analyzers with conflicting dependencies case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have AssemblyLoading_MultipleVersions
to test loading different versions of the same assembly into one loader. I added a test AssemblyLoading_MultipleVersions_MultipleLoaders
to do the same but with each version in a different loader.
…AssemblyLoader.Core.cs Co-authored-by: Jared Parsons <jaredpparsons@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor feedback.
analyzer.GetType().GetMethod("Method")!.Invoke(analyzer, new object[] { sb }); | ||
Assert.Equal(ExecutionConditionUtil.IsCoreClr ? "1" : "42", sb.ToString()); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. In that test you're creating one DefaultAnalyzerAssemblyLoader
and loading two different versions of Delta into it and verifying that one fails. I'm saying create two DefaultAnalyzerAssemblyLoader
instances and load Delta1
into the first and Delta2
into the second. That is effectively how long lived hosts on .NET Core will work (new loader per compilation) and want to verify that it's working and that the correct Assembly
is loaded into each context
return loadContext.LoadFromAssemblyName(name); | ||
} | ||
|
||
internal static class TestAccessor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you opt to have a TestAccessor
here vs. just adding an internal
method on DefaultAnalyzerAssemblyLoader
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted people to feel bad about ever accessing this in the implementation. I was attempting to imitate TestAccessor
patterns in ChangedText.cs
, SegmentedArray`1.cs
, etc.
src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerAssemblyLoader.cs
Outdated
Show resolved
Hide resolved
|
||
namespace Microsoft.CodeAnalysis.Test.Utilities | ||
{ | ||
public sealed class AssemblyLoadTestFixture : IDisposable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a really nice change!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple nits, but otherwise looks great!
So basically this did not make it in time for the .NET 6 rc.1 daily builds? |
This will make 17.0 Preview 4 which should be in the .NET 6 SDK RC1 builds. |
Resolves #52177