Skip to content
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 @@ -3632,6 +3632,7 @@ private static bool TryAppendExpressionProgramOps(
activationSlots,
unified,
literalConstants,
stringConstants,
out reason))
{
return true;
Expand All @@ -3647,6 +3648,7 @@ private static bool TryAppendExpressionProgramOps(
activationSlots,
unified,
literalConstants,
stringConstants,
out reason))
{
return true;
Expand Down Expand Up @@ -3695,6 +3697,7 @@ private static bool TryAppendExpressionProgramOps(
activationSlots,
unified,
literalConstants,
stringConstants,
out reason))
{
return true;
Expand Down Expand Up @@ -3740,6 +3743,7 @@ private static bool TryAppendExpressionProgramOps(
activationSlots,
unified,
literalConstants,
stringConstants,
out reason))
{
return true;
Expand Down Expand Up @@ -6351,6 +6355,125 @@ private static bool TryAppendSimpleObjectLiteralSpan(
return true;
}

private static bool TryMeasureSimpleObjectLiteralSpan(
ExpressionProgram expressionProgram,
int startIndex,
ActivationSlotShape activationSlots,
out int spanLength)
{
if (expressionProgram.GetOperation(startIndex).Kind != ExpressionOpKind.CreateObject)
{
spanLength = 0;
return false;
}

var stringConstants = expressionProgram.StringConstants.AsSpan();
var i = startIndex + 1;
while (i < expressionProgram.OperationCount)
{
if (TryMeasureSimpleBinaryOperandSpan(
expressionProgram,
i,
activationSlots,
out var keySpanLength,
out _) &&
i + keySpanLength < expressionProgram.OperationCount &&
expressionProgram.GetOperation(i + keySpanLength).Kind == ExpressionOpKind.ResolvePropertyKey)
{
i += keySpanLength + 1;
if (i >= expressionProgram.OperationCount ||
!CanAppendSimpleOperandLoad(expressionProgram.GetOperation(i), expressionProgram, activationSlots))
{
spanLength = 0;
return false;
}

i++;
if (i >= expressionProgram.OperationCount)
{
spanLength = 0;
return false;
}

var computedDefineOp = expressionProgram.GetOperation(i);
if (computedDefineOp.Kind != ExpressionOpKind.DefineComputedObjectProperty ||
computedDefineOp.AllowNameInference)
{
spanLength = 0;
return false;
}

i++;
continue;
}

var firstOp = expressionProgram.GetOperation(i);
if (!CanAppendSimpleOperandLoad(firstOp, expressionProgram, activationSlots))
{
break;
}

i++;
if (i >= expressionProgram.OperationCount)
{
spanLength = 0;
return false;
}

var secondOp = expressionProgram.GetOperation(i);
if (secondOp.Kind == ExpressionOpKind.DefineObjectProperty)
{
if (secondOp.GetString(stringConstants).IsPrivateName() ||
secondOp.AllowNameInference)
{
spanLength = 0;
return false;
}

i++;
}
else if (secondOp.Kind == ExpressionOpKind.ResolvePropertyKey)
{
i++;
if (i >= expressionProgram.OperationCount ||
!CanAppendSimpleOperandLoad(expressionProgram.GetOperation(i), expressionProgram, activationSlots))
{
spanLength = 0;
return false;
}

i++;
if (i >= expressionProgram.OperationCount)
{
spanLength = 0;
return false;
}

var computedDefineOp = expressionProgram.GetOperation(i);
if (computedDefineOp.Kind != ExpressionOpKind.DefineComputedObjectProperty ||
computedDefineOp.AllowNameInference)
{
spanLength = 0;
return false;
}

i++;
}
else if (secondOp.Kind == ExpressionOpKind.ObjectSpread)
{
i++;
}
else
{
spanLength = 0;
return false;
}
}

spanLength = i - startIndex;
return true;
}

private static bool TryMeasureSimpleBinaryOperandSpan(
ExpressionProgram expressionProgram,
int startIndex,
Expand Down Expand Up @@ -6555,6 +6678,7 @@ private static bool TryAppendFirstBoundaryComputedCompoundPropertySet(
ActivationSlotShape activationSlots,
ImmutableArray<UnifiedBytecodeInstruction>.Builder unified,
ImmutableArray<JsValue>.Builder literalConstants,
ImmutableArray<string>.Builder stringConstants,
out string reason)
{
if (expressionProgram.OperationCount < 9)
Expand Down Expand Up @@ -6623,6 +6747,9 @@ private static bool TryAppendFirstBoundaryComputedCompoundPropertySet(
var stagedLiterals = ImmutableArray.CreateBuilder<JsValue>();
stagedLiterals.AddRange(literalConstants);

var stagedStrings = ImmutableArray.CreateBuilder<string>();
stagedStrings.AddRange(stringConstants);

if (!TryAppendActivationValueLoad(
expressionProgram.GetOperation(0),
expressionProgram,
Expand All @@ -6638,6 +6765,7 @@ private static bool TryAppendFirstBoundaryComputedCompoundPropertySet(
activationSlots,
stagedUnified,
stagedLiterals,
stagedStrings,
startInclusive: 1,
endExclusive: suffixStart,
out reason))
Expand Down Expand Up @@ -6666,6 +6794,8 @@ private static bool TryAppendFirstBoundaryComputedCompoundPropertySet(
unified.AddRange(stagedUnified);
literalConstants.Clear();
literalConstants.AddRange(stagedLiterals);
stringConstants.Clear();
stringConstants.AddRange(stagedStrings);
reason = string.Empty;
return true;
}
Expand Down Expand Up @@ -6843,6 +6973,7 @@ private static bool TryAppendFirstBoundaryComputedLogicalPropertySet(
ActivationSlotShape activationSlots,
ImmutableArray<UnifiedBytecodeInstruction>.Builder unified,
ImmutableArray<JsValue>.Builder literalConstants,
ImmutableArray<string>.Builder stringConstants,
out string reason)
{
if (expressionProgram.OperationCount < 15)
Expand Down Expand Up @@ -6934,6 +7065,9 @@ jump.Kind is not (ExpressionOpKind.JumpIfFalse or ExpressionOpKind.JumpIfTrue or
var stagedLiterals = ImmutableArray.CreateBuilder<JsValue>();
stagedLiterals.AddRange(literalConstants);

var stagedStrings = ImmutableArray.CreateBuilder<string>();
stagedStrings.AddRange(stringConstants);

if (!TryAppendActivationValueLoad(
expressionProgram.GetOperation(0),
expressionProgram,
Expand All @@ -6949,6 +7083,7 @@ jump.Kind is not (ExpressionOpKind.JumpIfFalse or ExpressionOpKind.JumpIfTrue or
activationSlots,
stagedUnified,
stagedLiterals,
stagedStrings,
startInclusive: 1,
endExclusive: suffixStart,
out reason))
Expand Down Expand Up @@ -6999,6 +7134,8 @@ jump.Kind is not (ExpressionOpKind.JumpIfFalse or ExpressionOpKind.JumpIfTrue or
unified.AddRange(stagedUnified);
literalConstants.Clear();
literalConstants.AddRange(stagedLiterals);
stringConstants.Clear();
stringConstants.AddRange(stagedStrings);
reason = string.Empty;
return true;
}
Expand Down Expand Up @@ -7147,6 +7284,7 @@ private static bool TryAppendFirstBoundaryComputedPropertySet(
ActivationSlotShape activationSlots,
ImmutableArray<UnifiedBytecodeInstruction>.Builder unified,
ImmutableArray<JsValue>.Builder literalConstants,
ImmutableArray<string>.Builder stringConstants,
out string reason)
{
if (expressionProgram.OperationCount < 4)
Expand Down Expand Up @@ -7185,6 +7323,9 @@ private static bool TryAppendFirstBoundaryComputedPropertySet(
var stagedLiterals = ImmutableArray.CreateBuilder<JsValue>();
stagedLiterals.AddRange(literalConstants);

var stagedStrings = ImmutableArray.CreateBuilder<string>();
stagedStrings.AddRange(stringConstants);

if (!TryAppendActivationValueLoad(
expressionProgram.GetOperation(0),
expressionProgram,
Expand All @@ -7200,6 +7341,7 @@ private static bool TryAppendFirstBoundaryComputedPropertySet(
activationSlots,
stagedUnified,
stagedLiterals,
stagedStrings,
startInclusive: 1,
endExclusive: valueIndex,
out reason))
Expand All @@ -7223,6 +7365,8 @@ private static bool TryAppendFirstBoundaryComputedPropertySet(
unified.AddRange(stagedUnified);
literalConstants.Clear();
literalConstants.AddRange(stagedLiterals);
stringConstants.Clear();
stringConstants.AddRange(stagedStrings);
reason = string.Empty;
return true;
}
Expand Down Expand Up @@ -7472,6 +7616,7 @@ private static bool TryAppendFirstBoundaryComputedPropertyUpdate(
ActivationSlotShape activationSlots,
ImmutableArray<UnifiedBytecodeInstruction>.Builder unified,
ImmutableArray<JsValue>.Builder literalConstants,
ImmutableArray<string>.Builder stringConstants,
out string reason)
{
if (expressionProgram.OperationCount < 3)
Expand Down Expand Up @@ -7504,6 +7649,9 @@ private static bool TryAppendFirstBoundaryComputedPropertyUpdate(
var stagedLiterals = ImmutableArray.CreateBuilder<JsValue>();
stagedLiterals.AddRange(literalConstants);

var stagedStrings = ImmutableArray.CreateBuilder<string>();
stagedStrings.AddRange(stringConstants);

if (!TryAppendActivationValueLoad(
expressionProgram.GetOperation(0),
expressionProgram,
Expand All @@ -7519,6 +7667,7 @@ private static bool TryAppendFirstBoundaryComputedPropertyUpdate(
activationSlots,
stagedUnified,
stagedLiterals,
stagedStrings,
startInclusive: 1,
endExclusive: propertyUpdateIndex,
out reason))
Expand All @@ -7533,6 +7682,8 @@ private static bool TryAppendFirstBoundaryComputedPropertyUpdate(
unified.AddRange(stagedUnified);
literalConstants.Clear();
literalConstants.AddRange(stagedLiterals);
stringConstants.Clear();
stringConstants.AddRange(stagedStrings);
reason = string.Empty;
return true;
}
Expand Down Expand Up @@ -7731,6 +7882,7 @@ private static bool TryAppendFirstBoundaryOptionalNamedThenComputedPropertyDelet
activationSlots,
unified,
literalConstants,
stringConstants,
startInclusive: 2,
endExclusive: expressionProgram.OperationCount - 1,
out reason))
Expand Down Expand Up @@ -7821,6 +7973,7 @@ private static bool TryAppendFirstBoundaryOptionalNamedThenOptionalComputedPrope
activationSlots,
unified,
literalConstants,
stringConstants,
startInclusive: jumpIndex + 1,
endExclusive: deleteIndex,
out reason))
Expand Down Expand Up @@ -7919,6 +8072,7 @@ private static bool TryAppendFirstBoundaryOptionalComputedPropertyDeleteWithJump
activationSlots,
unified,
literalConstants,
stringConstants,
startInclusive: jumpIndex + 1,
endExclusive: deleteIndex,
out reason))
Expand Down Expand Up @@ -8280,6 +8434,7 @@ private static bool TryAppendFirstBoundaryOptionalNamedThenComputed(
activationSlots,
unified,
literalConstants,
stringConstants,
startInclusive: optionalStartIndex + 1,
endExclusive: computedIndex,
out reason))
Expand Down Expand Up @@ -8425,6 +8580,7 @@ private static bool TryAppendFirstBoundaryOptionalComputedPropertyReadChain(
activationSlots,
unified,
literalConstants,
stringConstants,
startInclusive: jumpIndex + 1,
endExclusive: computedIndex,
out reason))
Expand Down Expand Up @@ -8453,6 +8609,7 @@ private static bool TryAppendComputedPropertyKeySpan(
ActivationSlotShape activationSlots,
ImmutableArray<UnifiedBytecodeInstruction>.Builder unified,
ImmutableArray<JsValue>.Builder literalConstants,
ImmutableArray<string>.Builder stringConstants,
int startInclusive,
int endExclusive,
out string reason)
Expand All @@ -8477,6 +8634,23 @@ private static bool TryAppendComputedPropertyKeySpan(

break;

case ExpressionOpKind.CreateObject:
if (!TryAppendSimpleObjectLiteralSpan(
expressionProgram,
index,
activationSlots,
unified,
literalConstants,
stringConstants,
out var objectSpanLength,
out reason))
{
return false;
}

index += objectSpanLength - 1;
break;

case ExpressionOpKind.UnaryPlus:
unified.Add(new UnifiedBytecodeInstruction(UnifiedBytecodeOpCode.UnaryPlus));
break;
Expand Down Expand Up @@ -8543,6 +8717,20 @@ private static bool IsSupportedComputedPropertyKeySpan(
stackDepth++;
break;

case ExpressionOpKind.CreateObject:
if (!TryMeasureSimpleObjectLiteralSpan(
expressionProgram,
index,
activationSlots,
out var objectSpanLength))
{
return false;
}

index += objectSpanLength - 1;
stackDepth++;
break;

case ExpressionOpKind.UnaryPlus:
case ExpressionOpKind.UnaryMinus:
case ExpressionOpKind.UnaryLogicalNot:
Expand Down
Loading