Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
alrz committed Jul 21, 2021
1 parent 9961685 commit 8ddbf28
Show file tree
Hide file tree
Showing 9 changed files with 506 additions and 140 deletions.
159 changes: 137 additions & 22 deletions src/Compilers/CSharp/Portable/Binder/DecisionDagBuilder.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private Tests MakeTestsAndBindingsForListPattern(BoundDagTemp input, BoundListPa
{
Debug.Assert(list.LengthProperty is not null);

var lengthEvaluation = new BoundDagPropertyEvaluation(syntax, list.LengthProperty, input);
var lengthEvaluation = new BoundDagPropertyEvaluation(syntax, list.LengthProperty, isLengthOrCount: true, input);
tests.Add(new Tests.One(lengthEvaluation));
var lengthTemp = new BoundDagTemp(syntax, _compilation.GetSpecialType(SpecialType.System_Int32), lengthEvaluation);
tests.Add(new Tests.One(list.HasSlice
Expand Down
1 change: 1 addition & 0 deletions src/Compilers/CSharp/Portable/BoundTree/BoundNodes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1429,6 +1429,7 @@
</Node>
<Node Name="BoundDagPropertyEvaluation" Base="BoundDagEvaluation">
<Field Name="Property" Type="PropertySymbol" Null="disallow"/>
<Field Name="IsLengthOrCount" Type="bool"/>
</Node>
<Node Name="BoundDagIndexEvaluation" Base="BoundDagEvaluation">
<Field Name="Property" Type="PropertySymbol" Null="disallow"/>
Expand Down
8 changes: 8 additions & 0 deletions src/Compilers/CSharp/Portable/BoundTree/Constructors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,14 @@ public BoundDagTemp(SyntaxNode syntax, TypeSymbol type, BoundDagEvaluation? sour
public static BoundDagTemp ForOriginalInput(BoundExpression expr) => new BoundDagTemp(expr.Syntax, expr.Type!, source: null);
}

internal partial class BoundDagPropertyEvaluation
{
public BoundDagPropertyEvaluation(SyntaxNode syntax, PropertySymbol property, BoundDagTemp input, bool hasErrors = false)
: this(syntax, property, isLengthOrCount: false, input, hasErrors)
{
}
}

internal partial class BoundCompoundAssignmentOperator
{
public BoundCompoundAssignmentOperator(SyntaxNode syntax,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/Utilities/IValueSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,9 @@ internal interface IValueSet<T> : IValueSet
/// </summary>
bool All(BinaryOperatorKind relation, T value);
}

internal interface INumericValueSet<T> : IValueSet<T>
{
INumericValueSet<T> Shift(int offset);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.PooledObjects;
using Roslyn.Utilities;
Expand All @@ -19,7 +20,7 @@ internal static partial class ValueSetFactory
/// <summary>
/// The implementation of a value set for an numeric type <typeparamref name="T"/>.
/// </summary>
private sealed class NumericValueSet<T, TTC> : IValueSet<T> where TTC : struct, INumericTC<T>
private sealed class NumericValueSet<T, TTC> : INumericValueSet<T> where TTC : struct, INumericTC<T>
{
private readonly ImmutableArray<(T first, T last)> _intervals;

Expand Down Expand Up @@ -51,6 +52,21 @@ internal NumericValueSet(ImmutableArray<(T first, T last)> intervals)

public bool IsEmpty => _intervals.Length == 0;

INumericValueSet<T> INumericValueSet<T>.Shift(int offset)
{
Debug.Assert(this is NumericValueSet<int, IntTC>);
if (offset == 0)
return this;
var builder = ArrayBuilder<(int first, int last)>.GetInstance();
foreach (var (first, last) in Unsafe.As<NumericValueSet<int, IntTC>>(this)._intervals)
{
builder.Add((
first == int.MaxValue ? first : first + offset,
last == int.MaxValue ? last : last + offset));
}
return Unsafe.As<INumericValueSet<T>>(new NumericValueSet<int, IntTC>(builder.ToImmutableAndFree()));
}

ConstantValue IValueSet.Sample
{
get
Expand Down
2 changes: 2 additions & 0 deletions src/Compilers/CSharp/Portable/Utilities/ValueSetFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ internal static partial class ValueSetFactory
internal static readonly IValueSetFactory<int> ForNint = NintValueSetFactory.Instance;
internal static readonly IValueSetFactory<uint> ForNuint = NuintValueSetFactory.Instance;

internal static readonly IValueSet PositiveIntValues = new NumericValueSet<int, IntTC>(0, int.MaxValue);

public static IValueSetFactory? ForSpecialType(SpecialType specialType, bool isNative = false)
{
switch (specialType)
Expand Down
Loading

0 comments on commit 8ddbf28

Please sign in to comment.