Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Unified Diff: pkg/compiler/lib/src/cps_ir/type_propagation.dart

Issue 1685893002: cpsir: insert guard and force specialization for [] and []= (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/cps_ir/type_propagation.dart
diff --git a/pkg/compiler/lib/src/cps_ir/type_propagation.dart b/pkg/compiler/lib/src/cps_ir/type_propagation.dart
index fe35b1ff8c5440455a3e48ffd0345c7591f5c5aa..73be876376c684beac826f61ae981cc7d954ef3b 100644
--- a/pkg/compiler/lib/src/cps_ir/type_propagation.dart
+++ b/pkg/compiler/lib/src/cps_ir/type_propagation.dart
@@ -810,6 +810,7 @@ class TransformingVisitor extends DeepRecursiveVisitor {
final List<Node> stack = <Node>[];
TypeCheckOperator checkIsNumber;
+ TypeCheckOperator checkIsInteger;
TransformingVisitor(this.compiler,
this.functionCompiler,
@@ -819,6 +820,9 @@ class TransformingVisitor extends DeepRecursiveVisitor {
checkIsNumber = new ClassTypeCheckOperator(
helpers.jsNumberClass,
BuiltinOperator.IsNotNumber);
+ checkIsInteger = new ClassTypeCheckOperator(
+ helpers.jsIntClass,
+ BuiltinOperator.IsNotInteger);
}
void transform(FunctionDefinition root) {
@@ -1468,9 +1472,14 @@ class TransformingVisitor extends DeepRecursiveVisitor {
case '[]':
Primitive index = node.dartArgument(0);
- // TODO(asgerf): Consider inserting a guard and specialize anyway.
- if (!lattice.isDefinitelyInt(getValue(index))) return null;
CpsFragment cps = new CpsFragment(node.sourceInformation);
+ if (!lattice.isDefinitelyInt(getValue(index))) {
+ // Insert a guard and specialize anyways.
asgerf 2016/02/10 08:37:04 In case the array is null, we will now throw an Ar
Siggi Cherem (dart-lang) 2016/02/12 00:14:00 good catch. Done
+ cps.ifTruthy(checkIsInteger.makeCheck(cps, index))
+ .invokeStaticThrower(helpers.throwIllegalArgumentException,
+ [index]);
+ index = checkIsInteger.makeRefinement(cps, index, classWorld);
+ }
receiver = makeBoundsCheck(cps, receiver, index);
GetIndex get = cps.letPrim(new GetIndex(receiver, index));
node.replaceUsesWith(get);
@@ -1485,8 +1494,14 @@ class TransformingVisitor extends DeepRecursiveVisitor {
}
Primitive index = node.dartArgument(0);
Primitive value = node.dartArgument(1);
- if (!lattice.isDefinitelyInt(getValue(index))) return null;
CpsFragment cps = new CpsFragment(node.sourceInformation);
+ if (!lattice.isDefinitelyInt(getValue(index))) {
+ // Insert a guard and specialize anyways.
+ cps.ifTruthy(checkIsInteger.makeCheck(cps, index))
+ .invokeStaticThrower(helpers.throwIllegalArgumentException,
+ [index]);
+ index = checkIsInteger.makeRefinement(cps, index, classWorld);
+ }
receiver = makeBoundsCheck(cps, receiver, index);
cps.letPrim(new SetIndex(receiver, index, value));
assert(node.hasNoUses);
@@ -2888,6 +2903,7 @@ class TypePropagationVisitor implements Visitor {
case BuiltinOperator.IsFalsy:
case BuiltinOperator.IsNumber:
case BuiltinOperator.IsNotNumber:
+ case BuiltinOperator.IsNotInteger:
case BuiltinOperator.IsFloor:
case BuiltinOperator.IsNumberAndFloor:
setValue(node, nonConstant(typeSystem.boolType));
@@ -3423,7 +3439,9 @@ class ClassTypeCheckOperator extends TypeCheckOperator {
}
Primitive makeCheck(CpsFragment cps, Primitive value) {
- return cps.applyBuiltin(negatedOperator, [value]);
+ return cps.applyBuiltin(negatedOperator,
+ negatedOperator == BuiltinOperator.IsNotInteger
+ ? [value, value, value] : [value]);
asgerf 2016/02/10 08:37:04 For integers, we can omit the floor test if the va
Siggi Cherem (dart-lang) 2016/02/12 00:14:00 I see - good point. I replaced it with the type te
}
Primitive makeRefinement(CpsFragment cps, Primitive value, World world) {

Powered by Google App Engine
This is Rietveld 408576698