Skip to content

Commit 9fbfe9f

Browse files
authored
Merge pull request #74985 from dotnet/revert-74780-isolatedALC
Revert "Load analyzers and generators in isolated ALCs in our OOP process"
2 parents 82ea19e + a59061f commit 9fbfe9f

22 files changed

+118
-742
lines changed

src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerWorkspaceFactory.cs

+1-6
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,7 @@ public LanguageServerWorkspaceFactory(
5757
public async Task InitializeSolutionLevelAnalyzersAsync(ImmutableArray<string> analyzerPaths)
5858
{
5959
var references = new List<AnalyzerFileReference>();
60-
var loaderProvider = Workspace.Services.GetRequiredService<IAnalyzerAssemblyLoaderProvider>();
61-
62-
// Load all analyzers into a fresh shadow copied load context. In the future, if we want to support reloading
63-
// of solution-level analyzer references, we should just need to listen for changes to those analyzer paths and
64-
// then call back into this method to update the solution accordingly.
65-
var analyzerLoader = loaderProvider.CreateNewShadowCopyLoader();
60+
var analyzerLoader = Workspace.Services.GetRequiredService<IAnalyzerAssemblyLoaderProvider>().SharedShadowCopyLoader;
6661

6762
foreach (var analyzerPath in analyzerPaths)
6863
{

src/VisualStudio/Core/Test.Next/Remote/SerializationValidator.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ public async Task<T> GetValueAsync<T>(Checksum checksum)
110110

111111
public async Task<Solution> GetSolutionAsync(SolutionAssetStorage.Scope scope)
112112
{
113-
var solutionInfo = await new AssetProvider(this).CreateSolutionInfoAsync(
114-
scope.SolutionChecksum, this.Services.SolutionServices, CancellationToken.None).ConfigureAwait(false);
113+
var solutionInfo = await new AssetProvider(this).CreateSolutionInfoAsync(scope.SolutionChecksum, CancellationToken.None).ConfigureAwait(false);
115114

116115
var workspace = new AdhocWorkspace(Services.HostServices);
117116
return workspace.AddSolution(solutionInfo);

src/VisualStudio/Core/Test.Next/Services/SolutionServiceTests.cs

+1-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
using Microsoft.CodeAnalysis.Diagnostics;
1616
using Microsoft.CodeAnalysis.Editor.Test;
1717
using Microsoft.CodeAnalysis.Formatting;
18-
using Microsoft.CodeAnalysis.Host;
1918
using Microsoft.CodeAnalysis.Remote;
2019
using Microsoft.CodeAnalysis.Remote.Testing;
2120
using Microsoft.CodeAnalysis.Serialization;
@@ -447,10 +446,7 @@ public async Task TestRemoteWorkspace()
447446
await Verify(remoteWorkspace, currentSolution, remoteSolution3);
448447

449448
// move to new solution backward
450-
var solutionInfo2 = await assetProvider.CreateSolutionInfoAsync(
451-
await solution1.CompilationState.GetChecksumAsync(CancellationToken.None),
452-
remoteWorkspace.Services.SolutionServices,
453-
CancellationToken.None);
449+
var solutionInfo2 = await assetProvider.CreateSolutionInfoAsync(await solution1.CompilationState.GetChecksumAsync(CancellationToken.None), CancellationToken.None);
454450
var solution2 = remoteWorkspace.GetTestAccessor().CreateSolutionFromInfo(solutionInfo2);
455451

456452
// move to new solution forward

src/Workspaces/Core/Portable/Serialization/SerializerService_Reference.cs

+10-20
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Diagnostics.CodeAnalysis;
99
using System.IO;
1010
using System.Reflection.Metadata;
11+
using System.Threading;
1112
using Microsoft.CodeAnalysis.Diagnostics;
1213
using Microsoft.CodeAnalysis.Host;
1314
using Microsoft.CodeAnalysis.Shared.Extensions;
@@ -53,24 +54,15 @@ private static Checksum CreateChecksum(MetadataReference reference)
5354

5455
protected virtual Checksum CreateChecksum(AnalyzerReference reference)
5556
{
56-
#if NET
57-
// If we're in the oop side and we're being asked to produce our local checksum (so we can compare it to the
58-
// host checksum), then we want to just defer to the underlying analyzer reference of our isolated reference.
59-
// This underlying reference corresponds to the reference that the host has, and we do not want to make any
60-
// changes as long as they're both in agreement.
61-
if (reference is IsolatedAnalyzerFileReference { UnderlyingAnalyzerFileReference: var underlyingReference })
62-
reference = underlyingReference;
63-
#endif
64-
6557
using var stream = SerializableBytes.CreateWritableStream();
6658

6759
using (var writer = new ObjectWriter(stream, leaveOpen: true))
6860
{
6961
switch (reference)
7062
{
71-
case AnalyzerFileReference fileReference:
72-
writer.WriteString(fileReference.FullPath);
73-
writer.WriteGuid(TryGetAnalyzerFileReferenceMvid(fileReference));
63+
case AnalyzerFileReference file:
64+
writer.WriteString(file.FullPath);
65+
writer.WriteGuid(TryGetAnalyzerFileReferenceMvid(file));
7466
break;
7567

7668
case AnalyzerImageReference analyzerImageReference:
@@ -117,11 +109,11 @@ protected virtual void WriteAnalyzerReferenceTo(AnalyzerReference reference, Obj
117109
{
118110
switch (reference)
119111
{
120-
case AnalyzerFileReference fileReference:
112+
case AnalyzerFileReference file:
121113
writer.WriteString(nameof(AnalyzerFileReference));
122-
writer.WriteString(fileReference.FullPath);
114+
writer.WriteString(file.FullPath);
123115

124-
// Note: it is intentional that we are not writing the MVID of the analyzer file reference over in (even
116+
// Note: it is intentional that we are not writing the MVID of the analyzer file reference over (even
125117
// though we mixed it into the checksum). We don't actually need the data on the other side as it will
126118
// be read out from the file itself. So the flow is as follows when an analyzer-file-reference changes:
127119
//
@@ -158,10 +150,8 @@ protected virtual AnalyzerReference ReadAnalyzerReferenceFrom(ObjectReader reade
158150
switch (reader.ReadString())
159151
{
160152
case nameof(AnalyzerFileReference):
161-
// Rehydrate the analyzer file reference with the simple shared shadow copy loader. Note: we won't
162-
// actually use this instance we create. Instead, the caller will use create an IsolatedAssemblyReferenceSet
163-
// from these to ensure that all the types can be safely loaded into their own ALC.
164-
return new AnalyzerFileReference(reader.ReadRequiredString(), _analyzerLoaderProvider.SharedShadowCopyLoader);
153+
var fullPath = reader.ReadRequiredString();
154+
return new AnalyzerFileReference(fullPath, _analyzerLoaderProvider.SharedShadowCopyLoader);
165155

166156
case nameof(AnalyzerImageReference):
167157
var guid = reader.ReadGuid();
@@ -296,7 +286,7 @@ private PortableExecutableReference ReadPortableExecutableReferenceFrom(ObjectRe
296286
// so that we can put xml doc comment as part of snapshot. but until we believe that is necessary,
297287
// it will go with simpler approach
298288
var documentProvider = filePath != null && _documentationService != null ?
299-
_documentationService.GetDocumentationProvider(filePath) : DocumentationProvider.Default;
289+
_documentationService.GetDocumentationProvider(filePath) : XmlDocumentationProvider.Default;
300290

301291
return new SerializedPortableExecutableReference(
302292
properties, filePath, metadata, storageHandles, documentProvider);

src/Workspaces/Core/Portable/Workspace/Host/Metadata/IAnalyzerAssemblyLoaderProvider.cs

+2-15
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,11 @@
99
using System.IO;
1010
using Microsoft.CodeAnalysis.Host.Mef;
1111

12-
#if NET
13-
using Microsoft.CodeAnalysis.Diagnostics;
14-
using System.Runtime.Loader;
15-
#endif
16-
1712
namespace Microsoft.CodeAnalysis.Host;
1813

1914
internal interface IAnalyzerAssemblyLoaderProvider : IWorkspaceService
2015
{
2116
IAnalyzerAssemblyLoaderInternal SharedShadowCopyLoader { get; }
22-
23-
#if NET
24-
/// <summary>
25-
/// Creates a fresh shadow copying loader that will load all <see cref="AnalyzerReference"/>s and <see
26-
/// cref="ISourceGenerator"/>s in a fresh <see cref="AssemblyLoadContext"/>.
27-
/// </summary>
28-
IAnalyzerAssemblyLoaderInternal CreateNewShadowCopyLoader();
29-
#endif
3017
}
3118

3219
/// <summary>
@@ -41,13 +28,13 @@ internal abstract class AbstractAnalyzerAssemblyLoaderProvider : IAnalyzerAssemb
4128
public AbstractAnalyzerAssemblyLoaderProvider(IEnumerable<IAnalyzerAssemblyResolver> externalResolvers)
4229
{
4330
_externalResolvers = externalResolvers.ToImmutableArray();
44-
_shadowCopyLoader = new(CreateNewShadowCopyLoader);
31+
_shadowCopyLoader = new(CreateShadowCopyLoader);
4532
}
4633

4734
public IAnalyzerAssemblyLoaderInternal SharedShadowCopyLoader
4835
=> _shadowCopyLoader.Value;
4936

50-
public IAnalyzerAssemblyLoaderInternal CreateNewShadowCopyLoader()
37+
private IAnalyzerAssemblyLoaderInternal CreateShadowCopyLoader()
5138
=> this.WrapLoader(DefaultAnalyzerAssemblyLoader.CreateNonLockingLoader(
5239
Path.Combine(Path.GetTempPath(), nameof(Roslyn), "AnalyzerAssemblyLoader"),
5340
_externalResolvers));

src/Workspaces/Core/Portable/Workspace/IsolatedAnalyzerFileReference.cs

-114
This file was deleted.

0 commit comments

Comments
 (0)