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

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

Issue 1600973003: dart2js cps: Handle unsafe .length calls in bounds check elimination. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/cps_ir/bounds_checker.dart
diff --git a/pkg/compiler/lib/src/cps_ir/bounds_checker.dart b/pkg/compiler/lib/src/cps_ir/bounds_checker.dart
index 44cbbb0e010ad425164794eefba72aa42dd37b0c..798875f1eed952c1eb98958d0e2a8695e9be7779 100644
--- a/pkg/compiler/lib/src/cps_ir/bounds_checker.dart
+++ b/pkg/compiler/lib/src/cps_ir/bounds_checker.dart
@@ -614,6 +614,16 @@ class BoundsChecker extends TrampolineRecursiveVisitor implements Pass {
@override
void visitInvokeMethod(InvokeMethod node) {
+ if (node.selector.isGetter && node.selector.name == 'length') {
+ // If the receiver type is not known to be indexable, the length call
+ // was not rewritten to GetLength. But if we can prove that the call only
+ // succeeds for indexables, we can trust that it returns the length.
+ TypeMask successType =
+ types.receiverTypeFor(node.selector, node.dartReceiver.type);
+ if (types.isDefinitelyIndexable(successType)) {
+ valueOf[node] = getLength(node.dartReceiver, currentEffectNumber);
+ }
+ }
// TODO(asgerf): What we really need is a "changes length" side effect flag.
if (world
.getSideEffectsOfSelector(node.selector, node.mask)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698