Use directory-scoped ALCs to load analyzers in .NET Core#55098
Use directory-scoped ALCs to load analyzers in .NET Core#55098RikkiGibson merged 29 commits intodotnet:mainfrom
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. |
jaredpar
left a comment
There was a problem hiding this comment.
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.
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.
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.
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.
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.
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>
| analyzer.GetType().GetMethod("Method")!.Invoke(analyzer, new object[] { sb }); | ||
| Assert.Equal(ExecutionConditionUtil.IsCoreClr ? "1" : "42", sb.ToString()); | ||
| } | ||
|
|
There was a problem hiding this comment.
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.
Why did you opt to have a TestAccessor here vs. just adding an internal method on DefaultAnalyzerAssemblyLoader?
There was a problem hiding this comment.
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 |
chsienki
left a comment
There was a problem hiding this comment.
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