Skip to content
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

Remove option controlling which persistence DB to use. #73969

Merged
merged 7 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<DocumentId, UnitTestingData> _pendingWork = [];

public UnitTestingSemanticChangeProcessor(
Expand Down Expand Up @@ -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<TKey, TValue>(NonReentrantLock gate, Dictionary<TKey, TValue> map, CancellationToken cancellationToken)
private static TValue DequeueWorker<TKey, TValue>(SemaphoreSlim gate, Dictionary<TKey, TValue> map, CancellationToken cancellationToken)
where TKey : notnull
{
using (gate.DisposableWait(cancellationToken))
Expand All @@ -283,7 +283,7 @@ private static TValue DequeueWorker<TKey, TValue>(NonReentrantLock gate, Diction
}
}

private static void ClearQueueWorker<TKey, TValue>(NonReentrantLock gate, Dictionary<TKey, TValue> map, Func<TValue, IDisposable> disposerSelector)
private static void ClearQueueWorker<TKey, TValue>(SemaphoreSlim gate, Dictionary<TKey, TValue> map, Func<TValue, IDisposable> disposerSelector)
where TKey : notnull
{
using (gate.DisposableWait(CancellationToken.None))
Expand Down Expand Up @@ -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<ProjectId, UnitTestingData> _pendingWork = [];

public UnitTestingProjectProcessor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,18 @@
// See the LICENSE file in the project root for more information.

using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Storage;

namespace Microsoft.CodeAnalysis.Host;

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<StorageDatabase> Database = new(
"dotnet_storage_database", WorkspaceConfigurationOptions.Default.CacheStorage, serializer: EditorConfigValueSerializer.CreateSerializerForEnum<StorageDatabase>());

public static readonly Option2<bool> ValidateCompilationTrackerStates = new(
"dotnet_validate_compilation_tracker_states", WorkspaceConfigurationOptions.Default.ValidateCompilationTrackerStates);

Expand Down
19 changes: 4 additions & 15 deletions src/Tools/AnalyzerRunner/IncrementalAnalyzerRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<IGlobalOptionService>().Single().Value;
globalOptions.SetGlobalOption(SolutionCrawlerOptionsStorage.BackgroundAnalysisScopeOption, LanguageNames.CSharp, _options.AnalysisScope);
globalOptions.SetGlobalOption(SolutionCrawlerOptionsStorage.BackgroundAnalysisScopeOption, LanguageNames.VisualBasic, _options.AnalysisScope);

var workspaceConfigurationService = (AnalyzerRunnerWorkspaceConfigurationService)_workspace.Services.GetRequiredService<IWorkspaceConfigurationService>();
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.");
}
}
}
Expand Down
11 changes: 1 addition & 10 deletions src/Tools/AnalyzerRunner/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public sealed class Options
public readonly int Iterations;

// Options specific to incremental analyzers
public readonly bool UsePersistentStorage;
public readonly ImmutableArray<string> IncrementalAnalyzerNames;
public readonly bool FullSolutionAnalysis;

Expand All @@ -52,7 +51,6 @@ public Options(
bool applyChanges,
bool useAll,
int iterations,
bool usePersistentStorage,
bool fullSolutionAnalysis,
ImmutableArray<string> incrementalAnalyzerNames)
: this(analyzerPath,
Expand All @@ -71,7 +69,6 @@ public Options(
testDocumentIterations: 0,
logFileName: null,
profileRoot: null,
usePersistentStorage,
fullSolutionAnalysis,
incrementalAnalyzerNames)
{ }
Expand All @@ -93,7 +90,6 @@ internal Options(
int testDocumentIterations,
string logFileName,
string profileRoot,
bool usePersistentStorage,
bool fullSolutionAnalysis,
ImmutableArray<string> incrementalAnalyzerNames)
{
Expand All @@ -113,7 +109,6 @@ internal Options(
TestDocumentIterations = testDocumentIterations;
LogFileName = logFileName;
ProfileRoot = profileRoot;
UsePersistentStorage = usePersistentStorage;
FullSolutionAnalysis = fullSolutionAnalysis;
IncrementalAnalyzerNames = incrementalAnalyzerNames;
}
Expand All @@ -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<string>();

Expand Down Expand Up @@ -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;
Expand All @@ -216,6 +207,7 @@ internal static Options Create(string[] args)
? "Unrecognized option " + arg
: "Unrecognized parameter " + arg));
}

