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 IFromIndexOperation completely #34306

Merged
merged 2 commits into from
Mar 26, 2019
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 @@ -1964,14 +1964,17 @@ private IOperation CreateBoundDiscardExpressionOperation(BoundDiscardExpression

private IOperation CreateFromEndIndexExpressionOperation(BoundFromEndIndexExpression boundIndex)
{
return new CSharpLazyFromEndIndexOperation(
return new CSharpLazyUnaryOperation(
operationFactory: this,
boundIndex.Operand,
UnaryOperatorKind.Hat,
isLifted: boundIndex.Type.IsNullableType(),
isChecked: false,
operatorMethod: null,
_semanticModel,
boundIndex.Syntax,
boundIndex.Type,
boundIndex.MethodOpt,
constantValue: default,
isImplicit: boundIndex.WasCompilerGenerated);
}

Expand Down
18 changes: 0 additions & 18 deletions src/Compilers/CSharp/Portable/Operations/CSharpOperationNodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1805,24 +1805,6 @@ protected override IObjectOrCollectionInitializerOperation CreateInitializer()
}
}

internal sealed class CSharpLazyFromEndIndexOperation : LazyFromEndIndexOperation
{
private readonly CSharpOperationFactory _operationFactory;
private readonly BoundNode _operand;

internal CSharpLazyFromEndIndexOperation(CSharpOperationFactory operationFactory, BoundNode operand, bool isLifted, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, IMethodSymbol symbol, bool isImplicit) :
base(isLifted, semanticModel, syntax, type, symbol, isImplicit)
{
_operationFactory = operationFactory;
_operand = operand;
}

protected override IOperation CreateOperand()
{
return _operationFactory.Create(_operand);
}
}

internal sealed class CSharpLazyRangeOperation : LazyRangeOperation
{
private readonly CSharpOperationFactory _operationFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7942,7 +7942,7 @@ void M(int arg)
Operand:
ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 0) (Syntax: '0')
RightOperand:
IFromEndIndexOperation (OperationKind.None, Type: System.Index) (Syntax: '^1')
IUnaryOperation (UnaryOperatorKind.Hat) (OperationKind.Unary, Type: System.Index) (Syntax: '^1')
Operand:
ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 1) (Syntax: '1')
";
Expand Down Expand Up @@ -8084,7 +8084,7 @@ void M(int? start, int? end)
Operand:
IParameterReferenceOperation: start (OperationKind.ParameterReference, Type: System.Int32?) (Syntax: 'start')
RightOperand:
IFromEndIndexOperation (IsLifted) (OperationKind.None, Type: System.Index?) (Syntax: '^end')
IUnaryOperation (UnaryOperatorKind.Hat, IsLifted) (OperationKind.Unary, Type: System.Index?) (Syntax: '^end')
Operand:
IParameterReferenceOperation: end (OperationKind.ParameterReference, Type: System.Int32?) (Syntax: 'end')
";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void M(int arg)
IVariableDeclaratorOperation (Symbol: System.Index x) (OperationKind.VariableDeclarator, Type: null) (Syntax: 'x = ^arg')
Initializer:
IVariableInitializerOperation (OperationKind.VariableInitializer, Type: null) (Syntax: '= ^arg')
IFromEndIndexOperation (OperationKind.None, Type: System.Index) (Syntax: '^arg')
IUnaryOperation (UnaryOperatorKind.Hat) (OperationKind.Unary, Type: System.Index) (Syntax: '^arg')
Operand:
IParameterReferenceOperation: arg (OperationKind.ParameterReference, Type: System.Int32) (Syntax: 'arg')
Initializer:
Expand All @@ -60,7 +60,7 @@ void M(int arg)
Left:
ILocalReferenceOperation: x (IsDeclaration: True) (OperationKind.LocalReference, Type: System.Index, IsImplicit) (Syntax: 'x = ^arg')
Right:
IFromEndIndexOperation (OperationKind.None, Type: System.Index) (Syntax: '^arg')
IUnaryOperation (UnaryOperatorKind.Hat) (OperationKind.Unary, Type: System.Index) (Syntax: '^arg')
Operand:
IParameterReferenceOperation: arg (OperationKind.ParameterReference, Type: System.Int32) (Syntax: 'arg')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3629,13 +3629,13 @@ void M(int arg)
}").VerifyDiagnostics();

