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

Side by Side Diff: pkg/compiler/lib/src/js_backend/backend.dart

Issue 1126063002: Recognize unmodifiable lists (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 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 | pkg/compiler/lib/src/ssa/codegen.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 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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 ClassElement jsBoolClass; 283 ClassElement jsBoolClass;
284 ClassElement jsPlainJavaScriptObjectClass; 284 ClassElement jsPlainJavaScriptObjectClass;
285 ClassElement jsUnknownJavaScriptObjectClass; 285 ClassElement jsUnknownJavaScriptObjectClass;
286 286
287 ClassElement jsIndexableClass; 287 ClassElement jsIndexableClass;
288 ClassElement jsMutableIndexableClass; 288 ClassElement jsMutableIndexableClass;
289 289
290 ClassElement jsMutableArrayClass; 290 ClassElement jsMutableArrayClass;
291 ClassElement jsFixedArrayClass; 291 ClassElement jsFixedArrayClass;
292 ClassElement jsExtendableArrayClass; 292 ClassElement jsExtendableArrayClass;
293 ClassElement jsUnmodifiableArrayClass;
293 ClassElement jsPositiveIntClass; 294 ClassElement jsPositiveIntClass;
294 ClassElement jsUInt32Class; 295 ClassElement jsUInt32Class;
295 ClassElement jsUInt31Class; 296 ClassElement jsUInt31Class;
296 297
297 Element jsIndexableLength; 298 Element jsIndexableLength;
298 Element jsArrayTypedConstructor; 299 Element jsArrayTypedConstructor;
299 Element jsArrayRemoveLast; 300 Element jsArrayRemoveLast;
300 Element jsArrayAdd; 301 Element jsArrayAdd;
301 Element jsStringSplit; 302 Element jsStringSplit;
302 Element jsStringToString; 303 Element jsStringToString;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 380
380 TypeMask _extendableArrayTypeCache; 381 TypeMask _extendableArrayTypeCache;
381 TypeMask get extendableArrayType { 382 TypeMask get extendableArrayType {
382 if (_extendableArrayTypeCache == null) { 383 if (_extendableArrayTypeCache == null) {
383 _extendableArrayTypeCache = 384 _extendableArrayTypeCache =
384 new TypeMask.nonNullExact(jsExtendableArrayClass, compiler.world); 385 new TypeMask.nonNullExact(jsExtendableArrayClass, compiler.world);
385 } 386 }
386 return _extendableArrayTypeCache; 387 return _extendableArrayTypeCache;
387 } 388 }
388 389
390 TypeMask _unmodifiableArrayTypeCache;
391 TypeMask get unmodifiableArrayType {
392 if (_unmodifiableArrayTypeCache == null) {
393 _unmodifiableArrayTypeCache =
394 new TypeMask.nonNullExact(jsUnmodifiableArrayClass, compiler.world);
395 }
396 return _fixedArrayTypeCache;
397 }
398
389 TypeMask _nonNullTypeCache; 399 TypeMask _nonNullTypeCache;
390 TypeMask get nonNullType { 400 TypeMask get nonNullType {
391 if (_nonNullTypeCache == null) { 401 if (_nonNullTypeCache == null) {
392 _nonNullTypeCache = 402 _nonNullTypeCache =
393 compiler.typesTask.dynamicType.nonNullable(); 403 compiler.typesTask.dynamicType.nonNullable();
394 } 404 }
395 return _nonNullTypeCache; 405 return _nonNullTypeCache;
396 } 406 }
397 407
398 /// Maps special classes to their implementation (JSXxx) class. 408 /// Maps special classes to their implementation (JSXxx) class.
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
1048 } 1058 }
1049 if (cls == closureClass) { 1059 if (cls == closureClass) {
1050 enqueue(enqueuer, findHelper('closureFromTearOff'), registry); 1060 enqueue(enqueuer, findHelper('closureFromTearOff'), registry);
1051 } 1061 }
1052 ClassElement result = null; 1062 ClassElement result = null;
1053 if (cls == compiler.stringClass || cls == jsStringClass) { 1063 if (cls == compiler.stringClass || cls == jsStringClass) {
1054 addInterceptors(jsStringClass, enqueuer, registry); 1064 addInterceptors(jsStringClass, enqueuer, registry);
1055 } else if (cls == compiler.listClass || 1065 } else if (cls == compiler.listClass ||
1056 cls == jsArrayClass || 1066 cls == jsArrayClass ||
1057 cls == jsFixedArrayClass || 1067 cls == jsFixedArrayClass ||
1058 cls == jsExtendableArrayClass) { 1068 cls == jsExtendableArrayClass ||
1069 cls == jsUnmodifiableArrayClass) {
1059 addInterceptors(jsArrayClass, enqueuer, registry); 1070 addInterceptors(jsArrayClass, enqueuer, registry);
1060 addInterceptors(jsMutableArrayClass, enqueuer, registry); 1071 addInterceptors(jsMutableArrayClass, enqueuer, registry);
1061 addInterceptors(jsFixedArrayClass, enqueuer, registry); 1072 addInterceptors(jsFixedArrayClass, enqueuer, registry);
1062 addInterceptors(jsExtendableArrayClass, enqueuer, registry); 1073 addInterceptors(jsExtendableArrayClass, enqueuer, registry);
1074 addInterceptors(jsUnmodifiableArrayClass, enqueuer, registry);
1063 } else if (cls == compiler.intClass || cls == jsIntClass) { 1075 } else if (cls == compiler.intClass || cls == jsIntClass) {
1064 addInterceptors(jsIntClass, enqueuer, registry); 1076 addInterceptors(jsIntClass, enqueuer, registry);
1065 addInterceptors(jsPositiveIntClass, enqueuer, registry); 1077 addInterceptors(jsPositiveIntClass, enqueuer, registry);
1066 addInterceptors(jsUInt32Class, enqueuer, registry); 1078 addInterceptors(jsUInt32Class, enqueuer, registry);
1067 addInterceptors(jsUInt31Class, enqueuer, registry); 1079 addInterceptors(jsUInt31Class, enqueuer, registry);
1068 addInterceptors(jsNumberClass, enqueuer, registry); 1080 addInterceptors(jsNumberClass, enqueuer, registry);
1069 } else if (cls == compiler.doubleClass || cls == jsDoubleClass) { 1081 } else if (cls == compiler.doubleClass || cls == jsDoubleClass) {
1070 addInterceptors(jsDoubleClass, enqueuer, registry); 1082 addInterceptors(jsDoubleClass, enqueuer, registry);
1071 addInterceptors(jsNumberClass, enqueuer, registry); 1083 addInterceptors(jsNumberClass, enqueuer, registry);
1072 } else if (cls == compiler.boolClass || cls == jsBoolClass) { 1084 } else if (cls == compiler.boolClass || cls == jsBoolClass) {
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
1632 bool hasDirectCheckFor(DartType type) { 1644 bool hasDirectCheckFor(DartType type) {
1633 Element element = type.element; 1645 Element element = type.element;
1634 return element == compiler.stringClass || 1646 return element == compiler.stringClass ||
1635 element == compiler.boolClass || 1647 element == compiler.boolClass ||
1636 element == compiler.numClass || 1648 element == compiler.numClass ||
1637 element == compiler.intClass || 1649 element == compiler.intClass ||
1638 element == compiler.doubleClass || 1650 element == compiler.doubleClass ||
1639 element == jsArrayClass || 1651 element == jsArrayClass ||
1640 element == jsMutableArrayClass || 1652 element == jsMutableArrayClass ||
1641 element == jsExtendableArrayClass || 1653 element == jsExtendableArrayClass ||
1642 element == jsFixedArrayClass; 1654 element == jsFixedArrayClass ||
1655 element == jsUnmodifiableArrayClass;
1643 } 1656 }
1644 1657
1645 /// Return [true] if the class is represented by a native JavaSCript type in 1658 /// Return [true] if the class is represented by a native JavaSCript type in
1646 /// the generated code. 1659 /// the generated code.
1647 bool isNativePrimitiveType(ClassElement cls ) { 1660 bool isNativePrimitiveType(ClassElement cls ) {
1648 // TODO(karlklose): cleanup/merge with hasDirectCheck, when the rest of the 1661 // TODO(karlklose): cleanup/merge with hasDirectCheck, when the rest of the
1649 // checks are implemented in the CPS IR. 1662 // checks are implemented in the CPS IR.
1650 return cls == compiler.intClass || 1663 return cls == compiler.intClass ||
1651 cls == compiler.numClass || 1664 cls == compiler.numClass ||
1652 cls == compiler.doubleClass || 1665 cls == compiler.doubleClass ||
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1864 } 1877 }
1865 1878
1866 ClassElement get intImplementation => jsIntClass; 1879 ClassElement get intImplementation => jsIntClass;
1867 ClassElement get uint32Implementation => jsUInt32Class; 1880 ClassElement get uint32Implementation => jsUInt32Class;
1868 ClassElement get uint31Implementation => jsUInt31Class; 1881 ClassElement get uint31Implementation => jsUInt31Class;
1869 ClassElement get positiveIntImplementation => jsPositiveIntClass; 1882 ClassElement get positiveIntImplementation => jsPositiveIntClass;
1870 ClassElement get doubleImplementation => jsDoubleClass; 1883 ClassElement get doubleImplementation => jsDoubleClass;
1871 ClassElement get numImplementation => jsNumberClass; 1884 ClassElement get numImplementation => jsNumberClass;
1872 ClassElement get stringImplementation => jsStringClass; 1885 ClassElement get stringImplementation => jsStringClass;
1873 ClassElement get listImplementation => jsArrayClass; 1886 ClassElement get listImplementation => jsArrayClass;
1874 ClassElement get constListImplementation => jsArrayClass; 1887 ClassElement get constListImplementation => jsUnmodifiableArrayClass;
1875 ClassElement get fixedListImplementation => jsFixedArrayClass; 1888 ClassElement get fixedListImplementation => jsFixedArrayClass;
1876 ClassElement get growableListImplementation => jsExtendableArrayClass; 1889 ClassElement get growableListImplementation => jsExtendableArrayClass;
1877 ClassElement get mapImplementation => mapLiteralClass; 1890 ClassElement get mapImplementation => mapLiteralClass;
1878 ClassElement get constMapImplementation => constMapLiteralClass; 1891 ClassElement get constMapImplementation => constMapLiteralClass;
1879 ClassElement get typeImplementation => typeLiteralClass; 1892 ClassElement get typeImplementation => typeLiteralClass;
1880 ClassElement get boolImplementation => jsBoolClass; 1893 ClassElement get boolImplementation => jsBoolClass;
1881 ClassElement get nullImplementation => jsNullClass; 1894 ClassElement get nullImplementation => jsNullClass;
1882 1895
1883 void registerStaticUse(Element element, Enqueuer enqueuer) { 1896 void registerStaticUse(Element element, Enqueuer enqueuer) {
1884 if (element == disableTreeShakingMarker) { 1897 if (element == disableTreeShakingMarker) {
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
2025 jsPositiveIntClass = findClass('JSPositiveInt'), 2038 jsPositiveIntClass = findClass('JSPositiveInt'),
2026 jsUInt32Class = findClass('JSUInt32'), 2039 jsUInt32Class = findClass('JSUInt32'),
2027 jsUInt31Class = findClass('JSUInt31'), 2040 jsUInt31Class = findClass('JSUInt31'),
2028 jsDoubleClass = findClass('JSDouble'), 2041 jsDoubleClass = findClass('JSDouble'),
2029 jsNumberClass = findClass('JSNumber'), 2042 jsNumberClass = findClass('JSNumber'),
2030 jsNullClass = findClass('JSNull'), 2043 jsNullClass = findClass('JSNull'),
2031 jsBoolClass = findClass('JSBool'), 2044 jsBoolClass = findClass('JSBool'),
2032 jsMutableArrayClass = findClass('JSMutableArray'), 2045 jsMutableArrayClass = findClass('JSMutableArray'),
2033 jsFixedArrayClass = findClass('JSFixedArray'), 2046 jsFixedArrayClass = findClass('JSFixedArray'),
2034 jsExtendableArrayClass = findClass('JSExtendableArray'), 2047 jsExtendableArrayClass = findClass('JSExtendableArray'),
2048 jsUnmodifiableArrayClass = findClass('JSUnmodifiableArray'),
2035 jsPlainJavaScriptObjectClass = findClass('PlainJavaScriptObject'), 2049 jsPlainJavaScriptObjectClass = findClass('PlainJavaScriptObject'),
2036 jsUnknownJavaScriptObjectClass = findClass('UnknownJavaScriptObject'), 2050 jsUnknownJavaScriptObjectClass = findClass('UnknownJavaScriptObject'),
2037 ]; 2051 ];
2038 2052
2039 jsIndexableClass = findClass('JSIndexable'); 2053 jsIndexableClass = findClass('JSIndexable');
2040 jsMutableIndexableClass = findClass('JSMutableIndexable'); 2054 jsMutableIndexableClass = findClass('JSMutableIndexable');
2041 } else if (uri == DART_JS_HELPER) { 2055 } else if (uri == DART_JS_HELPER) {
2042 initializeHelperClasses(); 2056 initializeHelperClasses();
2043 assertMethod = findHelper('assertHelper'); 2057 assertMethod = findHelper('assertHelper');
2044 2058
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
2108 2122
2109 // TODO(kasperl): Some tests do not define the special JSArray 2123 // TODO(kasperl): Some tests do not define the special JSArray
2110 // subclasses, so we check to see if they are defined before 2124 // subclasses, so we check to see if they are defined before
2111 // trying to resolve them. 2125 // trying to resolve them.
2112 if (jsFixedArrayClass != null) { 2126 if (jsFixedArrayClass != null) {
2113 jsFixedArrayClass.ensureResolved(compiler); 2127 jsFixedArrayClass.ensureResolved(compiler);
2114 } 2128 }
2115 if (jsExtendableArrayClass != null) { 2129 if (jsExtendableArrayClass != null) {
2116 jsExtendableArrayClass.ensureResolved(compiler); 2130 jsExtendableArrayClass.ensureResolved(compiler);
2117 } 2131 }
2132 if (jsUnmodifiableArrayClass != null) {
2133 jsUnmodifiableArrayClass.ensureResolved(compiler);
2134 }
2118 2135
2119 jsIndexableClass.ensureResolved(compiler); 2136 jsIndexableClass.ensureResolved(compiler);
2120 jsIndexableLength = compiler.lookupElementIn( 2137 jsIndexableLength = compiler.lookupElementIn(
2121 jsIndexableClass, 'length'); 2138 jsIndexableClass, 'length');
2122 if (jsIndexableLength != null && jsIndexableLength.isAbstractField) { 2139 if (jsIndexableLength != null && jsIndexableLength.isAbstractField) {
2123 AbstractFieldElement element = jsIndexableLength; 2140 AbstractFieldElement element = jsIndexableLength;
2124 jsIndexableLength = element.getter; 2141 jsIndexableLength = element.getter;
2125 } 2142 }
2126 2143
2127 jsArrayClass.ensureResolved(compiler); 2144 jsArrayClass.ensureResolved(compiler);
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after
2924 } 2941 }
2925 } 2942 }
2926 2943
2927 /// Records that [constant] is used by the element behind [registry]. 2944 /// Records that [constant] is used by the element behind [registry].
2928 class Dependency { 2945 class Dependency {
2929 final ConstantValue constant; 2946 final ConstantValue constant;
2930 final Element annotatedElement; 2947 final Element annotatedElement;
2931 2948
2932 const Dependency(this.constant, this.annotatedElement); 2949 const Dependency(this.constant, this.annotatedElement);
2933 } 2950 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/ssa/codegen.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698