Skip to content

Commit

Permalink
[flow][refactor] Replace GuardT with `possible_concrete_types_for_o…
Browse files Browse the repository at this point in the history
…perators_checking`

Summary:
`possible_concrete_types_for_operators_checking` concretizes in the same way as `GuardT` does, so let's just use `possible_concrete_types_for_operators_checking` instead.

Changelog: [internal]

Reviewed By: mvitousek

Differential Revision:
D60212610

------------------------------------------------------------------------
(from c34a3a471436f3737fb597cf40e21d86fbe47f0f)

fbshipit-source-id: 9009d435f0dbaac2aab04b43c8090de1682b64a1
  • Loading branch information
SamChou19815 authored and facebook-github-bot committed Jul 25, 2024
1 parent 0723c56 commit d9bc25b
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 55 deletions.
5 changes: 0 additions & 5 deletions src/typing/debug_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -800,11 +800,6 @@ and dump_use_t_ (depth, tvars) cx t =
(tvar ptvar)
)
t
| GuardT (pred, result, sink) ->
p
~reason:false
~extra:(spf "%s, %s, %s" (string_of_predicate pred) (kid result) (tout sink))
t
| HasOwnPropT _ -> p t
| PreprocessKitT _ -> p t
| LookupT { lookup_kind = kind; propref = prop; lookup_action = action; ids; _ } ->
Expand Down
4 changes: 1 addition & 3 deletions src/typing/default_resolve.ml
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ let rec default_resolve_touts ~flow ?resolve_callee cx loc u =
| ImplementsT _ -> ()
| MixinT (_, t) -> resolve t
| ToStringT { t_out; _ } -> default_resolve_touts ~flow cx loc t_out
| PredicateT (_, tvar)
| GuardT (_, _, tvar) ->
resolve_tvar tvar
| PredicateT (_, tvar) -> resolve_tvar tvar
| StrictEqT _ -> ()
| SpecializeT (_, _, _, _, tout) -> resolve tout
| ThisSpecializeT (_, _, k) -> resolve_cont k
Expand Down
36 changes: 0 additions & 36 deletions src/typing/flow_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1947,8 +1947,6 @@ struct
an intersection lower bound *)
| (IntersectionT _, PredicateT (_, tout)) ->
rec_flow_t cx trace ~use_op:unknown_use (l, OpenT tout)
(* same for guards *)
| (IntersectionT _, GuardT (pred, result, tout)) -> guard cx trace l pred result tout
(* ObjAssignFromT copies multiple properties from its incoming LB.
Here we simulate a merged object type by iterating over the
entire intersection. *)
Expand Down Expand Up @@ -4537,7 +4535,6 @@ struct
(* Don't refine opaque types based on its bound *)
| (OpaqueT _, PredicateT (_, tvar)) ->
rec_flow_t cx trace ~use_op:unknown_use (l, OpenT tvar)
| (OpaqueT _, GuardT (pred, result, sink)) -> guard cx trace l pred result sink
| (OpaqueT _, SealGenericT { reason = _; id; name; cont; no_infer }) ->
let reason = reason_of_t l in
continue cx trace (GenericT { reason; id; name; bound = l; no_infer }) cont
Expand Down Expand Up @@ -4572,7 +4569,6 @@ struct
(* types may be refined by predicates *)
(**************************************)
| (_, PredicateT (_, tvar)) -> rec_flow_t cx trace ~use_op:unknown_use (l, OpenT tvar)
| (_, GuardT (pred, result, sink)) -> guard cx trace l pred result sink
| (_, SentinelPropTestT (reason, obj, sense, enum, result)) ->
let t = Type_filter.sentinel_refinement l reason obj sense enum in
rec_flow_t cx trace ~use_op:unknown_use (t, OpenT result)
Expand Down Expand Up @@ -6199,7 +6195,6 @@ struct
| GetStaticsT _
| GetValuesT _
| GetDictValuesT _
| GuardT _
| FilterOptionalT _
| FilterMaybeT _
| DeepReadOnlyT _
Expand Down Expand Up @@ -7667,37 +7662,6 @@ struct
flow_opt cx ?trace (opt_t, FilterOptionalT (unknown_use, OpenT (reason, tvar)));
tvar

(**********)
(* guards *)
(**********)
and guard cx trace source pred result sink =
match pred with
| ExistsP -> begin
match Type_filter.exists cx source with
| DefT (_, EmptyT) -> ()
| _ -> rec_flow_t cx trace ~use_op:unknown_use (result, OpenT sink)
end
| NotP ExistsP -> begin
match Type_filter.not_exists cx source with
| DefT (_, EmptyT) -> ()
| _ -> rec_flow_t cx trace ~use_op:unknown_use (result, OpenT sink)
end
| MaybeP -> begin
match Type_filter.maybe cx source with
| DefT (_, EmptyT) -> ()
| _ -> rec_flow_t cx trace ~use_op:unknown_use (result, OpenT sink)
end
| NotP MaybeP -> begin
match Type_filter.not_maybe cx source with
| DefT (_, EmptyT) -> ()
| _ -> rec_flow_t cx trace ~use_op:unknown_use (result, OpenT sink)
end
| NotP (NotP p) -> guard cx trace source p result sink
| _ ->
let loc = loc_of_reason (fst sink) in
let pred_str = string_of_predicate pred in
add_output cx Error_message.(EInternal (loc, UnsupportedGuardPredicate pred_str))

and pick_use_op cx op1 op2 =
let ignore_root = function
| UnknownUse -> true
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 @@ -362,7 +362,6 @@ module Make (Observer : OBSERVER) (Flow : Flow_common.S) : S = struct
| GetEnumT _
| DebugPrintT _
| PredicateT _
| GuardT _
| CondT _
| SentinelPropTestT _
| CheckUnusedPromiseT _
Expand Down
37 changes: 35 additions & 2 deletions src/typing/predicate_kit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@ and prop_exists_test_generic key reason cx trace result orig_obj sense (pred, no
else
not_pred
in
rec_flow cx trace (t, GuardT (pred, orig_obj, result))
possible_concrete_types_for_operators_checking cx (TypeUtil.reason_of_t t) t
|> List.iter (fun t -> guard cx trace t pred orig_obj result)
| None ->
(* prop cannot be read *)
rec_flow_t cx trace ~use_op:unknown_use (orig_obj, OpenT result);
Expand Down Expand Up @@ -456,7 +457,8 @@ and prop_exists_test_generic key reason cx trace result orig_obj sense (pred, no
else
not_pred
in
rec_flow cx trace (t, GuardT (pred, orig_obj, result))
possible_concrete_types_for_operators_checking cx (TypeUtil.reason_of_t t) t
|> List.iter (fun t -> guard cx trace t pred orig_obj result)
else (
rec_flow_t cx trace ~use_op:unknown_use (orig_obj, OpenT result);
add_output
Expand Down Expand Up @@ -785,6 +787,37 @@ and sentinel_prop_test_generic key cx trace result orig_obj =
(* not enough info to refine *)
rec_flow_t cx trace ~use_op:unknown_use (orig_obj, OpenT result)

(**********)
(* guards *)
(**********)
and guard cx trace source pred result sink =
match pred with
| ExistsP -> begin
match Type_filter.exists cx source with
| DefT (_, EmptyT) -> ()
| _ -> rec_flow_t cx trace ~use_op:unknown_use (result, OpenT sink)
end
| NotP ExistsP -> begin
match Type_filter.not_exists cx source with
| DefT (_, EmptyT) -> ()
| _ -> rec_flow_t cx trace ~use_op:unknown_use (result, OpenT sink)
end
| MaybeP -> begin
match Type_filter.maybe cx source with
| DefT (_, EmptyT) -> ()
| _ -> rec_flow_t cx trace ~use_op:unknown_use (result, OpenT sink)
end
| NotP MaybeP -> begin
match Type_filter.not_maybe cx source with
| DefT (_, EmptyT) -> ()
| _ -> rec_flow_t cx trace ~use_op:unknown_use (result, OpenT sink)
end
| NotP (NotP p) -> guard cx trace source p result sink
| _ ->
let loc = loc_of_reason (fst sink) in
let pred_str = string_of_predicate pred in
add_output cx Error_message.(EInternal (loc, UnsupportedGuardPredicate pred_str))

let predicate cx t p =
concretize_and_run_predicate
cx
Expand Down
6 changes: 0 additions & 6 deletions src/typing/type.ml
Original file line number Diff line number Diff line change
Expand Up @@ -656,11 +656,6 @@ module rec TypeTerm : sig
}
(* operation specifying a type refinement via a predicate *)
| PredicateT of predicate_concretizer_variant * tvar
(* like PredicateT, GuardT guards a subsequent flow with a predicate on an
incoming type. Unlike PredicateT, the subsequent flow (if any) uses
an arbitrary LB specified in the GuardT value, rather than the filtered
result of the predicate itself *)
| GuardT of predicate * t * tvar
(* === *)
| StrictEqT of {
reason: Reason.t;
Expand Down Expand Up @@ -4078,7 +4073,6 @@ let string_of_use_ctor = function
| GetPrivatePropT _ -> "GetPrivatePropT"
| GetProtoT _ -> "GetProtoT"
| GetStaticsT _ -> "GetStaticsT"
| GuardT _ -> "GuardT"
| HasOwnPropT _ -> "HasOwnPropT"
| ImplementsT _ -> "ImplementsT"
| PreprocessKitT (_, tool) ->
Expand Down
2 changes: 0 additions & 2 deletions src/typing/typeUtil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ and reason_of_use_t = function
| GetPrivatePropT (_, reason, _, _, _, _) -> reason
| GetProtoT (reason, _) -> reason
| GetStaticsT (reason, _) -> reason
| GuardT (_, _, (r, _)) -> r
| HasOwnPropT (_, reason, _) -> reason
| ImplementsT (_, t) -> reason_of_t t
| PreprocessKitT (reason, _) -> reason
Expand Down Expand Up @@ -266,7 +265,6 @@ let rec util_use_op_of_use_t :
| DeepReadOnlyT _
| HooklikeT _
| PredicateT (_, _)
| GuardT (_, _, _)
| StrictEqT _
| ThisSpecializeT (_, _, _)
| LookupT _
Expand Down

0 comments on commit d9bc25b

Please sign in to comment.