Skip to content

Commit d1ed3e8

Browse files
Andrew Kennedymeta-codesync[bot]
authored andcommitted
Omit like types in decl hover
Summary: Currently we show like types (from pessimisation) even for "decl" types such as that shown when hovering over calls to functions. This is not very helpful, especially now that we're employing more clever pessimisation e.g. putting likes on parameter types in order to prevent like-propagation through to enforced returns. For this case, let's omit the likes. e.g. show {F1983163734} and not {F1983170217} Reviewed By: madgen Differential Revision: D85961760 fbshipit-source-id: c031eb41aba8f700ee0e07430572c72aa1362765
1 parent d561fde commit d1ed3e8

20 files changed

+74
-51
lines changed

hphp/hack/src/typing/tast_env.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ let print_ty_with_identity env ty sym_occurrence sym_definition =
5555
let print_decl_ty_with_identity env ty sym_occurrence sym_definition =
5656
Typing_print.full_decl_with_identity
5757
~verbose_fun:false
58+
~omit_likes:true
5859
env
5960
ty
6061
sym_occurrence

hphp/hack/src/typing/typing_print.ml

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -812,14 +812,28 @@ module Full = struct
812812
(* Prints a decl_ty. If there isn't enough fuel, the type is omitted. Each
813813
recursive call to print a type depletes the fuel by one. *)
814814
let rec decl_ty ~fuel :
815-
_ -> _ -> _ -> verbose_fun:bool -> decl_ty -> Fuel.t * Doc.t =
816-
fun to_doc st penv ~verbose_fun x ->
817-
Fuel.provide fuel (decl_ty_ to_doc st penv ~verbose_fun (get_node x))
815+
_ ->
816+
_ ->
817+
_ ->
818+
verbose_fun:bool ->
819+
omit_likes:bool ->
820+
decl_ty ->
821+
Fuel.t * Doc.t =
822+
fun to_doc st penv ~verbose_fun ~omit_likes x ->
823+
Fuel.provide
824+
fuel
825+
(decl_ty_ to_doc st penv ~verbose_fun ~omit_likes (get_node x))
818826

819827
and decl_ty_ ~fuel :
820-
_ -> _ -> _ -> verbose_fun:bool -> decl_phase ty_ -> Fuel.t * Doc.t =
821-
fun to_doc st penv ~verbose_fun x ->
822-
let ty = decl_ty ~verbose_fun in
828+
_ ->
829+
_ ->
830+
_ ->
831+
verbose_fun:bool ->
832+
omit_likes:bool ->
833+
decl_phase ty_ ->
834+
Fuel.t * Doc.t =
835+
fun to_doc st penv ~verbose_fun ~omit_likes x ->
836+
let ty = decl_ty ~verbose_fun ~omit_likes in
823837
let k ~fuel x = ty ~fuel to_doc st penv x in
824838
match x with
825839
| Tany _ -> (fuel, text "_")
@@ -845,7 +859,12 @@ module Full = struct
845859
(fuel, option_doc)
846860
| Tlike x ->
847861
let (fuel, ty_doc) = k ~fuel x in
848-
let like_doc = Concat [text "~"; ty_doc] in
862+
let like_doc =
863+
if omit_likes then
864+
ty_doc
865+
else
866+
Concat [text "~"; ty_doc]
867+
in
849868
(fuel, like_doc)
850869
| Tprim x -> (fuel, tprim x)
851870
| Tfun ft ->
@@ -857,7 +876,7 @@ module Full = struct
857876
penv
858877
~verbose:verbose_fun
859878
ft
860-
(fun_decl_implicit_params ~verbose_fun)
879+
(fun_decl_implicit_params ~verbose_fun ~omit_likes)
861880
| Tapply ((_, n), [ty])
862881
when String.equal n SN.Classes.cSupportDyn
863882
&& not (show_supportdyn_penv penv) ->
@@ -900,9 +919,9 @@ module Full = struct
900919
let class_ptr_doc = Concat [text "class<"; ty_doc; text ">"] in
901920
(fuel, class_ptr_doc)
902921

903-
and fun_decl_implicit_params ~fuel ~verbose_fun =
922+
and fun_decl_implicit_params ~fuel ~verbose_fun ~omit_likes =
904923
fun_implicit_params
905-
(decl_ty ~verbose_fun)
924+
(decl_ty ~verbose_fun ~omit_likes)
906925
(Typing_make_type.default_capability_decl Pos_or_decl.none)
907926
~fuel
908927

@@ -1456,7 +1475,7 @@ module Full = struct
14561475
to_string ~fuel ~ty text_strip_ns env x
14571476

14581477
let to_string_decl ~fuel (x : decl_ty) =
1459-
let ty = decl_ty ~verbose_fun:false in
1478+
let ty = decl_ty ~verbose_fun:false ~omit_likes:false in
14601479
to_string ~fuel ~ty Doc.text Declenv x
14611480

