Skip to content
This repository has been archived by the owner on Dec 1, 2024. It is now read-only.

Commit

Permalink
RefToInout: remaining special-case rules
Browse files Browse the repository at this point in the history
  • Loading branch information
jjergus committed Sep 16, 2019
1 parent 3462cbc commit 2352c87
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/Migrations/RefToInoutMigration.hack
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,32 @@ final class RefToInoutMigration extends BaseMigration {
'xml_parse_into_struct' => $n ==>
self::optionalToRequired($n, 2, 2),

// these have multiple by-ref params that need different rules
'msg_receive' => $n ==> {
$n['root'] = self::optionalToRequired($n, 7, 1, vec['true', '0']);
return self::refToInout($n, 2, 4);
},
'openssl_seal' => $n ==> {
$n['root'] = self::optionalToRequired($n, 5, 1, vec["'RC4'"]);
return self::refToInout($n, 1, 2);
},
'socket_recvfrom' => $n ==> {
$n['root'] = self::optionalToRequired($n, 5);
return self::refToInout($n, 1, 4);
},

// special cases
'array_multisort' => $n ==>
C\count($n['args']) < 1 || C\count($n['args']) > 9
? $n['root']
: (
self::renameImpl($n, 'array_multisort'.C\count($n['args']))
|> self::refToInout(
$$,
...Vec\keys(Vec\fill(C\count($n['args']), null)) // vec[0...n-1]
)
),

'headers_sent' => $n ==>
C\is_empty($n['args'])
? $n['root']
Expand Down Expand Up @@ -267,7 +292,6 @@ final class RefToInoutMigration extends BaseMigration {
if ($arg is null || !self::isRefOrInout($arg)) {
return $n['root'];
}

return self::renameImpl($n, $new_name) |> self::refToInout($$, $arg_idx);
}

Expand Down
16 changes: 16 additions & 0 deletions tests/examples/migrations/ref_to_inout.hack.expect
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,29 @@ function foo(): void {
$a = $b = null;
(new IntlTimeZone())->getOffset(1234567890, true, inout $a, inout $b);

// Functions with multiple combined rules.
$__unused_inout = null;
\msg_receive($queue, \MSG_IPC_NOWAIT, inout $out, 42, inout $out2, true, 0, inout $__unused_inout);
$__unused_inout = null;
\openssl_seal('analbumcover', inout $out, inout $out2, varray[], 'RC4', inout $__unused_inout);
$__unused_inout = null;
\socket_recvfrom($s, inout $out, 42, 0, inout $out2, inout $__unused_inout);

// Special cases.
\headers_sent();
$__unused_inout = null;
\headers_sent_with_file_line(inout $out, inout $__unused_inout);
\headers_sent_with_file_line(inout $out, inout $out2);
$__unused_inout = null;
\headers_sent_with_file_line(inout $out, inout $__unused_inout);

\array_multisort();
\array_multisort1(inout $a);
\array_multisort2(inout $a, inout $b);
\array_multisort5(inout $a, inout $b, inout $c, inout $d, inout $e);
\array_multisort8(inout $a, inout $b, inout $c, inout $d, inout $e, inout $f, inout $g, inout $h);
\array_multisort9(inout $a, inout $b, inout $c, inout $d, inout $e, inout $f, inout $g, inout $h, inout $i);
\array_multisort(&$a, &$b, &$c, &$d, &$e, &$f, &$g, &$h, &$i, &$j);
}

} // end of MyNamespace
Expand Down
13 changes: 13 additions & 0 deletions tests/examples/migrations/ref_to_inout.hack.in
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,24 @@ function foo(): void {
$a = $b = null;
(new IntlTimeZone())->getOffset(1234567890, true, &$a, &$b);

// Functions with multiple combined rules.
\msg_receive($queue, \MSG_IPC_NOWAIT, &$out, 42, &$out2);
\openssl_seal('analbumcover', &$out, &$out2, varray[]);
\socket_recvfrom($s, &$out, 42, 0, &$out2);

// Special cases.
\headers_sent();
\headers_sent(&$out);
\headers_sent(&$out, &$out2);
\headers_sent(inout $out);

\array_multisort();
\array_multisort(&$a);
\array_multisort(&$a, &$b);
\array_multisort(&$a, &$b, &$c, &$d, &$e);
\array_multisort(&$a, &$b, &$c, &$d, &$e, &$f, &$g, &$h);
\array_multisort(&$a, &$b, &$c, &$d, &$e, &$f, &$g, &$h, &$i);
\array_multisort(&$a, &$b, &$c, &$d, &$e, &$f, &$g, &$h, &$i, &$j);
}

} // end of MyNamespace
Expand Down

0 comments on commit 2352c87

Please sign in to comment.