Skip to content

Commit

Permalink
Change WaitHandle to Awaitable in hack
Browse files Browse the repository at this point in the history
Summary: - Removed all references to WaitHandle in hphp/hack

Reviewed By: jano

Differential Revision: D6912972

fbshipit-source-id: ee3ff98b6283217e1b90889c456c3dba1ff8edfe
  • Loading branch information
WizKid authored and hhvm-bot committed Feb 7, 2018
1 parent f9c9ef5 commit f918d01
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 38 deletions.
29 changes: 14 additions & 15 deletions hphp/hack/hhi/classes.hhi
Expand Up @@ -106,17 +106,16 @@ final class Generator<Tk, +Tv, -Ts> implements KeyedIterator<Tk, Tv> {
public function rewind(): void {} public function rewind(): void {}
} }


abstract class WaitHandle<+T> implements Awaitable<T> { abstract class Awaitable<+T> {
public function getWaitHandle(): this {}
public static function setOnIOWaitEnterCallback(?(function(): void) $callback) {} public static function setOnIOWaitEnterCallback(?(function(): void) $callback) {}
public static function setOnIOWaitExitCallback(?(function(): void) $callback) {} public static function setOnIOWaitExitCallback(?(function(): void) $callback) {}
public static function setOnJoinCallback(?(function(WaitableWaitHandle<mixed>): void) $callback) {} public static function setOnJoinCallback(?(function(WaitableWaitHandle<mixed>): void) $callback) {}
} }


final class StaticWaitHandle<+T> extends WaitHandle<T> { final class StaticWaitHandle<+T> extends Awaitable<T> {
} }


abstract class WaitableWaitHandle<+T> extends WaitHandle<T> { abstract class WaitableWaitHandle<+T> extends Awaitable<T> {
} }


