Enable pyre for mutable union tests
[hiphop-php.git] / hphp / hack / src / hackc / test / infer / locals.hack
blobc3117bdf11ad1bec69ca0407d43a2eadf942db8c
1 // RUN: %hackc compile-infer --fail-fast %s | FileCheck %s
3 // TEST-CHECK-BAL: define $root.no_locals
4 // CHECK: define $root.no_locals($this: *void, $a: .notnull *HackInt) : *void {
5 // CHECK: #b0:
6 // CHECK:   ret null
7 // CHECK: }
8 function no_locals(int $a) : void {
11 // TEST-CHECK-BAL: define $root.only_locals
12 // CHECK: define $root.only_locals($this: *void) : *void {
13 // CHECK: local $a: *void, $b: *void
14 // CHECK: #b0:
15 // CHECK:   store &$a <- $builtins.hack_int(1): *HackMixed
16 // CHECK:   store &$b <- $builtins.hack_int(2): *HackMixed
17 // CHECK:   ret null
18 // CHECK: }
19 function only_locals() : void {
20   $a = 1;
21   $b = 2;
24 // TEST-CHECK-BAL: define $root.params_and_locals
25 // CHECK: define $root.params_and_locals($this: *void, $a: .notnull *HackInt) : *void {
26 // CHECK: local $b: *void, $c: *void
27 // CHECK: #b0:
28 // CHECK:   store &$b <- $builtins.hack_int(1): *HackMixed
29 // CHECK:   store &$c <- $builtins.hack_int(2): *HackMixed
30 // CHECK:   ret null
31 // CHECK: }
32 function params_and_locals(int $a) : void {
33   $b = 1;
34   $c = 2;
37 // TEST-CHECK-BAL: define $root.locals_for_iter
38 // CHECK: define $root.locals_for_iter($this: *void, $d: .notnull *HackDict) : *void {
39 // CHECK: local $k: *void, $v: *void, iter0: *void, $0: *void
40 // CHECK: #b0:
41 // CHECK:   n0 = $builtins.hack_new_dict($builtins.hack_string("kind"), $builtins.hack_int(19), $builtins.hack_string("generic_types"), $builtins.hhbc_new_vec($builtins.hack_new_dict($builtins.hack_string("kind"), $builtins.hack_int(1)), $builtins.hack_new_dict($builtins.hack_string("kind"), $builtins.hack_int(1))))
42 // CHECK:   n1: *HackMixed = load &$d
43 // CHECK:   n2 = $builtins.hhbc_verify_param_type_ts(n1, n0)
44 // CHECK:   n3: *HackMixed = load &$d
45 // CHECK:   n4 = $builtins.hhbc_iter_base(n3)
46 // CHECK:   store &$0 <- n4: *HackMixed
47 // CHECK:   jmp b1
48 // CHECK: #b1:
49 // CHECK:   n5: *HackMixed = load &$0
50 // CHECK:   n6 = $builtins.hhbc_iter_init(&iter0, &$k, &$v, n5)
51 // CHECK:   jmp b2, b7
52 // CHECK:   .handlers b9
53 // CHECK: #b2:
54 // CHECK:   prune $builtins.hack_is_true(n6)
55 // CHECK:   jmp b3
56 // CHECK: #b3:
57 // CHECK:   n7: *HackMixed = load &$0
58 // CHECK:   n8: *HackMixed = load &iter0
59 // CHECK:   n9 = $builtins.hhbc_iter_next(n8, &$k, &$v, n7)
60 // CHECK:   jmp b5, b6
61 // CHECK:   .handlers b4
62 // CHECK: #b4(n10: *HackMixed):
63 // CHECK:   n11: *HackMixed = load &iter0
64 // CHECK:   n12 = $builtins.hhbc_iter_free(n11)
65 // CHECK:   throw n10
66 // CHECK:   .handlers b9
67 // CHECK: #b5:
68 // CHECK:   prune $builtins.hack_is_true(n9)
69 // CHECK:   jmp b8
70 // CHECK: #b6:
71 // CHECK:   prune ! $builtins.hack_is_true(n9)
72 // CHECK:   jmp b3
73 // CHECK: #b7:
74 // CHECK:   prune ! $builtins.hack_is_true(n6)
75 // CHECK:   jmp b8
76 // CHECK: #b8:
77 // CHECK:   jmp b10
78 // CHECK:   .handlers b9
79 // CHECK: #b9(n13: *HackMixed):
80 // CHECK:   store &$0 <- null: *HackMixed
81 // CHECK:   throw n13
82 // CHECK: #b10:
83 // CHECK:   store &$0 <- null: *HackMixed
84 // CHECK:   store &$0 <- null: *HackMixed
85 // CHECK:   ret null
86 // CHECK: }
87 function locals_for_iter(dict<int, int> $d) : void {
88   foreach ($d as $k => $v) {
89     // do nothing so we make sure that $k and $v declare locals on their own.
90   }