Skip to content

Commit

Permalink
[flow][cleanup] Type.trace -> Type.DepthTrace.t
Browse files Browse the repository at this point in the history
Summary:
This diff moves the logic of the trace management into type.ml, and rename it to be DepthTrace, since we only keep track of depth, to avoid future confusion.

Changelog: [internal]

Reviewed By: panagosg7

Differential Revision: D56735977

fbshipit-source-id: 4609af780131295018d1ccefd4a517a4ca5c0e9f
  • Loading branch information
SamChou19815 authored and facebook-github-bot committed Apr 30, 2024
1 parent 0061955 commit 9800136
Show file tree
Hide file tree
Showing 21 changed files with 173 additions and 147 deletions.
2 changes: 1 addition & 1 deletion src/typing/annotation_inference.ml
Expand Up @@ -211,7 +211,7 @@ module rec ConsGen : S = struct
let reason_op = AConstraint.display_reason_of_op op in
error_internal_reason cx msg reason_op

let dummy_trace = Trace.dummy_trace
let dummy_trace = DepthTrace.dummy_trace

(* Repositioning does not seem to have any perceptible impact in annotation
* inference. Instead of replicating the convoluted implementation of Flow_js
Expand Down
2 changes: 1 addition & 1 deletion src/typing/check_polarity.ml
Expand Up @@ -188,7 +188,7 @@ module Kit (Flow : Flow_common.S) : Flow_common.CHECK_POLARITY = struct
else
let out =
Tvar.mk_no_wrap_where cx r (fun tvar ->
let trace = Base.Option.value trace ~default:Trace.dummy_trace in
let trace = Base.Option.value trace ~default:DepthTrace.dummy_trace in
Flow.eval_destructor cx ~trace use_op r t ReadOnlyType tvar
)
in
Expand Down
2 changes: 1 addition & 1 deletion src/typing/custom_fun_kit.ml
Expand Up @@ -13,7 +13,7 @@ open TypeUtil
module type CUSTOM_FUN = sig
val run :
Context.t ->
Type.trace ->
Type.DepthTrace.t ->
use_op:Type.use_op ->
return_hint:Type.lazy_hint_t ->
Reason.t ->
Expand Down
2 changes: 1 addition & 1 deletion src/typing/custom_fun_kit.mli
Expand Up @@ -8,7 +8,7 @@
module type CUSTOM_FUN = sig
val run :
Context.t ->
Type.trace ->
Type.DepthTrace.t ->
use_op:Type.use_op ->
return_hint:Type.lazy_hint_t ->
Reason.t ->
Expand Down
7 changes: 4 additions & 3 deletions src/typing/debug_js.ml
Expand Up @@ -1997,10 +1997,11 @@ let dump_error_message =

module Verbose = struct
let print_if_verbose_lazy
cx ?(trace = Trace.dummy_trace) ?(delim = "") ?(indent = 0) (lines : string list Lazy.t) =
cx ?(trace = DepthTrace.dummy_trace) ?(delim = "") ?(indent = 0) (lines : string list Lazy.t)
=
match Context.verbose cx with
| Some { Verbose.indent = num_spaces; _ } when Context.is_verbose cx ->
let indent = max (indent + Trace.trace_depth trace - 1) 0 in
let indent = max (indent + DepthTrace.depth trace - 1) 0 in
let prefix = String.make (indent * num_spaces) ' ' in
let pid = Context.pid_prefix cx in
let add_prefix line = spf "\n%s%s%s" prefix pid line in
Expand All @@ -2009,7 +2010,7 @@ module Verbose = struct
| _ -> ()

let print_if_verbose
cx ?(trace = Trace.dummy_trace) ?(delim = "") ?(indent = 0) (lines : string list) =
cx ?(trace = DepthTrace.dummy_trace) ?(delim = "") ?(indent = 0) (lines : string list) =
if Context.is_verbose cx then print_if_verbose_lazy cx ~trace ~delim ~indent (lazy lines)

let print_types_if_verbose cx trace ?(note : string option) ((l : Type.t), (u : Type.use_t)) =
Expand Down
13 changes: 9 additions & 4 deletions src/typing/debug_js.mli
Expand Up @@ -35,14 +35,19 @@ val dump_flow : ?depth:int -> Context.t -> Type.t * Type.use_t -> string

module Verbose : sig
val print_if_verbose_lazy :
Context.t -> ?trace:Type.trace -> ?delim:string -> ?indent:int -> string list Lazy.t -> unit
Context.t ->
?trace:Type.DepthTrace.t ->
?delim:string ->
?indent:int ->
string list Lazy.t ->
unit

val print_if_verbose :
Context.t -> ?trace:Type.trace -> ?delim:string -> ?indent:int -> string list -> unit
Context.t -> ?trace:Type.DepthTrace.t -> ?delim:string -> ?indent:int -> string list -> unit

val print_types_if_verbose :
Context.t -> Type.trace -> ?note:string -> Type.t * Type.use_t -> unit
Context.t -> Type.DepthTrace.t -> ?note:string -> Type.t * Type.use_t -> unit

val print_unify_types_if_verbose :
Context.t -> Type.trace -> ?note:string -> Type.t * Type.t -> unit
Context.t -> Type.DepthTrace.t -> ?note:string -> Type.t * Type.t -> unit
end
64 changes: 38 additions & 26 deletions src/typing/flow_common.ml
Expand Up @@ -11,7 +11,7 @@ open Type
module type BASE = sig
val flow : Context.t -> Type.t * Type.use_t -> unit

val flow_opt : Context.t -> ?trace:Type.trace -> Type.t * Type.use_t -> unit
val flow_opt : Context.t -> ?trace:Type.DepthTrace.t -> Type.t * Type.use_t -> unit

val flow_p :
Context.t ->
Expand All @@ -26,36 +26,42 @@ module type BASE = sig

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

val rec_flow : Context.t -> Type.trace -> Type.t * Type.use_t -> unit
val rec_flow : Context.t -> Type.DepthTrace.t -> Type.t * Type.use_t -> unit

val rec_flow_t : Context.t -> Type.trace -> use_op:Type.use_op -> Type.t * Type.t -> unit
val rec_flow_t : Context.t -> Type.DepthTrace.t -> use_op:Type.use_op -> Type.t * Type.t -> unit

val rec_unify :
Context.t -> Type.trace -> use_op:Type.use_op -> ?unify_any:bool -> Type.t -> Type.t -> unit
Context.t ->
Type.DepthTrace.t ->
use_op:Type.use_op ->
?unify_any:bool ->
Type.t ->
Type.t ->
unit

val unify : Context.t -> ?use_op:Type.use_op -> Type.t -> Type.t -> unit

val unify_opt :
Context.t ->
?trace:Type.trace ->
?trace:Type.DepthTrace.t ->
use_op:Type.use_op ->
?unify_any:bool ->
Type.t ->
Type.t ->
unit

val filter_optional : Context.t -> ?trace:Type.trace -> reason -> Type.t -> Type.ident
val filter_optional : Context.t -> ?trace:Type.DepthTrace.t -> reason -> Type.t -> Type.ident

val mk_typeapp_instance_annot :
Context.t ->
?trace:Type.trace ->
?trace:Type.DepthTrace.t ->
use_op:Type.use_op ->
reason_op:Reason.reason ->
reason_tapp:Reason.reason ->
Expand All @@ -67,7 +73,7 @@ module type BASE = sig

val mk_typeapp_instance :
Context.t ->
?trace:Type.trace ->
?trace:Type.DepthTrace.t ->
use_op:Type.use_op ->
reason_op:Reason.reason ->
reason_tapp:Reason.reason ->
Expand All @@ -78,7 +84,7 @@ module type BASE = sig

val resolve_id :
Context.t ->
Type.trace ->
Type.DepthTrace.t ->
use_op:Type.use_op ->
?fully_resolved:bool ->
Type.ident ->
Expand All @@ -91,7 +97,7 @@ end
module type CHECK_POLARITY = sig
val check_polarity :
Context.t ->
?trace:Type.trace ->
?trace:Type.DepthTrace.t ->
Type.typeparam Subst_name.Map.t ->
Polarity.t ->
Type.t ->
Expand All @@ -100,13 +106,13 @@ end

module type BUILTINS = sig
val get_builtin_type :
Context.t -> ?trace:Type.trace -> Reason.reason -> ?use_desc:bool -> string -> Type.t
Context.t -> ?trace:Type.DepthTrace.t -> Reason.reason -> ?use_desc:bool -> string -> Type.t

val get_builtin_typeapp : Context.t -> reason -> ?use_desc:bool -> string -> Type.t list -> Type.t

val perform_read_prop_action :
Context.t ->
Type.trace ->
Type.DepthTrace.t ->
ALoc.t Type.virtual_use_op ->
Type.propref ->
Type.property_type ->
Expand All @@ -125,11 +131,11 @@ module type SUBTYPING = sig
Context.t -> Reason.reason -> Type.t -> Type.t list

val reposition_reason :
Context.t -> ?trace:Type.trace -> Reason.reason -> ?use_desc:bool -> Type.t -> Type.t
Context.t -> ?trace:Type.DepthTrace.t -> Reason.reason -> ?use_desc:bool -> Type.t -> Type.t

val eval_destructor :
Context.t ->
trace:Type.trace ->
trace:Type.DepthTrace.t ->
Type.use_op ->
Reason.reason ->
Type.t ->
Expand All @@ -139,7 +145,7 @@ module type SUBTYPING = sig

val multiflow_subtype :
Context.t ->
Type.trace ->
Type.DepthTrace.t ->
use_op:ALoc.t Type.virtual_use_op ->
Reason.reason ->
Type.call_arg list ->
Expand All @@ -148,7 +154,7 @@ module type SUBTYPING = sig

val flow_type_args :
Context.t ->
Type.trace ->
Type.DepthTrace.t ->
use_op:use_op ->
reason ->
reason ->
Expand All @@ -158,7 +164,7 @@ module type SUBTYPING = sig

val instantiate_this_class :
Context.t ->
Type.trace ->
Type.DepthTrace.t ->
reason_op:Reason.reason ->
reason_tapp:Reason.reason ->
Type.t ->
Expand All @@ -169,7 +175,7 @@ module type SUBTYPING = sig

val instantiate_poly_with_targs :
Context.t ->
Type.trace ->
Type.DepthTrace.t ->
use_op:Type.use_op ->
reason_op:Reason.reason ->
reason_tapp:Reason.t ->
Expand All @@ -182,7 +188,7 @@ module type SUBTYPING = sig

val instantiate_poly :
Context.t ->
Type.trace ->
Type.DepthTrace.t ->
use_op:Type.use_op ->
reason_op:Reason.reason ->
reason_tapp:Reason.reason ->
Expand All @@ -193,7 +199,7 @@ module type SUBTYPING = sig

val mk_typeapp_of_poly :
Context.t ->
Type.trace ->
Type.DepthTrace.t ->
use_op:Type.use_op ->
reason_op:Reason.reason ->
reason_tapp:Reason.reason ->
Expand All @@ -208,7 +214,7 @@ module type SUBTYPING = sig
val mk_instance :
Context.t ->
?type_t_kind:Type.type_t_kind ->
?trace:Type.trace ->
?trace:Type.DepthTrace.t ->
reason ->
?use_desc:bool ->
Type.t ->
Expand All @@ -218,7 +224,7 @@ end
module type EVAL = sig
val eval_selector :
Context.t ->
?trace:Type.trace ->
?trace:Type.DepthTrace.t ->
annot:bool ->
reason ->
Type.t ->
Expand All @@ -229,7 +235,7 @@ module type EVAL = sig

val mk_type_destructor :
Context.t ->
trace:Type.trace ->
trace:Type.DepthTrace.t ->
use_op ->
reason ->
Type.t ->
Expand All @@ -243,11 +249,17 @@ end

module type REACT = sig
val react_subtype_class_component_render :
Context.t -> Type.trace -> use_op:Type.use_op -> Type.t -> reason_op:reason -> Type.t -> unit
Context.t ->
Type.DepthTrace.t ->
use_op:Type.use_op ->
Type.t ->
reason_op:reason ->
Type.t ->
unit

val react_get_config :
Context.t ->
Type.trace ->
Type.DepthTrace.t ->
Type.t ->
use_op:ALoc.t Type.virtual_use_op ->
reason_op:Reason.reason ->
Expand Down

0 comments on commit 9800136

Please sign in to comment.