| OLD | NEW |
| 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 part of js_backend; | 5 part of js_backend; |
| 6 | 6 |
| 7 const VERBOSE_OPTIMIZER_HINTS = false; | 7 const VERBOSE_OPTIMIZER_HINTS = false; |
| 8 | 8 |
| 9 class JavaScriptItemCompilationContext extends ItemCompilationContext { | 9 class JavaScriptItemCompilationContext extends ItemCompilationContext { |
| 10 final Set<HInstruction> boundsChecked = new Set<HInstruction>(); | 10 final Set<HInstruction> boundsChecked = new Set<HInstruction>(); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 * generated. | 157 * generated. |
| 158 */ | 158 */ |
| 159 final Map<String, Selector> oneShotInterceptors; | 159 final Map<String, Selector> oneShotInterceptors; |
| 160 | 160 |
| 161 /** | 161 /** |
| 162 * The members of instantiated interceptor classes: maps a member name to the | 162 * The members of instantiated interceptor classes: maps a member name to the |
| 163 * list of members that have that name. This map is used by the codegen to | 163 * list of members that have that name. This map is used by the codegen to |
| 164 * know whether a send must be intercepted or not. | 164 * know whether a send must be intercepted or not. |
| 165 */ | 165 */ |
| 166 final Map<String, Set<Element>> interceptedElements; | 166 final Map<String, Set<Element>> interceptedElements; |
| 167 | 167 // TODO(sra): Not all methods in the Set always require an interceptor. A |
| 168 /** | 168 // method may be mixed into a true interceptor *and* a plain class. For the |
| 169 * The members of mixin classes that are mixed into an instantiated | 169 // method to work on the interceptor class it needs to use the explicit |
| 170 * interceptor class. This is a cached subset of [interceptedElements]. | 170 // receiver. This constrains the call on a known plain receiver to pass the |
| 171 * These members must be invoked with a correct explicit receiver even when | 171 // explicit receiver. https://code.google.com/p/dart/issues/detail?id=8942 |
| 172 * the receiver is not an intercepted class because the function uses the | |
| 173 * explicit interceptor parameter since it may be called on an intercepted | |
| 174 * class. | |
| 175 */ | |
| 176 final Map<String, Set<Element>> interceptedMixinElements = | |
| 177 new Map<String, Set<Element>>(); | |
| 178 | 172 |
| 179 /** | 173 /** |
| 180 * A map of specialized versions of the [getInterceptorMethod]. | 174 * A map of specialized versions of the [getInterceptorMethod]. |
| 181 * Since [getInterceptorMethod] is a hot method at runtime, we're | 175 * Since [getInterceptorMethod] is a hot method at runtime, we're |
| 182 * always specializing it based on the incoming type. The keys in | 176 * always specializing it based on the incoming type. The keys in |
| 183 * the map are the names of these specialized versions. Note that | 177 * the map are the names of these specialized versions. Note that |
| 184 * the generic version that contains all possible type checks is | 178 * the generic version that contains all possible type checks is |
| 185 * also stored in this map. | 179 * also stored in this map. |
| 186 */ | 180 */ |
| 187 final Map<String, Set<ClassElement>> specializedGetInterceptors; | 181 final Map<String, Set<ClassElement>> specializedGetInterceptors; |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 } | 360 } |
| 367 | 361 |
| 368 bool isInterceptedName(String name) { | 362 bool isInterceptedName(String name) { |
| 369 return interceptedElements[name] != null; | 363 return interceptedElements[name] != null; |
| 370 } | 364 } |
| 371 | 365 |
| 372 bool isInterceptedSelector(Selector selector) { | 366 bool isInterceptedSelector(Selector selector) { |
| 373 return interceptedElements[selector.name] != null; | 367 return interceptedElements[selector.name] != null; |
| 374 } | 368 } |
| 375 | 369 |
| 376 /** | |
| 377 * Returns `true` iff [selector] matches an element defined in a class mixed | |
| 378 * into an intercepted class. These selectors are not eligible for the 'dummy | |
| 379 * explicit receiver' optimization. | |
| 380 */ | |
| 381 bool isInterceptedMixinSelector(Selector selector) { | |
| 382 Set<Element> elements = interceptedMixinElements.putIfAbsent( | |
| 383 selector.name, | |
| 384 () { | |
| 385 Set<Element> elements = interceptedElements[selector.name]; | |
| 386 if (elements == null) return null; | |
| 387 return elements | |
| 388 .where((element) => | |
| 389 classesMixedIntoNativeClasses.contains( | |
| 390 element.getEnclosingClass())) | |
| 391 .toSet(); | |
| 392 }); | |
| 393 | |
| 394 if (elements == null) return false; | |
| 395 if (elements.isEmpty) return false; | |
| 396 return elements.any((element) => selector.applies(element, compiler)); | |
| 397 } | |
| 398 | |
| 399 final Map<String, Set<ClassElement>> interceptedClassesCache = | 370 final Map<String, Set<ClassElement>> interceptedClassesCache = |
| 400 new Map<String, Set<ClassElement>>(); | 371 new Map<String, Set<ClassElement>>(); |
| 401 | 372 |
| 402 /** | 373 /** |
| 403 * Returns a set of interceptor classes that contain a member named | 374 * Returns a set of interceptor classes that contain a member named |
| 404 * [name]. Returns [:null:] if there is no class. | 375 * [name]. Returns [:null:] if there is no class. |
| 405 */ | 376 */ |
| 406 Set<ClassElement> getInterceptedClassesOn(String name) { | 377 Set<ClassElement> getInterceptedClassesOn(String name) { |
| 407 Set<Element> intercepted = interceptedElements[name]; | 378 Set<Element> intercepted = interceptedElements[name]; |
| 408 if (intercepted == null) return null; | 379 if (intercepted == null) return null; |
| (...skipping 1466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1875 void visitTrue(TrueConstant constant) => copy(constant); | 1846 void visitTrue(TrueConstant constant) => copy(constant); |
| 1876 | 1847 |
| 1877 void visitFalse(FalseConstant constant) => copy(constant); | 1848 void visitFalse(FalseConstant constant) => copy(constant); |
| 1878 | 1849 |
| 1879 void visitString(StringConstant constant) => copy(constant); | 1850 void visitString(StringConstant constant) => copy(constant); |
| 1880 | 1851 |
| 1881 void visitType(TypeConstant constant) => copy(constant); | 1852 void visitType(TypeConstant constant) => copy(constant); |
| 1882 | 1853 |
| 1883 void visitInterceptor(InterceptorConstant constant) => copy(constant); | 1854 void visitInterceptor(InterceptorConstant constant) => copy(constant); |
| 1884 | 1855 |
| 1885 void visitDummyReceiver(DummyReceiverConstant constant) => copy(constant); | |
| 1886 | |
| 1887 void visitList(ListConstant constant) { | 1856 void visitList(ListConstant constant) { |
| 1888 copy(constant.entries); | 1857 copy(constant.entries); |
| 1889 copy(constant); | 1858 copy(constant); |
| 1890 } | 1859 } |
| 1891 void visitMap(MapConstant constant) { | 1860 void visitMap(MapConstant constant) { |
| 1892 copy(constant.keys); | 1861 copy(constant.keys); |
| 1893 copy(constant.values); | 1862 copy(constant.values); |
| 1894 copy(constant.protoValue); | 1863 copy(constant.protoValue); |
| 1895 copy(constant); | 1864 copy(constant); |
| 1896 } | 1865 } |
| 1897 | 1866 |
| 1898 void visitConstructed(ConstructedConstant constant) { | 1867 void visitConstructed(ConstructedConstant constant) { |
| 1899 copy(constant.fields); | 1868 copy(constant.fields); |
| 1900 copy(constant); | 1869 copy(constant); |
| 1901 } | 1870 } |
| 1902 } | 1871 } |
| OLD | NEW |