Skip to content

Commit 11d2c0f

Browse files
frank-emrichfacebook-github-bot
authored andcommitted
remove parameters field from kind definition
Summary: This diff is part of a series that removes the implementation of higher-kinded types from the type-checker. This diff removes the `parameters` field from `Typing_kinding_defs.kind`, our main representation of kinds. This means that higher-kinded type parameters cannot exist in the typing environment anymore. Reviewed By: mheiber Differential Revision: D74463076 fbshipit-source-id: 731fbccfcbbbc4405581c519bd62f91e824af16f
1 parent d575a67 commit 11d2c0f

File tree

9 files changed

+29
-101
lines changed

9 files changed

+29
-101
lines changed

hphp/hack/src/annotated_ast/aast_defs.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,7 @@ and ('ex, 'en) file_attribute = {
927927
and ('ex, 'en) tparam = {
928928
tp_variance: Ast_defs.variance; [@transform.opaque]
929929
tp_name: sid;
930+
(* TODO(T222659258) Can remove tp_parameters, now that HKTs are removed *)
930931
tp_parameters: ('ex, 'en) tparam list;
931932
tp_constraints: ((Ast_defs.constraint_kind[@transform.opaque]) * hint) list;
932933
tp_reified: reify_kind; [@transform.opaque]

hphp/hack/src/oxidized/gen/typing_kinding_defs.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// This source code is licensed under the MIT license found in the
44
// LICENSE file in the "hack" directory of this source tree.
55
//
6-
// @generated SignedSource<<8be733e9b0946dd30f0ee749ba761a48>>
6+
// @generated SignedSource<<47660976ed4933977f98d2fd9c51a99d>>
77
//
88
// To regenerate this file, run:
99
// hphp/hack/src/oxidized_regen.sh
@@ -44,7 +44,6 @@ pub struct Kind {
4444
pub enforceable: bool,
4545
pub newable: bool,
4646
pub require_dynamic: bool,
47-
pub parameters: Vec<NamedKind>,
4847
pub rank: isize,
4948
}
5049

hphp/hack/src/typing/env/typing_env.ml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,6 @@ let add_fresh_generic_parameter env pos prefix ~reified ~enforceable ~newable =
511511
enforceable;
512512
newable;
513513
require_dynamic = true;
514-
parameters = [];
515514
rank = 0;
516515
}
517516
in
@@ -536,8 +535,6 @@ let get_tpenv_tparams env =
536535
enforceable = _;
537536
newable = _;
538537
require_dynamic = _;
539-
(* FIXME what to do here? it seems dangerous to just traverse *)
540-
parameters = _;
541538
rank = _;
542539
}
543540
acc ->

hphp/hack/src/typing/type_parameter_env.ml

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,9 @@ let get_upper_bounds tpenv name =
9595
| None -> empty_bounds
9696
| Some { upper_bounds; _ } -> upper_bounds
9797

98-
let get_arity tpenv name =
99-
match get name tpenv with
100-
| None -> 0
101-
| Some { parameters; _ } -> List.length parameters
98+
let get_arity _tpenv _name =
99+
(* TODO(T222659258) Always 0 now that higher-kinded types are being removed *)
100+
0
102101

103102
let get_reified tpenv name =
104103
match get name tpenv with
@@ -160,7 +159,6 @@ let add_upper_bound_ tpenv name ty =
160159
enforceable = false;
161160
newable = false;
162161
require_dynamic = false;
163-
parameters = [];
164162
rank = 0;
165163
} )
166164
| Some (pos, tp) ->
@@ -185,7 +183,6 @@ let add_lower_bound_ tpenv name ty =
185183
enforceable = false;
186184
newable = false;
187185
require_dynamic = false;
188-
parameters = [];
189186
rank = 0;
190187
} )
191188
| Some (pos, tp) ->
@@ -226,7 +223,6 @@ let add_upper_bound ?intersect env_tpenv name ty =
226223
let enforceable = get_enforceable env_tpenv name in
227224
let newable = get_newable env_tpenv name in
228225
let require_dynamic = get_require_dynamic env_tpenv name in
229-
let parameters = [] in
230226
let rank = get_rank env_tpenv name in
231227
add
232228
~def_pos
@@ -238,7 +234,6 @@ let add_upper_bound ?intersect env_tpenv name ty =
238234
enforceable;
239235
newable;
240236
require_dynamic;
241-
parameters;
242237
rank;
243238
}
244239
tpenv
@@ -269,7 +264,6 @@ let add_lower_bound ?union env_tpenv name ty =
269264
let enforceable = get_enforceable env_tpenv name in
270265
let newable = get_newable env_tpenv name in
271266
let require_dynamic = get_require_dynamic env_tpenv name in
272-
let parameters = [] in
273267
let rank = get_rank env_tpenv name in
274268
add
275269
~def_pos
@@ -281,7 +275,6 @@ let add_lower_bound ?union env_tpenv name ty =
281275
enforceable;
282276
newable;
283277
require_dynamic;
284-
parameters;
285278
rank;
286279
}
287280
tpenv
@@ -325,8 +318,8 @@ let remove tpenv name =
325318
(* Add type parameters to environment, initially with no bounds.
326319
* Existing type parameters with the same name will be overridden. *)
327320
let add_generic_parameters tpenv tparaml =
328-
let rec make_param_info ast_tparam =
329-
let { tp_user_attributes; tp_tparams; _ } = ast_tparam in
321+
let make_param_info ast_tparam =
322+
let { tp_user_attributes; _ } = ast_tparam in
330323
let enforceable =
331324
Attributes.mem SN.UserAttributes.uaEnforceable tp_user_attributes
332325
in
@@ -336,9 +329,6 @@ let add_generic_parameters tpenv tparaml =
336329
let require_dynamic =
337330
Attributes.mem SN.UserAttributes.uaRequireDynamic tp_user_attributes
338331
in
339-
let nested_params =
340-
List.map tp_tparams ~f:(fun tp -> (tp.tp_name, make_param_info tp))
341-
in
342332

