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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/ssa/codegen.dart

Issue 17413013: Revert "Support runtime check of function types." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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 ssa; 5 part of ssa;
6 6
7 class SsaCodeGeneratorTask extends CompilerTask { 7 class SsaCodeGeneratorTask extends CompilerTask {
8 8
9 final JavaScriptBackend backend; 9 final JavaScriptBackend backend;
10 10
(...skipping 2196 matching lines...) Expand 10 before | Expand all | Expand 10 after
2207 world.registerStaticUse(helper); 2207 world.registerStaticUse(helper);
2208 String helperName = backend.namer.isolateAccess(helper); 2208 String helperName = backend.namer.isolateAccess(helper);
2209 push(new js.Call(new js.VariableUse(helperName), arguments)); 2209 push(new js.Call(new js.VariableUse(helperName), arguments));
2210 if (negative) push(new js.Prefix('!', pop())); 2210 if (negative) push(new js.Prefix('!', pop()));
2211 } 2211 }
2212 2212
2213 void checkType(HInstruction input, DartType type, {bool negative: false}) { 2213 void checkType(HInstruction input, DartType type, {bool negative: false}) {
2214 assert(invariant(input, !type.isMalformed, 2214 assert(invariant(input, !type.isMalformed,
2215 message: 'Attempt to check malformed type $type')); 2215 message: 'Attempt to check malformed type $type'));
2216 Element element = type.element; 2216 Element element = type.element;
2217
2217 if (element == backend.jsArrayClass) { 2218 if (element == backend.jsArrayClass) {
2218 checkArray(input, negative ? '!==': '==='); 2219 checkArray(input, negative ? '!==': '===');
2219 return; 2220 return;
2220 } else if (element == backend.jsMutableArrayClass) { 2221 } else if (element == backend.jsMutableArrayClass) {
2221 if (negative) { 2222 if (negative) {
2222 checkImmutableArray(input); 2223 checkImmutableArray(input);
2223 } else { 2224 } else {
2224 checkMutableArray(input); 2225 checkMutableArray(input);
2225 } 2226 }
2226 return; 2227 return;
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
2510 pushStatement(new js.Throw(call)); 2511 pushStatement(new js.Throw(call));
2511 } 2512 }
2512 currentContainer = oldContainer; 2513 currentContainer = oldContainer;
2513 body = unwrapStatement(body); 2514 body = unwrapStatement(body);
2514 pushStatement(new js.If.noElse(test, body), node); 2515 pushStatement(new js.If.noElse(test, body), node);
2515 return; 2516 return;
2516 } 2517 }
2517 2518
2518 assert(node.isCheckedModeCheck || node.isCastTypeCheck); 2519 assert(node.isCheckedModeCheck || node.isCastTypeCheck);
2519 DartType type = node.typeExpression; 2520 DartType type = node.typeExpression;
2520 assert(type.kind != TypeKind.TYPEDEF);
2521 if (type.kind == TypeKind.FUNCTION) { 2521 if (type.kind == TypeKind.FUNCTION) {
2522 // TODO(5022): We currently generate $isFunction checks for 2522 // TODO(5022): We currently generate $isFunction checks for
2523 // function types. 2523 // function types.
2524 world.registerIsCheck( 2524 world.registerIsCheck(
2525 compiler.functionClass.computeType(compiler), work.resolutionTree); 2525 compiler.functionClass.computeType(compiler), work.resolutionTree);
2526 } 2526 }
2527 world.registerIsCheck(type, work.resolutionTree); 2527 world.registerIsCheck(type, work.resolutionTree);
2528 2528
2529 CheckedModeHelper helper;
2530 FunctionElement helperElement; 2529 FunctionElement helperElement;
2531 if (node.isBooleanConversionCheck) { 2530 if (node.isBooleanConversionCheck) {
2532 helper = 2531 helperElement =
2533 const CheckedModeHelper(const SourceString('boolConversionCheck')); 2532 compiler.findHelper(const SourceString('boolConversionCheck'));
2534 } else { 2533 } else {
2535 helper = 2534 helperElement = backend.getCheckedModeHelper(type,
2536 backend.getCheckedModeHelper(type, typeCast: node.isCastTypeCheck); 2535 typeCast: node.isCastTypeCheck);
2537 } 2536 }
2538 2537 world.registerStaticUse(helperElement);
2539 push(helper.generateCall(this, node)); 2538 List<js.Expression> arguments = <js.Expression>[];
2539 use(node.checkedInput);
2540 arguments.add(pop());
2541 int parameterCount =
2542 helperElement.computeSignature(compiler).parameterCount;
2543 // TODO(johnniwinther): Refactor this to avoid using the parameter count
2544 // to determine how the helper should be called.
2545 if (node.typeExpression.kind == TypeKind.TYPE_VARIABLE) {
2546 assert(parameterCount == 2);
2547 use(node.typeRepresentation);
2548 arguments.add(pop());
2549 } else if (parameterCount == 2) {
2550 // 2 arguments implies that the method is either [propertyTypeCheck],
2551 // [propertyTypeCast] or [assertObjectIsSubtype].
2552 assert(!type.isMalformed);
2553 String additionalArgument = backend.namer.operatorIs(type.element);
2554 arguments.add(js.string(additionalArgument));
2555 } else if (parameterCount == 3) {
2556 // 3 arguments implies that the method is [malformedTypeCheck].
2557 assert(type.isMalformed);
2558 String reasons = Types.fetchReasonsFromMalformedType(type);
2559 arguments.add(js.string('$type'));
2560 // TODO(johnniwinther): Handle escaping correctly.
2561 arguments.add(js.string(reasons));
2562 } else if (parameterCount == 4) {
2563 Element element = type.element;
2564 String isField = backend.namer.operatorIs(element);
2565 arguments.add(js.string(isField));
2566 use(node.typeRepresentation);
2567 arguments.add(pop());
2568 String asField = backend.namer.substitutionName(element);
2569 arguments.add(js.string(asField));
2570 } else {
2571 assert(!type.isMalformed);
2572 // No additional arguments needed.
2573 }
2574 String helperName = backend.namer.isolateAccess(helperElement);
2575 push(new js.Call(new js.VariableUse(helperName), arguments));
2540 } 2576 }
2541 } 2577 }
2542 2578
2543 class SsaOptimizedCodeGenerator extends SsaCodeGenerator { 2579 class SsaOptimizedCodeGenerator extends SsaCodeGenerator {
2544 SsaOptimizedCodeGenerator(backend, work) : super(backend, work); 2580 SsaOptimizedCodeGenerator(backend, work) : super(backend, work);
2545 2581
2546 HBasicBlock beginGraph(HGraph graph) { 2582 HBasicBlock beginGraph(HGraph graph) {
2547 return graph.entry; 2583 return graph.entry;
2548 } 2584 }
2549 2585
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
2979 if (leftType.canBeNull() && rightType.canBeNull()) { 3015 if (leftType.canBeNull() && rightType.canBeNull()) {
2980 if (left.isConstantNull() || right.isConstantNull() || 3016 if (left.isConstantNull() || right.isConstantNull() ||
2981 (leftType.isPrimitive(compiler) && leftType == rightType)) { 3017 (leftType.isPrimitive(compiler) && leftType == rightType)) {
2982 return '=='; 3018 return '==';
2983 } 3019 }
2984 return null; 3020 return null;
2985 } else { 3021 } else {
2986 return '==='; 3022 return '===';
2987 } 3023 }
2988 } 3024 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/ssa/builder.dart ('k') | sdk/lib/_internal/compiler/implementation/ssa/nodes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698