diff --git a/src/Compilers/CSharp/Portable/Lowering/AsyncRewriter/AsyncIteratorMethodToStateMachineRewriter.cs b/src/Compilers/CSharp/Portable/Lowering/AsyncRewriter/AsyncIteratorMethodToStateMachineRewriter.cs index 69f7bd6dabb0a..b3fcbcd55aefe 100644 --- a/src/Compilers/CSharp/Portable/Lowering/AsyncRewriter/AsyncIteratorMethodToStateMachineRewriter.cs +++ b/src/Compilers/CSharp/Portable/Lowering/AsyncRewriter/AsyncIteratorMethodToStateMachineRewriter.cs @@ -52,7 +52,7 @@ internal AsyncIteratorMethodToStateMachineRewriter( FieldSymbol state, FieldSymbol builder, FieldSymbol? instanceIdField, - Roslyn.Utilities.IReadOnlySet hoistedVariables, + IReadOnlySet hoistedVariables, IReadOnlyDictionary nonReusableLocalProxies, SynthesizedLocalOrdinalsDispenser synthesizedLocalOrdinals, ArrayBuilder stateMachineStateDebugInfoBuilder, diff --git a/src/Compilers/CSharp/Portable/Lowering/AsyncRewriter/AsyncMethodToStateMachineRewriter.cs b/src/Compilers/CSharp/Portable/Lowering/AsyncRewriter/AsyncMethodToStateMachineRewriter.cs index 67f3255bb682e..0f4b9ce1c020d 100644 --- a/src/Compilers/CSharp/Portable/Lowering/AsyncRewriter/AsyncMethodToStateMachineRewriter.cs +++ b/src/Compilers/CSharp/Portable/Lowering/AsyncRewriter/AsyncMethodToStateMachineRewriter.cs @@ -70,7 +70,7 @@ internal AsyncMethodToStateMachineRewriter( FieldSymbol state, FieldSymbol builder, FieldSymbol? instanceIdField, - Roslyn.Utilities.IReadOnlySet hoistedVariables, + IReadOnlySet hoistedVariables, IReadOnlyDictionary nonReusableLocalProxies, SynthesizedLocalOrdinalsDispenser synthesizedLocalOrdinals, ArrayBuilder stateMachineStateDebugInfoBuilder, diff --git a/src/Compilers/CSharp/Portable/Lowering/IteratorRewriter/IteratorMethodToStateMachineRewriter.cs b/src/Compilers/CSharp/Portable/Lowering/IteratorRewriter/IteratorMethodToStateMachineRewriter.cs index 1cfae5948d2b1..15a83f4890660 100644 --- a/src/Compilers/CSharp/Portable/Lowering/IteratorRewriter/IteratorMethodToStateMachineRewriter.cs +++ b/src/Compilers/CSharp/Portable/Lowering/IteratorRewriter/IteratorMethodToStateMachineRewriter.cs @@ -58,7 +58,7 @@ internal IteratorMethodToStateMachineRewriter( FieldSymbol state, FieldSymbol current, FieldSymbol? instanceIdField, - Roslyn.Utilities.IReadOnlySet hoistedVariables, + IReadOnlySet hoistedVariables, IReadOnlyDictionary nonReusableLocalProxies, SynthesizedLocalOrdinalsDispenser synthesizedLocalOrdinals, ArrayBuilder stateMachineStateDebugInfoBuilder, diff --git a/src/Compilers/CSharp/Portable/Lowering/StateMachineRewriter/MethodToStateMachineRewriter.cs b/src/Compilers/CSharp/Portable/Lowering/StateMachineRewriter/MethodToStateMachineRewriter.cs index 9e8d545d5e069..43c6ed9c1abde 100644 --- a/src/Compilers/CSharp/Portable/Lowering/StateMachineRewriter/MethodToStateMachineRewriter.cs +++ b/src/Compilers/CSharp/Portable/Lowering/StateMachineRewriter/MethodToStateMachineRewriter.cs @@ -83,7 +83,7 @@ internal abstract class MethodToStateMachineRewriter : MethodToClassRewriter /// /// The set of local variables and parameters that were hoisted and need a proxy. /// - private readonly Roslyn.Utilities.IReadOnlySet _hoistedVariables; + private readonly IReadOnlySet _hoistedVariables; private readonly SynthesizedLocalOrdinalsDispenser _synthesizedLocalOrdinals; private int _nextFreeHoistedLocalSlot; @@ -102,7 +102,7 @@ public MethodToStateMachineRewriter( MethodSymbol originalMethod, FieldSymbol state, FieldSymbol? instanceIdField, - Roslyn.Utilities.IReadOnlySet hoistedVariables, + IReadOnlySet hoistedVariables, IReadOnlyDictionary nonReusableLocalProxies, SynthesizedLocalOrdinalsDispenser synthesizedLocalOrdinals, ArrayBuilder stateMachineStateDebugInfoBuilder, @@ -188,7 +188,7 @@ protected override NamedTypeSymbol ContainingType get { return OriginalMethod.ContainingType; } } - internal Roslyn.Utilities.IReadOnlySet HoistedVariables + internal IReadOnlySet HoistedVariables { get { diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedPrimaryConstructor.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedPrimaryConstructor.cs index 53e4a7af5e6da..496c60a5510cc 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedPrimaryConstructor.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedPrimaryConstructor.cs @@ -15,7 +15,7 @@ namespace Microsoft.CodeAnalysis.CSharp.Symbols internal sealed class SynthesizedPrimaryConstructor : SourceConstructorSymbolBase { private IReadOnlyDictionary? _capturedParameters = null; - private Roslyn.Utilities.IReadOnlySet? _parametersPassedToTheBase = null; + private IReadOnlySet? _parametersPassedToTheBase = null; public SynthesizedPrimaryConstructor( SourceMemberContainerTypeSymbol containingType, @@ -186,7 +186,7 @@ protected override bool ShouldBindAttributes(AttributeListSyntax attributeDeclar return false; } - public Roslyn.Utilities.IReadOnlySet GetParametersPassedToTheBase() + public IReadOnlySet GetParametersPassedToTheBase() { if (_parametersPassedToTheBase != null) { @@ -203,7 +203,7 @@ public Roslyn.Utilities.IReadOnlySet GetParametersPassedToTheBa return _parametersPassedToTheBase; } - internal void SetParametersPassedToTheBase(Roslyn.Utilities.IReadOnlySet value) + internal void SetParametersPassedToTheBase(IReadOnlySet value) { #if DEBUG var oldSet = _parametersPassedToTheBase; diff --git a/src/Compilers/Core/Portable/Collections/IOrderedReadOnlySet.cs b/src/Compilers/Core/Portable/Collections/IOrderedReadOnlySet.cs index 37b343f6f2671..f1993377fe6c0 100644 --- a/src/Compilers/Core/Portable/Collections/IOrderedReadOnlySet.cs +++ b/src/Compilers/Core/Portable/Collections/IOrderedReadOnlySet.cs @@ -3,11 +3,10 @@ // See the LICENSE file in the project root for more information. using System.Collections.Generic; -using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.Collections { - internal interface IOrderedReadOnlySet : Roslyn.Utilities.IReadOnlySet, IReadOnlyList + internal interface IOrderedReadOnlySet : IReadOnlySet, IReadOnlyList { } -} \ No newline at end of file +} diff --git a/src/Compilers/Core/Portable/Collections/OrderedSet.cs b/src/Compilers/Core/Portable/Collections/OrderedSet.cs index 5d110ddab08de..800846b1cdfcf 100644 --- a/src/Compilers/Core/Portable/Collections/OrderedSet.cs +++ b/src/Compilers/Core/Portable/Collections/OrderedSet.cs @@ -2,15 +2,13 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Collections; using System.Collections.Generic; using Microsoft.CodeAnalysis.PooledObjects; -using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.Collections { - internal sealed class OrderedSet : IEnumerable, Roslyn.Utilities.IReadOnlySet, IReadOnlyList, IOrderedReadOnlySet + internal sealed class OrderedSet : IOrderedReadOnlySet { private readonly HashSet _set; private readonly ArrayBuilder _list; @@ -87,5 +85,23 @@ public void Clear() _set.Clear(); _list.Clear(); } + + public bool IsProperSubsetOf(IEnumerable other) + => _set.IsProperSubsetOf(other); + + public bool IsProperSupersetOf(IEnumerable other) + => _set.IsProperSupersetOf(other); + + public bool IsSubsetOf(IEnumerable other) + => _set.IsSubsetOf(other); + + public bool IsSupersetOf(IEnumerable other) + => _set.IsSupersetOf(other); + + public bool Overlaps(IEnumerable other) + => _set.Overlaps(other); + + public bool SetEquals(IEnumerable other) + => _set.SetEquals(other); } } diff --git a/src/Compilers/Core/Portable/CommandLine/CommonCompiler.cs b/src/Compilers/Core/Portable/CommandLine/CommonCompiler.cs index 2aa77fd0bff23..a2ef4cec63f68 100644 --- a/src/Compilers/Core/Portable/CommandLine/CommonCompiler.cs +++ b/src/Compilers/Core/Portable/CommandLine/CommonCompiler.cs @@ -82,7 +82,7 @@ internal abstract partial class CommonCompiler /// The set of source file paths that are in the set of embedded paths. /// This is used to prevent reading source files that are embedded twice. /// - public Roslyn.Utilities.IReadOnlySet EmbeddedSourcePaths { get; } + public IReadOnlySet EmbeddedSourcePaths { get; } /// /// The used to access the file system inside this instance. @@ -483,7 +483,7 @@ protected abstract void ResolveEmbeddedFilesFromExternalSourceDirectives( OrderedSet embeddedFiles, DiagnosticBag diagnostics); - private static Roslyn.Utilities.IReadOnlySet GetEmbeddedSourcePaths(CommandLineArguments arguments) + private static IReadOnlySet GetEmbeddedSourcePaths(CommandLineArguments arguments) { if (arguments.EmbeddedFiles.IsEmpty) { diff --git a/src/Compilers/Core/Portable/InternalUtilities/IReadOnlySet.cs b/src/Compilers/Core/Portable/InternalUtilities/IReadOnlySet.cs index 75a01d97842e5..00d0e12056f3f 100644 --- a/src/Compilers/Core/Portable/InternalUtilities/IReadOnlySet.cs +++ b/src/Compilers/Core/Portable/InternalUtilities/IReadOnlySet.cs @@ -2,11 +2,78 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -namespace Roslyn.Utilities +#if NET6_0_OR_GREATER + +using System.Runtime.CompilerServices; + +#pragma warning disable RS0016 // Add public types and members to the declared API (this is a supporting forwarder for an internal polyfill API) +[assembly: TypeForwardedTo(typeof(System.Collections.Generic.IReadOnlySet<>))] +#pragma warning restore RS0016 // Add public types and members to the declared API + +#else + +namespace System.Collections.Generic; + +/// +/// Provides a readonly abstraction of a set. +/// +/// The type of elements in the set. +internal interface IReadOnlySet : IReadOnlyCollection { - internal interface IReadOnlySet - { - int Count { get; } - bool Contains(T item); - } -} \ No newline at end of file + /// + /// Determines if the set contains a specific item + /// + /// The item to check if the set contains. + /// if found; otherwise . + bool Contains(T item); + + /// + /// Determines whether the current set is a proper (strict) subset of a specified collection. + /// + /// The collection to compare to the current set. + /// if the current set is a proper subset of other; otherwise . + /// other is . + bool IsProperSubsetOf(IEnumerable other); + + /// + /// Determines whether the current set is a proper (strict) superset of a specified collection. + /// + /// The collection to compare to the current set. + /// if the collection is a proper superset of other; otherwise . + /// other is . + bool IsProperSupersetOf(IEnumerable other); + + /// + /// Determine whether the current set is a subset of a specified collection. + /// + /// The collection to compare to the current set. + /// if the current set is a subset of other; otherwise . + /// other is . + bool IsSubsetOf(IEnumerable other); + + /// + /// Determine whether the current set is a super set of a specified collection. + /// + /// The collection to compare to the current set + /// if the current set is a subset of other; otherwise . + /// other is . + bool IsSupersetOf(IEnumerable other); + + /// + /// Determines whether the current set overlaps with the specified collection. + /// + /// The collection to compare to the current set. + /// if the current set and other share at least one common element; otherwise, . + /// other is . + bool Overlaps(IEnumerable other); + + /// + /// Determines whether the current set and the specified collection contain the same elements. + /// + /// The collection to compare to the current set. + /// if the current set is equal to other; otherwise, . + /// other is . + bool SetEquals(IEnumerable other); +} + +#endif diff --git a/src/Compilers/Core/Portable/InternalUtilities/SetWithInsertionOrder.cs b/src/Compilers/Core/Portable/InternalUtilities/SetWithInsertionOrder.cs index 7fac2932aec68..c25a87c231d0b 100644 --- a/src/Compilers/Core/Portable/InternalUtilities/SetWithInsertionOrder.cs +++ b/src/Compilers/Core/Portable/InternalUtilities/SetWithInsertionOrder.cs @@ -6,6 +6,7 @@ using System.Collections; using System.Collections.Generic; using System.Collections.Immutable; +using Microsoft.CodeAnalysis.Collections; using Microsoft.CodeAnalysis.PooledObjects; namespace Roslyn.Utilities @@ -14,7 +15,7 @@ namespace Roslyn.Utilities /// A set that returns the inserted values in insertion order. /// The mutation operations are not thread-safe. /// - internal sealed class SetWithInsertionOrder : IEnumerable, IReadOnlySet + internal sealed class SetWithInsertionOrder : IOrderedReadOnlySet { private HashSet? _set = null; private ArrayBuilder? _elements = null; @@ -93,5 +94,26 @@ public IEnumerator GetEnumerator() public ImmutableArray AsImmutable() => _elements.ToImmutableArrayOrEmpty(); public T this[int i] => _elements![i]; + + private IReadOnlySet Set + => (IReadOnlySet?)_set ?? SpecializedCollections.EmptyReadOnlySet(); + + public bool IsProperSubsetOf(IEnumerable other) + => Set.IsProperSubsetOf(other); + + public bool IsProperSupersetOf(IEnumerable other) + => Set.IsProperSupersetOf(other); + + public bool IsSubsetOf(IEnumerable other) + => Set.IsSubsetOf(other); + + public bool IsSupersetOf(IEnumerable other) + => Set.IsSupersetOf(other); + + public bool Overlaps(IEnumerable other) + => Set.Overlaps(other); + + public bool SetEquals(IEnumerable other) + => Set.SetEquals(other); } } diff --git a/src/Compilers/VisualBasic/Portable/Lowering/AsyncRewriter/AsyncRewriter.AsyncMethodToClassRewriter.vb b/src/Compilers/VisualBasic/Portable/Lowering/AsyncRewriter/AsyncRewriter.AsyncMethodToClassRewriter.vb index 259b6175e919d..54eb8ed834cff 100644 --- a/src/Compilers/VisualBasic/Portable/Lowering/AsyncRewriter/AsyncRewriter.AsyncMethodToClassRewriter.vb +++ b/src/Compilers/VisualBasic/Portable/Lowering/AsyncRewriter/AsyncRewriter.AsyncMethodToClassRewriter.vb @@ -64,7 +64,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic F As SyntheticBoundNodeFactory, state As FieldSymbol, builder As FieldSymbol, - hoistedVariables As Roslyn.Utilities.IReadOnlySet(Of Symbol), + hoistedVariables As IReadOnlySet(Of Symbol), nonReusableLocalProxies As Dictionary(Of Symbol, CapturedSymbolOrExpression), stateMachineStateDebugInfoBuilder As ArrayBuilder(Of StateMachineStateDebugInfo), slotAllocatorOpt As VariableSlotAllocator, diff --git a/src/Compilers/VisualBasic/Portable/Lowering/IteratorRewriter/IteratorRewriter.IteratorMethodToClassRewriter.vb b/src/Compilers/VisualBasic/Portable/Lowering/IteratorRewriter/IteratorRewriter.IteratorMethodToClassRewriter.vb index 7be09edde9b92..448fc24891d65 100644 --- a/src/Compilers/VisualBasic/Portable/Lowering/IteratorRewriter/IteratorRewriter.IteratorMethodToClassRewriter.vb +++ b/src/Compilers/VisualBasic/Portable/Lowering/IteratorRewriter/IteratorRewriter.IteratorMethodToClassRewriter.vb @@ -27,7 +27,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic Friend Sub New(F As SyntheticBoundNodeFactory, state As FieldSymbol, current As FieldSymbol, - hoistedVariables As Roslyn.Utilities.IReadOnlySet(Of Symbol), + hoistedVariables As IReadOnlySet(Of Symbol), localProxies As Dictionary(Of Symbol, FieldSymbol), stateMachineStateDebugInfoBuilder As ArrayBuilder(Of StateMachineStateDebugInfo), slotAllocatorOpt As VariableSlotAllocator, diff --git a/src/Compilers/VisualBasic/Portable/Lowering/StateMachineRewriter/StateMachineRewriter.StateMachineMethodToClassRewriter.vb b/src/Compilers/VisualBasic/Portable/Lowering/StateMachineRewriter/StateMachineRewriter.StateMachineMethodToClassRewriter.vb index 70816a62cdf42..ac6abf1726dac 100644 --- a/src/Compilers/VisualBasic/Portable/Lowering/StateMachineRewriter/StateMachineRewriter.StateMachineMethodToClassRewriter.vb +++ b/src/Compilers/VisualBasic/Portable/Lowering/StateMachineRewriter/StateMachineRewriter.StateMachineMethodToClassRewriter.vb @@ -66,7 +66,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic ''' ''' The set of local variables and parameters that were hoisted and need a proxy. ''' - Private ReadOnly _hoistedVariables As Roslyn.Utilities.IReadOnlySet(Of Symbol) = Nothing + Private ReadOnly _hoistedVariables As IReadOnlySet(Of Symbol) = Nothing ''' ''' EnC support: the rewriter stores debug info for each await/yield in this builder. @@ -75,7 +75,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic Public Sub New(F As SyntheticBoundNodeFactory, stateField As FieldSymbol, - hoistedVariables As Roslyn.Utilities.IReadOnlySet(Of Symbol), + hoistedVariables As IReadOnlySet(Of Symbol), initialProxies As Dictionary(Of Symbol, TProxy), stateMachineStateDebugInfoBuilder As ArrayBuilder(Of StateMachineStateDebugInfo), slotAllocatorOpt As VariableSlotAllocator, diff --git a/src/Compilers/VisualBasic/Portable/Lowering/StateMachineRewriter/StateMachineRewriter.vb b/src/Compilers/VisualBasic/Portable/Lowering/StateMachineRewriter/StateMachineRewriter.vb index 06fe837d671ce..ab4a83cc72470 100644 --- a/src/Compilers/VisualBasic/Portable/Lowering/StateMachineRewriter/StateMachineRewriter.vb +++ b/src/Compilers/VisualBasic/Portable/Lowering/StateMachineRewriter/StateMachineRewriter.vb @@ -33,7 +33,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic Protected StateField As FieldSymbol Protected nonReusableLocalProxies As Dictionary(Of Symbol, TProxy) Protected nextFreeHoistedLocalSlot As Integer - Protected hoistedVariables As Roslyn.Utilities.IReadOnlySet(Of Symbol) + Protected hoistedVariables As IReadOnlySet(Of Symbol) Protected InitialParameters As Dictionary(Of Symbol, TProxy) Protected Sub New(body As BoundStatement, diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CompilerExtensions.projitems b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CompilerExtensions.projitems index b2444dcd6effc..685ea9d02f39f 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CompilerExtensions.projitems +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CompilerExtensions.projitems @@ -54,6 +54,7 @@ + diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/ObjectPools/PooledHashSet.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/ObjectPools/PooledHashSet.cs index be5b7d56e52ea..227dd7e35426f 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/ObjectPools/PooledHashSet.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/ObjectPools/PooledHashSet.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Roslyn.Utilities; +using System.Collections.Generic; namespace Microsoft.CodeAnalysis.PooledObjects {