343333
{
344334
lower_bounds = empty_bounds;
@@ -347,7 +337,6 @@ let add_generic_parameters tpenv tparaml =
347337
enforceable;
348338
newable;
349339
require_dynamic;
350-
parameters = nested_params;
351340
rank = 0;
352341
}
353342
in
@@ -358,8 +347,10 @@ let add_generic_parameters tpenv tparaml =
358347
in
359348
List.fold_left tparaml ~f:add_top ~init:tpenv
360349

361-
let get_parameter_names tpi =
362-
List.map tpi.parameters ~f:(fun (name, _) -> snd name)
350+
let get_parameter_names _tpi =
351+
(* TODO(T222659258) Always empty now that higher-kinded types are
352+
being removed *)
353+
[]
363354

364355
let force_lazy_values_tparam_info (info : tparam_info) =
365356
Typing_kinding_defs.force_lazy_values info

hphp/hack/src/typing/typing_kinding_defs.ml

Lines changed: 16 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ module SN = Naming_special_names
66

77
type tparam_bounds = TySet.t [@@deriving hash, show]
88

9-
(* TODO(T222659258) remove parameters field here *)
109
type kind = {
1110
lower_bounds: tparam_bounds;
1211
upper_bounds: tparam_bounds;
1312
reified: Aast.reify_kind;
1413
enforceable: bool;
1514
newable: bool;
1615
require_dynamic: bool;
17-
parameters: named_kind list;
1816
rank: int;
1917
}
2018

@@ -24,47 +22,18 @@ let dummy_name = (Pos_or_decl.none, "")
2422

2523
let with_dummy_name k = (dummy_name, k)
2624

27-
let get_arity k = List.length k.parameters
28-
29-
let string_of_kind (kind : kind) =
30-
let rec stringify toplevel k =
31-
match k.parameters with
32-
| [] -> "Type"
33-
| params ->
34-
let parts = List.map params ~f:(fun (_, pk) -> stringify false pk) in
35-
let res = String.concat ~sep:" -> " parts ^ " -> Type" in
36-
if toplevel then
37-
res
38-
else
39-
"(" ^ res ^ ")"
40-
in
41-
stringify true kind
42-
43-
let description_of_kind kind =
44-
match kind.parameters with
45-
| [] -> "a fully-applied type"
46-
| params
47-
when List.for_all params ~f:(fun (_, param) ->
48-
Int.( = ) 0 (get_arity param)) ->
49-
(* no higher-order arguments *)
50-
let param_count = List.length params in
51-
let args_desc =
52-
if Int.( = ) 1 param_count then
53-
"a single (fully-applied) type argument"
54-
else
55-
string_of_int param_count ^ "(fully-applied) type arguments"
56-
in
57-
"a type constructor expecting " ^ args_desc
58-
| _ -> "a type constructor of kind " ^ string_of_kind kind
25+
let get_arity _k =
26+
(* TODO(T222659258) Always 0 now that higher-kinded types are being removed *)
27+
0
5928

60-
let rec remove_bounds kind =
61-
{
62-
kind with
63-
lower_bounds = TySet.empty;
64-
upper_bounds = TySet.empty;
65-
parameters =
66-
List.map kind.parameters ~f:(fun (n, k) -> (n, remove_bounds k));
67-
}
29+
let string_of_kind (_kind : kind) =
30+
(* TODO(T222659258) Find and remove users of this *) "Type"
31+
32+
let description_of_kind _kind =
33+
(* TODO(T222659258) Find and remove users of this *) "a fully-applied type"
34+
35+
let remove_bounds kind =
36+
{ kind with lower_bounds = TySet.empty; upper_bounds = TySet.empty }
6837

