Skip to content

Commit

Permalink
Use single builder for effects. Strengthen op kind logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jcouv committed Mar 5, 2018
1 parent 032159d commit d9b3a95
Showing 1 changed file with 6 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,14 @@ internal sealed partial class LocalRewriter
public override BoundNode VisitTupleBinaryOperator(BoundTupleBinaryOperator node)
{
var boolType = node.Type; // we can re-use the bool type
var leftInit = ArrayBuilder<BoundExpression>.GetInstance();
var rightInit = ArrayBuilder<BoundExpression>.GetInstance();
var initEffects = ArrayBuilder<BoundExpression>.GetInstance();
var temps = ArrayBuilder<LocalSymbol>.GetInstance();

BoundExpression newLeft = ReplaceTerminalElementsWithTemps(node.Left, node.Operators, leftInit, temps);
BoundExpression newRight = ReplaceTerminalElementsWithTemps(node.Right, node.Operators, rightInit, temps);
BoundExpression newLeft = ReplaceTerminalElementsWithTemps(node.Left, node.Operators, initEffects, temps);
BoundExpression newRight = ReplaceTerminalElementsWithTemps(node.Right, node.Operators, initEffects, temps);

var returnValue = RewriteTupleNestedOperators(node.Operators, newLeft, newRight, boolType, temps, node.OperatorKind);

leftInit.AddRange(rightInit);
rightInit.Free();

BoundExpression result = MakeSequenceOrResultValue(temps.ToImmutableAndFree(), leftInit.ToImmutableAndFree(), returnValue);
BoundExpression result = MakeSequenceOrResultValue(temps.ToImmutableAndFree(), initEffects.ToImmutableAndFree(), returnValue);
return result;
}

Expand Down Expand Up @@ -250,7 +245,7 @@ private BoundExpression GetTuplePart(BoundExpression tuple, int i)
{
// Example:
// (1, 2) == (1, 2);
if (IsTupleExpression(tuple.Kind))
if (tuple.Kind == BoundKind.TupleLiteral)
{
return ((BoundTupleLiteral)tuple).Arguments[i];
}
Expand Down Expand Up @@ -300,7 +295,7 @@ private BoundExpression RewriteTupleSingleOperator(TupleBinaryOperatorInfo.Singl

// PROTOTYPE(tuple-equality) checked
// We leave the null literal in nullable-null conversions unconverted because MakeBinaryOperator has special rules for it
bool isNullableNullConversion = ((operatorKind & BinaryOperatorKind.NullableNull) == 0);
bool isNullableNullConversion = operatorKind.OperandTypes() != BinaryOperatorKind.NullableNull;
BoundExpression convertedLeft = (isNullableNullConversion && left.IsLiteralNull())
? left
: MakeConversionNode(left.Syntax, left, single.LeftConversion, single.LeftConvertedType, @checked: false);
Expand Down

0 comments on commit d9b3a95

Please sign in to comment.