abstract class ResumableWaitHandle<+T> extends WaitableWaitHandle<T> { abstract class ResumableWaitHandle<+T> extends WaitableWaitHandle<T> {
Expand All @@ -135,27 +134,27 @@ final class AsyncGeneratorWaitHandle<Tk, +Tv>


final class AwaitAllWaitHandle extends WaitableWaitHandle<void> { final class AwaitAllWaitHandle extends WaitableWaitHandle<void> {
public static function fromArray<T>( public static function fromArray<T>(
array<WaitHandle<T>> $deps array<Awaitable<T>> $deps
): WaitHandle<void>; ): Awaitable<void>;
public static function fromDict<Tk, Tv>( public static function fromDict<Tk, Tv>(
dict<Tk, WaitHandle<Tv>> $deps dict<Tk, Awaitable<Tv>> $deps
): WaitHandle<void>; ): Awaitable<void>;
public static function fromMap<Tk, Tv>( public static function fromMap<Tk, Tv>(
ConstMap<Tk, WaitHandle<Tv>> $deps ConstMap<Tk, Awaitable<Tv>> $deps
): WaitHandle<void>; ): Awaitable<void>;
public static function fromVec<T>( public static function fromVec<T>(
vec<WaitHandle<T>> $deps vec<Awaitable<T>> $deps
): WaitHandle<void>; ): Awaitable<void>;
public static function fromVector<T>( public static function fromVector<T>(
ConstVector<WaitHandle<T>> $deps ConstVector<Awaitable<T>> $deps
): WaitHandle<void>; ): Awaitable<void>;
public static function setOnCreateCallback( public static function setOnCreateCallback(
?(function(AwaitAllWaitHandle, Vector<mixed>): void) $callback ?(function(AwaitAllWaitHandle, Vector<mixed>): void) $callback
): void {} ): void {}
} }


final class ConditionWaitHandle<T> extends WaitableWaitHandle<T> { final class ConditionWaitHandle<T> extends WaitableWaitHandle<T> {
public static function create(WaitHandle<void> $child): ConditionWaitHandle<T> {} public static function create(Awaitable<void> $child): ConditionWaitHandle<T> {}
public static function setOnCreateCallback(?(function(ConditionWaitHandle<T>, WaitableWaitHandle<void>): void) $callback) {} public static function setOnCreateCallback(?(function(ConditionWaitHandle<T>, WaitableWaitHandle<void>): void) $callback) {}
public function succeed(T $result): void {} public function succeed(T $result): void {}
public function fail(Exception $exception): void {} public function fail(Exception $exception): void {}
Expand Down
4 changes: 0 additions & 4 deletions hphp/hack/hhi/interfaces.hhi
Expand Up @@ -827,10 +827,6 @@ interface ArrayAccess<Tk, Tv> {
public function offsetUnset(Tk $key): void; public function offsetUnset(Tk $key): void;
} }


interface Awaitable<+T> {
public function getWaitHandle(): WaitHandle<T>;
}

/** /**
* @see http://www.php.net/manual/en/jsonserializable.jsonserialize.php * @see http://www.php.net/manual/en/jsonserializable.jsonserialize.php
*/ */
Expand Down
2 changes: 1 addition & 1 deletion hphp/hack/src/hhbc/emit_body.ml
Expand Up @@ -214,7 +214,7 @@ let emit_deprecation_warning scope = function


let rec is_awaitable h = let rec is_awaitable h =
match h with match h with
| _, A.Happly ((_, ("WaitHandle" | "Awaitable")), ([] | [_])) -> true | _, A.Happly ((_, "Awaitable"), ([] | [_])) -> true
| _, (A.Hsoft h | A.Hoption h) -> is_awaitable h | _, (A.Hsoft h | A.Hoption h) -> is_awaitable h
| _ -> false | _ -> false


Expand Down
12 changes: 6 additions & 6 deletions hphp/hack/src/hhbc/emit_type_hint.ml
Expand Up @@ -123,22 +123,22 @@ let rec hint_to_type_constraint
TC.make tc_name tc_flags TC.make tc_name tc_flags


(* Elide the Awaitable class for async return types only *) (* Elide the Awaitable class for async return types only *)
| A.Happly ((_, ("WaitHandle" | "Awaitable")), [(_, A.Happly((_, "void"), []))]) | A.Happly ((_, "Awaitable"), [(_, A.Happly((_, "void"), []))])
when skipawaitable -> when skipawaitable ->
TC.make None [] TC.make None []


| A.Happly ((_, ("WaitHandle" | "Awaitable")), [h]) | A.Happly ((_, "Awaitable"), [h])
| A.Hoption (_, A.Happly ((_, ("WaitHandle" | "Awaitable")), [h])) | A.Hoption (_, A.Happly ((_, "Awaitable"), [h]))
when skipawaitable -> when skipawaitable ->
hint_to_type_constraint ~kind ~tparams ~skipawaitable:false ~namespace h hint_to_type_constraint ~kind ~tparams ~skipawaitable:false ~namespace h


| A.Hoption (_, A.Hsoft (_, A.Happly ((_, ("WaitHandle" | "Awaitable")), [h]))) | A.Hoption (_, A.Hsoft (_, A.Happly ((_, "Awaitable"), [h])))
when skipawaitable -> when skipawaitable ->
make_tc_with_flags_if_non_empty_flags ~kind ~tparams ~skipawaitable ~namespace make_tc_with_flags_if_non_empty_flags ~kind ~tparams ~skipawaitable ~namespace
h [TC.Soft; TC.HHType; TC.ExtendedHint] h [TC.Soft; TC.HHType; TC.ExtendedHint]


| A.Happly ((_, ("WaitHandle" | "Awaitable")), []) | A.Happly ((_, "Awaitable"), [])
| A.Hoption (_, A.Happly ((_, ("WaitHandle" | "Awaitable")), [])) | A.Hoption (_, A.Happly ((_, "Awaitable"), []))
when skipawaitable -> when skipawaitable ->
TC.make None [] TC.make None []


Expand Down
1 change: 0 additions & 1 deletion hphp/hack/src/parser/hh_autoimport.ml
Expand Up @@ -64,7 +64,6 @@ let alias_map = List.fold_left ~f:add_alias ~init:SMap.empty


HH_ONLY_TYPE("Awaitable"); HH_ONLY_TYPE("Awaitable");
HH_ONLY_TYPE("AsyncGenerator"); HH_ONLY_TYPE("AsyncGenerator");
HH_ONLY_TYPE("WaitHandle");
HH_ONLY_TYPE("StaticWaitHandle"); HH_ONLY_TYPE("StaticWaitHandle");
HH_ONLY_TYPE("WaitableWaitHandle"); HH_ONLY_TYPE("WaitableWaitHandle");
HH_ONLY_TYPE("ResumableWaitHandle"); HH_ONLY_TYPE("ResumableWaitHandle");
Expand Down
1 change: 0 additions & 1 deletion hphp/hack/src/parser/namespaces.ml
Expand Up @@ -52,7 +52,6 @@ let autoimport_classes = [
"AsyncKeyedIterator"; "AsyncKeyedIterator";
"InvariantException"; "InvariantException";
"AsyncGenerator"; "AsyncGenerator";
"WaitHandle";
"StaticWaitHandle"; "StaticWaitHandle";
"WaitableWaitHandle"; "WaitableWaitHandle";
"ResumableWaitHandle"; "ResumableWaitHandle";
Expand Down
2 changes: 1 addition & 1 deletion hphp/hack/test/typecheck/stdclass_final.php.exp
@@ -1,4 +1,4 @@
File "stdclass_final.php", line 3, characters 7-18: File "stdclass_final.php", line 3, characters 7-18:
You cannot extend final class stdClass (Typing[4035]) You cannot extend final class stdClass (Typing[4035])
File "hhi_lib__srcs/classes.hhi", line 188, characters 13-20: File "hhi_lib__srcs/classes.hhi", line 187, characters 13-20:
Declaration is here Declaration is here
2 changes: 1 addition & 1 deletion hphp/hack/test/typecheck/stdclass_static_members.php.exp
@@ -1,4 +1,4 @@
File "stdclass_static_members.php", line 4, characters 13-23: File "stdclass_static_members.php", line 4, characters 13-23:
Could not find class variable $staticProp in type stdClass (Typing[4090]) Could not find class variable $staticProp in type stdClass (Typing[4090])
File "hhi_lib__srcs/classes.hhi", line 188, characters 13-20: File "hhi_lib__srcs/classes.hhi", line 187, characters 13-20:
Declaration of stdClass is here Declaration of stdClass is here
2 changes: 1 addition & 1 deletion hphp/hack/test/typecheck/stdclass_strict.php.exp
Expand Up @@ -2,5 +2,5 @@ File "stdclass_strict.php", line 9, characters 7-9:
Could not find member foo in an object of type stdClass (Typing[4053]) Could not find member foo in an object of type stdClass (Typing[4053])
File "stdclass_strict.php", line 8, characters 8-21: File "stdclass_strict.php", line 8, characters 8-21:
This is why I think it is an object of type stdClass This is why I think it is an object of type stdClass
File "hhi_lib__srcs/classes.hhi", line 188, characters 13-20: File "hhi_lib__srcs/classes.hhi", line 187, characters 13-20:
Declaration of stdClass is here Declaration of stdClass is here
2 changes: 1 addition & 1 deletion hphp/test/quick/xenon/xenon.php
Expand Up @@ -72,7 +72,7 @@ function main($a) {
'include', 'include',
AwaitAllWaitHandle::class.'::fromArray', AwaitAllWaitHandle::class.'::fromArray',
RescheduleWaitHandle::class.'::create', RescheduleWaitHandle::class.'::create',
WaitHandle::class.'::result', WaitableWaitHandle::class.'::result',
); );
verifyTestRun($stacks, $required_functions, $optional_functions); verifyTestRun($stacks, $required_functions, $optional_functions);
if ($success) { if ($success) {
Expand Down
4 changes: 2 additions & 2 deletions hphp/test/slow/async/asio_callbacks_io_wait.php
@@ -1,10 +1,10 @@
<?hh <?hh


WaitHandle::setOnIOWaitEnterCallback(function() { WaitableWaitHandle::setOnIOWaitEnterCallback(function() {
echo "io wait enter\n"; echo "io wait enter\n";
}); });


WaitHandle::setOnIOWaitExitCallback(function() { WaitableWaitHandle::setOnIOWaitExitCallback(function() {
echo "io wait exit\n"; echo "io wait exit\n";
}); });


Expand Down
2 changes: 1 addition & 1 deletion hphp/test/slow/async/awaitall.php
Expand Up @@ -11,7 +11,7 @@ function reschedule() {
); );
} }


function t(WaitHandle $wh, $a): void { function t(Awaitable $wh, $a): void {
echo $wh->getName(), ' ', count($a), "\nbefore: "; echo $wh->getName(), ' ', count($a), "\nbefore: ";
foreach ($a as $k => $aa) { foreach ($a as $k => $aa) {
echo "$k:", HH\Asio\has_finished($aa) ? 1 : 0, ","; echo "$k:", HH\Asio\has_finished($aa) ? 1 : 0, ",";
Expand Down
2 changes: 1 addition & 1 deletion hphp/test/slow/async/no-mock.php
@@ -1,7 +1,7 @@
<?hh <?hh


<<__MockClass>> <<__MockClass>>
class MyWaitHandle extends WaitHandle { class MyWaitHandle extends WaitableWaitHandle {
public function __construct() { public function __construct() {
echo "Ha ha!\n"; echo "Ha ha!\n";
} }
Expand Down
4 changes: 2 additions & 2 deletions hphp/test/slow/async/return-annotation-8.php
@@ -1,4 +1,4 @@
<?hh <?hh
async function f(): WaitHandle {} async function f(): Awaitable {}
async function g(): WaitHandle<void> {} async function g(): Awaitable<void> {}
echo "Done\n"; echo "Done\n";

0 comments on commit f918d01

Please sign in to comment.