Skip to content

Commit b30da05

Browse files
SamChou19815meta-codesync[bot]
authored andcommitted
[flow] Remove attached error in SpeculationSingletonError
Summary: Mostly a revert of D80179072, since it's unused. Changelog: [internal] Reviewed By: panagosg7 Differential Revision: D84386554 fbshipit-source-id: 383e63ad568e70b91a3accc19545b31d9b78f217
1 parent 0a8732d commit b30da05

7 files changed

Lines changed: 24 additions & 36 deletions

File tree

src/typing/flow_js.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ struct
175175
l
176176
(UseT (unknown_use, u))
177177
with
178-
| exception Flow_js_utils.SpeculationSingletonError _ -> false
178+
| exception Flow_js_utils.SpeculationSingletonError -> false
179179
| _ -> true
180180

181181
(* get prop *)
@@ -6789,7 +6789,7 @@ struct
67896789
evaluate_type_destructor cx ~trace use_op reason t d tvar
67906790
)
67916791
with
6792-
| Flow_js_utils.SpeculationSingletonError _ ->
6792+
| Flow_js_utils.SpeculationSingletonError ->
67936793
let opaque_type_args =
67946794
Base.List.mapi stuck_eval_targs ~f:(fun i t ->
67956795
( Subst_name.Synthetic { name = string_of_int i; op_kind = None; ts = [] },
@@ -7760,7 +7760,7 @@ struct
77607760
&& not (TvarVisitors.has_unresolved_tvars cx t2)
77617761
then
77627762
try SpeculationKit.try_unify cx trace t1 use_op t2 with
7763-
| Flow_js_utils.SpeculationSingletonError _ ->
7763+
| Flow_js_utils.SpeculationSingletonError ->
77647764
let explanation =
77657765
let open Flow_intermediate_error_types in
77667766
match unify_cause with

src/typing/flow_js_utils.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ let use_op_of_lookup_action = function
484484

485485
exception SpeculativeError of Error_message.t
486486

487-
exception SpeculationSingletonError of Error_message.t
487+
exception SpeculationSingletonError
488488

489489
(* [src_cx] is the context in which the error is created, and [dst_cx] the context
490490
* in which it is recorded. *)

src/typing/implicit_instantiation.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ module Make (Observer : OBSERVER) (Flow : Flow_common.S) : S = struct
160160

161161
let speculative_subtyping_succeeds cx trace use_op l u =
162162
match SpeculationKit.try_singleton_throw_on_failure cx trace l (UseT (use_op, u)) with
163-
| exception Flow_js_utils.SpeculationSingletonError _ -> false
163+
| exception Flow_js_utils.SpeculationSingletonError -> false
164164
| _ -> true
165165

166166
(* This visitor records the polarities at which BoundTs are found. We follow the bounds of each
@@ -1775,7 +1775,7 @@ module Kit (FlowJs : Flow_common.S) (Instantiation_helper : Flow_js_utils.Instan
17751775
any_substituted_check_t
17761776
(UseT (use_op, any_substituted_extends_t))
17771777
with
1778-
| exception Flow_js_utils.SpeculationSingletonError _ ->
1778+
| exception Flow_js_utils.SpeculationSingletonError ->
17791779
(* When all the GenericT and infer types are replaced with any, and subtyping
17801780
check still cannot succeed, then we can safely conclude that, in every possible
17811781
instantiation, we will always take the false branch *)

src/typing/speculation_flow.ml

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@ let try_custom = SpeculationKit.try_custom
1313
let flow_t_unsafe cx (l, u) =
1414
SpeculationKit.try_singleton_throw_on_failure cx DepthTrace.dummy_trace l (UseT (unknown_use, u))
1515

16-
let speculation_error_opt cx t u =
16+
let is_flow_successful cx t u =
1717
match SpeculationKit.try_singleton_throw_on_failure cx DepthTrace.dummy_trace t u with
18-
| exception Flow_js_utils.SpeculationSingletonError e -> Some e
19-
| () -> None
20-
21-
let is_flow_successful cx t u = Base.Option.is_none (speculation_error_opt cx t u)
18+
| exception Flow_js_utils.SpeculationSingletonError -> false
19+
| () -> true
2220

2321
let is_subtyping_successful cx l u = is_flow_successful cx l (UseT (unknown_use, u))
2422

@@ -27,18 +25,13 @@ let resolved_lower_flow_unsafe cx r (l, u) =
2725
| [] -> ()
2826
| [l] -> Flow_js.flow cx (l, u)
2927
| l0 :: ls ->
30-
let error_opt =
31-
Base.List.fold ls ~init:(speculation_error_opt cx l0 u) ~f:(fun acc l ->
32-
let r = speculation_error_opt cx l u in
33-
match (acc, r) with
34-
| (None, _) -> None
35-
| (_, None) -> None
36-
| (Some e, Some _) -> Some e
28+
let successful =
29+
Base.List.fold ls ~init:(is_flow_successful cx l0 u) ~f:(fun acc l ->
30+
let r = is_flow_successful cx l u in
31+
acc || r
3732
)
3833
in
39-
(match error_opt with
40-
| None -> ()
41-
| Some e -> raise (Flow_js_utils.SpeculationSingletonError e))
34+
if not successful then raise Flow_js_utils.SpeculationSingletonError
4235

4336
let resolved_lower_flow_t_unsafe cx r (l, u) =
4437
resolved_lower_flow_unsafe cx r (l, UseT (unknown_use, u))
@@ -48,20 +41,15 @@ let resolved_upper_flow_t_unsafe cx r (l, u) =
4841
| [] -> ()
4942
| [u] -> Flow_js.flow_t cx (l, u)
5043
| u0 :: us ->
51-
let error_opt =
44+
let successful =
5245
Base.List.fold
5346
us
54-
~init:(speculation_error_opt cx l (UseT (unknown_use, u0)))
47+
~init:(is_flow_successful cx l (UseT (unknown_use, u0)))
5548
~f:(fun acc u ->
56-
let r = speculation_error_opt cx l (UseT (unknown_use, u)) in
57-
match (acc, r) with
58-
| (None, _) -> None
59-
| (_, None) -> None
60-
| (Some e, Some _) -> Some e)
49+
let r = is_flow_successful cx l (UseT (unknown_use, u)) in
50+
acc || r)
6151
in
62-
(match error_opt with
63-
| None -> ()
64-
| Some e -> raise (Flow_js_utils.SpeculationSingletonError e))
52+
if not successful then raise Flow_js_utils.SpeculationSingletonError
6553

6654
let get_method_type_unsafe cx t reason propref =
6755
Tvar.mk_where cx reason (fun prop_t ->
@@ -76,5 +64,5 @@ let get_method_type_opt cx t reason propref =
7664
resolved_lower_flow_unsafe cx reason (t, use_t)
7765
)
7866
with
79-
| exception Flow_js_utils.SpeculationSingletonError _ -> None
67+
| exception Flow_js_utils.SpeculationSingletonError -> None
8068
| t -> Some t

src/typing/speculation_kit.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ module Make (Flow : INPUT) : OUTPUT = struct
348348
| SingletonCustomCase _
349349
| SingletonUnifyCase _ ->
350350
(match msgs with
351-
| [msg] -> raise (SpeculationSingletonError msg)
351+
| [_msg] -> raise SpeculationSingletonError
352352
| _ ->
353353
failwith
354354
("SingletonCase should not have exactly one error, but we got "

src/typing/subtyping_kit.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ module Make (Flow : INPUT) : OUTPUT = struct
309309
SpeculationKit.try_unify cx trace lt use_op ut;
310310
false
311311
with
312-
| Flow_js_utils.SpeculationSingletonError _ -> true
312+
| Flow_js_utils.SpeculationSingletonError -> true
313313
then
314314
(name, lt, ut) :: invariant_subtyping_failed_prop_names
315315
else
@@ -1081,7 +1081,7 @@ module Make (Flow : INPUT) : OUTPUT = struct
10811081
flow_type_args cx trace ~use_op lreason ureason ltargs utargs
10821082
)
10831083
with
1084-
| SpeculationSingletonError _ ->
1084+
| SpeculationSingletonError ->
10851085
add_output
10861086
cx
10871087
(Error_message.EIncompatibleWithUseOp

src/typing/type_hint.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ let in_sandbox_cx cx t ~f =
4343
in
4444
Context.reset_errors cx Flow_error.ErrorSet.empty;
4545
match f (Tvar_resolver.resolved_t cx ~no_lowers ~filter_empty:false t) with
46-
| (exception Flow_js_utils.SpeculationSingletonError _)
46+
| (exception Flow_js_utils.SpeculationSingletonError)
4747
| (exception UnconstrainedTvarException)
4848
| (exception DecompFuncParamOutOfBoundsException) ->
4949
Context.reset_errors cx original_errors;

0 commit comments

Comments
 (0)