Skip to content

Commit

Permalink
[flow][refactor][EZ] Inline the last cache_instantiation
Browse files Browse the repository at this point in the history
Summary:
This is the last site where we can potentially cache. Inline it to limit the damage.

Changelog: [internal]

Reviewed By: panagosg7

Differential Revision: D56861814

fbshipit-source-id: 7c0be612477c8a8482fbc7ee7bcaac0c8a25fc99
  • Loading branch information
SamChou19815 authored and facebook-github-bot committed May 2, 2024
1 parent 787994d commit d377d4d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 29 deletions.
2 changes: 0 additions & 2 deletions src/typing/annotation_inference.ml
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,6 @@ module rec ConsGen : S = struct
(* Instantiation *)
(*****************)
module Instantiation_helper = struct
let cache_instantiate _cx _trace ~use_op:_ ?cache:_ _typeparam _reason_op _reason_tapp t = t

(* We will not be solving implicit instantiation problems here. The only case
* where we will need to use this function is when a PolyT needs to be used
* as a monomorphic type. In this case, the only sensible thing to do is to
Expand Down
16 changes: 0 additions & 16 deletions src/typing/flow_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -225,22 +225,6 @@ struct
open SubtypingKit

module InstantiationHelper = struct
(* Given a type parameter, a supplied type argument for specializing it, and a
reason for specialization, either return the type argument or, when directed,
look up the instantiation cache for an existing type argument for the same
purpose and unify it with the supplied type argument. *)
let cache_instantiate cx trace ~use_op ?(cache = false) typeparam reason_op reason_tapp t =
if cache then (
match desc_of_reason reason_tapp with
(* This reason description cannot be trusted for caching purposes. *)
| RTypeAppImplicit _ -> t
| _ ->
let t_ = ImplicitTypeArgument.mk_targ cx typeparam reason_op reason_tapp in
FlowJs.rec_unify cx trace ~use_op ~unify_any:true t t_;
t_
) else
t

let mk_targ = ImplicitTypeArgument.mk_targ

let is_subtype = FlowJs.rec_flow_t
Expand Down
11 changes: 0 additions & 11 deletions src/typing/flow_js_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -996,17 +996,6 @@ let fix_this_instance cx reason (reason_i, i, is_this, this_name) =
Lazy.force i'

module type Instantiation_helper_sig = sig
val cache_instantiate :
Context.t ->
Type.DepthTrace.t ->
use_op:Type.use_op ->
?cache:bool ->
Type.typeparam ->
Reason.t ->
Reason.t ->
Type.t ->
Type.t

val reposition : Context.t -> ?trace:Type.DepthTrace.t -> ALoc.t -> Type.t -> Type.t

val is_subtype : Context.t -> Type.DepthTrace.t -> use_op:use_op -> Type.t * Type.t -> unit
Expand Down
17 changes: 17 additions & 0 deletions src/typing/implicit_instantiation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,23 @@ module Kit (FlowJs : Flow_common.S) (Instantiation_helper : Flow_js_utils.Instan
module SpeculationKit = Speculation_kit.Make (Flow)
open Instantiation_helper

(* Given a type parameter, a supplied type argument for specializing it, and a
reason for specialization, either return the type argument or, when directed,
unify the supplied type argument with a fresh type argument tvar. *)
let cache_instantiate cx trace ~use_op ?(cache = false) typeparam reason_op reason_tapp t =
if cache then (
match desc_of_reason reason_tapp with
(* This reason description cannot be trusted for caching purposes. *)
| RTypeAppImplicit _ -> t
| _ ->
let t_ =
Instantiation_utils.ImplicitTypeArgument.mk_targ cx typeparam reason_op reason_tapp
in
FlowJs.rec_unify cx trace ~use_op ~unify_any:true t t_;
t_
) else
t

let instantiate_poly_with_subst_map
cx ~cache trace poly_t inferred_targ_map ~use_op ~reason_op ~reason_tapp =
let inferred_targ_map =
Expand Down

0 comments on commit d377d4d

Please sign in to comment.