From 9714fc41c35d363910c00bfad48b4fa97550e857 Mon Sep 17 00:00:00 2001 From: Sam Zhou Date: Thu, 25 Jul 2024 17:58:42 -0700 Subject: [PATCH] [flow] Kill $Flow$DebugPrint Summary: Changelog: [errors] Support for special function type `$Flow$DebugPrint` is removed. To see the internal representation of type, use `flow type-at-pos` command with flag `--debug-print-internal-repr`. Note that this is for debugging purpose only, and you should never depend on the output of `--debug-print-internal-repr` Reviewed By: mvitousek Differential Revision: D60250443 fbshipit-source-id: a720c526453a813c5880c10fde7dc9310f68f160 --- src/parser_utils/type_sig/type_sig.ml | 1 - src/parser_utils/type_sig/type_sig_parse.ml | 5 --- src/typing/debug_js.ml | 5 ++- src/typing/default_resolve.ml | 1 - src/typing/errors/error_message.ml | 16 ++++++---- src/typing/flow_js.ml | 35 +-------------------- src/typing/implicit_instantiation.ml | 1 - src/typing/ty_normalizer.ml | 15 --------- src/typing/type.ml | 7 +---- src/typing/typeUtil.ml | 2 -- src/typing/type_annotation.ml | 1 - src/typing/type_mapper.ml | 2 +- src/typing/type_sig_merge.ml | 3 -- src/typing/type_visitor.ml | 2 +- 14 files changed, 16 insertions(+), 80 deletions(-) diff --git a/src/parser_utils/type_sig/type_sig.ml b/src/parser_utils/type_sig/type_sig.ml index 0853b04957c..f60229957f0 100644 --- a/src/parser_utils/type_sig/type_sig.ml +++ b/src/parser_utils/type_sig/type_sig.ml @@ -629,7 +629,6 @@ type ('loc, 'a) annot = | ReactElementConfig of 'loc * 'a | ReactElementRef of 'loc * 'a | ReactImmutable of 'loc * 'a - | FlowDebugPrint of 'loc | FunAnnot of 'loc * ('loc, 'a) fun_sig | ComponentAnnot of 'loc * ('loc, 'a) component_sig | MappedTypeAnnot of { diff --git a/src/parser_utils/type_sig/type_sig_parse.ml b/src/parser_utils/type_sig/type_sig_parse.ml index b65cb097528..013d19cc852 100644 --- a/src/parser_utils/type_sig/type_sig_parse.ml +++ b/src/parser_utils/type_sig/type_sig_parse.ml @@ -2551,11 +2551,6 @@ and maybe_special_unqualified_generic opts scope tbls xs loc targs ref_loc = Annot (ReactImmutable (loc, t)) | _ -> Err (loc, CheckError) end - | "$Flow$DebugPrint" -> begin - match targs with - | None -> Annot (FlowDebugPrint loc) - | _ -> Err (loc, CheckError) - end | "$Flow$EnforceOptimized" -> begin match targs with | Some (_, { arguments = [t]; _ }) -> annot opts scope tbls xs t diff --git a/src/typing/debug_js.ml b/src/typing/debug_js.ml index 6b2d947057c..e9e4d2a4806 100644 --- a/src/typing/debug_js.ml +++ b/src/typing/debug_js.ml @@ -127,7 +127,6 @@ let rec dump_t_ (depth, tvars) cx t = in let custom_fun = function | ObjectGetPrototypeOf -> "ObjectGetPrototypeOf" - | DebugPrint -> "DebugPrint" in let instance_t { static = _; super = _; implements = _; inst = { class_id; type_args; _ } } = spf @@ -694,7 +693,6 @@ and dump_use_t_ (depth, tvars) cx t = | ConstructorT _ -> p t | CopyNamedExportsT _ -> p t | CopyTypeExportsT _ -> p t - | DebugPrintT _ -> p t | ElemT (_use_op, _reason, obj, _access) -> p ~extra:(spf "obj: %s" (kid obj)) t | ConditionalT { @@ -1211,7 +1209,6 @@ let dump_error_message = "EIncompatibleProp { reason_prop = %s; reason_obj = %s; special = _; prop = _; use_op = _ }" (dump_reason cx reason_prop) (dump_reason cx reason_obj) - | EDebugPrint (reason, _) -> spf "EDebugPrint (%s, _)" (dump_reason cx reason) | EExportValueAsType (reason, name) -> spf "EExportValueAsType (%s, %s)" (dump_reason cx reason) (display_string_of_name name) | EImportValueAsType (reason, str) -> @@ -1940,6 +1937,8 @@ let dump_error_message = spf "ECannotCallReactComponent (%s)" (dump_reason cx reason) | ENegativeTypeGuardConsistency { reason; _ } -> spf "ENegativeTypeGuardConsistency (%s)" (dump_reason cx reason) + | ETemporaryHardcodedErrorForPrototyping (reason, _) -> + spf "ETemporaryHardcodedErrorForPrototyping (%s, _)" (dump_reason cx reason) module Verbose = struct let print_if_verbose_lazy diff --git a/src/typing/default_resolve.ml b/src/typing/default_resolve.ml index a7aeabfdda1..48634d19e72 100644 --- a/src/typing/default_resolve.ml +++ b/src/typing/default_resolve.ml @@ -159,7 +159,6 @@ let rec default_resolve_touts ~flow ?resolve_callee cx loc u = resolve t | ReactKitT (_, _, tool) -> resolve_react_tool tool | PreprocessKitT _ -> _TODO - | DebugPrintT _ -> () | SentinelPropTestT (_, _, _, _, tvar) -> resolve_tvar tvar | OptionalChainT { t_out; voided_out; _ } -> resolve voided_out; diff --git a/src/typing/errors/error_message.ml b/src/typing/errors/error_message.ml index a0efba102c9..fa7e7df4a7e 100644 --- a/src/typing/errors/error_message.ml +++ b/src/typing/errors/error_message.ml @@ -40,7 +40,6 @@ and 'loc t' = special: lower_kind option; use_op: 'loc virtual_use_op option; } - | EDebugPrint of 'loc virtual_reason * string | EExportValueAsType of 'loc virtual_reason * name | EImportValueAsType of 'loc virtual_reason * string | EImportTypeAsTypeof of 'loc virtual_reason * string @@ -621,6 +620,9 @@ and 'loc t' = arg: 'loc virtual_reason; } | ECannotCallReactComponent of { reason: 'loc virtual_reason } + (* As the name suggest, don't use this for production purposes, but feel free to use it to + * quickly test out some ideas. *) + | ETemporaryHardcodedErrorForPrototyping of 'loc virtual_reason * string and enum_kind = | ConcreteEnumKind @@ -957,7 +959,6 @@ let rec map_loc_of_error_message (f : 'a -> 'b) : 'a t' -> 'b t' = { create_element_loc = f create_element_loc; invalid_react = map_reason invalid_react } | EFunctionCallExtraArg (rl, ru, n, op) -> EFunctionCallExtraArg (map_reason rl, map_reason ru, n, map_use_op op) - | EDebugPrint (r, s) -> EDebugPrint (map_reason r, s) | EExportValueAsType (r, s) -> EExportValueAsType (map_reason r, s) | EImportValueAsType (r, s) -> EImportValueAsType (map_reason r, s) | EImportTypeAsTypeof (r, s) -> EImportTypeAsTypeof (map_reason r, s) @@ -1374,6 +1375,8 @@ let rec map_loc_of_error_message (f : 'a -> 'b) : 'a t' -> 'b t' = | EUnionOptimizationOnNonUnion { loc; arg } -> EUnionOptimizationOnNonUnion { loc = f loc; arg = map_reason arg } | ECannotCallReactComponent { reason } -> ECannotCallReactComponent { reason = map_reason reason } + | ETemporaryHardcodedErrorForPrototyping (r, s) -> + ETemporaryHardcodedErrorForPrototyping (map_reason r, s) let desc_of_reason r = Reason.desc_of_reason ~unwrap:(is_scalar_reason r) r @@ -1502,7 +1505,7 @@ let util_use_op_of_msg nope util = function ) | EIncompatibleReactDeepReadOnly { lower; upper; use_op; dro_loc } -> util use_op (fun use_op -> EIncompatibleReactDeepReadOnly { lower; upper; use_op; dro_loc }) - | EDebugPrint (_, _) + | ETemporaryHardcodedErrorForPrototyping (_, _) | EExportValueAsType (_, _) | EImportValueAsType (_, _) | EImportTypeAsTypeof (_, _) @@ -1705,7 +1708,7 @@ let loc_of_msg : 'loc t' -> 'loc option = function | EImportTypeAsTypeof (reason, _) | EExportValueAsType (reason, _) | EImportValueAsType (reason, _) - | EDebugPrint (reason, _) + | ETemporaryHardcodedErrorForPrototyping (reason, _) | EComputedPropertyWithUnion reason -> Some (loc_of_reason reason) | EEnumAllMembersAlreadyChecked { loc; _ } @@ -2132,7 +2135,8 @@ let friendly_message_of_msg = function suggestion = None; use_op = Base.Option.value ~default:unknown_use use_op; } - | EDebugPrint (_, str) -> Normal (MessagePlainTextReservedForInternalErrorOnly str) + | ETemporaryHardcodedErrorForPrototyping (_, str) -> + Normal (MessagePlainTextReservedForInternalErrorOnly str) | EExportValueAsType (_, export_name) -> Normal (MessageExportValueAsType (display_string_of_name export_name)) | EImportValueAsType (_, export_name) -> Normal (MessageImportValueAsType export_name) @@ -2952,7 +2956,7 @@ let error_code_of_message err : error_code option = | EComparison _ -> Some InvalidCompare | EComputedPropertyWithUnion _ -> Some InvalidComputedProp - | EDebugPrint (_, _) -> None + | ETemporaryHardcodedErrorForPrototyping (_, _) -> None | EIncorrectTypeWithReplacement { kind; _ } -> (match IncorrectType.error_type_of_kind kind with | IncorrectType.DeprecatedUtility -> Some DeprecatedUtility diff --git a/src/typing/flow_js.ml b/src/typing/flow_js.ml index 5dd696322f9..0a226c63a8e 100644 --- a/src/typing/flow_js.ml +++ b/src/typing/flow_js.ml @@ -513,12 +513,6 @@ struct None in rec_flow cx trace (reposition ~trace cx loc ?annot_loc:(annot_loc_of_reason r) ?desc t, u) - (*************) - (* Debugging *) - (*************) - | (_, DebugPrintT reason) -> - let str = Debug_js.dump_t ~depth:10 cx l in - add_output cx (Error_message.EDebugPrint (reason, str)) | (DefT (reason, EmptyT), ConvertEmptyPropsToMixedT (_, tout)) -> rec_flow_t cx trace ~use_op:unknown_use (MixedT.make reason, tout) | (_, ConvertEmptyPropsToMixedT (_, tout)) -> @@ -3034,7 +3028,7 @@ struct call_args_iter (fun t -> rec_flow cx trace (t, UseT (use_op, any))) call_args_tlist; rec_flow_t cx ~use_op trace (AnyT.why src reason_op, OpenT call_tout) (* Special handlers for builtin functions *) - | ( CustomFunT (_, (ObjectGetPrototypeOf | DebugPrint)), + | ( CustomFunT (_, ObjectGetPrototypeOf), CallT { use_op; call_action = ConcretizeCallee tout; _ } ) -> rec_flow_t cx trace ~use_op (l, OpenT tout) @@ -3051,30 +3045,6 @@ struct let l = extract_non_spread cx arg in rec_flow cx trace (l, GetProtoT (reason_op, call_tout)) | (_, ReactKitT (use_op, reason_op, tool)) -> ReactJs.run cx trace ~use_op reason_op l tool - (* Facebookisms are special Facebook-specific functions that are not - expressable with our current type syntax, so we've hacked in special - handling. Terminate with extreme prejudice. *) - | ( CustomFunT (_, DebugPrint), - CallT - { - use_op; - reason = reason_op; - call_action = Funcalltype { call_targs = None; call_args_tlist; call_tout; _ }; - return_hint = _; - } - ) -> - List.iter - (fun arg -> - match arg with - | Arg t -> rec_flow cx trace (t, DebugPrintT reason_op) - | SpreadArg t -> - add_output - cx - (Error_message.EUnsupportedSyntax - (loc_of_t t, Flow_intermediate_error_types.SpreadArgument) - )) - call_args_tlist; - rec_flow_t cx ~use_op trace (VoidT.why reason_op, OpenT call_tout) | ( CustomFunT (_, ObjectGetPrototypeOf), MethodT (use_op, reason_call, _, Named { name = OrdinaryName "call"; _ }, action) ) -> @@ -6268,7 +6238,6 @@ struct true (* These types have no t_out, so can't propagate anything. Thus we short-circuit by returning true *) - | DebugPrintT _ | StrictEqT _ | HasOwnPropT _ | ExtractReactRefT _ @@ -6285,7 +6254,6 @@ struct true (* TODO: Punt on these for now, but figure out whether these should fall through or not *) | UseT (_, CustomFunT (_, ObjectGetPrototypeOf)) - | UseT (_, CustomFunT (_, DebugPrint)) | UseT _ -> true @@ -6354,7 +6322,6 @@ struct | TypeAppT _ | UnionT _ | IntersectionT _ - | CustomFunT (_, DebugPrint) | ThisTypeAppT _ | InternalEnforceUnionOptimizedT _ -> false diff --git a/src/typing/implicit_instantiation.ml b/src/typing/implicit_instantiation.ml index 8df5757791e..6eced289863 100644 --- a/src/typing/implicit_instantiation.ml +++ b/src/typing/implicit_instantiation.ml @@ -360,7 +360,6 @@ module Make (Observer : OBSERVER) (Flow : Flow_common.S) : S = struct | EnumCastT _ | EnumExhaustiveCheckT _ | GetEnumT _ - | DebugPrintT _ | PredicateT _ | CondT _ | SentinelPropTestT _ diff --git a/src/typing/ty_normalizer.ml b/src/typing/ty_normalizer.ml index c7be57b555d..8eb2b609f94 100644 --- a/src/typing/ty_normalizer.ml +++ b/src/typing/ty_normalizer.ml @@ -1348,20 +1348,6 @@ module Make (I : INPUT) : S = struct | ObjectGetPrototypeOf -> return Ty.(mk_fun ~params:[(Some "o", explicit_any, non_opt_param)] (ReturnType explicit_any)) - (* debugPrint: (_: any[]) => void *) - | DebugPrint -> - return - Ty.( - mk_fun - ~params: - [ - ( Some "_", - Arr { arr_readonly = false; arr_literal = None; arr_elt_t = explicit_any }, - non_opt_param - ); - ] - (ReturnType Void) - ) ) and subst_name ~env loc t bound name = @@ -1418,7 +1404,6 @@ module Make (I : INPUT) : S = struct Type.( function | ObjectGetPrototypeOf -> return (builtin_t (Reason.OrdinaryName "Object$GetPrototypeOf")) - | DebugPrint -> return (builtin_t (Reason.OrdinaryName "$Flow$DebugPrint")) ) and custom_fun ~env t = diff --git a/src/typing/type.ml b/src/typing/type.ml index 0e37a26b832..62f2a6413e5 100644 --- a/src/typing/type.ml +++ b/src/typing/type.ml @@ -764,7 +764,6 @@ module rec TypeTerm : sig | ReactKitT of use_op * reason * React.tool (* tools for preprocessing types *) | PreprocessKitT of reason * intersection_preprocess_tool - | DebugPrintT of reason | SentinelPropTestT of reason * t * sense * UnionEnum.star * tvar | OptionalChainT of { reason: reason; @@ -1681,11 +1680,8 @@ module rec TypeTerm : sig and t_out = t - and custom_fun_kind = - (* builtins *) + and custom_fun_kind = (* builtins *) | ObjectGetPrototypeOf - (* Internal tools *) - | DebugPrint and concretization_target = | ConcretizeForImportsExports of ident @@ -4055,7 +4051,6 @@ let string_of_use_ctor = function | ConstructorT _ -> "ConstructorT" | CopyNamedExportsT _ -> "CopyNamedExportsT" | CopyTypeExportsT _ -> "CopyTypeExportsT" - | DebugPrintT _ -> "DebugPrintT" | ElemT _ -> "ElemT" | EnumCastT _ -> "EnumCastT" | EnumExhaustiveCheckT _ -> "EnumExhaustiveCheckT" diff --git a/src/typing/typeUtil.ml b/src/typing/typeUtil.ml index 5f0f5866803..cd60c9f1aa5 100644 --- a/src/typing/typeUtil.ml +++ b/src/typing/typeUtil.ml @@ -53,7 +53,6 @@ and reason_of_use_t = function | ConstructorT { reason; _ } -> reason | CopyNamedExportsT (reason, _, _) -> reason | CopyTypeExportsT (reason, _, _) -> reason - | DebugPrintT reason -> reason | ElemT (_, reason, _, _) -> reason | EnumCastT { enum = (reason, _); _ } -> reason | EnumExhaustiveCheckT { reason; _ } -> reason @@ -288,7 +287,6 @@ let rec util_use_op_of_use_t : } | PreprocessKitT (_, _) | ExtractReactRefT _ - | DebugPrintT _ | SentinelPropTestT (_, _, _, _, _) | OptionalChainT _ | CondT (_, _, _, _) diff --git a/src/typing/type_annotation.ml b/src/typing/type_annotation.ml index 4bd559b08ca..d51d020ca5a 100644 --- a/src/typing/type_annotation.ml +++ b/src/typing/type_annotation.ml @@ -1385,7 +1385,6 @@ module Make (ConsGen : Type_annotation_sig.ConsGen) (Statement : Statement_sig.S ) targs ) - | "$Flow$DebugPrint" -> mk_custom_fun cx loc t_ast targs ident DebugPrint | "$Flow$EnforceOptimized" -> check_type_arg_arity cx loc t_ast targs 1 (fun () -> let (ts, targs) = convert_type_params () in diff --git a/src/typing/type_mapper.ml b/src/typing/type_mapper.ml index 5362a9af1d2..19f52dddd32 100644 --- a/src/typing/type_mapper.ml +++ b/src/typing/type_mapper.ml @@ -159,7 +159,7 @@ class virtual ['a] t = else NamespaceT namespace_t' | InternalEnforceUnionOptimizedT _ -> t - | CustomFunT (_r, (ObjectGetPrototypeOf | DebugPrint)) -> t + | CustomFunT (_r, ObjectGetPrototypeOf) -> t | AnyT _ -> t | OptionalT { reason; type_ = t'; use_desc } -> let t'' = self#type_ cx map_cx t' in diff --git a/src/typing/type_sig_merge.ml b/src/typing/type_sig_merge.ml index 9b73f7cea3e..a280881f5c2 100644 --- a/src/typing/type_sig_merge.ml +++ b/src/typing/type_sig_merge.ml @@ -957,9 +957,6 @@ and merge_annot env file = function let t = merge env file t in let id = eval_id_of_aloc file loc in Type.(EvalT (t, TypeDestructorT (use_op, reason, ReactDRO (loc, ImmutableAnnot)), id)) - | FlowDebugPrint loc -> - let reason = Reason.(mk_reason RFunctionType loc) in - Type.CustomFunT (reason, Type.DebugPrint) | Renders (loc, t, renders_variant) -> let t = merge { env with in_renders_arg = true } file t in let reason = diff --git a/src/typing/type_visitor.ml b/src/typing/type_visitor.ml index dc9a8ed4d07..53a9a489f1f 100644 --- a/src/typing/type_visitor.ml +++ b/src/typing/type_visitor.ml @@ -30,7 +30,7 @@ class ['a] t = | ObjProtoT _ | NullProtoT _ -> acc - | CustomFunT (_, (ObjectGetPrototypeOf | DebugPrint)) -> acc + | CustomFunT (_, ObjectGetPrototypeOf) -> acc | EvalT (t, defer_use_t, id) -> let acc = self#type_ cx P.Positive acc t in let acc = self#defer_use_type cx acc defer_use_t in