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

Replace Roslyn.Utilities.IReadOnlySet with System.Collections.Generic.IReadOnlySet #70297

Merged
merged 1 commit into from
Oct 12, 2023
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 @@ -52,7 +52,7 @@ internal AsyncIteratorMethodToStateMachineRewriter(
FieldSymbol state,
FieldSymbol builder,
FieldSymbol? instanceIdField,
Roslyn.Utilities.IReadOnlySet<Symbol> hoistedVariables,
IReadOnlySet<Symbol> hoistedVariables,
IReadOnlyDictionary<Symbol, CapturedSymbolReplacement> nonReusableLocalProxies,
SynthesizedLocalOrdinalsDispenser synthesizedLocalOrdinals,
ArrayBuilder<StateMachineStateDebugInfo> stateMachineStateDebugInfoBuilder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ internal AsyncMethodToStateMachineRewriter(
FieldSymbol state,
FieldSymbol builder,
FieldSymbol? instanceIdField,
Roslyn.Utilities.IReadOnlySet<Symbol> hoistedVariables,
IReadOnlySet<Symbol> hoistedVariables,
IReadOnlyDictionary<Symbol, CapturedSymbolReplacement> nonReusableLocalProxies,
SynthesizedLocalOrdinalsDispenser synthesizedLocalOrdinals,
ArrayBuilder<StateMachineStateDebugInfo> stateMachineStateDebugInfoBuilder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ internal IteratorMethodToStateMachineRewriter(
FieldSymbol state,
FieldSymbol current,
FieldSymbol? instanceIdField,
Roslyn.Utilities.IReadOnlySet<Symbol> hoistedVariables,
IReadOnlySet<Symbol> hoistedVariables,
IReadOnlyDictionary<Symbol, CapturedSymbolReplacement> nonReusableLocalProxies,
SynthesizedLocalOrdinalsDispenser synthesizedLocalOrdinals,
ArrayBuilder<StateMachineStateDebugInfo> stateMachineStateDebugInfoBuilder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ internal abstract class MethodToStateMachineRewriter : MethodToClassRewriter
/// <summary>
/// The set of local variables and parameters that were hoisted and need a proxy.
/// </summary>
private readonly Roslyn.Utilities.IReadOnlySet<Symbol> _hoistedVariables;
private readonly IReadOnlySet<Symbol> _hoistedVariables;

private readonly SynthesizedLocalOrdinalsDispenser _synthesizedLocalOrdinals;
private int _nextFreeHoistedLocalSlot;
Expand All @@ -102,7 +102,7 @@ public MethodToStateMachineRewriter(
MethodSymbol originalMethod,
FieldSymbol state,
FieldSymbol? instanceIdField,
Roslyn.Utilities.IReadOnlySet<Symbol> hoistedVariables,
IReadOnlySet<Symbol> hoistedVariables,
IReadOnlyDictionary<Symbol, CapturedSymbolReplacement> nonReusableLocalProxies,
SynthesizedLocalOrdinalsDispenser synthesizedLocalOrdinals,
ArrayBuilder<StateMachineStateDebugInfo> stateMachineStateDebugInfoBuilder,
Expand Down Expand Up @@ -188,7 +188,7 @@ protected override NamedTypeSymbol ContainingType
get { return OriginalMethod.ContainingType; }
}

internal Roslyn.Utilities.IReadOnlySet<Symbol> HoistedVariables
internal IReadOnlySet<Symbol> HoistedVariables
{
get
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Microsoft.CodeAnalysis.CSharp.Symbols
internal sealed class SynthesizedPrimaryConstructor : SourceConstructorSymbolBase
{
private IReadOnlyDictionary<ParameterSymbol, FieldSymbol>? _capturedParameters = null;
private Roslyn.Utilities.IReadOnlySet<ParameterSymbol>? _parametersPassedToTheBase = null;
private IReadOnlySet<ParameterSymbol>? _parametersPassedToTheBase = null;

public SynthesizedPrimaryConstructor(
SourceMemberContainerTypeSymbol containingType,
Expand Down Expand Up @@ -186,7 +186,7 @@ protected override bool ShouldBindAttributes(AttributeListSyntax attributeDeclar
return false;
}

public Roslyn.Utilities.IReadOnlySet<ParameterSymbol> GetParametersPassedToTheBase()
public IReadOnlySet<ParameterSymbol> GetParametersPassedToTheBase()
{
if (_parametersPassedToTheBase != null)
{
Expand All @@ -203,7 +203,7 @@ public Roslyn.Utilities.IReadOnlySet<ParameterSymbol> GetParametersPassedToTheBa
return _parametersPassedToTheBase;
}

internal void SetParametersPassedToTheBase(Roslyn.Utilities.IReadOnlySet<ParameterSymbol> value)
internal void SetParametersPassedToTheBase(IReadOnlySet<ParameterSymbol> value)
{
#if DEBUG
var oldSet = _parametersPassedToTheBase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> : Roslyn.Utilities.IReadOnlySet<T>, IReadOnlyList<T>
internal interface IOrderedReadOnlySet<T> : IReadOnlySet<T>, IReadOnlyList<T>
{
}
}
}
22 changes: 19 additions & 3 deletions src/Compilers/Core/Portable/Collections/OrderedSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> : IEnumerable<T>, Roslyn.Utilities.IReadOnlySet<T>, IReadOnlyList<T>, IOrderedReadOnlySet<T>
internal sealed class OrderedSet<T> : IOrderedReadOnlySet<T>
{
private readonly HashSet<T> _set;
private readonly ArrayBuilder<T> _list;
Expand Down Expand Up @@ -87,5 +85,23 @@ public void Clear()
_set.Clear();
_list.Clear();
}

public bool IsProperSubsetOf(IEnumerable<T> other)
=> _set.IsProperSubsetOf(other);

public bool IsProperSupersetOf(IEnumerable<T> other)
=> _set.IsProperSupersetOf(other);

public bool IsSubsetOf(IEnumerable<T> other)
=> _set.IsSubsetOf(other);

public bool IsSupersetOf(IEnumerable<T> other)
=> _set.IsSupersetOf(other);

public bool Overlaps(IEnumerable<T> other)
=> _set.Overlaps(other);

public bool SetEquals(IEnumerable<T> other)
=> _set.SetEquals(other);
}
}
4 changes: 2 additions & 2 deletions src/Compilers/Core/Portable/CommandLine/CommonCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/// </summary>
public Roslyn.Utilities.IReadOnlySet<string> EmbeddedSourcePaths { get; }
public IReadOnlySet<string> EmbeddedSourcePaths { get; }

/// <summary>
/// The <see cref="ICommonCompilerFileSystem"/> used to access the file system inside this instance.
Expand Down Expand Up @@ -483,7 +483,7 @@ protected abstract void ResolveEmbeddedFilesFromExternalSourceDirectives(
OrderedSet<string> embeddedFiles,
DiagnosticBag diagnostics);

private static Roslyn.Utilities.IReadOnlySet<string> GetEmbeddedSourcePaths(CommandLineArguments arguments)
private static IReadOnlySet<string> GetEmbeddedSourcePaths(CommandLineArguments arguments)
{
if (arguments.EmbeddedFiles.IsEmpty)
{
Expand Down
81 changes: 74 additions & 7 deletions src/Compilers/Core/Portable/InternalUtilities/IReadOnlySet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
/// Provides a readonly abstraction of a set.
/// </summary>
/// <typeparam name="T">The type of elements in the set.</typeparam>
internal interface IReadOnlySet<T> : IReadOnlyCollection<T>
{
internal interface IReadOnlySet<T>
{
int Count { get; }
bool Contains(T item);
}
}
/// <summary>
/// Determines if the set contains a specific item
/// </summary>
/// <param name="item">The item to check if the set contains.</param>
/// <returns><see langword="true" /> if found; otherwise <see langword="false" />.</returns>
bool Contains(T item);

/// <summary>
/// Determines whether the current set is a proper (strict) subset of a specified collection.
/// </summary>
/// <param name="other">The collection to compare to the current set.</param>
/// <returns><see langword="true" /> if the current set is a proper subset of other; otherwise <see langword="false" />.</returns>
/// <exception cref="ArgumentNullException">other is <see langword="null" />.</exception>
bool IsProperSubsetOf(IEnumerable<T> other);

/// <summary>
/// Determines whether the current set is a proper (strict) superset of a specified collection.
/// </summary>
/// <param name="other">The collection to compare to the current set.</param>
/// <returns><see langword="true" /> if the collection is a proper superset of other; otherwise <see langword="false" />.</returns>
/// <exception cref="ArgumentNullException">other is <see langword="null" />.</exception>
bool IsProperSupersetOf(IEnumerable<T> other);

/// <summary>
/// Determine whether the current set is a subset of a specified collection.
/// </summary>
/// <param name="other">The collection to compare to the current set.</param>
/// <returns><see langword="true" /> if the current set is a subset of other; otherwise <see langword="false" />.</returns>
/// <exception cref="ArgumentNullException">other is <see langword="null" />.</exception>
bool IsSubsetOf(IEnumerable<T> other);

/// <summary>
/// Determine whether the current set is a super set of a specified collection.
/// </summary>
/// <param name="other">The collection to compare to the current set</param>
/// <returns><see langword="true" /> if the current set is a subset of other; otherwise <see langword="false" />.</returns>
/// <exception cref="ArgumentNullException">other is <see langword="null" />.</exception>
bool IsSupersetOf(IEnumerable<T> other);

/// <summary>
/// Determines whether the current set overlaps with the specified collection.
/// </summary>
/// <param name="other">The collection to compare to the current set.</param>
/// <returns><see langword="true" /> if the current set and other share at least one common element; otherwise, <see langword="false" />.</returns>
/// <exception cref="ArgumentNullException">other is <see langword="null" />.</exception>
bool Overlaps(IEnumerable<T> other);

/// <summary>
/// Determines whether the current set and the specified collection contain the same elements.
/// </summary>
/// <param name="other">The collection to compare to the current set.</param>
/// <returns><see langword="true" /> if the current set is equal to other; otherwise, <see langword="false" />.</returns>
/// <exception cref="ArgumentNullException">other is <see langword="null" />.</exception>
bool SetEquals(IEnumerable<T> other);
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -14,7 +15,7 @@ namespace Roslyn.Utilities
/// A set that returns the inserted values in insertion order.
/// The mutation operations are not thread-safe.
/// </summary>
internal sealed class SetWithInsertionOrder<T> : IEnumerable<T>, IReadOnlySet<T>
internal sealed class SetWithInsertionOrder<T> : IOrderedReadOnlySet<T>
{
private HashSet<T>? _set = null;
private ArrayBuilder<T>? _elements = null;
Expand Down Expand Up @@ -93,5 +94,26 @@ public IEnumerator<T> GetEnumerator()
public ImmutableArray<T> AsImmutable() => _elements.ToImmutableArrayOrEmpty();

public T this[int i] => _elements![i];

private IReadOnlySet<T> Set
=> (IReadOnlySet<T>?)_set ?? SpecializedCollections.EmptyReadOnlySet<T>();

public bool IsProperSubsetOf(IEnumerable<T> other)
=> Set.IsProperSubsetOf(other);

public bool IsProperSupersetOf(IEnumerable<T> other)
=> Set.IsProperSupersetOf(other);

public bool IsSubsetOf(IEnumerable<T> other)
=> Set.IsSubsetOf(other);

public bool IsSupersetOf(IEnumerable<T> other)
=> Set.IsSupersetOf(other);

public bool Overlaps(IEnumerable<T> other)
=> Set.Overlaps(other);

public bool SetEquals(IEnumerable<T> other)
=> Set.SetEquals(other);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
''' <summary>
''' The set of local variables and parameters that were hoisted and need a proxy.
''' </summary>
Private ReadOnly _hoistedVariables As Roslyn.Utilities.IReadOnlySet(Of Symbol) = Nothing
Private ReadOnly _hoistedVariables As IReadOnlySet(Of Symbol) = Nothing

''' <summary>
''' EnC support: the rewriter stores debug info for each await/yield in this builder.
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\Compilers\Core\Portable\Collections\BitVector.cs" Link="Collections\BitVector.cs" />
<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\Compilers\Core\Portable\Collections\TemporaryArrayExtensions.cs" Link="Collections\TemporaryArrayExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\Compilers\Core\Portable\Collections\TemporaryArray`1.cs" Link="Collections\TemporaryArray`1.cs" />
<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\Compilers\Core\Portable\Collections\IOrderedReadOnlySet.cs" Link="Collections\IOrderedReadOnlySet.cs" />
<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\Compilers\Core\Portable\InternalUtilities\Hash.cs" Link="InternalUtilities\Hash.cs" />
<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\Compilers\Core\Portable\InternalUtilities\GeneratedCodeUtilities.cs" Link="InternalUtilities\GeneratedCodeUtilities.cs" />
<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\Compilers\Core\Portable\Serialization\IObjectWritable.cs" Link="Serialization\IObjectWritable.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down