Skip to content

Commit

Permalink
[flow] Kill $Call
Browse files Browse the repository at this point in the history
Summary:
This diff kills the support for `$Call` from userland. `$Call` in the source code will no longer resolve to the builtin $Call type. Since `$TupleMap` still exists, not much code is deleted for now.

For now, we might still output `$Call` for normalizers, since `$TupleMap` still uses `$Call` under the hood. However, I don't think it will ever appear, because we either show the fully evaluated type or completely unevaluated type. Since there is no more toplevel `$Call`, it should never show up. [example](https://flow.org/try/#1N4Igxg9gdgZglgcxALlAIwIZoKYBsD6uEEAztvhgE6UYCe+JADpdhgCYowa5kA0I2KAFcAtiRQAXSkOz9sADwxgJ+NPTbYuQ3BMnTZA+Y2yU4IwRO4A6SFBIrGVDGM7c+h46fNRLuKxJIGWh8MeT0ZfhYlCStpHzNsFBAMIQkIEQwJODAQfiEyfBE4eWw2fDgofDBMsAALfAA3KjgsXGxxZC4eAw0G-GhcWn9aY3wWZldu-g1mbGqJUoBaCRHEzrcDEgBrbAk62kXhXFxJ923d-cPRHEpTgyEoMDaqZdW7vKgoOfaSKgOKpqmDA+d4gB5fMA-P6LCCMLLQbiLOoYCqgh6-GDYRYIXYLSgkRZkCR4jpddwPfJLZjpOBkO4AX34kA0SRWxgABABBdkAXnZABIACpCRhtACyGEYAB4ANrCEQ3AC6vHZUsFAD4ABSCgCUvPV7I1AG4ADpQDRPKjYdm2ezsjDILmmx7QO1oXn2mUABkVztyIAaJhIcGgSQaXqsACYACwANisXpA9KAA) shows an attempt to make `$Call` show up, but it still doesn't show up.

Changelog: [errors] Support for the deprecated `$Call` type is removed. `$Call` will now resolve to whatever `$Call` points to in the global libdef. If you need more time to migrate, you can create a shim like `$Call<F, T> = $TupleMap<[T], F>[0]`, but please note that we intend to remove support for `$TupleMap` eventually.

Reviewed By: panagosg7

Differential Revision: D62785430

fbshipit-source-id: 108b49da9d7247cd26ed029603768e3658855abb
  • Loading branch information
