| OLD | NEW |
| 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 import "package:expect/expect.dart"; |
| 5 import 'compiler_helper.dart'; | 6 import 'compiler_helper.dart'; |
| 6 | 7 |
| 7 const String FIB = r""" | 8 const String FIB = r""" |
| 8 fib(n) { | 9 fib(n) { |
| 9 if (n <= 1) return 1; | 10 if (n <= 1) return 1; |
| 10 return add(fib(n - 1), fib(n - 2)); | 11 return add(fib(n - 1), fib(n - 2)); |
| 11 } | 12 } |
| 12 | 13 |
| 13 // We need this artificial add method because | 14 // We need this artificial add method because |
| 14 // our optimizer will actually add type checks | 15 // our optimizer will actually add type checks |
| (...skipping 12 matching lines...) Expand all Loading... |
| 27 var isLeaf = (bar() != null) && bar(); | 28 var isLeaf = (bar() != null) && bar(); |
| 28 // Because we're using a local variable, the graph gets an empty | 29 // Because we're using a local variable, the graph gets an empty |
| 29 // block between the [isLeaf] phi and the next instruction that uses | 30 // block between the [isLeaf] phi and the next instruction that uses |
| 30 // it. The optimizer must take that new block into account in order | 31 // it. The optimizer must take that new block into account in order |
| 31 // to have the phi be generate at use uste. | 32 // to have the phi be generate at use uste. |
| 32 if (isLeaf) return null; | 33 if (isLeaf) return null; |
| 33 return true; | 34 return true; |
| 34 } | 35 } |
| 35 """; | 36 """; |
| 36 | 37 |
| 38 // Test that a synthesized [HTypeConversion] node added due to the is |
| 39 // check is code motion invariant. No 'else' should be generated in |
| 40 // this code snippet (the new [HTypeConversion] is put in the else |
| 41 // branch, but the else branch dominates the rest of the code in this |
| 42 // snippet). |
| 43 const String TEST = r""" |
| 44 foo(a) { |
| 45 if (a is !int) throw a; |
| 46 if (a < 0) throw a; |
| 47 return a + a; |
| 48 } |
| 49 """; |
| 50 |
| 37 main() { | 51 main() { |
| 38 // Make sure we don't introduce a new variable. | 52 // Make sure we don't introduce a new variable. |
| 39 RegExp regexp = new RegExp("var $anyIdentifier ="); | 53 RegExp regexp = new RegExp("var $anyIdentifier ="); |
| 40 compileAndDoNotMatch(FIB, 'fib', regexp); | 54 compileAndDoNotMatch(FIB, 'fib', regexp); |
| 41 | 55 |
| 42 regexp = new RegExp("isLeaf"); | 56 regexp = new RegExp("isLeaf"); |
| 43 compileAndDoNotMatch(BAR, 'bar', regexp); | 57 compileAndDoNotMatch(BAR, 'bar', regexp); |
| 58 |
| 59 String generated = compile(TEST, entry: 'foo'); |
| 60 Expect.isFalse(generated.contains('else')); |
| 61 // Regression check to ensure that there is no floating variable |
| 62 // expression. |
| 63 Expect.isFalse(new RegExp('^[ ]*a;').hasMatch(generated)); |
| 44 } | 64 } |
| OLD | NEW |