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

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

Issue 22903036: Use predicates to check simple function types. (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
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 /** 7 /**
8 * A function element that represents a closure call. The signature is copied 8 * A function element that represents a closure call. The signature is copied
9 * from the given element. 9 * from the given element.
10 */ 10 */
(...skipping 2158 matching lines...) Expand 10 before | Expand all | Expand 10 after
2169 FunctionType methodType, 2169 FunctionType methodType,
2170 Map<FunctionType, bool> functionTypeChecks, 2170 Map<FunctionType, bool> functionTypeChecks,
2171 FunctionTypeSignatureEmitter emitFunctionTypeSignature, 2171 FunctionTypeSignatureEmitter emitFunctionTypeSignature,
2172 FunctionTypeTestEmitter emitIsFunctionTypeTest) { 2172 FunctionTypeTestEmitter emitIsFunctionTypeTest) {
2173 bool hasDynamicFunctionTypeCheck = false; 2173 bool hasDynamicFunctionTypeCheck = false;
2174 int neededPredicates = 0; 2174 int neededPredicates = 0;
2175 functionTypeChecks.forEach((FunctionType functionType, bool knownSubtype) { 2175 functionTypeChecks.forEach((FunctionType functionType, bool knownSubtype) {
2176 if (!knownSubtype) { 2176 if (!knownSubtype) {
2177 registerDynamicFunctionTypeCheck(functionType); 2177 registerDynamicFunctionTypeCheck(functionType);
2178 hasDynamicFunctionTypeCheck = true; 2178 hasDynamicFunctionTypeCheck = true;
2179 } else { 2179 } else if (!backend.rti.isSimpleFunctionType(functionType)) {
2180 // Simple function types are always checked using predicates and should
2181 // not provoke generation of signatures.
2180 neededPredicates++; 2182 neededPredicates++;
2181 } 2183 }
2182 }); 2184 });
2183 bool alwaysUseSignature = false; 2185 bool alwaysUseSignature = false;
2184 if (hasDynamicFunctionTypeCheck || 2186 if (hasDynamicFunctionTypeCheck ||
2185 neededPredicates > MAX_FUNCTION_TYPE_PREDICATES) { 2187 neededPredicates > MAX_FUNCTION_TYPE_PREDICATES) {
2186 emitFunctionTypeSignature(method, methodType); 2188 emitFunctionTypeSignature(method, methodType);
2187 alwaysUseSignature = true; 2189 alwaysUseSignature = true;
2188 } 2190 }
2189 functionTypeChecks.forEach((FunctionType functionType, bool knownSubtype) { 2191 functionTypeChecks.forEach((FunctionType functionType, bool knownSubtype) {
2190 if (knownSubtype) { 2192 if (knownSubtype) {
2191 if (alwaysUseSignature) { 2193 if (backend.rti.isSimpleFunctionType(functionType)) {
2194 // Simple function types are always checked using predicates.
2195 emitIsFunctionTypeTest(functionType);
2196 } else if (alwaysUseSignature) {
2192 registerDynamicFunctionTypeCheck(functionType); 2197 registerDynamicFunctionTypeCheck(functionType);
2193 } else { 2198 } else {
2194 emitIsFunctionTypeTest(functionType); 2199 emitIsFunctionTypeTest(functionType);
2195 } 2200 }
2196 } 2201 }
2197 }); 2202 });
2198 } 2203 }
2199 2204
2200 /** 2205 /**
2201 * Return a function that returns true if its argument is a class 2206 * Return a function that returns true if its argument is a class
(...skipping 1950 matching lines...) Expand 10 before | Expand all | Expand 10 after
4152 4157
4153 const String HOOKS_API_USAGE = """ 4158 const String HOOKS_API_USAGE = """
4154 // The code supports the following hooks: 4159 // The code supports the following hooks:
4155 // dartPrint(message) - if this function is defined it is called 4160 // dartPrint(message) - if this function is defined it is called
4156 // instead of the Dart [print] method. 4161 // instead of the Dart [print] method.
4157 // dartMainRunner(main) - if this function is defined, the Dart [main] 4162 // dartMainRunner(main) - if this function is defined, the Dart [main]
4158 // method will not be invoked directly. 4163 // method will not be invoked directly.
4159 // Instead, a closure that will invoke [main] is 4164 // Instead, a closure that will invoke [main] is
4160 // passed to [dartMainRunner]. 4165 // passed to [dartMainRunner].
4161 """; 4166 """;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698