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

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

Issue 21065002: Treat ambiguous types as malformed. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Status updated. Created 7 years, 4 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 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 codegen.use(node.context); 98 codegen.use(node.context);
99 arguments.add(codegen.pop()); 99 arguments.add(codegen.pop());
100 } else { 100 } else {
101 codegen.use(node.context); 101 codegen.use(node.context);
102 arguments.add(codegen.pop()); 102 arguments.add(codegen.pop());
103 } 103 }
104 } 104 }
105 } 105 }
106 } 106 }
107 107
108 class AmbiguousTypeCheckedModeHelper extends CheckedModeHelper {
109 const AmbiguousTypeCheckedModeHelper(SourceString name) : super(name);
110
111 void generateAdditionalArguments(SsaCodeGenerator codegen,
112 HTypeConversion node,
113 List<jsAst.Expression> arguments) {
114 DartType type = node.typeExpression;
115 assert(type.containsAmbiguousTypes);
116 String reasons = Types.fetchReasonsFromAmbiguousType(type);
117
118 arguments.add(js.string(quote('$type')));
119 arguments.add(js.string(quote(reasons)));
120 }
121
122 String quote(String string) => string.replaceAll('"', r'\"');
123 }
124
125 /* 108 /*
126 * Invariants: 109 * Invariants:
127 * canInline(function) implies canInline(function, insideLoop:true) 110 * canInline(function) implies canInline(function, insideLoop:true)
128 * !canInline(function, insideLoop: true) implies !canInline(function) 111 * !canInline(function, insideLoop: true) implies !canInline(function)
129 */ 112 */
130 class FunctionInlineCache { 113 class FunctionInlineCache {
131 final Map<FunctionElement, bool> canBeInlined = 114 final Map<FunctionElement, bool> canBeInlined =
132 new Map<FunctionElement, bool>(); 115 new Map<FunctionElement, bool>();
133 116
134 final Map<FunctionElement, bool> canBeInlinedInsideLoop = 117 final Map<FunctionElement, bool> canBeInlinedInsideLoop =
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 world.registerInstantiatedClass(compiler.boolClass, elements); 829 world.registerInstantiatedClass(compiler.boolClass, elements);
847 bool inCheckedMode = compiler.enableTypeAssertions; 830 bool inCheckedMode = compiler.enableTypeAssertions;
848 // [registerIsCheck] is also called for checked mode checks, so we 831 // [registerIsCheck] is also called for checked mode checks, so we
849 // need to register checked mode helpers. 832 // need to register checked mode helpers.
850 if (inCheckedMode) { 833 if (inCheckedMode) {
851 CheckedModeHelper helper = getCheckedModeHelper(type, typeCast: false); 834 CheckedModeHelper helper = getCheckedModeHelper(type, typeCast: false);
852 if (helper != null) world.addToWorkList(helper.getElement(compiler)); 835 if (helper != null) world.addToWorkList(helper.getElement(compiler));
853 // We also need the native variant of the check (for DOM types). 836 // We also need the native variant of the check (for DOM types).
854 helper = getNativeCheckedModeHelper(type, typeCast: false); 837 helper = getNativeCheckedModeHelper(type, typeCast: false);
855 if (helper != null) world.addToWorkList(helper.getElement(compiler)); 838 if (helper != null) world.addToWorkList(helper.getElement(compiler));
856 if (type.containsAmbiguousTypes) {
857 enqueueInResolution(getThrowMalformedSubtypeError(), elements);
858 return;
859 }
860 } else if (type.containsAmbiguousTypes) {
861 registerThrowRuntimeError(elements);
862 return;
863 } 839 }
864 bool isTypeVariable = type.kind == TypeKind.TYPE_VARIABLE; 840 bool isTypeVariable = type.kind == TypeKind.TYPE_VARIABLE;
865 if (!type.isRaw || type.containsTypeVariables) { 841 if (!type.isRaw || type.containsTypeVariables) {
866 enqueueInResolution(getSetRuntimeTypeInfo(), elements); 842 enqueueInResolution(getSetRuntimeTypeInfo(), elements);
867 enqueueInResolution(getGetRuntimeTypeInfo(), elements); 843 enqueueInResolution(getGetRuntimeTypeInfo(), elements);
868 enqueueInResolution(getGetRuntimeTypeArgument(), elements); 844 enqueueInResolution(getGetRuntimeTypeArgument(), elements);
869 if (inCheckedMode) { 845 if (inCheckedMode) {
870 enqueueInResolution(getAssertSubtype(), elements); 846 enqueueInResolution(getAssertSubtype(), elements);
871 } 847 }
872 enqueueInResolution(getCheckSubtype(), elements); 848 enqueueInResolution(getCheckSubtype(), elements);
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
1113 * Returns the checked mode helper for the type check/type cast for [type]. If 1089 * Returns the checked mode helper for the type check/type cast for [type]. If
1114 * [nativeCheckOnly] is [:true:], only names for native helpers are returned. 1090 * [nativeCheckOnly] is [:true:], only names for native helpers are returned.
1115 */ 1091 */
1116 CheckedModeHelper getCheckedModeHelperInternal(DartType type, 1092 CheckedModeHelper getCheckedModeHelperInternal(DartType type,
1117 {bool typeCast, 1093 {bool typeCast,
1118 bool nativeCheckOnly}) { 1094 bool nativeCheckOnly}) {
1119 assert(type.kind != TypeKind.TYPEDEF); 1095 assert(type.kind != TypeKind.TYPEDEF);
1120 Element element = type.element; 1096 Element element = type.element;
1121 bool nativeCheck = nativeCheckOnly || 1097 bool nativeCheck = nativeCheckOnly ||
1122 emitter.nativeEmitter.requiresNativeIsCheck(element); 1098 emitter.nativeEmitter.requiresNativeIsCheck(element);
1123 if (type.containsAmbiguousTypes) { 1099 if (type == compiler.types.voidType) {
1124 // Check for malformed types first, because the type may be a list type
1125 // with a malformed argument type.
1126 if (nativeCheckOnly) return null;
1127 return typeCast
1128 ? const AmbiguousTypeCheckedModeHelper(
1129 const SourceString('malformedTypeCast'))
1130 : const AmbiguousTypeCheckedModeHelper(
1131 const SourceString('malformedTypeCheck'));
1132 } else if (type == compiler.types.voidType) {
1133 assert(!typeCast); // Cannot cast to void. 1100 assert(!typeCast); // Cannot cast to void.
1134 if (nativeCheckOnly) return null; 1101 if (nativeCheckOnly) return null;
1135 return const CheckedModeHelper(const SourceString('voidTypeCheck')); 1102 return const CheckedModeHelper(const SourceString('voidTypeCheck'));
1136 } else if (element == jsStringClass || element == compiler.stringClass) { 1103 } else if (element == jsStringClass || element == compiler.stringClass) {
1137 if (nativeCheckOnly) return null; 1104 if (nativeCheckOnly) return null;
1138 return typeCast 1105 return typeCast
1139 ? const CheckedModeHelper(const SourceString("stringTypeCast")) 1106 ? const CheckedModeHelper(const SourceString("stringTypeCast"))
1140 : const CheckedModeHelper(const SourceString('stringTypeCheck')); 1107 : const CheckedModeHelper(const SourceString('stringTypeCheck'));
1141 } else if (element == jsDoubleClass || element == compiler.doubleClass) { 1108 } else if (element == jsDoubleClass || element == compiler.doubleClass) {
1142 if (nativeCheckOnly) return null; 1109 if (nativeCheckOnly) return null;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1248 } 1215 }
1249 1216
1250 Element getExceptionUnwrapper() { 1217 Element getExceptionUnwrapper() {
1251 return compiler.findHelper(const SourceString('unwrapException')); 1218 return compiler.findHelper(const SourceString('unwrapException'));
1252 } 1219 }
1253 1220
1254 Element getThrowRuntimeError() { 1221 Element getThrowRuntimeError() {
1255 return compiler.findHelper(const SourceString('throwRuntimeError')); 1222 return compiler.findHelper(const SourceString('throwRuntimeError'));
1256 } 1223 }
1257 1224
1258 Element getThrowMalformedSubtypeError() {
1259 return compiler.findHelper(
1260 const SourceString('throwMalformedSubtypeError'));
1261 }
1262
1263 Element getThrowAbstractClassInstantiationError() { 1225 Element getThrowAbstractClassInstantiationError() {
1264 return compiler.findHelper( 1226 return compiler.findHelper(
1265 const SourceString('throwAbstractClassInstantiationError')); 1227 const SourceString('throwAbstractClassInstantiationError'));
1266 } 1228 }
1267 1229
1268 Element getStringInterpolationHelper() { 1230 Element getStringInterpolationHelper() {
1269 return compiler.findHelper(const SourceString('S')); 1231 return compiler.findHelper(const SourceString('S'));
1270 } 1232 }
1271 1233
1272 Element getWrapExceptionHelper() { 1234 Element getWrapExceptionHelper() {
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
1486 } 1448 }
1487 } 1449 }
1488 1450
1489 /// Records that [type] is used by [user.element]. 1451 /// Records that [type] is used by [user.element].
1490 class Dependency { 1452 class Dependency {
1491 final DartType type; 1453 final DartType type;
1492 final TreeElements user; 1454 final TreeElements user;
1493 1455
1494 const Dependency(this.type, this.user); 1456 const Dependency(this.type, this.user);
1495 } 1457 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698