SamChou19815 authored and facebook-github-bot committed Sep 17, 2024
1 parent 60e45e0 commit 3e97fed
Show file tree
Hide file tree
Showing 18 changed files with 35 additions and 118 deletions.
13 changes: 5 additions & 8 deletions src/common/reason.ml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ type 'loc virtual_reason_desc =
| RFunctionType
| RFunctionBody
| RFunctionCall of 'loc virtual_reason_desc
| RFunctionCallType
| RFunctionUnusedArgument
| RJSXChild
| RJSXFunctionCall of string
Expand Down Expand Up @@ -261,11 +260,11 @@ let rec map_desc_locs f = function
| RObjectType | RInterfaceType | RArray | RArrayLit | RConstArrayLit | REmptyArrayLit
| RArrayType | RArrayElement | RArrayNthElement _ | RArrayHole | RROArrayType | RTupleType
| RTupleElement _ | RTupleLength _ | RTupleOutOfBoundsAccess _ | RTupleUnknownElementFromInexact
| RFunction _ | RFunctionType | RFunctionBody | RFunctionCallType | RFunctionUnusedArgument
| RJSXChild | RJSXFunctionCall _ | RJSXIdentifier _ | RJSXElementProps _ | RJSXElement _
| RJSXText | RFbt | RUninitialized | RPossiblyUninitialized | RUnannotatedNext
| REmptyArrayElement | RMappedType | RTypeGuard | RTypeGuardParam _ | RComponent _
| RComponentType | RInferredUnionElemArray _ ) as r ->
| RFunction _ | RFunctionType | RFunctionBody | RFunctionUnusedArgument | RJSXChild
| RJSXFunctionCall _ | RJSXIdentifier _ | RJSXElementProps _ | RJSXElement _ | RJSXText | RFbt
| RUninitialized | RPossiblyUninitialized | RUnannotatedNext | REmptyArrayElement | RMappedType
| RTypeGuard | RTypeGuardParam _ | RComponent _ | RComponentType | RInferredUnionElemArray _ )
as r ->
r
| RFunctionCall desc -> RFunctionCall (map_desc_locs f desc)
| RUnknownUnspecifiedProperty desc -> RUnknownUnspecifiedProperty (map_desc_locs f desc)
Expand Down Expand Up @@ -586,7 +585,6 @@ let rec string_of_desc = function
| RFunctionType -> "function type"
| RFunctionBody -> "function body"
| RFunctionCall d -> spf "call of %s" (string_of_desc d)
| RFunctionCallType -> "`$Call`"
| RFunctionUnusedArgument -> "unused function argument"
| RJSXChild -> "JSX child"
| RJSXFunctionCall raw_jsx -> spf "`%s(...)`" raw_jsx
Expand Down Expand Up @@ -1349,7 +1347,6 @@ let classification_of_reason_desc desc =
| RFunctionType
| RFunctionBody
| RFunctionCall _
| RFunctionCallType
| RFunctionUnusedArgument
| RJSXChild
| RJSXFunctionCall _
Expand Down
1 change: 0 additions & 1 deletion src/common/reason.mli
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ type 'loc virtual_reason_desc =
| RFunctionType
| RFunctionBody
| RFunctionCall of 'loc virtual_reason_desc
| RFunctionCallType
| RFunctionUnusedArgument
| RJSXChild
| RJSXFunctionCall of string
Expand Down
5 changes: 0 additions & 5 deletions src/parser_utils/type_sig/type_sig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -588,11 +588,6 @@ type ('loc, 'a) annot =
true_type: 'a;
false_type: 'a;
}
| Call of {
loc: 'loc;
fn: 'a;
args: 'a list;
}
| TupleMap of {
loc: 'loc;
tup: 'a;
Expand Down
8 changes: 0 additions & 8 deletions src/parser_utils/type_sig/type_sig_parse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2427,14 +2427,6 @@ and maybe_special_unqualified_generic opts scope tbls xs loc targs ref_loc =
| Some (_, { arguments = [(loc, _)]; _ }) -> Err (push_loc tbls loc, CheckError)
| _ -> Err (loc, CheckError)
end
| "$Call" -> begin
match targs with
| Some (_, { arguments = fn :: args; _ }) ->
let fn = annot opts scope tbls xs fn in
let args = List.map (annot opts scope tbls xs) args in
Annot (Call { loc; fn; args })
| _ -> Err (loc, CheckError)
end
| "$TupleMap" -> begin
match targs with
| Some (_, { arguments = [tup; fn]; _ }) ->
Expand Down
16 changes: 4 additions & 12 deletions src/typing/flow_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3934,7 +3934,7 @@ struct
let use_op = Frame (TupleMapFunCompatibility { value = reason_of_t x }, use_op) in
EvalT
( funt,
TypeDestructorT (use_op, reason_op, CallType { from_maptype = true; args = [x] }),
TypeDestructorT (use_op, reason_op, CallType { args = [x] }),
Eval.generate_id ()
)
in
Expand Down Expand Up @@ -3981,10 +3981,7 @@ struct
let iter = Flow_js_utils.lookup_builtin_value cx "$iterate" reason in
let elemt =
EvalT
( iter,
TypeDestructorT (use_op, reason, CallType { from_maptype = true; args = [l] }),
Eval.generate_id ()
)
(iter, TypeDestructorT (use_op, reason, CallType { args = [l] }), Eval.generate_id ())
in
let t = DefT (reason, ArrT (ROArrayAT (elemt, None))) in
rec_flow cx trace (t, MapTypeT (use_op, reason, TupleMap funt, tout))
Expand Down Expand Up @@ -6811,14 +6808,9 @@ struct
trace
(t, Object.(ObjKitT (use_op, reason, Resolve Next, Required, OpenT tout)))
| ValuesType -> rec_flow cx trace (t, GetValuesT (reason, OpenT tout))
| CallType { from_maptype; args } ->
| CallType { args } ->
let args = Base.List.map ~f:(fun arg -> Arg arg) args in
let call_kind =
if from_maptype then
MapTypeKind
else
CallTypeKind
in
let call_kind = MapTypeKind in
let call = mk_functioncalltype ~call_kind reason None args tout in
let call = { call with call_strict_arity = false } in
let use_op =
Expand Down
2 changes: 1 addition & 1 deletion src/typing/implicit_instantiation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,7 @@ module Kit (FlowJs : Flow_common.S) (Instantiation_helper : Flow_js_utils.Instan
call_tout;
call_strict_arity;
call_speculation_hint_state;
call_kind = (MapTypeKind | CallTypeKind) as call_kind;
call_kind = MapTypeKind as call_kind;
call_specialized_callee;
}
)
Expand Down
2 changes: 1 addition & 1 deletion src/typing/ty_normalizer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1588,7 +1588,7 @@ module Make (I : INPUT) : S = struct
in
Ty.IndexedAccess { _object = ty; index = index'; optional = true }
| T.OptionalIndexedAccessResultType _ -> return ty
| T.CallType { from_maptype = _; args = ts } ->
| T.CallType { args = ts } ->
let%map tys = mapM (type__ ~env) ts in
Ty.Utility (Ty.Call (ty, tys))
| T.ConditionalType
Expand Down
6 changes: 1 addition & 5 deletions src/typing/type.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,6 @@ module rec TypeTerm : sig

and call_kind =
| MapTypeKind
| CallTypeKind
| RegularCallKind

(* speculation id * case id *)
Expand Down Expand Up @@ -1585,10 +1584,7 @@ module rec TypeTerm : sig
}
| RestType of Object.Rest.merge_mode * t
| ValuesType
| CallType of {
from_maptype: bool;
args: t list;
}
| CallType of { args: t list }
| ConditionalType of {
distributive_tparam_name: Subst_name.t option;
infer_tparams: typeparam list;
Expand Down
16 changes: 0 additions & 16 deletions src/typing/type_annotation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1129,22 +1129,6 @@ module Make (Statement : Statement_sig.S) : Type_annotation_sig.S = struct
)
| _ -> error_type cx loc (Error_message.EExportsAnnot loc) t_ast
)
| "$Call" ->
Flow_js_utils.add_output cx (Error_message.EDeprecatedDollarCall loc);
(match convert_type_params () with
| (fn :: args, targs) ->
let reason = mk_reason RFunctionCallType loc in
reconstruct_ast
(mk_type_destructor
cx
(use_op reason)
reason
fn
(CallType { from_maptype = false; args })
(mk_eval_id cx loc)
)
targs
| _ -> error_type cx loc (Error_message.ETypeParamMinArity (loc, 1)) t_ast)
| "$TupleMap" ->
check_type_arg_arity cx loc t_ast targs 2 (fun () ->
let (t1, t2, targs) =
Expand Down
4 changes: 2 additions & 2 deletions src/typing/type_mapper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -635,12 +635,12 @@ class virtual ['a] t =
else
RestType (options, x')
| ValuesType -> t
| CallType { from_maptype; args } ->
| CallType { args } ->
let args' = ListUtils.ident_map (self#type_ cx map_cx) args in
if args' == args then
t
else
CallType { from_maptype; args = args' }
CallType { args = args' }
| ConditionalType { distributive_tparam_name; infer_tparams; extends_t; true_t; false_t } ->
let infer_tparams' = ListUtils.ident_map (self#type_param cx map_cx) infer_tparams in
let extends_t' = self#type_ cx map_cx extends_t in
Expand Down
7 changes: 0 additions & 7 deletions src/typing/type_sig_merge.ml
Original file line number Diff line number Diff line change
Expand Up @@ -858,13 +858,6 @@ and merge_annot env file = function
(match distributive_tparam with
| None -> convert None env
| Some (TParam { name; _ }) -> convert (Some (Subst_name.Name name)) env)
| Call { loc; fn; args } ->
let reason = Reason.(mk_reason RFunctionCallType loc) in
let use_op = Type.Op (Type.TypeApplication { type_ = reason }) in
let fn = merge env file fn in
let args = List.map (merge env file) args in
let id = eval_id_of_aloc file loc in
Type.(EvalT (fn, TypeDestructorT (use_op, reason, CallType { from_maptype = false; args }), id))
| TupleMap { loc; tup; fn } ->
let reason = Reason.(mk_reason RTupleMap loc) in
let use_op = Type.Op (Type.TypeApplication { type_ = reason }) in
Expand Down
2 changes: 1 addition & 1 deletion src/typing/type_visitor.ml
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class ['a] t =
in
acc
| RestType (_, t) -> self#type_ cx pole_TODO acc t
| CallType { from_maptype = _; args } -> self#list (self#type_ cx pole_TODO) acc args
| CallType { args } -> self#list (self#type_ cx pole_TODO) acc args
| ConditionalType { distributive_tparam_name = _; infer_tparams; extends_t; true_t; false_t }
->
let acc = self#list (self#type_param cx pole_TODO) acc infer_tparams in
Expand Down
2 changes: 0 additions & 2 deletions tests/lint_all_warn/deprecated_types.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// @flow

type A = $Call<() => number>;

function foo(x: mixed): %checks {
return x === 1;
}
Expand Down
19 changes: 5 additions & 14 deletions tests/lint_all_warn/lint_all_warn.exp
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,21 @@ References:
^^^^^^^ [2]


Warning --------------------------------------------------------------------------------------- deprecated_types.js:3:10

Deprecated type. Use conditional types instead. See https://flow.org/en/docs/types/conditional/ for more information on
conditional types. [deprecated-type]

3| type A = $Call<() => number>;
^^^^^^^^^^^^^^^^^^^


Warning --------------------------------------------------------------------------------------- deprecated_types.js:5:23
Warning --------------------------------------------------------------------------------------- deprecated_types.js:3:23

Deprecated type. Use type guards instead. See https://flow.org/en/docs/types/type-guards/ for more information on type
guards. [deprecated-type]

5| function foo(x: mixed): %checks {
3| function foo(x: mixed): %checks {
^^^^^^^^^


Warning --------------------------------------------------------------------------------------- deprecated_types.js:8:41
Warning --------------------------------------------------------------------------------------- deprecated_types.js:6:41

Deprecated type. Use type guards instead. See https://flow.org/en/docs/types/type-guards/ for more information on type
guards. [deprecated-type]

8| declare function bar(x: mixed): boolean %checks(x === 1);
6| declare function bar(x: mixed): boolean %checks(x === 1);
^^^^^^^^^^^^^^^^


Expand Down Expand Up @@ -70,4 +61,4 @@ References:



Found 1 error and 5 warnings
Found 1 error and 4 warnings
4 changes: 2 additions & 2 deletions tests/lint_suppressions_single/deprecated.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
type Foo = $Call<() => string>; // error
declare function bar(x: mixed): boolean %checks(x === 1);; // error
// $FlowFixMe[deprecated-type]
type Bar = $Call<() => string>; // suppressed
declare function baz(x: mixed): boolean %checks(x === 1);; // suppressed
10 changes: 5 additions & 5 deletions tests/lint_suppressions_single/lint_suppressions_single.exp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ References:
^^^^ [2]


Error ----------------------------------------------------------------------------------------------- deprecated.js:1:12
Error ----------------------------------------------------------------------------------------------- deprecated.js:1:41

Deprecated type. Use conditional types instead. See https://flow.org/en/docs/types/conditional/ for more information on
conditional types. [deprecated-type]
Deprecated type. Use type guards instead. See https://flow.org/en/docs/types/type-guards/ for more information on type
guards. [deprecated-type]

1| type Foo = $Call<() => string>; // error
^^^^^^^^^^^^^^^^^^^
1| declare function bar(x: mixed): boolean %checks(x === 1);; // error
^^^^^^^^^^^^^^^^


Error ------------------------------------------------------------------------------------------ simple_sketchies.js:5:7
Expand Down
30 changes: 8 additions & 22 deletions tests/lti_implicit_instantiation/lti_implicit_instantiation.exp
Original file line number Diff line number Diff line change
Expand Up @@ -169,34 +169,20 @@ References:
^ [2]


Error ------------------------------------------------------------------------------------------------ no_infer.js:34:15
Error ------------------------------------------------------------------------------------------------- no_infer.js:36:1

Cannot instantiate `$Call` because `V` [1] is underconstrained by `$Call` [2]. Either add explicit type arguments or
cast the expression to your expected type. [underconstrained-implicit-instantiation]
Cannot resolve name `f7`. [cannot-resolve-name]

no_infer.js:34:15
34| v2: NoInfer<$Call<<V>(V) => V, 1>> // error: underconstrained
^^^^^^^^^^^^^^^^^^^^^ [2]
36| f7({a: ''}, {a: ''}); // ok
^^

References:
no_infer.js:34:22
34| v2: NoInfer<$Call<<V>(V) => V, 1>> // error: underconstrained
^ [1]

Error ------------------------------------------------------------------------------------------------- no_infer.js:37:1

Error ------------------------------------------------------------------------------------------------ no_infer.js:43:17
Cannot resolve name `f7`. [cannot-resolve-name]

Cannot call `f7` with object literal bound to `v2` because number [1] is incompatible with string [2] in property `a`.
[incompatible-call]

no_infer.js:43:17
43| f7({a: ''}, {a: 3}); // error: number ~> string
^ [1]

References:
no_infer.js:40:32
40| v2: NoInfer<{[K in keyof T]: T[K]}>
^^^^ [2]
37| f7({a: ''}, {a: 3}); // error: number ~> string
^^


Error ------------------------------------------------------------------------------------------ polyt_flow_error.js:2:7
Expand Down
6 changes: 0 additions & 6 deletions tests/lti_implicit_instantiation/no_infer.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ f5(1, 1); // ok
f5(1, '1'); // error: string ~> number

declare function f6<T>(
v1: T,
v2: NoInfer<$Call<<V>(V) => V, 1>> // error: underconstrained
): void;
f6(1, 1); // ok

declare function f7<T>(
v1: T,
v2: NoInfer<{[K in keyof T]: T[K]}>
): void;
Expand Down

0 comments on commit 3e97fed

Please sign in to comment.