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

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

Issue 1713983002: dart2js cps: Add SetLength instruction. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Use trust-primitives and refine type of length to uint32' 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 00cbfb1d37122a703f688baf094c626d8d9af4e8..d47e82b0d59cc381664d695943ba0c7e2acc6745 100644
--- a/pkg/compiler/lib/src/cps_ir/type_propagation.dart
+++ b/pkg/compiler/lib/src/cps_ir/type_propagation.dart
@@ -1522,8 +1522,38 @@ class TransformingVisitor extends DeepRecursiveVisitor {
}
switch (node.selector.name) {
case 'length':
- if (!node.selector.isGetter) return null;
- return new GetLength(receiver);
+ if (node.selector.isGetter) {
+ return new GetLength(receiver);
+ }
+ if (node.selector.isSetter) {
+ if (!typeSystem.isDefinitelyExtendableArray(receiver.type,
+ allowNull: true)) {
+ return null;
+ }
+ CpsFragment cps = new CpsFragment(node.sourceInformation);
+ Primitive newLength = node.dartArgument(0);
+ if (!typeSystem.isDefinitelyUint(newLength.type)) {
+ // TODO(asgerf): We could let the SetLength instruction throw for
+ // negative right-hand sides (see length setter in js_array.dart).
+ if (compiler.trustPrimitives) {
+ newLength = cps.refine(newLength, typeSystem.uint32Type);
+ newLength.type = typeSystem.uint32Type;
+ } else {
+ return null;
+ }
+ }
+ cps.letPrim(new ApplyBuiltinMethod(
+ BuiltinMethod.SetLength,
+ receiver,
+ [newLength],
+ node.sourceInformation));
+ if (!typeSystem.isDefinitelyUint32(newLength.type)) {
+ // If the setter succeeded, the length must have been a uint32.
+ cps.refine(newLength, typeSystem.uint32Type);
+ }
+ return cps;
+ }
+ return null;
case '[]':
Primitive index = node.dartArgument(0);
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/builtin_operator.dart ('k') | pkg/compiler/lib/src/js_backend/codegen/codegen.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698