string expectedOperationTree = @"
IFromEndIndexOperation (OperationKind.None, Type: System.Index) (Syntax: '^arg')
IUnaryOperation (UnaryOperatorKind.Hat) (OperationKind.Unary, Type: System.Index) (Syntax: '^arg')
Operand:
IParameterReferenceOperation: arg (OperationKind.ParameterReference, Type: System.Int32) (Syntax: 'arg')
";

var operation = (IFromEndIndexOperation)VerifyOperationTreeForTest<PrefixUnaryExpressionSyntax>(compilation, expectedOperationTree);
Assert.Equal("System.Index..ctor(System.Int32 value, [System.Boolean fromEnd = false])", operation.Symbol.ToTestDisplayString());
var operation = (IUnaryOperation)VerifyOperationTreeForTest<PrefixUnaryExpressionSyntax>(compilation, expectedOperationTree);
Assert.Null(operation.OperatorMethod);
}

[Fact]
Expand All @@ -3652,13 +3652,13 @@ void M(int? arg)
}").VerifyDiagnostics();

string expectedOperationTree = @"
IFromEndIndexOperation (IsLifted) (OperationKind.None, Type: System.Index?) (Syntax: '^arg')
IUnaryOperation (UnaryOperatorKind.Hat, IsLifted) (OperationKind.Unary, Type: System.Index?) (Syntax: '^arg')
Operand:
IParameterReferenceOperation: arg (OperationKind.ParameterReference, Type: System.Int32?) (Syntax: 'arg')
";

var operation = (IFromEndIndexOperation)VerifyOperationTreeForTest<PrefixUnaryExpressionSyntax>(compilation, expectedOperationTree);
Assert.Equal("System.Index..ctor(System.Int32 value, [System.Boolean fromEnd = false])", operation.Symbol.ToTestDisplayString());
var operation = (IUnaryOperation)VerifyOperationTreeForTest<PrefixUnaryExpressionSyntax>(compilation, expectedOperationTree);
Assert.Null(operation.OperatorMethod);
}

[Fact]
Expand All @@ -3675,16 +3675,16 @@ void M(byte arg)
}").VerifyDiagnostics();

string expectedOperationTree = @"
IFromEndIndexOperation (OperationKind.None, Type: System.Index) (Syntax: '^arg')
IUnaryOperation (UnaryOperatorKind.Hat) (OperationKind.Unary, Type: System.Index) (Syntax: '^arg')
Operand:
IConversionOperation (TryCast: False, Unchecked) (OperationKind.Conversion, Type: System.Int32, IsImplicit) (Syntax: 'arg')
Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: True, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
Operand:
IParameterReferenceOperation: arg (OperationKind.ParameterReference, Type: System.Byte) (Syntax: 'arg')
";

var operation = (IFromEndIndexOperation)VerifyOperationTreeForTest<PrefixUnaryExpressionSyntax>(compilation, expectedOperationTree);
Assert.Equal("System.Index..ctor(System.Int32 value, [System.Boolean fromEnd = false])", operation.Symbol.ToTestDisplayString());
var operation = (IUnaryOperation)VerifyOperationTreeForTest<PrefixUnaryExpressionSyntax>(compilation, expectedOperationTree);
Assert.Null(operation.OperatorMethod);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51911,7 +51911,7 @@ static void F(object? x)
}";
var comp = CreateCompilation(new[] { source }, options: WithNonNullTypesTrue());
comp.VerifyDiagnostics(
// (3,16): warning CS8618: Non-nullable field 'F' is uninitialized.
// (3,16): warning CS8618: Non-nullable field 'F' is uninitialized.
// internal T F;
Diagnostic(ErrorCode.WRN_UninitializedNonNullableField, "F").WithArguments("field", "F").WithLocation(3, 16),
// (21,27): warning CS8625: Cannot convert null literal to non-nullable reference type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6577,11 +6577,6 @@ public override IOperation VisitDelegateCreation(IDelegateCreationOperation oper
operation.Syntax, operation.Type, operation.ConstantValue, IsImplicit(operation));
}

