diff --git a/src/Features/Core/Portable/ExternalAccess/UnitTesting/SolutionCrawler/UnitTestingWorkCoordinator.UnitTestingSemanticChangeProcessor.cs b/src/Features/Core/Portable/ExternalAccess/UnitTesting/SolutionCrawler/UnitTestingWorkCoordinator.UnitTestingSemanticChangeProcessor.cs index 50944b47f0218..931cbd82838b7 100644 --- a/src/Features/Core/Portable/ExternalAccess/UnitTesting/SolutionCrawler/UnitTestingWorkCoordinator.UnitTestingSemanticChangeProcessor.cs +++ b/src/Features/Core/Portable/ExternalAccess/UnitTesting/SolutionCrawler/UnitTestingWorkCoordinator.UnitTestingSemanticChangeProcessor.cs @@ -35,7 +35,7 @@ private sealed class UnitTestingSemanticChangeProcessor : UnitTestingIdleProcess private readonly UnitTestingRegistration _registration; private readonly UnitTestingProjectProcessor _processor; - private readonly NonReentrantLock _workGate = new(); + private readonly SemaphoreSlim _workGate = new(initialCount: 1); private readonly Dictionary _pendingWork = []; public UnitTestingSemanticChangeProcessor( @@ -263,7 +263,7 @@ public void Enqueue(Project project, DocumentId documentId, Document? document, Logger.Log(FunctionId.WorkCoordinator_SemanticChange_Enqueue, s_enqueueLogger, Environment.TickCount, documentId, changedMember != null); } - private static TValue DequeueWorker(NonReentrantLock gate, Dictionary map, CancellationToken cancellationToken) + private static TValue DequeueWorker(SemaphoreSlim gate, Dictionary map, CancellationToken cancellationToken) where TKey : notnull { using (gate.DisposableWait(cancellationToken)) @@ -283,7 +283,7 @@ private static TValue DequeueWorker(NonReentrantLock gate, Diction } } - private static void ClearQueueWorker(NonReentrantLock gate, Dictionary map, Func disposerSelector) + private static void ClearQueueWorker(SemaphoreSlim gate, Dictionary map, Func disposerSelector) where TKey : notnull { using (gate.DisposableWait(CancellationToken.None)) @@ -327,7 +327,7 @@ private class UnitTestingProjectProcessor : UnitTestingIdleProcessor private readonly UnitTestingRegistration _registration; private readonly UnitTestingIncrementalAnalyzerProcessor _processor; - private readonly NonReentrantLock _workGate = new(); + private readonly SemaphoreSlim _workGate = new(initialCount: 1); private readonly Dictionary _pendingWork = []; public UnitTestingProjectProcessor( diff --git a/src/LanguageServer/Protocol/Features/Options/WorkspaceConfigurationOptionsStorage.cs b/src/LanguageServer/Protocol/Features/Options/WorkspaceConfigurationOptionsStorage.cs index 9407236192274..9793df666da8a 100644 --- a/src/LanguageServer/Protocol/Features/Options/WorkspaceConfigurationOptionsStorage.cs +++ b/src/LanguageServer/Protocol/Features/Options/WorkspaceConfigurationOptionsStorage.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using Microsoft.CodeAnalysis.Options; -using Microsoft.CodeAnalysis.Storage; namespace Microsoft.CodeAnalysis.Host; @@ -11,15 +10,11 @@ internal static class WorkspaceConfigurationOptionsStorage { public static WorkspaceConfigurationOptions GetWorkspaceConfigurationOptions(this IGlobalOptionService globalOptions) => new( - CacheStorage: globalOptions.GetOption(Database), SourceGeneratorExecution: globalOptions.GetOption(SourceGeneratorExecution) ?? (globalOptions.GetOption(SourceGeneratorExecutionBalancedFeatureFlag) ? SourceGeneratorExecutionPreference.Balanced : SourceGeneratorExecutionPreference.Automatic), ValidateCompilationTrackerStates: globalOptions.GetOption(ValidateCompilationTrackerStates)); - public static readonly Option2 Database = new( - "dotnet_storage_database", WorkspaceConfigurationOptions.Default.CacheStorage, serializer: EditorConfigValueSerializer.CreateSerializerForEnum()); - public static readonly Option2 ValidateCompilationTrackerStates = new( "dotnet_validate_compilation_tracker_states", WorkspaceConfigurationOptions.Default.ValidateCompilationTrackerStates); diff --git a/src/Tools/AnalyzerRunner/IncrementalAnalyzerRunner.cs b/src/Tools/AnalyzerRunner/IncrementalAnalyzerRunner.cs index a501677df6270..f4d0ac450fbe9 100644 --- a/src/Tools/AnalyzerRunner/IncrementalAnalyzerRunner.cs +++ b/src/Tools/AnalyzerRunner/IncrementalAnalyzerRunner.cs @@ -5,13 +5,10 @@ #nullable disable using System; -using System.Collections.Immutable; using System.Linq; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Diagnostics; -using Microsoft.CodeAnalysis.FindSymbols.SymbolTree; using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.SolutionCrawler; @@ -39,25 +36,17 @@ public async Task RunAsync(CancellationToken cancellationToken) return; } - var usePersistentStorage = _options.UsePersistentStorage; - var exportProvider = _workspace.Services.SolutionServices.ExportProvider; var globalOptions = exportProvider.GetExports().Single().Value; globalOptions.SetGlobalOption(SolutionCrawlerOptionsStorage.BackgroundAnalysisScopeOption, LanguageNames.CSharp, _options.AnalysisScope); globalOptions.SetGlobalOption(SolutionCrawlerOptionsStorage.BackgroundAnalysisScopeOption, LanguageNames.VisualBasic, _options.AnalysisScope); - var workspaceConfigurationService = (AnalyzerRunnerWorkspaceConfigurationService)_workspace.Services.GetRequiredService(); - workspaceConfigurationService.Options = new(CacheStorage: usePersistentStorage ? StorageDatabase.SQLite : StorageDatabase.None); - - if (usePersistentStorage) + var persistentStorageService = _workspace.Services.SolutionServices.GetPersistentStorageService(); + var persistentStorage = await persistentStorageService.GetStorageAsync(SolutionKey.ToSolutionKey(_workspace.CurrentSolution), cancellationToken).ConfigureAwait(false); + if (persistentStorage is NoOpPersistentStorage) { - var persistentStorageService = _workspace.Services.SolutionServices.GetPersistentStorageService(); - var persistentStorage = await persistentStorageService.GetStorageAsync(SolutionKey.ToSolutionKey(_workspace.CurrentSolution), cancellationToken).ConfigureAwait(false); - if (persistentStorage is NoOpPersistentStorage) - { - throw new InvalidOperationException("Benchmark is not configured to use persistent storage."); - } + throw new InvalidOperationException("Benchmark is not configured to use persistent storage."); } } } diff --git a/src/Tools/AnalyzerRunner/Options.cs b/src/Tools/AnalyzerRunner/Options.cs index 5a4cb23d42159..a12f71192a59a 100644 --- a/src/Tools/AnalyzerRunner/Options.cs +++ b/src/Tools/AnalyzerRunner/Options.cs @@ -26,7 +26,6 @@ public sealed class Options public readonly int Iterations; // Options specific to incremental analyzers - public readonly bool UsePersistentStorage; public readonly ImmutableArray IncrementalAnalyzerNames; public readonly bool FullSolutionAnalysis; @@ -52,7 +51,6 @@ public Options( bool applyChanges, bool useAll, int iterations, - bool usePersistentStorage, bool fullSolutionAnalysis, ImmutableArray incrementalAnalyzerNames) : this(analyzerPath, @@ -71,7 +69,6 @@ public Options( testDocumentIterations: 0, logFileName: null, profileRoot: null, - usePersistentStorage, fullSolutionAnalysis, incrementalAnalyzerNames) { } @@ -93,7 +90,6 @@ internal Options( int testDocumentIterations, string logFileName, string profileRoot, - bool usePersistentStorage, bool fullSolutionAnalysis, ImmutableArray incrementalAnalyzerNames) { @@ -113,7 +109,6 @@ internal Options( TestDocumentIterations = testDocumentIterations; LogFileName = logFileName; ProfileRoot = profileRoot; - UsePersistentStorage = usePersistentStorage; FullSolutionAnalysis = fullSolutionAnalysis; IncrementalAnalyzerNames = incrementalAnalyzerNames; } @@ -136,7 +131,6 @@ internal static Options Create(string[] args) int testDocumentIterations = 10; string logFileName = null; string profileRoot = null; - var usePersistentStorage = false; var fullSolutionAnalysis = false; var incrementalAnalyzerNames = ImmutableArray.CreateBuilder(); @@ -192,9 +186,6 @@ internal static Options Create(string[] args) case "/profileroot": profileRoot = ReadValue(); break; - case "/persist": - usePersistentStorage = true; - break; case "/fsa": fullSolutionAnalysis = true; break; @@ -216,6 +207,7 @@ internal static Options Create(string[] args) ? "Unrecognized option " + arg : "Unrecognized parameter " + arg)); } + break; } } @@ -247,7 +239,6 @@ internal static Options Create(string[] args) testDocumentIterations: testDocumentIterations, logFileName: logFileName, profileRoot: profileRoot, - usePersistentStorage: usePersistentStorage, fullSolutionAnalysis: fullSolutionAnalysis, incrementalAnalyzerNames: incrementalAnalyzerNames.ToImmutable()); } diff --git a/src/Tools/IdeCoreBenchmarks/CSharpIdeAnalyzerBenchmarks.cs b/src/Tools/IdeCoreBenchmarks/CSharpIdeAnalyzerBenchmarks.cs index 60ae9f8d76de1..91d922f3c3dd2 100644 --- a/src/Tools/IdeCoreBenchmarks/CSharpIdeAnalyzerBenchmarks.cs +++ b/src/Tools/IdeCoreBenchmarks/CSharpIdeAnalyzerBenchmarks.cs @@ -58,7 +58,6 @@ public void Setup() applyChanges: false, useAll: false, iterations: 1, - usePersistentStorage: false, fullSolutionAnalysis: false, incrementalAnalyzerNames: ImmutableArray.Empty); diff --git a/src/Tools/IdeCoreBenchmarks/IncrementalAnalyzerBenchmarks.cs b/src/Tools/IdeCoreBenchmarks/IncrementalAnalyzerBenchmarks.cs index 7a6a80f878acc..df987e3066a5c 100644 --- a/src/Tools/IdeCoreBenchmarks/IncrementalAnalyzerBenchmarks.cs +++ b/src/Tools/IdeCoreBenchmarks/IncrementalAnalyzerBenchmarks.cs @@ -56,7 +56,6 @@ public void Setup() applyChanges: false, useAll: false, iterations: 1, - usePersistentStorage: false, fullSolutionAnalysis: true, incrementalAnalyzerNames: ImmutableArray.Create(AnalyzerName)); diff --git a/src/VisualStudio/Core/Def/Options/VisualStudioOptionStorage.cs b/src/VisualStudio/Core/Def/Options/VisualStudioOptionStorage.cs index 03065fce406a1..e7f245264a26b 100644 --- a/src/VisualStudio/Core/Def/Options/VisualStudioOptionStorage.cs +++ b/src/VisualStudio/Core/Def/Options/VisualStudioOptionStorage.cs @@ -279,7 +279,6 @@ public bool TryFetch(LocalUserRegistryOptionPersister persister, OptionKey2 opti {"dotnet_extract_method_no_ref_or_out_structs", new RoamingProfileStorage("TextEditor.%LANGUAGE%.Specific.Don't Put Out Or Ref On Strcut")}, {"dotnet_fade_out_unreachable_code", new RoamingProfileStorage("TextEditor.%LANGUAGE%.Specific.FadeOutUnreachableCode")}, {"dotnet_fade_out_unused_imports", new RoamingProfileStorage("TextEditor.%LANGUAGE%.Specific.FadeOutUnusedImports")}, - {"dotnet_storage_database", new LocalUserProfileStorage(@"Roslyn\Internal\OnOff\Features", "Database")}, {"dotnet_add_imports_on_paste", new RoamingProfileStorage("TextEditor.%LANGUAGE%.Specific.AddImportsOnPaste2")}, {"dotnet_always_use_default_symbol_servers", new RoamingProfileStorage("TextEditor.AlwaysUseDefaultSymbolServers")}, {"csharp_insert_block_comment_start_string", new RoamingProfileStorage("TextEditor.%LANGUAGE%.Specific.Auto Insert Block Comment Start String")}, diff --git a/src/Workspaces/Core/Portable/Storage/PersistentStorageExtensions.cs b/src/Workspaces/Core/Portable/Storage/PersistentStorageExtensions.cs index 8f755ae561ce6..66b2b49e8f1c5 100644 --- a/src/Workspaces/Core/Portable/Storage/PersistentStorageExtensions.cs +++ b/src/Workspaces/Core/Portable/Storage/PersistentStorageExtensions.cs @@ -14,18 +14,12 @@ internal static class PersistentStorageExtensions { public static IChecksummedPersistentStorageService GetPersistentStorageService(this SolutionServices services) { - var workspaceConfiguration = services.GetService(); var configuration = services.GetRequiredService(); - var cacheStorage = workspaceConfiguration?.Options.CacheStorage; - return cacheStorage switch - { -#if !DOTNET_BUILD_FROM_SOURCE - StorageDatabase.SQLite - => services.GetService() ?? - NoOpPersistentStorageService.GetOrThrow(configuration), +#if DOTNET_BUILD_FROM_SOURCE + return NoOpPersistentStorageService.GetOrThrow(configuration); +#else + return services.GetService() ?? NoOpPersistentStorageService.GetOrThrow(configuration); #endif - _ => NoOpPersistentStorageService.GetOrThrow(configuration), - }; } } diff --git a/src/Workspaces/Core/Portable/Storage/StorageDatabase.cs b/src/Workspaces/Core/Portable/Storage/StorageDatabase.cs deleted file mode 100644 index 2f9cf9a4a83b2..0000000000000 --- a/src/Workspaces/Core/Portable/Storage/StorageDatabase.cs +++ /dev/null @@ -1,11 +0,0 @@ -// 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. - -namespace Microsoft.CodeAnalysis.Storage; - -internal enum StorageDatabase -{ - None = 0, - SQLite = 1, -} diff --git a/src/Workspaces/Core/Portable/Utilities/Documentation/XmlDocumentationProvider.cs b/src/Workspaces/Core/Portable/Utilities/Documentation/XmlDocumentationProvider.cs index 56e2bde04c946..f0d7b0f914862 100644 --- a/src/Workspaces/Core/Portable/Utilities/Documentation/XmlDocumentationProvider.cs +++ b/src/Workspaces/Core/Portable/Utilities/Documentation/XmlDocumentationProvider.cs @@ -21,7 +21,7 @@ namespace Microsoft.CodeAnalysis; /// public abstract class XmlDocumentationProvider : DocumentationProvider { - private readonly NonReentrantLock _gate = new(); + private readonly SemaphoreSlim _gate = new(initialCount: 1); private Dictionary _docComments; /// diff --git a/src/Workspaces/Core/Portable/Workspace/Host/Metadata/MetadataReferenceCache.cs b/src/Workspaces/Core/Portable/Workspace/Host/Metadata/MetadataReferenceCache.cs index bbcefc0a74fac..c7a19fed7d7a2 100644 --- a/src/Workspaces/Core/Portable/Workspace/Host/Metadata/MetadataReferenceCache.cs +++ b/src/Workspaces/Core/Portable/Workspace/Host/Metadata/MetadataReferenceCache.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; +using System.Threading; using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.Host; @@ -36,7 +37,7 @@ public MetadataReference GetReference(string path, MetadataReferenceProperties p /// private class ReferenceSet(MetadataReferenceCache cache) { - private readonly NonReentrantLock _gate = new(); + private readonly SemaphoreSlim _gate = new(initialCount: 1); // metadata references are held weakly, so even though this is a cache that enables reuse, it does not control lifetime. private readonly Dictionary> _references = []; diff --git a/src/Workspaces/Core/Portable/Workspace/IWorkspaceConfigurationService.cs b/src/Workspaces/Core/Portable/Workspace/IWorkspaceConfigurationService.cs index 7001dd71f4377..0ca130ae00be6 100644 --- a/src/Workspaces/Core/Portable/Workspace/IWorkspaceConfigurationService.cs +++ b/src/Workspaces/Core/Portable/Workspace/IWorkspaceConfigurationService.cs @@ -6,7 +6,6 @@ using System.Composition; using System.Runtime.Serialization; using Microsoft.CodeAnalysis.Host.Mef; -using Microsoft.CodeAnalysis.Storage; namespace Microsoft.CodeAnalysis.Host; @@ -34,9 +33,8 @@ internal sealed class DefaultWorkspaceConfigurationService() : IWorkspaceConfigu /// [DataContract] internal readonly record struct WorkspaceConfigurationOptions( - [property: DataMember(Order = 0)] StorageDatabase CacheStorage = StorageDatabase.SQLite, - [property: DataMember(Order = 1)] SourceGeneratorExecutionPreference SourceGeneratorExecution = SourceGeneratorExecutionPreference.Automatic, - [property: DataMember(Order = 2)] bool ValidateCompilationTrackerStates = + [property: DataMember(Order = 0)] SourceGeneratorExecutionPreference SourceGeneratorExecution = SourceGeneratorExecutionPreference.Automatic, + [property: DataMember(Order = 1)] bool ValidateCompilationTrackerStates = #if DEBUG // We will default this on in DEBUG builds true #else @@ -44,17 +42,11 @@ internal readonly record struct WorkspaceConfigurationOptions( #endif ) { - public WorkspaceConfigurationOptions() - : this(CacheStorage: StorageDatabase.SQLite) - { - } - public static readonly WorkspaceConfigurationOptions Default = new(); /// /// These values are such that the correctness of remote services is not affected if these options are changed from defaults /// to non-defaults while the services have already been executing. /// - public static readonly WorkspaceConfigurationOptions RemoteDefault = new( - CacheStorage: StorageDatabase.None); + public static readonly WorkspaceConfigurationOptions RemoteDefault = new(); } diff --git a/src/Workspaces/Core/Portable/Workspace/Solution/ProjectDependencyGraph.cs b/src/Workspaces/Core/Portable/Workspace/Solution/ProjectDependencyGraph.cs index db5c420b28c49..5d1b58e2b371f 100644 --- a/src/Workspaces/Core/Portable/Workspace/Solution/ProjectDependencyGraph.cs +++ b/src/Workspaces/Core/Portable/Workspace/Solution/ProjectDependencyGraph.cs @@ -35,7 +35,7 @@ public partial class ProjectDependencyGraph private readonly ImmutableDictionary> _referencesMap; // guards lazy computed data - private readonly NonReentrantLock _dataLock = new(); + private readonly SemaphoreSlim _dataLock = new(initialCount: 1); /// /// The lazily-initialized map of projects to projects which reference them. This field is either null, or diff --git a/src/Workspaces/CoreTest/Options/OptionSerializerTests.cs b/src/Workspaces/CoreTest/Options/OptionSerializerTests.cs index 62608e022fbe0..80dcdc11fd448 100644 --- a/src/Workspaces/CoreTest/Options/OptionSerializerTests.cs +++ b/src/Workspaces/CoreTest/Options/OptionSerializerTests.cs @@ -67,7 +67,6 @@ public void SerializationAndDeserializationForEnum() var options = new IOption2[] { InlineDiagnosticsOptionsStorage.Location, - WorkspaceConfigurationOptionsStorage.Database, SolutionCrawlerOptionsStorage.BackgroundAnalysisScopeOption, SolutionCrawlerOptionsStorage.CompilerDiagnosticsScopeOption, ImplementTypeOptionsStorage.InsertionBehavior,