6938
module Simple = struct
7039
type bounds_for_wildcard =
@@ -101,7 +70,6 @@ module Simple = struct
10170
enforceable;
10271
newable;
10372
require_dynamic = false;
104-
parameters = [];
10573
rank = 0;
10674
},
10775
NonLocalized [] )
@@ -122,16 +90,7 @@ module Simple = struct
12290
Attributes.mem SN.UserAttributes.uaNewable tp_user_attributes
12391
in
12492
let (st, _) = fully_applied_type ~reified ~enforceable ~newable () in
125-
( tp_name,
126-
{
127-
st with
128-
parameters = named_internal_kinds_of_decl_tparams decl_tparam.tp_tparams;
129-
} )
130-
131-
(* not public *)
132-
and named_internal_kinds_of_decl_tparams (tparams : decl_tparam list) :
133-
named_full_kind list =
134-
List.map tparams ~f:named_internal_kind_of_decl_tparam
93+
(tp_name, st)
13594

13695
(* public *)
13796
and named_kind_of_decl_tparam decl_tparam : named_kind =
@@ -144,14 +103,12 @@ module Simple = struct
144103
let named_kinds_of_decl_tparams decl_tparams : named_kind list =
145104
List.map decl_tparams ~f:named_kind_of_decl_tparam
146105

147-
let type_with_params_to_simple_kind ?reified ?enforceable ?newable tparams =
106+
let type_with_params_to_simple_kind ?reified ?enforceable ?newable _tparams =
148107
let (st, _) = fully_applied_type ?reified ?enforceable ?newable () in
149-
( { st with parameters = named_internal_kinds_of_decl_tparams tparams },
150-
NonLocalized [] )
108+
(st, NonLocalized [])
151109

152110
(** Returns the type parameters of the kind, more or less. *)
153-
let get_named_parameter_kinds (kind, _) : named_kind list =
154-
List.map kind.parameters ~f:(fun (n, fk) -> (n, (fk, NonLocalized [])))
111+
let get_named_parameter_kinds (_kind, _) : named_kind list = []
155112

156113
let from_full_kind fk =
157114
let wildcard_bounds =
@@ -165,15 +122,14 @@ module Simple = struct
165122
let with_dummy_name = with_dummy_name
166123
end
167124

168-
let rec force_lazy_values (kind : kind) =
125+
let force_lazy_values (kind : kind) =
169126
let {
170127
lower_bounds;
171128
upper_bounds;
172129
reified;
173130
enforceable;
174131
newable;
175132
require_dynamic;
176-
parameters;
177133
rank;
178134
} =
179135
kind
@@ -185,9 +141,5 @@ let rec force_lazy_values (kind : kind) =
185141
enforceable;
186142
newable;
187143
require_dynamic;
188-
parameters = List.map parameters ~f:force_lazy_values_named_kind;
189144
rank;
190145
}
191-
192-
and force_lazy_values_named_kind ((p, kind) : named_kind) =
193-
(p, force_lazy_values kind)

hphp/hack/src/typing/typing_kinding_defs.mli

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ type kind = {
2525
require_dynamic: bool;
2626
(** Set if class is marked <<__SupportDynamicType>> and
2727
generic parameter does *not* have attribute <<__NoRequireDynamic>> *)
28-
parameters: named_kind list;
2928
rank: int;
3029
}
3130

hphp/hack/src/typing/typing_log.ml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ let reify_kind_as_value k =
321321
let tyset_as_value env tys =
322322
Set (TySet.fold (fun t s -> SSet.add (Pr.debug env t) s) tys SSet.empty)
323323

324-
let rec tparam_info_as_value env tpinfo =
324+
let tparam_info_as_value env tpinfo =
325325
let Typing_kinding_defs.
326326
{
327327
lower_bounds;
@@ -330,7 +330,6 @@ let rec tparam_info_as_value env tpinfo =
330330
enforceable;
331331
newable;
332332
require_dynamic;
333-
parameters;
334333
rank;
335334
} =
336335
tpinfo
@@ -343,18 +342,9 @@ let rec tparam_info_as_value env tpinfo =
343342
("enforceable", bool_as_value enforceable);
344343
("newable", bool_as_value newable);
345344
("require_dynamic", bool_as_value require_dynamic);
346-
("parameters", named_tparam_info_list_as_value env parameters);
347345
("rank", string_as_value (Int.to_string rank));
348346
]
349347

350-
and named_tparam_info_list_as_value env parameters =
351-
let param_values =
352-
List.map parameters ~f:(fun (name, param) ->
353-
list_as_value
354-
[string_as_value (snd name); tparam_info_as_value env param])
355-
in
356-
list_as_value param_values
357-
358348
let tpenv_as_value env tpenv =
359349
make_map
360350
[

hphp/hack/src/typing/typing_subtype.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8985,7 +8985,6 @@ end = struct
89858985
enforceable;
89868986
newable;
89878987
require_dynamic;
8988-
parameters = [];
89898988
rank;
89908989
}
89918990
in

hphp/hack/test/map_reduce/tast_hashes/tast_hashes_test.php.exp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"tast_hashes": {
33
"tast_hashes_test.php": {
44
"tast_hashes": {
5-
"class_tast_hashes": { "\\A": 190846743, "\\B": 556599326 },
5+
"class_tast_hashes": { "\\A": 399326371, "\\B": 902123085 },
66
"gconst_tast_hashes": { "\\B": 561084034 }
77
},
88
"error_hashes": []

0 commit comments

Comments
 (0)