OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 // Test that branch fusion correctly sets branch environment for comparisons | |
5 // that require unboxing and does not fuse branches that can deoptimize. | |
6 | |
7 var sideEffect = true; | |
8 | |
9 barDouble(a, b) { | |
10 sideEffect = false; | |
11 final result = (a == b); | |
12 sideEffect = !sideEffect; | |
13 return result; | |
14 } | |
15 fooDouble(a, b) => barDouble(a, b) ? 1 : 0; | |
16 | |
17 barMint(a, b) { | |
18 sideEffect = false; | |
19 final result = (a == b); | |
Florian Schneider
2013/02/13 14:08:43
Why "final" here and "var" below in barPoly?
Vyacheslav Egorov (Google)
2013/02/13 14:10:19
cleaned up
| |
20 sideEffect = !sideEffect; | |
21 return result; | |
22 } | |
23 fooMint(a, b) => barMint(a, b) ? 1 : 0; | |
24 | |
25 class A { | |
26 operator == (other) => identical(this, other); | |
27 } | |
28 | |
29 class B extends A { | |
30 } | |
31 | |
32 class C extends A { | |
33 } | |
34 | |
35 barPoly(a, b) { | |
36 sideEffect = false; | |
37 var x = a == b; | |
38 sideEffect = !sideEffect; | |
39 return x; | |
40 } | |
41 | |
42 fooPoly(a, b) { | |
43 var result = barPoly(a, b) ? 1 : 0; | |
44 return result; | |
45 } | |
46 | |
47 main () { | |
48 final a = 1.0; | |
49 final b = 1 << 62; | |
50 final x = new A(), y = new B(), z = new C(); | |
51 for (var i = 0; i < 10000; i++) { | |
52 Expect.equals(1, fooDouble(a, a)); | |
53 Expect.isTrue(sideEffect); | |
54 Expect.equals(0, fooMint(b, 0)); | |
55 Expect.isTrue(sideEffect); | |
56 Expect.equals(1, fooPoly(x, x)); | |
57 Expect.equals(0, fooPoly(y, x)); | |
58 } | |
59 Expect.equals(1, fooDouble(z, z)); | |
60 Expect.isTrue(sideEffect); | |
61 Expect.equals(1, fooMint(z, z)); | |
62 Expect.isTrue(sideEffect); | |
63 Expect.equals(1, fooPoly(z, z)); | |
64 Expect.isTrue(sideEffect); | |
65 } | |
66 | |
67 | |
68 | |
OLD | NEW |