Skip to content

Commit c15faea

Browse files
rakudramacommit-bot@chromium.org
authored andcommitted
[dart2js] Use 'isInvariant' property of method calls
The 'isInvariant' property of ir.MethodInvocation nodes allows dart2js to lower JSArray.add to Array.push in more cases. It is set in the expansion of List literals. Change-Id: I6c08ec449e6f7e2b2d839e9faeeff2c338f29e5a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/171080 Commit-Queue: Stephen Adams <[email protected]> Reviewed-by: Mayank Patke <[email protected]>
1 parent 959d2b0 commit c15faea

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

pkg/compiler/lib/src/ssa/builder_kernel.dart

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4963,22 +4963,28 @@ class KernelSsaGraphBuilder extends ir.Visitor {
49634963

49644964
AbstractValue resultType =
49654965
_typeInferenceMap.resultTypeOfSelector(selector, receiverType);
4966+
HInvokeDynamic invoke;
49664967
if (selector.isGetter) {
4967-
push(new HInvokeDynamicGetter(selector, receiverType, element, inputs,
4968-
isIntercepted, resultType, sourceInformation));
4968+
invoke = HInvokeDynamicGetter(selector, receiverType, element, inputs,
4969+
isIntercepted, resultType, sourceInformation);
49694970
} else if (selector.isSetter) {
4970-
push(new HInvokeDynamicSetter(selector, receiverType, element, inputs,
4971-
isIntercepted, resultType, sourceInformation));
4971+
invoke = HInvokeDynamicSetter(selector, receiverType, element, inputs,
4972+
isIntercepted, resultType, sourceInformation);
49724973
} else if (selector.isClosureCall) {
49734974
assert(!isIntercepted);
4974-
push(new HInvokeClosure(
4975+
invoke = HInvokeClosure(
49754976
selector, receiverType, inputs, resultType, typeArguments)
4976-
..sourceInformation = sourceInformation);
4977+
..sourceInformation = sourceInformation;
49774978
} else {
4978-
push(new HInvokeDynamicMethod(selector, receiverType, inputs, resultType,
4979+
invoke = HInvokeDynamicMethod(selector, receiverType, inputs, resultType,
49794980
typeArguments, sourceInformation,
4980-
isIntercepted: isIntercepted));
4981+
isIntercepted: isIntercepted);
4982+
}
4983+
if (node is ir.MethodInvocation) {
4984+
invoke.isInvariant = node.isInvariant;
4985+
invoke.isBoundsSafe = node.isBoundsSafe;
49814986
}
4987+
push(invoke);
49824988
}
49834989

49844990
HInstruction _invokeJsInteropFunction(

pkg/compiler/lib/src/ssa/nodes.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,6 +1709,17 @@ abstract class HInvokeDynamic extends HInvoke {
17091709
AbstractValue _receiverType;
17101710
final AbstractValue _originalReceiverType;
17111711

1712+
/// `true` if the type parameters at the call known to be invariant with
1713+
/// respect to the type parameters of the receiver instance. This corresponds
1714+
/// to the [ir.MethodInvocation.isInvariant] property and may be updated with
1715+
/// additional analysis.
1716+
bool isInvariant = false;
1717+
1718+
/// `true` for an indexed getter or setter if the index is known to be in
1719+
/// range. This corresponds to the [ir.MethodInvocation.isBoundsSafe] property
1720+
/// but and may updated with additional analysis.
1721+
bool isBoundsSafe = false;
1722+
17121723
// Cached target when non-nullable receiver type and selector determine a
17131724
// single target. This is in effect a direct call (except for a possible
17141725
// `null` receiver). The element should only be set if the inputs are correct

pkg/compiler/lib/src/ssa/optimize.dart

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -679,12 +679,15 @@ class SsaInstructionSimplifier extends HBaseVisitor
679679
if (applies(commonElements.jsArrayRemoveLast)) {
680680
target = commonElements.jsArrayRemoveLast;
681681
} else if (applies(commonElements.jsArrayAdd)) {
682-
// The codegen special cases array calls, but does not
683-
// inline argument type checks.
684-
if (!_closedWorld.annotationsData
682+
// Codegen special cases array calls to `Array.push`, but does not
683+
// inline argument type checks. We lower if the check always passes
684+
// (due to invariance or being a top-type), or if the check is not
685+
// emitted.
686+
if (node.isInvariant ||
687+
input is HLiteralList ||
688+
!_closedWorld.annotationsData
685689
.getParameterCheckPolicy(commonElements.jsArrayAdd)
686-
.isEmitted ||
687-
input is HLiteralList) {
690+
.isEmitted) {
688691
target = commonElements.jsArrayAdd;
689692
}
690693
}

0 commit comments

Comments
 (0)