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

Side by Side Diff: pkg/compiler/lib/src/ssa/codegen.dart

Issue 763883004: Fix for issue 21579 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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 | tests/compiler/dart2js_extra/21579_test.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 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 2449 matching lines...) Expand 10 before | Expand all | Expand 10 after
2460 attachLocationToLast(node); 2460 attachLocationToLast(node);
2461 } 2461 }
2462 } 2462 }
2463 } 2463 }
2464 2464
2465 void emitIsViaInterceptor(HIsViaInterceptor node, bool negative) { 2465 void emitIsViaInterceptor(HIsViaInterceptor node, bool negative) {
2466 checkTypeViaProperty(node.interceptor, node.typeExpression, negative); 2466 checkTypeViaProperty(node.interceptor, node.typeExpression, negative);
2467 attachLocationToLast(node); 2467 attachLocationToLast(node);
2468 } 2468 }
2469 2469
2470 js.Expression generateTest(HInstruction input, TypeMask checkedType) { 2470 js.Expression generateReceiverOrArgumentTypeTest(
2471 HInstruction input, TypeMask checkedType) {
2471 ClassWorld classWorld = compiler.world; 2472 ClassWorld classWorld = compiler.world;
2472 TypeMask receiver = input.instructionType; 2473 TypeMask inputType = input.instructionType;
2473 // Figure out if it is beneficial to turn this into a null check. 2474 // Figure out if it is beneficial to turn this into a null check.
2474 // V8 generally prefers 'typeof' checks, but for integers and 2475 // V8 generally prefers 'typeof' checks, but for integers and
2475 // indexable primitives we cannot compile this test into a single 2476 // indexable primitives we cannot compile this test into a single
2476 // typeof check so the null check is cheaper. 2477 // typeof check so the null check is cheaper.
2477 bool turnIntoNumCheck = input.isIntegerOrNull(compiler) 2478 bool isIntCheck = checkedType.containsOnlyInt(classWorld);
2478 && checkedType.containsOnlyInt(classWorld); 2479 bool turnIntoNumCheck = isIntCheck && input.isIntegerOrNull(compiler);
2479 bool turnIntoNullCheck = !turnIntoNumCheck 2480 bool turnIntoNullCheck = !turnIntoNumCheck
2480 && (checkedType.nullable() == receiver) 2481 && (checkedType.nullable() == inputType)
2481 && (checkedType.containsOnlyInt(classWorld) 2482 && (isIntCheck
2482 || checkedType.satisfies(backend.jsIndexableClass, classWorld)); 2483 || checkedType.satisfies(backend.jsIndexableClass, classWorld));
sra1 2014/12/03 01:26:19 If we remove this line, string checks on string-or
2483 js.Expression test; 2484
2484 if (turnIntoNullCheck) { 2485 if (turnIntoNullCheck) {
2485 use(input); 2486 use(input);
2486 test = new js.Binary("==", pop(), new js.LiteralNull()); 2487 return new js.Binary("==", pop(), new js.LiteralNull());
2487 } else if (checkedType.containsOnlyInt(classWorld) && !turnIntoNumCheck) { 2488 } else if (isIntCheck && !turnIntoNumCheck) {
2488 // input is !int 2489 // input is !int
2489 checkInt(input, '!=='); 2490 checkBigInt(input, '!==');
2490 test = pop(); 2491 return pop();
2491 } else if (checkedType.containsOnlyNum(classWorld) || turnIntoNumCheck) { 2492 } else if (turnIntoNumCheck || checkedType.containsOnlyNum(classWorld)) {
2492 // input is !num 2493 // input is !num
2493 checkNum(input, '!=='); 2494 checkNum(input, '!==');
2494 test = pop(); 2495 return pop();
2495 } else if (checkedType.containsOnlyBool(classWorld)) { 2496 } else if (checkedType.containsOnlyBool(classWorld)) {
2496 // input is !bool 2497 // input is !bool
2497 checkBool(input, '!=='); 2498 checkBool(input, '!==');
2498 test = pop(); 2499 return pop();
2499 } else if (checkedType.containsOnlyString(classWorld)) { 2500 } else if (checkedType.containsOnlyString(classWorld)) {
2500 // input is !string 2501 // input is !string
2501 checkString(input, '!=='); 2502 checkString(input, '!==');
2502 test = pop(); 2503 return pop();
2503 } else if (checkedType.satisfies(backend.jsExtendableArrayClass,
2504 classWorld)) {
2505 // input is !Object || input is !Array || input.isFixed
2506 checkObject(input, '!==');
2507 js.Expression objectTest = pop();
2508 checkArray(input, '!==');
2509 js.Expression arrayTest = pop();
2510 checkFixedArray(input);
2511 test = new js.Binary('||', objectTest, arrayTest);
2512 test = new js.Binary('||', test, pop());
2513 } else if (checkedType.satisfies(backend.jsMutableArrayClass, classWorld)) {
2514 // input is !Object
2515 // || ((input is !Array || input.isImmutable)
2516 // && input is !JsIndexingBehavior)
2517 checkObject(input, '!==');
2518 js.Expression objectTest = pop();
2519 checkArray(input, '!==');
2520 js.Expression arrayTest = pop();
2521 checkImmutableArray(input);
2522 js.Binary notArrayOrImmutable = new js.Binary('||', arrayTest, pop());
2523
2524 js.Binary notIndexing = checkIndexingBehavior(input, negative: true)
2525 ? new js.Binary('&&', notArrayOrImmutable, pop())
2526 : notArrayOrImmutable;
2527 test = new js.Binary('||', objectTest, notIndexing);
2528 } else if (checkedType.satisfies(backend.jsArrayClass, classWorld)) {
2529 // input is !Object
2530 // || (input is !Array && input is !JsIndexingBehavior)
2531 checkObject(input, '!==');
2532 js.Expression objectTest = pop();
2533 checkArray(input, '!==');
2534 js.Expression arrayTest = pop();
2535
2536 js.Expression notIndexing = checkIndexingBehavior(input, negative: true)
2537 ? new js.Binary('&&', arrayTest, pop())
2538 : arrayTest;
2539 test = new js.Binary('||', objectTest, notIndexing);
2540 } else if (checkedType.satisfies(backend.jsIndexableClass, classWorld)) {
2541 // input is !String
2542 // && (input is !Object
2543 // || (input is !Array && input is !JsIndexingBehavior))
2544 checkString(input, '!==');
2545 js.Expression stringTest = pop();
2546 checkObject(input, '!==');
2547 js.Expression objectTest = pop();
2548 checkArray(input, '!==');
2549 js.Expression arrayTest = pop();
2550
2551 js.Binary notIndexingTest = checkIndexingBehavior(input, negative: true)
2552 ? new js.Binary('&&', arrayTest, pop())
2553 : arrayTest;
2554 js.Binary notObjectOrIndexingTest =
2555 new js.Binary('||', objectTest, notIndexingTest);
2556 test = new js.Binary('&&', stringTest, notObjectOrIndexingTest);
2557 } else {
2558 compiler.internalError(input, 'Unexpected check.');
2559 } 2504 }
2560 return test; 2505 compiler.internalError(input, 'Unexpected check.');
2506 return null;
2561 } 2507 }
2562 2508
2563 void visitTypeConversion(HTypeConversion node) { 2509 void visitTypeConversion(HTypeConversion node) {
2564 if (node.isArgumentTypeCheck || node.isReceiverTypeCheck) { 2510 if (node.isArgumentTypeCheck || node.isReceiverTypeCheck) {
2565 ClassWorld classWorld = compiler.world; 2511 ClassWorld classWorld = compiler.world;
2566 // An int check if the input is not int or null, is not 2512 // An int check if the input is not int or null, is not
2567 // sufficient for doing an argument or receiver check. 2513 // sufficient for doing an argument or receiver check.
2568 assert(compiler.trustTypeAnnotations || 2514 assert(compiler.trustTypeAnnotations ||
2569 !node.checkedType.containsOnlyInt(classWorld) || 2515 !node.checkedType.containsOnlyInt(classWorld) ||
2570 node.checkedInput.isIntegerOrNull(compiler)); 2516 node.checkedInput.isIntegerOrNull(compiler));
2571 js.Expression test = generateTest(node.checkedInput, node.checkedType); 2517 js.Expression test = generateReceiverOrArgumentTypeTest(
2518 node.checkedInput, node.checkedType);
2572 js.Block oldContainer = currentContainer; 2519 js.Block oldContainer = currentContainer;
2573 js.Statement body = new js.Block.empty(); 2520 js.Statement body = new js.Block.empty();
2574 currentContainer = body; 2521 currentContainer = body;
2575 if (node.isArgumentTypeCheck) { 2522 if (node.isArgumentTypeCheck) {
2576 generateThrowWithHelper('iae', node.checkedInput); 2523 generateThrowWithHelper('iae', node.checkedInput);
2577 } else if (node.isReceiverTypeCheck) { 2524 } else if (node.isReceiverTypeCheck) {
2578 use(node.checkedInput); 2525 use(node.checkedInput);
2579 String methodName = 2526 String methodName =
2580 backend.namer.invocationName(node.receiverTypeCheckSelector); 2527 backend.namer.invocationName(node.receiverTypeCheckSelector);
2581 js.Expression call = js.propertyCall(pop(), methodName, []); 2528 js.Expression call = js.propertyCall(pop(), methodName, []);
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
2715 js.PropertyAccess accessHelper(String name) { 2662 js.PropertyAccess accessHelper(String name) {
2716 Element helper = backend.findHelper(name); 2663 Element helper = backend.findHelper(name);
2717 if (helper == null) { 2664 if (helper == null) {
2718 // For mocked-up tests. 2665 // For mocked-up tests.
2719 return js.js('(void 0).$name'); 2666 return js.js('(void 0).$name');
2720 } 2667 }
2721 registry.registerStaticUse(helper); 2668 registry.registerStaticUse(helper);
2722 return backend.namer.elementAccess(helper); 2669 return backend.namer.elementAccess(helper);
2723 } 2670 }
2724 } 2671 }
OLDNEW
« no previous file with comments | « no previous file | tests/compiler/dart2js_extra/21579_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698