internal override IOperation VisitFromEndIndexOperation(IFromEndIndexOperation operation, int? argument)
{
return new FromEndIndexOperation(operation.IsLifted, semanticModel: null, operation.Syntax, operation.Type, Visit(operation.Operand), operation.Symbol, isImplicit: IsImplicit(operation));
}

public override IOperation VisitRangeOperation(IRangeOperation operation, int? argument)
{
if (!(operation.LeftOperand is null))
Expand Down
36 changes: 0 additions & 36 deletions src/Compilers/Core/Portable/Operations/IIndexOperation.cs

This file was deleted.

5 changes: 0 additions & 5 deletions src/Compilers/Core/Portable/Operations/OperationCloner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -635,11 +635,6 @@ public override IOperation VisitStaticLocalInitializationSemaphore(IStaticLocalI
throw ExceptionUtilities.Unreachable;
}

internal override IOperation VisitFromEndIndexOperation(IFromEndIndexOperation operation, object argument)
{
return new FromEndIndexOperation(operation.IsLifted, ((Operation)operation).OwningSemanticModel, operation.Syntax, operation.Type, Visit(operation.Operand), operation.Symbol, operation.IsImplicit);
}

public override IOperation VisitRangeOperation(IRangeOperation operation, object argument)
{
return new RangeOperation(operation.IsLifted, ((Operation)operation).OwningSemanticModel, operation.Syntax, operation.Type, Visit(operation.LeftOperand), Visit(operation.RightOperand), operation.Method, operation.IsImplicit);
Expand Down
74 changes: 0 additions & 74 deletions src/Compilers/Core/Portable/Operations/OperationNodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9491,80 +9491,6 @@ public override IObjectOrCollectionInitializerOperation Initializer
}
}

internal abstract class BaseFromEndIndexOperation : Operation, IFromEndIndexOperation
{
protected BaseFromEndIndexOperation(bool isLifted, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, IMethodSymbol symbol, bool isImplicit) :
base(OperationKind.None, semanticModel, syntax, type, constantValue: default, isImplicit: isImplicit)
{
IsLifted = isLifted;
Symbol = symbol;
}

public abstract IOperation Operand { get; }
public bool IsLifted { get; }
public IMethodSymbol Symbol { get; }

public sealed override IEnumerable<IOperation> Children
{
get
{
IOperation operand = Operand;
if (operand != null)
{
yield return operand;
}
}
}

public override void Accept(OperationVisitor visitor)
{
visitor.VisitFromEndIndexOperation(this);
}

public override TResult Accept<TArgument, TResult>(OperationVisitor<TArgument, TResult> visitor, TArgument argument)
{
return visitor.VisitFromEndIndexOperation(this, argument);
}
}

internal sealed class FromEndIndexOperation : BaseFromEndIndexOperation
{
public FromEndIndexOperation(bool isLifted, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, IOperation operand, IMethodSymbol symbol, bool isImplicit) :
base(isLifted, semanticModel, syntax, type, symbol, isImplicit)
{
Operand = Operation.SetParentOperation(operand, this);
}

public override IOperation Operand { get; }
}

internal abstract class LazyFromEndIndexOperation : BaseFromEndIndexOperation
{
private IOperation _operandInterlocked = s_unset;

public LazyFromEndIndexOperation(bool isLifted, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, IMethodSymbol symbol, bool isImplicit) :
base(isLifted, semanticModel, syntax, type, symbol, isImplicit)
{
}

protected abstract IOperation CreateOperand();

public override IOperation Operand
{
get
{
if (_operandInterlocked == s_unset)
{
IOperation operand = CreateOperand();
SetParentOperation(operand, this);
Interlocked.CompareExchange(ref _operandInterlocked, operand, s_unset);
}

return _operandInterlocked;
}
}
}

