Skip to content

Commit

Permalink
[flow][refactor] Rename the type EnumT to EnumValueT
Browse files Browse the repository at this point in the history
Summary:
To reduce confusion between these two types, and the names of future types that will enable generic Flow Enums, rename `EnumT` to `EnumValueT`. Thus we now have `EnumObjectT` and `EnumValueT` - both types should be clear in what they represent.

Changelog: [internal]

Reviewed By: SamChou19815

Differential Revision: D54927576

fbshipit-source-id: 8796c9ba0f7c74a09b54fb5d705c008debf91235
  • Loading branch information
gkz authored and facebook-github-bot committed Mar 15, 2024
1 parent aa587bb commit c2d8c5f
Show file tree
Hide file tree
Showing 16 changed files with 59 additions and 56 deletions.
2 changes: 1 addition & 1 deletion src/services/coverage/coverage.ml
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ let visitor =
| DefT (_, StrT _)
| DefT (_, VoidT)
| DefT (_, EnumObjectT _)
| DefT (_, EnumT _) ->
| DefT (_, EnumValueT _) ->
Kind.Checked
(* Concrete uncovered constructors *)
(* TODO: Rethink coverage for these types *)
Expand Down
4 changes: 2 additions & 2 deletions src/typing/annotation_inference.ml
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ module rec ConsGen : S = struct
let reposition cx ?trace:_ loc t = reposition cx loc t

let enum_proto cx ~reason (enum_reason, enum) =
let enum_t = DefT (enum_reason, EnumT enum) in
let enum_t = DefT (enum_reason, EnumValueT enum) in
let { representation_t; _ } = enum in
get_builtin_typeapp cx reason "$EnumProto" [enum_t; representation_t]

