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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/universe/universe.dart

Issue 14416014: After a dynamic call, refine the receiver type by looking at the potential targets of that call. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library universe; 5 library universe;
6 6
7 import '../closure.dart'; 7 import '../closure.dart';
8 import '../elements/elements.dart'; 8 import '../elements/elements.dart';
9 import '../dart2jslib.dart'; 9 import '../dart2jslib.dart';
10 import '../dart_types.dart'; 10 import '../dart_types.dart';
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 return hasMatchingSelector(invokedSetters[member.name], member, compiler); 84 return hasMatchingSelector(invokedSetters[member.name], member, compiler);
85 } 85 }
86 86
87 bool hasFieldGetter(Element member, Compiler compiler) { 87 bool hasFieldGetter(Element member, Compiler compiler) {
88 return fieldGetters.contains(member); 88 return fieldGetters.contains(member);
89 } 89 }
90 90
91 bool hasFieldSetter(Element member, Compiler compiler) { 91 bool hasFieldSetter(Element member, Compiler compiler) {
92 return fieldSetters.contains(member); 92 return fieldSetters.contains(member);
93 } 93 }
94
95 bool onlyReachesFinalFields(Selector getterSelector, Compiler compiler) {
96 assert(getterSelector.isGetter());
97 Selector setterSelector = new Selector.setterFrom(getterSelector);
98 if (getterSelector.mask != null) {
99 setterSelector = new TypedSelector(getterSelector.mask, setterSelector);
100 }
101
102 bool hasInvokedSetter = invokedSetters[setterSelector.name] != null
103 && !invokedSetters[setterSelector.name].isEmpty;
104
105 Iterable<Element> targets =
106 compiler.world.allFunctions.filter(setterSelector);
107 for (Element target in targets) {
108 assert(!target.isAbstractField());
109 // Final fields have been filtered out.
110 assert(!target.modifiers.isFinal());
111 if (target.isNative()) return false;
112 if (!target.isField()) return false;
113 if (hasInvokedSetter) return false;
114 }
115 return true;
116 }
94 } 117 }
95 118
96 class SelectorKind { 119 class SelectorKind {
97 final String name; 120 final String name;
98 const SelectorKind(this.name); 121 const SelectorKind(this.name);
99 122
100 static const SelectorKind GETTER = const SelectorKind('getter'); 123 static const SelectorKind GETTER = const SelectorKind('getter');
101 static const SelectorKind SETTER = const SelectorKind('setter'); 124 static const SelectorKind SETTER = const SelectorKind('setter');
102 static const SelectorKind CALL = const SelectorKind('call'); 125 static const SelectorKind CALL = const SelectorKind('call');
103 static const SelectorKind OPERATOR = const SelectorKind('operator'); 126 static const SelectorKind OPERATOR = const SelectorKind('operator');
(...skipping 29 matching lines...) Expand all
133 156
134 Selector.getter(SourceString name, LibraryElement library) 157 Selector.getter(SourceString name, LibraryElement library)
135 : this(SelectorKind.GETTER, name, library, 0); 158 : this(SelectorKind.GETTER, name, library, 0);
136 159
137 Selector.getterFrom(Selector selector) 160 Selector.getterFrom(Selector selector)
138 : this(SelectorKind.GETTER, selector.name, selector.library, 0); 161 : this(SelectorKind.GETTER, selector.name, selector.library, 0);
139 162
140 Selector.setter(SourceString name, LibraryElement library) 163 Selector.setter(SourceString name, LibraryElement library)
141 : this(SelectorKind.SETTER, name, library, 1); 164 : this(SelectorKind.SETTER, name, library, 1);
142 165
166 Selector.setterFrom(Selector selector)
167 : this(SelectorKind.SETTER, selector.name, selector.library, 1);
168
143 Selector.unaryOperator(SourceString name) 169 Selector.unaryOperator(SourceString name)
144 : this(SelectorKind.OPERATOR, 170 : this(SelectorKind.OPERATOR,
145 Elements.constructOperatorName(name, true), 171 Elements.constructOperatorName(name, true),
146 null, 0); 172 null, 0);
147 173
148 Selector.binaryOperator(SourceString name) 174 Selector.binaryOperator(SourceString name)
149 : this(SelectorKind.OPERATOR, 175 : this(SelectorKind.OPERATOR,
150 Elements.constructOperatorName(name, false), 176 Elements.constructOperatorName(name, false),
151 null, 1); 177 null, 1);
152 178
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 // bar() => foo(); // The call to 'foo' is a typed selector. 474 // bar() => foo(); // The call to 'foo' is a typed selector.
449 // } 475 // }
450 if (element.getEnclosingClass().isClosure()) { 476 if (element.getEnclosingClass().isClosure()) {
451 return appliesUntyped(element, compiler); 477 return appliesUntyped(element, compiler);
452 } 478 }
453 479
454 if (!mask.canHit(element, this, compiler)) return false; 480 if (!mask.canHit(element, this, compiler)) return false;
455 return appliesUntyped(element, compiler); 481 return appliesUntyped(element, compiler);
456 } 482 }
457 } 483 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/universe/function_set.dart ('k') | tests/compiler/dart2js/code_motion_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698