break;
}
}
Expand Down Expand Up @@ -247,7 +239,6 @@ internal static Options Create(string[] args)
testDocumentIterations: testDocumentIterations,
logFileName: logFileName,
profileRoot: profileRoot,
usePersistentStorage: usePersistentStorage,
fullSolutionAnalysis: fullSolutionAnalysis,
incrementalAnalyzerNames: incrementalAnalyzerNames.ToImmutable());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public void Setup()
applyChanges: false,
useAll: false,
iterations: 1,
usePersistentStorage: false,
fullSolutionAnalysis: false,
incrementalAnalyzerNames: ImmutableArray<string>.Empty);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public void Setup()
applyChanges: false,
useAll: false,
iterations: 1,
usePersistentStorage: false,
fullSolutionAnalysis: true,
incrementalAnalyzerNames: ImmutableArray.Create(AnalyzerName));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,12 @@ internal static class PersistentStorageExtensions
{
public static IChecksummedPersistentStorageService GetPersistentStorageService(this SolutionServices services)
{
var workspaceConfiguration = services.GetService<IWorkspaceConfigurationService>();
var configuration = services.GetRequiredService<IPersistentStorageConfiguration>();

var cacheStorage = workspaceConfiguration?.Options.CacheStorage;
return cacheStorage switch
{
#if !DOTNET_BUILD_FROM_SOURCE
StorageDatabase.SQLite
=> services.GetService<SQLitePersistentStorageService>() ??
NoOpPersistentStorageService.GetOrThrow(configuration),
#if DOTNET_BUILD_FROM_SOURCE
return NoOpPersistentStorageService.GetOrThrow(configuration);
#else
return services.GetService<SQLitePersistentStorageService>() ?? NoOpPersistentStorageService.GetOrThrow(configuration);
#endif
_ => NoOpPersistentStorageService.GetOrThrow(configuration),
};
}
}
11 changes: 0 additions & 11 deletions src/Workspaces/Core/Portable/Storage/StorageDatabase.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Microsoft.CodeAnalysis;
/// </summary>
public abstract class XmlDocumentationProvider : DocumentationProvider
{
private readonly NonReentrantLock _gate = new();
private readonly SemaphoreSlim _gate = new(initialCount: 1);
private Dictionary<string, string> _docComments;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.Host;
Expand Down Expand Up @@ -36,7 +37,7 @@ public MetadataReference GetReference(string path, MetadataReferenceProperties p
/// </summary>
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<MetadataReferenceProperties, WeakReference<MetadataReference>> _references = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Composition;
using System.Runtime.Serialization;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Storage;

namespace Microsoft.CodeAnalysis.Host;

Expand Down Expand Up @@ -34,27 +33,20 @@ internal sealed class DefaultWorkspaceConfigurationService() : IWorkspaceConfigu
/// </summary>
[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
false
#endif
)
{
public WorkspaceConfigurationOptions()
: this(CacheStorage: StorageDatabase.SQLite)
{
}

public static readonly WorkspaceConfigurationOptions Default = new();

/// <summary>
/// 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.
/// </summary>
public static readonly WorkspaceConfigurationOptions RemoteDefault = new(
CacheStorage: StorageDatabase.None);
public static readonly WorkspaceConfigurationOptions RemoteDefault = new();
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public partial class ProjectDependencyGraph
private readonly ImmutableDictionary<ProjectId, ImmutableHashSet<ProjectId>> _referencesMap;

// guards lazy computed data
private readonly NonReentrantLock _dataLock = new();
private readonly SemaphoreSlim _dataLock = new(initialCount: 1);

/// <summary>
/// The lazily-initialized map of projects to projects which reference them. This field is either null, or
Expand Down
1 change: 0 additions & 1 deletion src/Workspaces/CoreTest/Options/OptionSerializerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public void SerializationAndDeserializationForEnum()
var options = new IOption2[]
{
InlineDiagnosticsOptionsStorage.Location,
WorkspaceConfigurationOptionsStorage.Database,
SolutionCrawlerOptionsStorage.BackgroundAnalysisScopeOption,
SolutionCrawlerOptionsStorage.CompilerDiagnosticsScopeOption,
ImplementTypeOptionsStorage.InsertionBehavior,
Expand Down
Loading