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

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

Issue 23003031: Extract interceptor calls from raw is-checks. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 7 years, 3 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
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 part of js_backend; 5 part of js_backend;
6 6
7 class JavaScriptItemCompilationContext extends ItemCompilationContext { 7 class JavaScriptItemCompilationContext extends ItemCompilationContext {
8 final Set<HInstruction> boundsChecked; 8 final Set<HInstruction> boundsChecked;
9 9
10 JavaScriptItemCompilationContext() 10 JavaScriptItemCompilationContext()
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 * always specializing it based on the incoming type. The keys in 261 * always specializing it based on the incoming type. The keys in
262 * the map are the names of these specialized versions. Note that 262 * the map are the names of these specialized versions. Note that
263 * the generic version that contains all possible type checks is 263 * the generic version that contains all possible type checks is
264 * also stored in this map. 264 * also stored in this map.
265 */ 265 */
266 final Map<String, Set<ClassElement>> specializedGetInterceptors; 266 final Map<String, Set<ClassElement>> specializedGetInterceptors;
267 267
268 /** 268 /**
269 * Set of classes whose methods are intercepted. 269 * Set of classes whose methods are intercepted.
270 */ 270 */
271 final Set<ClassElement> interceptedClasses = new Set<ClassElement>(); 271 final Set<ClassElement> _interceptedClasses = new Set<ClassElement>();
272 272
273 /** 273 /**
274 * Set of classes used as mixins on native classes. Methods on these classes 274 * Set of classes used as mixins on native classes. Methods on these classes
275 * might also be mixed in to non-native classes. 275 * might also be mixed in to non-native classes.
276 */ 276 */
277 final Set<ClassElement> classesMixedIntoNativeClasses = 277 final Set<ClassElement> classesMixedIntoNativeClasses =
278 new Set<ClassElement>(); 278 new Set<ClassElement>();
279 279
280 /** 280 /**
281 * Set of classes whose `operator ==` methods handle `null` themselves. 281 * Set of classes whose `operator ==` methods handle `null` themselves.
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 jsArrayClass, const SourceString('add')); 550 jsArrayClass, const SourceString('add'));
551 551
552 jsStringClass.ensureResolved(compiler); 552 jsStringClass.ensureResolved(compiler);
553 jsStringSplit = compiler.lookupElementIn( 553 jsStringSplit = compiler.lookupElementIn(
554 jsStringClass, const SourceString('split')); 554 jsStringClass, const SourceString('split'));
555 jsStringConcat = compiler.lookupElementIn( 555 jsStringConcat = compiler.lookupElementIn(
556 jsStringClass, const SourceString('concat')); 556 jsStringClass, const SourceString('concat'));
557 jsStringToString = compiler.lookupElementIn( 557 jsStringToString = compiler.lookupElementIn(
558 jsStringClass, const SourceString('toString')); 558 jsStringClass, const SourceString('toString'));
559 559
560 for (ClassElement cls in classes) {
561 if (cls != null) interceptedClasses.add(cls);
562 }
563
564 typeLiteralClass = compiler.findHelper(const SourceString('TypeImpl')); 560 typeLiteralClass = compiler.findHelper(const SourceString('TypeImpl'));
565 mapLiteralClass = 561 mapLiteralClass =
566 compiler.coreLibrary.find(const SourceString('LinkedHashMap')); 562 compiler.coreLibrary.find(const SourceString('LinkedHashMap'));
567 constMapLiteralClass = 563 constMapLiteralClass =
568 compiler.findHelper(const SourceString('ConstantMap')); 564 compiler.findHelper(const SourceString('ConstantMap'));
569 565
570 objectEquals = compiler.lookupElementIn( 566 objectEquals = compiler.lookupElementIn(
571 compiler.objectClass, const SourceString('==')); 567 compiler.objectClass, const SourceString('=='));
572 568
573 specialOperatorEqClasses 569 specialOperatorEqClasses
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 } 619 }
624 }, 620 },
625 includeSuperAndInjectedMembers: true); 621 includeSuperAndInjectedMembers: true);
626 } 622 }
627 } 623 }
628 624
629 void addInterceptors(ClassElement cls, 625 void addInterceptors(ClassElement cls,
630 Enqueuer enqueuer, 626 Enqueuer enqueuer,
631 TreeElements elements) { 627 TreeElements elements) {
632 if (enqueuer.isResolutionQueue) { 628 if (enqueuer.isResolutionQueue) {
629 _interceptedClasses.add(jsInterceptorClass);
630 _interceptedClasses.add(cls);
633 cls.ensureResolved(compiler); 631 cls.ensureResolved(compiler);
634 cls.forEachMember((ClassElement classElement, Element member) { 632 cls.forEachMember((ClassElement classElement, Element member) {
635 // All methods on [Object] are shadowed by [Interceptor]. 633 // All methods on [Object] are shadowed by [Interceptor].
636 if (classElement == compiler.objectClass) return; 634 if (classElement == compiler.objectClass) return;
637 Set<Element> set = interceptedElements.putIfAbsent( 635 Set<Element> set = interceptedElements.putIfAbsent(
638 member.name, () => new Set<Element>()); 636 member.name, () => new Set<Element>());
639 set.add(member); 637 set.add(member);
640 }, 638 },
641 includeSuperAndInjectedMembers: true); 639 includeSuperAndInjectedMembers: true);
642 } 640 }
643 enqueueClass(enqueuer, cls, elements); 641 enqueueClass(enqueuer, cls, elements);
644 } 642 }
645 643
644 Set<ClassElement> get interceptedClasses {
645 assert(compiler.enqueuer.resolution.queueIsClosed);
646 return _interceptedClasses;
647 }
648
646 void registerSpecializedGetInterceptor(Set<ClassElement> classes) { 649 void registerSpecializedGetInterceptor(Set<ClassElement> classes) {
647 String name = namer.getInterceptorName(getInterceptorMethod, classes); 650 String name = namer.getInterceptorName(getInterceptorMethod, classes);
648 if (classes.contains(jsInterceptorClass)) { 651 if (classes.contains(jsInterceptorClass)) {
649 // We can't use a specialized [getInterceptorMethod], so we make 652 // We can't use a specialized [getInterceptorMethod], so we make
650 // sure we emit the one with all checks. 653 // sure we emit the one with all checks.
651 specializedGetInterceptors[name] = interceptedClasses; 654 specializedGetInterceptors[name] = interceptedClasses;
652 } else { 655 } else {
653 specializedGetInterceptors[name] = classes; 656 specializedGetInterceptors[name] = classes;
654 } 657 }
655 } 658 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 } 707 }
705 } 708 }
706 ClassElement result = null; 709 ClassElement result = null;
707 if (cls == compiler.stringClass || cls == jsStringClass) { 710 if (cls == compiler.stringClass || cls == jsStringClass) {
708 addInterceptors(jsStringClass, enqueuer, elements); 711 addInterceptors(jsStringClass, enqueuer, elements);
709 } else if (cls == compiler.listClass 712 } else if (cls == compiler.listClass
710 || cls == jsArrayClass 713 || cls == jsArrayClass
711 || cls == jsFixedArrayClass 714 || cls == jsFixedArrayClass
712 || cls == jsExtendableArrayClass) { 715 || cls == jsExtendableArrayClass) {
713 addInterceptors(jsArrayClass, enqueuer, elements); 716 addInterceptors(jsArrayClass, enqueuer, elements);
714 enqueueClass(enqueuer, jsFixedArrayClass, elements); 717 addInterceptors(jsMutableArrayClass, enqueuer, elements);
715 enqueueClass(enqueuer, jsExtendableArrayClass, elements); 718 addInterceptors(jsFixedArrayClass, enqueuer, elements);
719 addInterceptors(jsExtendableArrayClass, enqueuer, elements);
716 } else if (cls == compiler.intClass || cls == jsIntClass) { 720 } else if (cls == compiler.intClass || cls == jsIntClass) {
717 addInterceptors(jsIntClass, enqueuer, elements); 721 addInterceptors(jsIntClass, enqueuer, elements);
718 addInterceptors(jsNumberClass, enqueuer, elements); 722 addInterceptors(jsNumberClass, enqueuer, elements);
719 } else if (cls == compiler.doubleClass || cls == jsDoubleClass) { 723 } else if (cls == compiler.doubleClass || cls == jsDoubleClass) {
720 addInterceptors(jsDoubleClass, enqueuer, elements); 724 addInterceptors(jsDoubleClass, enqueuer, elements);
721 addInterceptors(jsNumberClass, enqueuer, elements); 725 addInterceptors(jsNumberClass, enqueuer, elements);
722 } else if (cls == compiler.boolClass || cls == jsBoolClass) { 726 } else if (cls == compiler.boolClass || cls == jsBoolClass) {
723 addInterceptors(jsBoolClass, enqueuer, elements); 727 addInterceptors(jsBoolClass, enqueuer, elements);
724 } else if (cls == compiler.nullClass || cls == jsNullClass) { 728 } else if (cls == compiler.nullClass || cls == jsNullClass) {
725 addInterceptors(jsNullClass, enqueuer, elements); 729 addInterceptors(jsNullClass, enqueuer, elements);
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
1277 ? const PropertyCheckedModeHelper( 1281 ? const PropertyCheckedModeHelper(
1278 const SourceString('propertyTypeCast')) 1282 const SourceString('propertyTypeCast'))
1279 : const PropertyCheckedModeHelper( 1283 : const PropertyCheckedModeHelper(
1280 const SourceString('propertyTypeCheck')); 1284 const SourceString('propertyTypeCheck'));
1281 } 1285 }
1282 } 1286 }
1283 } 1287 }
1284 } 1288 }
1285 } 1289 }
1286 1290
1291 /**
1292 * Returns [:true:] if the checking of [type] is performed directly on the
1293 * object and not on an interceptor.
1294 */
1295 bool hasDirectCheckFor(DartType type) {
1296 Element element = type.element;
1297 return element == compiler.stringClass ||
1298 element == compiler.boolClass ||
1299 element == compiler.numClass ||
1300 element == compiler.intClass ||
1301 element == compiler.doubleClass ||
1302 element == jsArrayClass ||
1303 element == jsMutableArrayClass ||
1304 element == jsExtendableArrayClass ||
1305 element == jsFixedArrayClass;
1306 }
1307
1287 Element getExceptionUnwrapper() { 1308 Element getExceptionUnwrapper() {
1288 return compiler.findHelper(const SourceString('unwrapException')); 1309 return compiler.findHelper(const SourceString('unwrapException'));
1289 } 1310 }
1290 1311
1291 Element getThrowRuntimeError() { 1312 Element getThrowRuntimeError() {
1292 return compiler.findHelper(const SourceString('throwRuntimeError')); 1313 return compiler.findHelper(const SourceString('throwRuntimeError'));
1293 } 1314 }
1294 1315
1295 Element getThrowAbstractClassInstantiationError() { 1316 Element getThrowAbstractClassInstantiationError() {
1296 return compiler.findHelper( 1317 return compiler.findHelper(
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
1621 copy(constant.values); 1642 copy(constant.values);
1622 copy(constant.protoValue); 1643 copy(constant.protoValue);
1623 copy(constant); 1644 copy(constant);
1624 } 1645 }
1625 1646
1626 void visitConstructed(ConstructedConstant constant) { 1647 void visitConstructed(ConstructedConstant constant) {
1627 copy(constant.fields); 1648 copy(constant.fields);
1628 copy(constant); 1649 copy(constant);
1629 } 1650 }
1630 } 1651 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698