OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // This unit test of dart2js checks that a SSA bailout target | 5 // This unit test of dart2js checks that a SSA bailout target |
6 // instruction gets removed from the graph when it's not used. | 6 // instruction gets removed from the graph when it's not used. |
7 | 7 |
8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
9 import 'compiler_helper.dart'; | 9 import 'compiler_helper.dart'; |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... |
25 foo([]); | 25 foo([]); |
26 // Force bailout on [a]. | 26 // Force bailout on [a]. |
27 for (int i = 0; i < 100; i++) a[0] = 42; | 27 for (int i = 0; i < 100; i++) a[0] = 42; |
28 // Force bailout on [:a.length:]. | 28 // Force bailout on [:a.length:]. |
29 for (int i = 0; i < 200; i++) a[0] = -a.length; | 29 for (int i = 0; i < 200; i++) a[0] = -a.length; |
30 } | 30 } |
31 '''; | 31 '''; |
32 | 32 |
33 main() { | 33 main() { |
34 String generated = compile(TEST, entry: 'foo'); | 34 String generated = compile(TEST, entry: 'foo'); |
35 | |
36 // Check that we only have one bailout call. The second bailout call | 35 // Check that we only have one bailout call. The second bailout call |
37 // is dead code because we know [:a.length:] is an int. | 36 // is dead code because we know [:a.length:] is an int. |
38 checkNumberOfMatches(new RegExp('bailout').allMatches(generated).iterator, 1); | 37 checkNumberOfMatches(new RegExp('bailout').allMatches(generated).iterator, 1); |
39 | 38 |
40 // Check that the foo method does not have any call to | 39 // Check that the foo method does not have any call to |
41 // 'getInterceptor'. The environment for the second bailout contains | 40 // 'getInterceptor'. The environment for the second bailout contains |
42 // the interceptor of [:a.length:], but since the bailout is | 41 // the interceptor of [:a.length:], but since the bailout is |
43 // removed, the interceptor is removed too. | 42 // removed, the interceptor is removed too. |
44 if (generated.contains(r'getInterceptor(a).$is')) { | 43 if (generated.contains(r'getInterceptor(a).$is')) { |
45 // If we have an interceptor for a type check, it should be the only one. | 44 // If we have an interceptor for a type check, it should be the only one. |
46 checkNumberOfMatches( | 45 checkNumberOfMatches( |
47 new RegExp('getInterceptor').allMatches(generated).iterator, 1); | 46 new RegExp('getInterceptor').allMatches(generated).iterator, 1); |
48 } else { | 47 } else { |
49 Expect.isTrue(!generated.contains('getInterceptor')); | 48 Expect.isTrue(!generated.contains('getInterceptor')); |
50 } | 49 } |
51 | 50 |
52 generated = compileAll(TEST); | 51 compileAll(TEST).then((generated) { |
53 | 52 // Check that the foo bailout method is generated. |
54 // Check that the foo bailout method is generated. | 53 checkNumberOfMatches( |
55 checkNumberOfMatches( | 54 new RegExp('foo\\\$bailout').allMatches(generated).iterator, 2); |
56 new RegExp('foo\\\$bailout').allMatches(generated).iterator, 2); | |
57 | 55 |
58 // Check that it's the only bailout method. | 56 // Check that it's the only bailout method. |
59 checkNumberOfMatches(new RegExp('bailout').allMatches(generated).iterator, 2); | 57 checkNumberOfMatches(new RegExp('bailout').allMatches(generated).iterator, 2
); |
60 | 58 |
61 // Check that the bailout method has a case 2 for the state, which | 59 // Check that the bailout method has a case 2 for the state, which |
62 // is the second bailout in foo. | 60 // is the second bailout in foo. |
63 Expect.isTrue(generated.contains('case 2:')); | 61 Expect.isTrue(generated.contains('case 2:')); |
64 | 62 |
65 // Finally, make sure that the reason foo does not contain | 63 // Finally, make sure that the reason foo does not contain |
66 // 'getInterceptor' is not because the compiler renamed it. | 64 // 'getInterceptor' is not because the compiler renamed it. |
67 Expect.isTrue(generated.contains('getInterceptor')); | 65 Expect.isTrue(generated.contains('getInterceptor')); |
| 66 }); |
68 } | 67 } |
OLD | NEW |