Skip to content

Commit 29d2221

Browse files
Andrew Kennedymeta-codesync[bot]
authored andcommitted
Revert D46446190: Remove defined field from Typing_local_types
Summary: D46446190 added a `defined` field to `Typing_local_types.local` and renamed `is_local_defined` to `is_local_present` to support flow-sensitive checking for typed local variables. Now that typed locals have been removed, this machinery is no longer needed. This reverts: - The `defined` field from `Typing_local_types.local` - The `~is_defined` parameter from `Env.set_local` - The rename of `is_local_defined` to `is_local_present` - The logic to keep undefined locals in the environment at control-flow joins - The `defined` checks in `get_local_in_ctx` and `get_local_ty_in_ctx` Reviewed By: mheiber Differential Revision: D98128752 fbshipit-source-id: f7f6ff36fde40e34c1e9bbc1c517174e9113068a
1 parent 68b41e1 commit 29d2221

11 files changed

Lines changed: 67 additions & 162 deletions

hphp/hack/src/typing/env/typing_env.ml

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,8 +1204,7 @@ module M = struct
12041204
* that the local currently has, and an expression_id generated from
12051205
* the last assignment to this local.
12061206
*)
1207-
let set_local
1208-
?(immutable = false) ?macro_splice_vars ~is_defined env x new_type pos =
1207+
let set_local ?(immutable = false) ?macro_splice_vars env x new_type pos =
12091208
let new_type =
12101209
match get_node new_type with
12111210
| Tunion [ty] -> ty
@@ -1227,13 +1226,7 @@ module M = struct
12271226
in
12281227
let local =
12291228
Typing_local_types.
1230-
{
1231-
ty = new_type;
1232-
defined = is_defined;
1233-
pos;
1234-
eid = expr_id;
1235-
macro_splice_vars;
1236-
}
1229+
{ ty = new_type; pos; eid = expr_id; macro_splice_vars }
12371230
in
12381231
set_local_ env x local
12391232

@@ -1295,7 +1288,7 @@ module M = struct
12951288
let all_locals =
12961289
LID.Map.fold
12971290
(fun k v acc ->
1298-
if LID.is_user_denotable k && v.Typing_local_types.defined then
1291+
if LID.is_user_denotable k then
12991292
(k, v, None) :: acc
13001293
else
13011294
acc)
@@ -1341,27 +1334,20 @@ module M = struct
13411334
Typing_local_types.
13421335
{
13431336
ty = Typing_make_type.nothing Reason.none;
1344-
defined = false;
13451337
pos = Pos.none;
13461338
eid = make_expression_id env;
13471339
macro_splice_vars = None;
13481340
}
13491341
| Some ctx ->
13501342
let lcl = LID.Map.find_opt x ctx.LEnvC.local_types in
1351-
let error () =
1352-
if not_found_is_ok x ctx then
1353-
()
1354-
else
1355-
undefined_err_fun x ctx
1356-
in
13571343
begin
13581344
match lcl with
1359-
| None -> error ()
1360-
| Some local ->
1361-
if local.Typing_local_types.defined then
1345+
| None ->
1346+
if not_found_is_ok x ctx then
13621347
()
13631348
else
1364-
error ()
1349+
undefined_err_fun x ctx
1350+
| Some _ -> ()
13651351
end;
13661352
lcl
13671353

@@ -1372,20 +1358,11 @@ module M = struct
13721358
Typing_local_types.
13731359
{
13741360
ty = Typing_make_type.nothing Reason.none;
1375-
defined = false;
13761361
pos = Pos.none;
13771362
eid = make_expression_id env;
13781363
macro_splice_vars = None;
13791364
} )
1380-
| Some local ->
1381-
let open Typing_local_types in
1382-
let ty =
1383-
if local.defined then
1384-
local.ty
1385-
else
1386-
Typing_make_type.nothing Reason.none
1387-
in
1388-
(true, { local with ty })
1365+
| Some local -> (true, local)
13891366

13901367
let get_local_in_next_continuation ?error_if_undef_at_pos:p env x =
13911368
let undefined_err_fun = local_undefined_error ~env p in
@@ -1416,9 +1393,7 @@ module M = struct
14161393
let set_locals env locals =
14171394
LID.Map.fold (fun lid ty env -> set_local_ env lid ty) locals env
14181395

1419-
(* If the local is present in the local environment. It might be defined, or
1420-
it might have a bound (or both). *)
1421-
let is_local_present env x =
1396+
let is_local_defined env x =
14221397
let next_cont = next_cont_opt env in
14231398
Option.is_some next_cont && fst (get_local_ env x)
14241399

@@ -1432,9 +1407,9 @@ module M = struct
14321407
| Some next_cont -> begin
14331408
let open Typing_local_types in
14341409
match LID.Map.find_opt x next_cont.LEnvC.local_types with
1435-
| Some Typing_local_types.{ ty; defined; pos; eid; macro_splice_vars }
1410+
| Some Typing_local_types.{ ty; pos; eid; macro_splice_vars }
14361411
when not (Expression_id.equal eid new_eid) ->
1437-
let local = { ty; defined; pos; eid = new_eid; macro_splice_vars } in
1412+
let local = { ty; pos; eid = new_eid; macro_splice_vars } in
14381413
let per_cont_env = LEnvC.add_to_cont C.Next x local per_cont_env in
14391414
let env = { env with lenv = { env.lenv with per_cont_env } } in
14401415
if Expression_id.is_immutable eid then
@@ -2148,7 +2123,6 @@ module M = struct
21482123
Typing_local_types.
21492124
{
21502125
ty;
2151-
defined = true;
21522126
pos;
21532127
eid = Expression_id.make env.expression_id_provider;
21542128
macro_splice_vars = None;

hphp/hack/src/typing/env/typing_env.mli

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,6 @@ val all_continuations : env -> Typing_continuations.t list
401401
val set_local :
402402
?immutable:bool ->
403403
?macro_splice_vars:(Pos.t * Typing_defs.locl_ty) Local_id.Map.t ->
404-
is_defined:bool ->
405404
env ->
406405
Local_id.t ->
407406
locl_ty ->
@@ -427,7 +426,7 @@ val set_fake_members : env -> Typing_fake_members.t -> env
427426

428427
val set_loaded_packages : env -> Typing_local_packages.t -> env
429428

430-
val is_local_present : env -> Local_id.t -> bool
429+
val is_local_defined : env -> Local_id.t -> bool
431430

432431
val get_local_check_defined : env -> Aast.lid -> Typing_local_types.local
433432

0 commit comments

Comments
 (0)