internal abstract class BaseRangeOperation : Operation, IRangeOperation
{
protected BaseRangeOperation(bool isLifted, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, IMethodSymbol symbol, bool isImplicit) :
Expand Down
10 changes: 0 additions & 10 deletions src/Compilers/Core/Portable/Operations/OperationVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -590,11 +590,6 @@ public virtual void VisitStaticLocalInitializationSemaphore(IStaticLocalInitiali
DefaultVisit(operation);
}

internal virtual void VisitFromEndIndexOperation(IFromEndIndexOperation operation)
{
DefaultVisit(operation);
}

public virtual void VisitRangeOperation(IRangeOperation operation)
{
DefaultVisit(operation);
Expand Down Expand Up @@ -1203,11 +1198,6 @@ public virtual TResult VisitStaticLocalInitializationSemaphore(IStaticLocalIniti
return DefaultVisit(operation, argument);
}

internal virtual TResult VisitFromEndIndexOperation(IFromEndIndexOperation operation, TArgument argument)
{
return DefaultVisit(operation, argument);
}

public virtual TResult VisitRangeOperation(IRangeOperation operation, TArgument argument)
{
return DefaultVisit(operation, argument);
Expand Down
5 changes: 5 additions & 0 deletions src/Compilers/Core/Portable/Operations/UnaryOperatorKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public enum UnaryOperatorKind
/// Represents the C# 'false' operator and VB 'IsFalse' operator.
/// </summary>
False = 0x6,

/// <summary>
/// Represents the C# '^' operator.
/// </summary>
Hat = 0x7,
Copy link
Contributor

@AlekseyTs AlekseyTs Mar 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hat [](start = 8, length = 3)

Is this how it will be called in the language spec? #Closed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
}

1 change: 1 addition & 0 deletions src/Compilers/Core/Portable/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ Microsoft.CodeAnalysis.Operations.ISwitchOperation.ExitLabel.get -> Microsoft.Co
Microsoft.CodeAnalysis.Operations.ISwitchOperation.Locals.get -> System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.ILocalSymbol>
Microsoft.CodeAnalysis.Operations.ITryOperation.ExitLabel.get -> Microsoft.CodeAnalysis.ILabelSymbol
Microsoft.CodeAnalysis.Operations.IUsingOperation.Locals.get -> System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.ILocalSymbol>
Microsoft.CodeAnalysis.Operations.UnaryOperatorKind.Hat = 7 -> Microsoft.CodeAnalysis.Operations.UnaryOperatorKind
Microsoft.CodeAnalysis.SymbolDisplayMiscellaneousOptions.AllowDefaultLiteral = 128 -> Microsoft.CodeAnalysis.SymbolDisplayMiscellaneousOptions
Microsoft.CodeAnalysis.SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier = 64 -> Microsoft.CodeAnalysis.SymbolDisplayMiscellaneousOptions
Microsoft.CodeAnalysis.SymbolDisplayPartKind.ConstantName = 30 -> Microsoft.CodeAnalysis.SymbolDisplayPartKind
Expand Down
14 changes: 0 additions & 14 deletions src/Test/Utilities/Portable/Compilation/OperationTreeVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1884,20 +1884,6 @@ public override void VisitStaticLocalInitializationSemaphore(IStaticLocalInitial
LogCommonPropertiesAndNewLine(operation);
}

internal override void VisitFromEndIndexOperation(IFromEndIndexOperation operation)
{
LogString(nameof(IFromEndIndexOperation));

if (operation.IsLifted)
{
LogString(" (IsLifted)");
}

LogCommonPropertiesAndNewLine(operation);

Visit(operation.Operand, nameof(operation.Operand));
}

public override void VisitRangeOperation(IRangeOperation operation)
{
LogString(nameof(IRangeOperation));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1434,12 +1434,6 @@ public override void VisitStaticLocalInitializationSemaphore(IStaticLocalInitial
Assert.True(operation.Local.IsStatic);
}

internal override void VisitFromEndIndexOperation(IFromEndIndexOperation operation)
{
Assert.Equal(OperationKind.None, operation.Kind);
Assert.Same(operation.Operand, operation.Children.Single());
}

public override void VisitRangeOperation(IRangeOperation operation)
{
Assert.Equal(OperationKind.Range, operation.Kind);
Expand Down