Expand Down Expand Up @@ -577,7 +577,7 @@ module rec ConsGen : S = struct
| (DefT (lreason, EnumObjectT enum), Annot_UseT_TypeT _) ->
(* an enum object value annotation becomes the enum type *)
mk_enum_type lreason enum
| (DefT (enum_reason, EnumT _), Annot_UseT_TypeT (reason, _)) ->
| (DefT (enum_reason, EnumValueT _), Annot_UseT_TypeT (reason, _)) ->
Flow_js_utils.add_output cx Error_message.(EEnumMemberUsedAsType { reason; enum_reason });
AnyT.error reason
| (l, Annot_UseT_TypeT (reason_use, _)) ->
Expand Down
2 changes: 1 addition & 1 deletion src/typing/check_polarity.ml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module Kit (Flow : Flow_common.S) : Flow_common.CHECK_POLARITY = struct
| DefT (_, CharSetT _)
| DefT (_, EmptyT)
| DefT (_, EnumObjectT _)
| DefT (_, EnumT _)
| DefT (_, EnumValueT _)
| DefT (_, MixedT _)
| DefT (_, NullT)
| DefT (_, NumT _)
Expand Down
7 changes: 5 additions & 2 deletions src/typing/debug_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,10 @@ let rec dump_t_ (depth, tvars) cx t =
| DefT (_, TypeT (kind, arg)) ->
p ~extra:(spf "%s, %s" (string_of_type_t_kind kind) (kid arg)) t
| DefT
(_, EnumT { enum_name; enum_id; members = _; representation_t = _; has_unknown_members = _ })
( _,
EnumValueT
{ enum_name; enum_id; members = _; representation_t = _; has_unknown_members = _ }
)
| DefT
( _,
EnumObjectT
Expand Down Expand Up @@ -955,7 +958,7 @@ and dump_use_t_ (depth, tvars) cx t =
| ConcretizeTypeAppsT _ -> p t
| TypeCastT (_, arg) -> p ~reason:false ~extra:(kid arg) t
| EnumCastT { use_op = _; enum = (reason, enum) } ->
p ~reason:false ~extra:(kid (DefT (reason, EnumT enum))) t
p ~reason:false ~extra:(kid (DefT (reason, EnumValueT enum))) t
| EnumExhaustiveCheckT { check; _ } ->
let check_str =
match check with
Expand Down
24 changes: 12 additions & 12 deletions src/typing/flow_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,21 @@ let strict_equatable_error cond_context (l, r) =
| (_, DefT (_, EnumObjectT _)) ->
Some (Lazy.force comparison_error)
(* We allow comparison between enums of the same type. *)
| (DefT (_, EnumT { enum_id = id1; _ }), DefT (_, EnumT { enum_id = id2; _ }))
| (DefT (_, EnumValueT { enum_id = id1; _ }), DefT (_, EnumValueT { enum_id = id2; _ }))
when ALoc.equal_id id1 id2 ->
None
(* We allow the comparison of enums to null and void outside of switches. *)
| (DefT (_, EnumT _), DefT (_, (NullT | VoidT)))
| (DefT (_, (NullT | VoidT)), DefT (_, EnumT _)) -> begin
| (DefT (_, EnumValueT _), DefT (_, (NullT | VoidT)))
| (DefT (_, (NullT | VoidT)), DefT (_, EnumValueT _)) -> begin
match cond_context with
| Some (SwitchTest _) -> Some (Lazy.force comparison_error)
| None
| Some _ ->
None
end
(* We don't allow the comparison of enums and other types in general. *)
| (DefT (_, EnumT _), _)
| (_, DefT (_, EnumT _)) ->
| (DefT (_, EnumValueT _), _)
| (_, DefT (_, EnumValueT _)) ->
Some (Lazy.force comparison_error)
(* We don't check other strict equality comparisons. *)
| _ -> None
Expand Down Expand Up @@ -352,7 +352,7 @@ struct

let enum_proto cx ~reason (enum_reason, enum) =
let enum_object_t = DefT (enum_reason, EnumObjectT enum) in
let enum_t = DefT (enum_reason, EnumT enum) in
let enum_t = DefT (enum_reason, EnumValueT enum) in
let { representation_t; _ } = enum in
FlowJs.get_builtin_typeapp cx reason "$EnumProto" [enum_object_t; enum_t; representation_t]

Expand Down Expand Up @@ -776,17 +776,17 @@ struct
(***************************)
(* type cast e.g. `(x: T)` *)
(***************************)
| (DefT (reason, EnumT enum), TypeCastT (use_op, cast_to_t)) ->
| (DefT (reason, EnumValueT enum), TypeCastT (use_op, cast_to_t)) ->
rec_flow cx trace (cast_to_t, EnumCastT { use_op; enum = (reason, enum) })
| (UnionT _, TypeCastT (_, (UnionT _ as u)))
when union_optimization_guard cx ~equiv:false TypeUtil.quick_subtype l u ->
()
| (UnionT (_, rep1), TypeCastT _) -> flow_all_in_union cx trace rep1 u
| (_, TypeCastT (use_op, cast_to_t)) -> rec_flow cx trace (l, UseT (use_op, cast_to_t))
(**********************************************************************)
(* enum cast e.g. `(x: T)` where `x` is an `EnumT` *)
(* enum cast e.g. `(x: T)` where `x` is an `EnumValueT` *)
(* We allow enums to be explicitly cast to their representation type. *)
(* When we specialize `TypeCastT` when the LHS is an `EnumT`, the *)
(* When we specialize `TypeCastT` when the LHS is an `EnumValueT`, the *)
(* `cast_to_t` of `TypeCastT` must then be resolved. So we call flow *)
(* with it on the LHS, and `EnumCastT` on the RHS. When we actually *)
(* turn this into a `UseT`, it must placed back on the RHS. *)
Expand All @@ -795,7 +795,7 @@ struct
when TypeUtil.quick_subtype representation_t cast_to_t ->
rec_flow cx trace (representation_t, UseT (use_op, cast_to_t))
| (cast_to_t, EnumCastT { use_op; enum = (reason, enum) }) ->
rec_flow cx trace (DefT (reason, EnumT enum), UseT (use_op, cast_to_t))
rec_flow cx trace (DefT (reason, EnumValueT enum), UseT (use_op, cast_to_t))
(******************)
(* Module exports *)
(******************)
Expand Down Expand Up @@ -5335,7 +5335,7 @@ struct
add_output cx ~trace (Error_message.EEnumInvalidObjectFunction { reason; enum_reason });
rec_flow cx trace (AnyT.error reason, result)
(* Entry point to exhaustive checking logic - when resolving the discriminant as an enum. *)
| ( DefT (enum_reason, EnumT enum),
| ( DefT (enum_reason, EnumValueT enum),
EnumExhaustiveCheckT
{
reason = check_reason;
Expand Down Expand Up @@ -5397,7 +5397,7 @@ struct
~default_case
~incomplete_out
~discriminant_after_check
| ( DefT (enum_reason, EnumT { members; _ }),
| ( DefT (enum_reason, EnumValueT { members; _ }),
EnumExhaustiveCheckT
{
reason;
Expand Down
6 changes: 3 additions & 3 deletions src/typing/flow_js_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,15 @@ let equatable = function
| ( DefT
( _,
( NumT _ | StrT _ | BoolT _ | SingletonNumT _ | SingletonStrT _ | SingletonBoolT _
| SymbolT | EnumObjectT _ | EnumT _ )
| SymbolT | EnumObjectT _ | EnumValueT _ )
),
_
)
| ( _,
DefT
( _,
( NumT _ | StrT _ | BoolT _ | SingletonNumT _ | SingletonStrT _ | SingletonBoolT _
| SymbolT | EnumObjectT _ | EnumT _ )
| SymbolT | EnumObjectT _ | EnumValueT _ )
)
) ->
false
Expand Down Expand Up @@ -1200,7 +1200,7 @@ module ValueToTypeReferenceTransform = struct
| DefT (lreason, EnumObjectT enum) ->
(* an enum object value annotation becomes the enum type *)
mk_enum_type lreason enum
| DefT (enum_reason, EnumT _) ->
| DefT (enum_reason, EnumValueT _) ->
add_output cx ~trace Error_message.(EEnumMemberUsedAsType { reason = reason_op; enum_reason });
AnyT.error reason_op
| DefT (reason_component, ReactAbstractComponentT _) as l ->
Expand Down
2 changes: 1 addition & 1 deletion src/typing/members.ml
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ let rec extract_type cx this_t =
| ObjProtoT _
| OpaqueT _
| DefT (_, TypeT _)
| DefT (_, EnumT _) ->
| DefT (_, EnumValueT _) ->
FailureUnhandledType this_t

let rec extract_members ?(exclude_proto_members = false) cx = function
Expand Down
8 changes: 4 additions & 4 deletions src/typing/merge_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ let detect_sketchy_null_checks cx tast =
| DefT (_, NumT _) -> { exists_check with number_loc = t_loc }
| DefT (_, BigIntT _) -> { exists_check with bigint_loc = t_loc }
| DefT (_, MixedT _) -> { exists_check with mixed_loc = t_loc }
| DefT (_, EnumT { representation_t = DefT (_, BoolT _); _ }) ->
| DefT (_, EnumValueT { representation_t = DefT (_, BoolT _); _ }) ->
{ exists_check with enum_bool_loc = t_loc }
| DefT (_, EnumT { representation_t = DefT (_, StrT _); _ }) ->
| DefT (_, EnumValueT { representation_t = DefT (_, StrT _); _ }) ->
{ exists_check with enum_string_loc = t_loc }
| DefT (_, EnumT { representation_t = DefT (_, NumT _); _ }) ->
| DefT (_, EnumValueT { representation_t = DefT (_, NumT _); _ }) ->
{ exists_check with enum_number_loc = t_loc }
| DefT (_, EnumT { representation_t = DefT (_, BigIntT _); _ }) ->
| DefT (_, EnumValueT { representation_t = DefT (_, BigIntT _); _ }) ->
{ exists_check with enum_bigint_loc = t_loc }
| _ -> exists_check
in
Expand Down
2 changes: 1 addition & 1 deletion src/typing/resolvableTypeJob.ml
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ and collect_of_type ?log_unresolved cx acc = function
| DefT (_, SingletonStrT _)
| DefT (_, SingletonBigIntT _)
| DefT (_, CharSetT _)
| DefT (_, EnumT _)
| DefT (_, EnumValueT _)
| DefT (_, EnumObjectT _)
| AnyT _ ->
acc
Expand Down
2 changes: 1 addition & 1 deletion src/typing/speculation_kit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ module Make (Flow : INPUT) : OUTPUT = struct
( _,
( NumT _ | BigIntT _ | StrT _ | MixedT _ | SymbolT | FunT _ | ObjT _ | ArrT _
| ClassT _ | InstanceT _ | CharSetT _ | TypeT _ | PolyT _ | ReactAbstractComponentT _
| EnumT _ | EnumObjectT _ )
| EnumValueT _ | EnumObjectT _ )
)
when Base.Option.is_some (UnionRep.check_enum rep) ->
add_output
Expand Down
8 changes: 4 additions & 4 deletions src/typing/subtyping_kit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2138,7 +2138,7 @@ module Make (Flow : INPUT) : OUTPUT = struct
| (DefT (_, EnumObjectT { enum_id = id1; _ }), DefT (_, EnumObjectT { enum_id = id2; _ }))
when ALoc.equal_id id1 id2 ->
()
| (DefT (_, EnumT { enum_id = id1; _ }), DefT (_, EnumT { enum_id = id2; _ }))
| (DefT (_, EnumValueT { enum_id = id1; _ }), DefT (_, EnumValueT { enum_id = id2; _ }))
when ALoc.equal_id id1 id2 ->
()
| ( DefT
Expand Down Expand Up @@ -2166,7 +2166,7 @@ module Make (Flow : INPUT) : OUTPUT = struct
)
| ( DefT
( _,
EnumT
EnumValueT
{
enum_id = id1;
enum_name = n1;
Expand All @@ -2178,7 +2178,7 @@ module Make (Flow : INPUT) : OUTPUT = struct
),
DefT
( _,
EnumT
EnumValueT
{
enum_id = id2;
enum_name = n2;
Expand All @@ -2195,7 +2195,7 @@ module Make (Flow : INPUT) : OUTPUT = struct
&& SSet.equal (SSet.of_list @@ SMap.keys m1) (SSet.of_list @@ SMap.keys m2)
&& has_unknown1 = has_unknown2 ->
rec_flow_t cx trace ~use_op (r1, r2)
| (DefT (enum_reason, EnumT { representation_t; _ }), t)
| (DefT (enum_reason, EnumValueT { representation_t; _ }), t)
when TypeUtil.quick_subtype representation_t t ->
let representation_type =
match representation_t with
Expand Down
6 changes: 3 additions & 3 deletions src/typing/ty_normalizer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ module Make (I : INPUT) : S = struct
| DefT (reason, EnumObjectT _) ->
let%map symbol = Reason_utils.local_type_alias_symbol env reason in
Ty.TypeOf (Ty.TSymbol symbol, None)
| DefT (reason, EnumT _) ->
| DefT (reason, EnumValueT _) ->
let%map symbol = Reason_utils.local_type_alias_symbol env reason in
Ty.Generic (symbol, Ty.EnumKind, None)
| DefT (_, CharSetT s) -> return (Ty.CharSet (String_utils.CharSet.to_string s))
Expand Down Expand Up @@ -2118,7 +2118,7 @@ module Make (I : INPUT) : S = struct
class_or_interface_decl ~env r None static super inst
(* Enums *)
| DefT (reason, EnumObjectT _)
| DefT (_, TypeT (ImportEnumKind, DefT (reason, EnumT _))) ->
| DefT (_, TypeT (ImportEnumKind, DefT (reason, EnumValueT _))) ->
enum_decl ~env reason
| DefT (reason, ReactAbstractComponentT { component_kind = Nominal (_, name); _ }) ->
component_decl ~env None name reason
Expand Down Expand Up @@ -2511,7 +2511,7 @@ module Make (I : INPUT) : S = struct
| DefT (r, (StrT _ | SingletonStrT _)) -> primitive ~env r "String"
| DefT (r, (BoolT _ | SingletonBoolT _)) -> primitive ~env r "Boolean"
| DefT (r, SymbolT) -> primitive ~env r "Symbol"
| DefT (_, EnumT _) -> return no_members
| DefT (_, EnumValueT _) -> return no_members
| ObjProtoT r -> primitive ~env r "Object"
| FunProtoT r -> primitive ~env r "Function"
| DefT (r, ObjT o) ->
Expand Down
6 changes: 3 additions & 3 deletions src/typing/type.ml
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ module rec TypeTerm : sig
}
| RendersT of canonical_renders_form
(* Enum types *)
| EnumT of enum_t
| EnumValueT of enum_t
| EnumObjectT of enum_t

(* A syntactic render type "renders T" uses an EvalT to be translated into a canonical form.
Expand Down Expand Up @@ -3983,7 +3983,7 @@ let string_of_def_ctor = function
| CharSetT _ -> "CharSetT"
| ClassT _ -> "ClassT"
| EmptyT -> "EmptyT"
| EnumT _ -> "EnumT"
| EnumValueT _ -> "EnumValueT"
| EnumObjectT _ -> "EnumObjectT"
| FunT _ -> "FunT"
| InstanceT _ -> "InstanceT"
Expand Down Expand Up @@ -4515,7 +4515,7 @@ let mk_enum_type reason enum =
| _ -> desc)
reason
in
DefT (reason, EnumT enum)
DefT (reason, EnumValueT enum)

let call_of_method_app
call_this_t
Expand Down
Loading

0 comments on commit c2d8c5f

Please sign in to comment.