-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Load analyzers and generators in isolated ALCs in our OOP process #74780
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
Merged
Merged
Changes from all commits
Commits
Show all changes
191 commits
Select commit
Hold shift + click to select a range
4a74960
In progress
CyrusNajmabadi 9b15720
in progress
CyrusNajmabadi fcd2791
in progress
CyrusNajmabadi 476346f
in progress
CyrusNajmabadi eb9e531
Finish up
CyrusNajmabadi 4f33bb9
in progress
CyrusNajmabadi 1fcd8fa
in progress
CyrusNajmabadi 6598832
Add back
CyrusNajmabadi eda27b0
dedicated file
CyrusNajmabadi 6276106
in progress
CyrusNajmabadi ee79e75
in progress
CyrusNajmabadi ef8c9b3
simplify
CyrusNajmabadi bb30403
Revert
CyrusNajmabadi 40d111f
Share more
CyrusNajmabadi 72527b7
docs
CyrusNajmabadi 9c5ce93
Docs
CyrusNajmabadi df1fa06
Docs
CyrusNajmabadi e1c8108
Docs
CyrusNajmabadi abf7d7d
Unique path
CyrusNajmabadi e5508fd
Doc
CyrusNajmabadi d82d2a9
Simplify
CyrusNajmabadi 0000865
Change ifdefs
CyrusNajmabadi 46931b1
Change ifdefs
CyrusNajmabadi b943bf8
Merge remote-tracking branch 'upstream/main' into isolatedALC
CyrusNajmabadi cf71ad8
in progress
CyrusNajmabadi e0b00d5
move
CyrusNajmabadi cdf0aed
fix
CyrusNajmabadi e650f96
Simplify
CyrusNajmabadi 682c455
Simplify
CyrusNajmabadi 6bbd6aa
move to common location
CyrusNajmabadi a729ef1
Move to shared location
CyrusNajmabadi 3cf946d
Merge remote-tracking branch 'upstream/main' into isolatedALC
CyrusNajmabadi 9fd7fc8
Docs
CyrusNajmabadi 3dcf644
Docs
CyrusNajmabadi a83ebc5
Docs
CyrusNajmabadi 4925999
Docs
CyrusNajmabadi 84a60b6
Similar logic
CyrusNajmabadi 34db05b
Sharing
CyrusNajmabadi 6ba258a
Docs
CyrusNajmabadi 8e70d06
restore
CyrusNajmabadi b771f97
Docs
CyrusNajmabadi df5764f
Docs
CyrusNajmabadi 514c0b4
Docs
CyrusNajmabadi 306e783
not abstract
CyrusNajmabadi 658abfa
renames
CyrusNajmabadi 8eda644
Docs
CyrusNajmabadi 4cf1330
Merge remote-tracking branch 'dibarbet/fix_design_time_build' into is…
CyrusNajmabadi 730c883
in progress
CyrusNajmabadi e6a3883
Make protected
CyrusNajmabadi 91d97dc
simplify
CyrusNajmabadi 78c734e
Fix
CyrusNajmabadi 217a496
Fix
CyrusNajmabadi a7959ce
primary constructor
CyrusNajmabadi a6c5e97
Merge branch 'checksummedObject' into isolatedALC
CyrusNajmabadi abc6af5
Fix
CyrusNajmabadi 8661560
Fix
CyrusNajmabadi bd8f926
Merge remote-tracking branch 'upstream/main' into isolatedALC
CyrusNajmabadi 5b481d6
Fix
CyrusNajmabadi a07bb12
Jared pattern
CyrusNajmabadi 8d2d21a
Revert
CyrusNajmabadi 694080c
Merge remote-tracking branch 'upstream/main' into isolatedALC
CyrusNajmabadi fe82439
revert
CyrusNajmabadi 3fff183
revert
CyrusNajmabadi 14a7ff4
no default
CyrusNajmabadi 01d109e
Update src/Workspaces/CoreTestUtilities/Remote/TestSerializerService.cs
CyrusNajmabadi 7c001e5
Simplify
CyrusNajmabadi d4450d9
Wrapping
CyrusNajmabadi 3f3e15c
contract messages
CyrusNajmabadi ae16400
Rename
CyrusNajmabadi 39bcc6e
Add gc
CyrusNajmabadi dfc26e0
move code
CyrusNajmabadi f534e72
Collection expression
CyrusNajmabadi 32518fb
asserts
CyrusNajmabadi ea7f576
blank lines
CyrusNajmabadi 6f5a76f
Sort usings
CyrusNajmabadi 063d9a2
Make a counter instead
CyrusNajmabadi d105e2f
Merge branch 'main' into isolatedALC
CyrusNajmabadi 7b7392a
Different approach
CyrusNajmabadi fd6fb98
in progress
CyrusNajmabadi 65620d2
in progress
CyrusNajmabadi b597d4a
Cleanup
CyrusNajmabadi a478c33
Trivially bail out
CyrusNajmabadi 07b0497
File change notifications working
CyrusNajmabadi f554f3e
Merge remote-tracking branch 'upstream/main' into isolatedALC
CyrusNajmabadi e9d636d
Merge branch 'moveType' into isolatedALC
CyrusNajmabadi 362cf63
Merge branch 'moveType' into isolatedALC
CyrusNajmabadi 10af3cf
Merge branch 'analyzerWatching' into isolatedALC
CyrusNajmabadi ae1c683
Make static
CyrusNajmabadi 23307e0
Merge branch 'analyzerWatching' into isolatedALC
CyrusNajmabadi e5711f8
Merge remote-tracking branch 'upstream/main' into isolatedALC
CyrusNajmabadi f224ba0
Merge branch 'unloadAll' into isolatedALC
CyrusNajmabadi a960412
Merge remote-tracking branch 'upstream/main' into isolatedALC
CyrusNajmabadi fa01f64
Merge branch 'batching' into isolatedALC
CyrusNajmabadi 5a69e9c
in progresS
CyrusNajmabadi 3c7e326
Merge remote-tracking branch 'upstream/main' into isolatedALC
CyrusNajmabadi 18b5893
in progress
CyrusNajmabadi f6cd0bd
Rename
CyrusNajmabadi efda682
Remove
CyrusNajmabadi a3ebfc9
Working test
CyrusNajmabadi f01eaf8
Renames
CyrusNajmabadi e801da2
Merge branch 'main' into isolatedALC
CyrusNajmabadi 01e8e65
Update src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerAssembl…
CyrusNajmabadi c53f25a
Cleanup api
CyrusNajmabadi 24b7698
keealive
CyrusNajmabadi 2aaa1bc
Merge branch 'main' into isolatedALC
CyrusNajmabadi ef90315
in progress
CyrusNajmabadi 1352fff
Merge branch 'stringFileWatching' into isolatedALC
CyrusNajmabadi b31dca4
in progress
CyrusNajmabadi b030aa4
in progress
CyrusNajmabadi f836f16
in progress
CyrusNajmabadi ae5aa2e
in progress
CyrusNajmabadi 5c9d7b4
in progress
CyrusNajmabadi 188e44d
Simplify
CyrusNajmabadi f44e95f
more work
CyrusNajmabadi e637c25
Merge remote-tracking branch 'upstream/main' into isolatedALC
CyrusNajmabadi 57152d8
in progress
CyrusNajmabadi da0e43e
Move and rename
CyrusNajmabadi d3d3866
Merge remote-tracking branch 'upstream/main' into isolatedALC
CyrusNajmabadi 587b6c3
Downsream fallout
CyrusNajmabadi bcb33a8
Tests
CyrusNajmabadi 9470752
Use new context
CyrusNajmabadi f851590
move back
CyrusNajmabadi a5244a6
Docs
CyrusNajmabadi df51cbd
revert
CyrusNajmabadi 1bd7e08
REvert
CyrusNajmabadi 1fa9eec
Simplify
CyrusNajmabadi c551d72
move
CyrusNajmabadi d688f8e
REvert
CyrusNajmabadi 73fc9ff
REvert
CyrusNajmabadi 523035e
in progress
CyrusNajmabadi a5964bd
partials
CyrusNajmabadi 857f0e0
cleanup
CyrusNajmabadi 5ed0d68
cleanup
CyrusNajmabadi c363a01
REvert
CyrusNajmabadi 6854ae1
Sort
CyrusNajmabadi 438db6f
REvert
CyrusNajmabadi 55d9748
Sort
CyrusNajmabadi 3124d1e
Remove
CyrusNajmabadi 520508b
Merge branch 'passAlongServices' into isolatedALC
CyrusNajmabadi 81d0fd3
Merge branch 'passAlongServices' into isolatedALC
CyrusNajmabadi 2e2393e
REmove
CyrusNajmabadi 28b0ca4
Use helper
CyrusNajmabadi d1a3c0d
in progress
CyrusNajmabadi 7e871f6
in progress
CyrusNajmabadi abb4df4
In progress
CyrusNajmabadi 393b5a2
in progress
CyrusNajmabadi 20a88fa
In progress
CyrusNajmabadi 79f701c
move to strings
CyrusNajmabadi 390ada5
Don't go through the workspace
CyrusNajmabadi 642ac91
Merge branch 'fileChangeWorkQueue' into isolatedALC
CyrusNajmabadi 24bfad2
REvert
CyrusNajmabadi a1e46b6
Merge branch 'fileChangeWorkQueue' into isolatedALC
CyrusNajmabadi b99b396
Merge branch 'fileChangeWorkQueue' into isolatedALC
CyrusNajmabadi c4162c0
Merge remote-tracking branch 'upstream/main' into isolatedALC
CyrusNajmabadi 9dc6b7e
Merge remote-tracking branch 'upstream/main' into isolatedALC
CyrusNajmabadi cc270ee
Update src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostW…
CyrusNajmabadi 82f7120
only in net
CyrusNajmabadi f86a8aa
docs
CyrusNajmabadi a6b6d9e
Merge branch 'isolatedALC' of https://github.com/CyrusNajmabadi/rosly…
CyrusNajmabadi 9ad33f7
move
CyrusNajmabadi 4f961ff
rename
CyrusNajmabadi d0bfc65
docs
CyrusNajmabadi 1975a1a
docs
CyrusNajmabadi 7462d05
docs
CyrusNajmabadi 266e439
Simplify logic
CyrusNajmabadi b823683
update test
CyrusNajmabadi ab4ba87
Fix comment
CyrusNajmabadi 176b8a8
pass id
CyrusNajmabadi 57aee0e
simplify
CyrusNajmabadi 4758f3b
stop watching references
CyrusNajmabadi 75a4955
Merge remote-tracking branch 'upstream/main' into isolatedALC
CyrusNajmabadi a613d6a
Fix
CyrusNajmabadi a90f7ec
Share code
CyrusNajmabadi 1ef5673
name our directory
CyrusNajmabadi cbf85eb
Merge branch 'loaderProvider' into isolatedALC
CyrusNajmabadi 81afa79
Simplify
CyrusNajmabadi 9e011e7
Merge branch 'loaderProvider' into isolatedALC
CyrusNajmabadi 49435a4
Merge branch 'loaderProvider' into isolatedALC
CyrusNajmabadi 14139ef
inline
CyrusNajmabadi c793b18
remove
CyrusNajmabadi 9eba2a5
Merge branch 'loaderProvider' into isolatedALC
CyrusNajmabadi c03b6da
Docs
CyrusNajmabadi c622459
Merge branch 'loaderProvider' into isolatedALC
CyrusNajmabadi ae387e5
Merge branch 'loaderProvider' into isolatedALC
CyrusNajmabadi 82ddb42
move into pp region
CyrusNajmabadi 059e3ff
Merge remote-tracking branch 'upstream/main' into isolatedALC
CyrusNajmabadi bd46648
remove
CyrusNajmabadi 4b77dc5
Merge remote-tracking branch 'upstream/main' into isolatedALC
CyrusNajmabadi 9be2700
Update src/Workspaces/Core/Portable/Workspace/ProjectSystem/ProjectSy…
CyrusNajmabadi ca06773
Update src/Workspaces/CoreTest/SolutionTests/SolutionWithSourceGenera…
CyrusNajmabadi 70c973c
Merge remote-tracking branch 'upstream/main' into isolatedALC
CyrusNajmabadi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
src/Workspaces/Core/Portable/Workspace/IsolatedAnalyzerFileReference.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
#if NET | ||
|
||
using System; | ||
using System.Collections.Immutable; | ||
using System.Runtime.CompilerServices; | ||
using Microsoft.CodeAnalysis.Diagnostics; | ||
using System.Runtime.Loader; | ||
using Roslyn.Utilities; | ||
|
||
namespace Microsoft.CodeAnalysis; | ||
|
||
/// <summary> | ||
/// Wrapper around a real <see cref="AnalyzerFileReference"/>. An "isolated" analyzer reference is an analyzer | ||
/// reference associated with an <see cref="AssemblyLoadContext"/> that is connected to a set of other "isolated" | ||
/// analyzer references. This allows for loading the analyzers and generators from it in a way that is associated with | ||
/// that load context, keeping them separate from other analyzers and generators loaded in other load contexts, while | ||
/// also allowing all of those instances to be collected when no longer needed. Being isolated means that if any of the | ||
/// underlying assembly references change, that they can be loaded side by side with the prior references. This enables | ||
/// functionality like live reloading of analyzers and generators when they change on disk. Note: this is only | ||
/// supported on .Net Core, and not .Net Framework, as only the former has <see cref="AssemblyLoadContext"/>s. | ||
/// </summary> | ||
/// <remarks> | ||
/// The purpose of this type is to allow passing out a <see cref="AnalyzerReference"/> to the rest of the system that | ||
/// then ensures that as long as it is alive (or any <see cref="DiagnosticAnalyzer"/> or <see cref="ISourceGenerator"/> | ||
/// it passes out is alive), that the <see cref="IsolatedAnalyzerReferenceSet"/> (and its corresponding <see | ||
/// cref="AssemblyLoadContext"/>) is kept alive as well. | ||
/// </remarks> | ||
internal sealed class IsolatedAnalyzerFileReference( | ||
IsolatedAnalyzerReferenceSet isolatedAnalyzerReferenceSet, | ||
AnalyzerFileReference underlyingAnalyzerReference) | ||
: AnalyzerReference | ||
{ | ||
/// <summary> | ||
/// Conditional weak tables that ensure that as long as a particular <see cref="DiagnosticAnalyzer"/> or <see | ||
/// cref="ISourceGenerator"/> is alive, that the corresponding <see cref="IsolatedAnalyzerReferenceSet"/> (and its | ||
/// corresponding <see cref="AssemblyLoadContext"/> is kept alive. | ||
/// </summary> | ||
private static readonly ConditionalWeakTable<DiagnosticAnalyzer, IsolatedAnalyzerReferenceSet> s_analyzerToPinnedReferenceSet = []; | ||
|
||
/// <inheritdoc cref="s_analyzerToPinnedReferenceSet"/> | ||
private static readonly ConditionalWeakTable<ISourceGenerator, IsolatedAnalyzerReferenceSet> s_generatorToPinnedReferenceSet = []; | ||
|
||
/// <summary> | ||
/// We keep a strong reference here. As long as this <see cref="IsolatedAnalyzerFileReference"/> is passed out and | ||
/// held onto (say by a Project instance), it should keep the IsolatedAssemblyReferenceSet (and its ALC) alive. | ||
/// </summary> | ||
private readonly IsolatedAnalyzerReferenceSet _isolatedAnalyzerReferenceSet = isolatedAnalyzerReferenceSet; | ||
|
||
/// <summary> | ||
/// The actual real <see cref="AnalyzerReference"/> we defer our operations to. | ||
/// </summary> | ||
public readonly AnalyzerFileReference UnderlyingAnalyzerFileReference = underlyingAnalyzerReference; | ||
|
||
public override string Display => UnderlyingAnalyzerFileReference.Display; | ||
public override string? FullPath => UnderlyingAnalyzerFileReference.FullPath; | ||
public override object Id => UnderlyingAnalyzerFileReference.Id; | ||
|
||
public override ImmutableArray<DiagnosticAnalyzer> GetAnalyzers(string language) | ||
=> PinAnalyzers(static (reference, language) => reference.GetAnalyzers(language), language); | ||
|
||
public override ImmutableArray<DiagnosticAnalyzer> GetAnalyzersForAllLanguages() | ||
=> PinAnalyzers(static (reference, _) => reference.GetAnalyzersForAllLanguages(), default(VoidResult)); | ||
|
||
[Obsolete] | ||
public override ImmutableArray<ISourceGenerator> GetGenerators() | ||
=> PinGenerators(static (reference, _) => reference.GetGenerators(), default(VoidResult)); | ||
|
||
public override ImmutableArray<ISourceGenerator> GetGenerators(string language) | ||
=> PinGenerators(static (reference, language) => reference.GetGenerators(language), language); | ||
|
||
public override ImmutableArray<ISourceGenerator> GetGeneratorsForAllLanguages() | ||
=> PinGenerators(static (reference, _) => reference.GetGeneratorsForAllLanguages(), default(VoidResult)); | ||
|
||
private ImmutableArray<DiagnosticAnalyzer> PinAnalyzers<TArg>(Func<AnalyzerReference, TArg, ImmutableArray<DiagnosticAnalyzer>> getItems, TArg arg) | ||
=> PinItems(s_analyzerToPinnedReferenceSet, getItems, arg); | ||
|
||
private ImmutableArray<ISourceGenerator> PinGenerators<TArg>(Func<AnalyzerReference, TArg, ImmutableArray<ISourceGenerator>> getItems, TArg arg) | ||
=> PinItems(s_generatorToPinnedReferenceSet, getItems, arg); | ||
|
||
private ImmutableArray<TItem> PinItems<TItem, TArg>( | ||
ConditionalWeakTable<TItem, IsolatedAnalyzerReferenceSet> table, | ||
Func<AnalyzerReference, TArg, ImmutableArray<TItem>> getItems, | ||
TArg arg) | ||
where TItem : class | ||
{ | ||
// Keep a reference from each generator to the IsolatedAssemblyReferenceSet. This will ensure it (and the ALC | ||
// it points at) stays alive as long as the generator instance stays alive. | ||
var items = getItems(this.UnderlyingAnalyzerFileReference, arg); | ||
|
||
foreach (var item in items) | ||
table.TryAdd(item, _isolatedAnalyzerReferenceSet); | ||
|
||
// Note: we want to keep ourselves alive during this call so that neither we nor our reference set get GC'ed | ||
// while we're computing the items. | ||
GC.KeepAlive(this); | ||
|
||
return items; | ||
} | ||
|
||
public override bool Equals(object? obj) | ||
=> ReferenceEquals(this, obj); | ||
|
||
public override int GetHashCode() | ||
=> RuntimeHelpers.GetHashCode(this); | ||
|
||
public override string ToString() | ||
=> $"{nameof(IsolatedAnalyzerFileReference)}({UnderlyingAnalyzerFileReference})"; | ||
} | ||
|
||
#endif |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@dibarbet fyi
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.
note: this is just for solution-level analyzers. Project level analyzers will reload automatically.
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.
Fine with me. Will have to reload VSCode to reload sln level analyzers, but those should be way way less common than project based ones.