14621481
(** For functions and methods, interpret supportdyn as use of <<__SupportDynamicType>> attribute *)
@@ -1620,12 +1639,13 @@ module Full = struct
16201639
definition_opt
16211640

16221641
let to_string_decl_with_identity
1623-
~fuel ~verbose_fun env (x : decl_ty) occurrence definition_opt =
1642+
~fuel ~verbose_fun ~omit_likes env (x : decl_ty) occurrence definition_opt
1643+
=
16241644
to_string_with_identity
16251645
~fuel
16261646
env
16271647
x
1628-
(decl_ty ~verbose_fun)
1648+
(decl_ty ~verbose_fun ~omit_likes)
16291649
~default_capability:
16301650
(Typing_make_type.default_capability_decl Pos_or_decl.none)
16311651
~constraints:Nothing
@@ -1903,7 +1923,10 @@ let full_strip_ns_decl ?(msg = true) ~verbose_fun env ty =
19031923
supply_fuel
19041924
~msg
19051925
env.genv.tcopt
1906-
(Full.to_string_strip_ns ~ty:(Full.decl_ty ~verbose_fun) (Loclenv env) ty)
1926+
(Full.to_string_strip_ns
1927+
~ty:(Full.decl_ty ~verbose_fun ~omit_likes:false)
1928+
(Loclenv env)
1929+
ty)
19071930

19081931
let full_with_identity ~hide_internals env x occurrence definition_opt =
19091932
supply_fuel
@@ -1915,11 +1938,13 @@ let full_with_identity ~hide_internals env x occurrence definition_opt =
19151938
occurrence
19161939
definition_opt)
19171940

1918-
let full_decl_with_identity env ~verbose_fun x occurrence definition_opt =
1941+
let full_decl_with_identity
1942+
env ~omit_likes ~verbose_fun x occurrence definition_opt =
19191943
supply_fuel
19201944
env.genv.tcopt
19211945
(Full.to_string_decl_with_identity
19221946
~verbose_fun
1947+
~omit_likes
19231948
env
19241949
x
19251950
occurrence

hphp/hack/src/typing/typing_print.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ val full_with_identity :
5555
(** Pretty print a type and all of its associated declaration information. *)
5656
val full_decl_with_identity :
5757
env ->
58+
omit_likes:bool ->
5859
verbose_fun:bool ->
5960
Typing_defs.decl_ty ->
6061
'b SymbolOccurrence.t ->

hphp/hack/test/hover/ctx.php.exp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function any<T>(
44
Traversable<T> $traversable,
55
optional ?(function(
66
T
7-
)[T/[ctx $predicate]]: ~bool) $predicate
7+
)[T/[ctx $predicate]]: bool) $predicate
88
)[T/[ctx $predicate]ctx $predicate]: bool
99
---
1010
Instantiation:

hphp/hack/test/hover/enum_class_label_argument.php.exp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function app<Ta, Tr>(
22
HH\EnumClass\Label<Funcs, Func<Ta, Tr>> $l,
33
Ta $arg
4-
): ~Tr
4+
): Tr
55
---
66
Instantiation:
77
Ta = (int, int);

hphp/hack/test/hover/enum_class_label_argument2.php.exp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function app<Ta, Tr>(
22
HH\EnumClass\Label<Funcs, Func<Ta, Tr>> $l,
33
Ta $arg
4-
): ~Tr
4+
): Tr
55
---
66
Instantiation:
77
Ta = (int, int);

hphp/hack/test/hover/enum_class_label_argument3.php.exp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function app<Ta, Tr>(
22
HH\EnumClass\Label<Funcs, Func<Ta, Tr>> $l,
33
Ta $arg
4-
): ~Tr
4+
): Tr
55
---
66
Instantiation:
77
Ta = (int, int);

hphp/hack/test/hover/enum_class_label_argument4.php.exp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Defined in `CL`
33
public function app<Ta, Tr>(
44
HH\EnumClass\Label<Funcs, Func<Ta, Tr>> $l,
55
Ta $arg
6-
): ~Tr
6+
): Tr
77
---
88
Instantiation:
99
Ta = (int, int);
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
async function bar(ExampleContext $_): Awaitable<
2-
~ExprTree<
2+
ExprTree<
33
ExampleDsl,
44
ExampleDsl::TAst,
5-
(function(ExampleString): ~ExampleInt)
5+
(function(ExampleString): ExampleInt)
66
>
77
>

hphp/hack/test/hover/expression_tree_splice_compound2.php.exp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function from(string $_): ~ExprTree<
1+
function from(string $_): ExprTree<
22
ExampleDsl,
33
ExampleDsl::TAst,
44
ExampleString
@@ -16,6 +16,4 @@ Defined in `ExampleDsl`
1616
public static function lift<
1717
THack as TInfer as ?ExampleAutoLiftable,
1818
TInfer
19-
>(ExampleUnion<THack, TInfer> $e): ~ExampleExpression<
20-
TInfer
21-
>
19+
>(ExampleUnion<THack, TInfer> $e): ExampleExpression<TInfer>

0 commit comments

Comments
 (0)