Skip to content

Commit

Permalink
[flow] Kill $Flow$DebugPrint
Browse files Browse the repository at this point in the history
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
  • Loading branch information
SamChou19815 authored and facebook-github-bot committed Jul 26, 2024
1 parent d9bc25b commit 9714fc4
Show file tree
Hide file tree
Showing 14 changed files with 16 additions and 80 deletions.
1 change: 0 additions & 1 deletion src/parser_utils/type_sig/type_sig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 0 additions & 5 deletions src/parser_utils/type_sig/type_sig_parse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/typing/debug_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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) ->
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/typing/default_resolve.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 10 additions & 6 deletions src/typing/errors/error_message.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 (_, _)
Expand Down Expand Up @@ -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; _ }
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
35 changes: 1 addition & 34 deletions src/typing/flow_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)) ->
Expand Down Expand Up @@ -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)
Expand All @@ -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)
) ->
Expand Down Expand Up @@ -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 _
Expand All @@ -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

Expand Down Expand Up @@ -6354,7 +6322,6 @@ struct
| TypeAppT _
| UnionT _
| IntersectionT _
| CustomFunT (_, DebugPrint)
| ThisTypeAppT _
| InternalEnforceUnionOptimizedT _ ->
false
Expand Down
1 change: 0 additions & 1 deletion src/typing/implicit_instantiation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ module Make (Observer : OBSERVER) (Flow : Flow_common.S) : S = struct
| EnumCastT _
| EnumExhaustiveCheckT _
| GetEnumT _
| DebugPrintT _
| PredicateT _
| CondT _
| SentinelPropTestT _
Expand Down
15 changes: 0 additions & 15 deletions src/typing/ty_normalizer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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 =
Expand Down
7 changes: 1 addition & 6 deletions src/typing/type.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -4055,7 +4051,6 @@ let string_of_use_ctor = function
| ConstructorT _ -> "ConstructorT"
| CopyNamedExportsT _ -> "CopyNamedExportsT"
| CopyTypeExportsT _ -> "CopyTypeExportsT"
| DebugPrintT _ -> "DebugPrintT"
| ElemT _ -> "ElemT"
| EnumCastT _ -> "EnumCastT"
| EnumExhaustiveCheckT _ -> "EnumExhaustiveCheckT"
Expand Down
2 changes: 0 additions & 2 deletions src/typing/typeUtil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -288,7 +287,6 @@ let rec util_use_op_of_use_t :
}
| PreprocessKitT (_, _)
| ExtractReactRefT _
| DebugPrintT _
| SentinelPropTestT (_, _, _, _, _)
| OptionalChainT _
| CondT (_, _, _, _)
Expand Down
1 change: 0 additions & 1 deletion src/typing/type_annotation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/typing/type_mapper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions src/typing/type_sig_merge.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
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 @@ -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
Expand Down

0 comments on commit 9714fc4

Please sign in to comment.