Skip to content

Commit

Permalink
[flow][cleanup][EZ] Inline cache_instantiate in non-caching cases
Browse files Browse the repository at this point in the history
Summary:
In this code path, we are running the non-caching version of cache_instantiate, which, according to the [implementation](https://github.com/facebook/flow/blob/fcb60a07fdf2242fa88e32d7e21ca1932ea16b13/src/typing/flow_js.ml#L227-L242), is just an identitiy function. Let's just inline it.

Changelog: [internal]

Reviewed By: panagosg7

Differential Revision: D56853727

fbshipit-source-id: e52c8a26daf4c1450c154d7fe913a8e7e0a7188a
  • Loading branch information
SamChou19815 authored and facebook-github-bot committed May 2, 2024
1 parent 49cb907 commit 787994d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 28 deletions.
2 changes: 0 additions & 2 deletions src/typing/flow_common.ml
Expand Up @@ -179,7 +179,6 @@ module type SUBTYPING = sig
use_op:Type.use_op ->
reason_op:Reason.reason ->
reason_tapp:Reason.t ->
?cache:bool ->
?errs_ref:Context.subst_cache_err list ref ->
?unify_bounds:bool ->
ALoc.t * Type.typeparam Nel.t * Type.t ->
Expand All @@ -192,7 +191,6 @@ module type SUBTYPING = sig
use_op:Type.use_op ->
reason_op:Reason.reason ->
reason_tapp:Reason.reason ->
?cache:bool ->
?unify_bounds:bool ->
ALoc.t * Type.typeparam Nel.t * Type.t ->
Type.t * (Type.t * Subst_name.t) list
Expand Down
1 change: 0 additions & 1 deletion src/typing/flow_js.ml
Expand Up @@ -7997,7 +7997,6 @@ struct
~use_op
~reason_op
~reason_tapp
~cache:false
(tparams_loc, xs, t)
(List.rev ts)
in
Expand Down
30 changes: 5 additions & 25 deletions src/typing/flow_js_utils.ml
Expand Up @@ -1017,16 +1017,13 @@ module type Instantiation_helper_sig = sig
end

module Instantiation_kit (H : Instantiation_helper_sig) = struct
let cache_instantiate = H.cache_instantiate

(* Instantiate a polymorphic definition given type arguments. *)
let instantiate_poly_with_targs
cx
trace
~use_op
~reason_op
~reason_tapp
?cache:_
?errs_ref
?(unify_bounds = false)
(tparams_loc, xs, t)
Expand Down Expand Up @@ -1057,14 +1054,13 @@ module Instantiation_kit (H : Instantiation_helper_sig) = struct
(AnyT (reason_op, AnyError None), [], all_ts)
| (_, t :: ts) -> (t, ts, (t, typeparam.name) :: all_ts)
in
let t_ = cache_instantiate cx trace ~use_op typeparam reason_op reason_tapp t in
let frame = Frame (TypeParamBound { name = typeparam.name }, use_op) in
if not (Context.in_implicit_instantiation cx) then
if unify_bounds then
H.unify cx trace ~use_op:frame (t_, subst cx ~use_op map typeparam.bound)
H.unify cx trace ~use_op:frame (t, subst cx ~use_op map typeparam.bound)
else
H.is_subtype cx trace ~use_op:frame (t_, subst cx ~use_op map typeparam.bound);
(Subst_name.Map.add typeparam.name t_ map, ts, all_ts))
H.is_subtype cx trace ~use_op:frame (t, subst cx ~use_op map typeparam.bound);
(Subst_name.Map.add typeparam.name t map, ts, all_ts))
(Subst_name.Map.empty, ts, [])
xs
in
Expand All @@ -1079,15 +1075,7 @@ module Instantiation_kit (H : Instantiation_helper_sig) = struct
let mk_typeapp_of_poly
cx trace ~use_op ~reason_op ~reason_tapp ?(cache = false) id tparams_loc xs t ts =
if cache then
instantiate_poly_with_targs
cx
trace
~use_op
~reason_op
~reason_tapp
~cache
(tparams_loc, xs, t)
ts
instantiate_poly_with_targs cx trace ~use_op ~reason_op ~reason_tapp (tparams_loc, xs, t) ts
|> fst
else
let key = (id, ts) in
Expand Down Expand Up @@ -1127,22 +1115,14 @@ module Instantiation_kit (H : Instantiation_helper_sig) = struct

(* Instantiate a polymorphic definition by creating fresh type arguments. *)
let instantiate_poly
cx
trace
~use_op
~reason_op
~reason_tapp
?(cache = false)
?(unify_bounds = false)
(tparams_loc, xs, t) =
cx trace ~use_op ~reason_op ~reason_tapp ?(unify_bounds = false) (tparams_loc, xs, t) =
let ts = xs |> Nel.map (fun typeparam -> H.mk_targ cx typeparam reason_op reason_tapp) in
instantiate_poly_with_targs
cx
trace
~use_op
~reason_op
~reason_tapp
~cache
~unify_bounds
(tparams_loc, xs, t)
(Nel.to_list ts)
Expand Down

0 comments on commit 787994d

Please sign in to comment.