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 {
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
15 // CHECK: store &$a <- $builtins.hack_int(1): *HackMixed
16 // CHECK: store &$b <- $builtins.hack_int(2): *HackMixed
19 function only_locals() : void {
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
28 // CHECK: store &$b <- $builtins.hack_int(1): *HackMixed
29 // CHECK: store &$c <- $builtins.hack_int(2): *HackMixed
32 function params_and_locals(int $a) : void {
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
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
49 // CHECK: n5: *HackMixed = load &$0
50 // CHECK: n6 = $builtins.hhbc_iter_init(&iter0, &$k, &$v, n5)
52 // CHECK: .handlers b9
54 // CHECK: prune $builtins.hack_is_true(n6)
57 // CHECK: n7: *HackMixed = load &$0
58 // CHECK: n8: *HackMixed = load &iter0
59 // CHECK: n9 = $builtins.hhbc_iter_next(n8, &$k, &$v, n7)
61 // CHECK: .handlers b4
62 // CHECK: #b4(n10: *HackMixed):
63 // CHECK: n11: *HackMixed = load &iter0
64 // CHECK: n12 = $builtins.hhbc_iter_free(n11)
66 // CHECK: .handlers b9
68 // CHECK: prune $builtins.hack_is_true(n9)
71 // CHECK: prune ! $builtins.hack_is_true(n9)
74 // CHECK: prune ! $builtins.hack_is_true(n6)
78 // CHECK: .handlers b9
79 // CHECK: #b9(n13: *HackMixed):
80 // CHECK: store &$0 <- null: *HackMixed
83 // CHECK: store &$0 <- null: *HackMixed
84 // CHECK: store &$0 <- null: *HackMixed
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.