Skip to content

Commit

Permalink
[flow] print Forced FullyResolved tvars in Debug_js
Browse files Browse the repository at this point in the history
Summary:
With this change Debug_js will attempt to print FullyResolved tvars that have already been forced.

Changelog: [internal]

Reviewed By: SamChou19815

Differential Revision: D55496056

fbshipit-source-id: 080d7819dc700bdee5d777770d22428c719f6e29
  • Loading branch information
panagosg7 authored and facebook-github-bot committed Mar 28, 2024
1 parent 009b910 commit 9ed8857
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/typing/debug_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,13 @@ and dump_tvar_ (depth, tvars) cx id =
| Goto goto -> spf "%d, Goto %d" id goto.parent
| Root { constraints = Resolved t; _ } ->
spf "%d, Resolved %s" id (dump_t_ (depth - 1, stack) cx t)
| Root { constraints = FullyResolved _; _ } -> spf "%d, FullyResolved" id
| Root { constraints = FullyResolved s; _ } ->
let payload =
match ForcingState.get_forced s with
| None -> "unevaluated"
| Some t -> dump_t_ (depth - 1, stack) cx t
in
spf "%d, FullyResolved %s" id payload
| Root { constraints = Unresolved { lower; upper; _ }; _ } ->
if lower = TypeMap.empty && upper = UseTypeMap.empty then
spf "%d" id
Expand Down
9 changes: 9 additions & 0 deletions src/typing/type.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3238,6 +3238,8 @@ module Constraint = struct

val force : on_error:(Reason.t -> TypeTerm.t) -> t -> TypeTerm.t

val get_forced : t -> TypeTerm.t option

val map : f:(TypeTerm.t -> TypeTerm.t) -> t -> t
end = struct
type state =
Expand Down Expand Up @@ -3269,6 +3271,13 @@ module Constraint = struct
s.state <- Forced;
t

let get_forced s =
match s.state with
| Unforced
| Forcing ->
None
| Forced -> Some (Lazy.force_val s.valid)

let map ~f s = { valid = Lazy.map f s.valid; error_reason = s.error_reason; state = Unforced }
end

Expand Down

0 comments on commit 9ed8857

Please sign in to comment.