Skip to content

Commit 642bb45

Browse files
Andrew Kennedymeta-codesync[bot]
authored andcommitted
Remove disallow_invalid_arraykey configuration
Summary: This has been set to true for years. Reviewed By: mheiber Differential Revision: D84158739 fbshipit-source-id: 946407b86e580b0a29cf993489dadc3e1aeca1fc
1 parent 1ef5cf7 commit 642bb45

11 files changed

Lines changed: 120 additions & 153 deletions

File tree

hphp/hack/src/client_and_server/serverConfig.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,6 @@ let load_config (config : Config_file_common.t) (options : GlobalOptions.t) :
380380
~po
381381
?tco_language_feature_logging:(bool_opt "language_feature_logging" config)
382382
?tco_timeout:(int_opt "timeout" config)
383-
?tco_disallow_invalid_arraykey:(bool_opt "disallow_invalid_arraykey" config)
384383
?tco_constraint_array_index:(bool_opt "constraint_array_index" config)
385384
?tco_constraint_array_index_assign:
386385
(bool_opt "constraint_array_index_assign" config)

hphp/hack/src/options/globalOptions.ml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ type t = {
102102
tco_log_inference_constraints: bool;
103103
tco_language_feature_logging: bool;
104104
tco_timeout: int;
105-
tco_disallow_invalid_arraykey: bool;
106105
tco_constraint_array_index: bool;
107106
tco_constraint_array_index_assign: bool;
108107
tco_constraint_method_call: bool;
@@ -223,7 +222,6 @@ let default =
223222
tco_log_inference_constraints = false;
224223
tco_language_feature_logging = false;
225224
tco_timeout = 0;
226-
tco_disallow_invalid_arraykey = true;
227225
tco_constraint_array_index = true;
228226
tco_constraint_array_index_assign = false;
229227
tco_constraint_method_call = false;
@@ -343,7 +341,6 @@ let set
343341
?so_naming_sqlite_path
344342
?tco_language_feature_logging
345343
?tco_timeout
346-
?tco_disallow_invalid_arraykey
347344
?tco_constraint_array_index
348345
?tco_constraint_array_index_assign
349346
?tco_constraint_method_call
@@ -496,10 +493,6 @@ let set
496493
tco_language_feature_logging =
497494
setting tco_language_feature_logging options.tco_language_feature_logging;
498495
tco_timeout = setting tco_timeout options.tco_timeout;
499-
tco_disallow_invalid_arraykey =
500-
setting
501-
tco_disallow_invalid_arraykey
502-
options.tco_disallow_invalid_arraykey;
503496
tco_constraint_array_index =
504497
setting tco_constraint_array_index options.tco_constraint_array_index;
505498
tco_constraint_array_index_assign =

hphp/hack/src/options/globalOptions.mli

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,6 @@ type t = {
9494
Currently used for lambdas. *)
9595
tco_timeout: int;
9696
(** If non-zero, give up type checking a class or function after this many seconds *)
97-
tco_disallow_invalid_arraykey: bool;
98-
(** Flag to disallow using values that get casted to array keys at runtime;
99-
like bools, floats, or null; as array keys. *)
10097
tco_constraint_array_index: bool;
10198
(** Flag to enable the constraint solver to infer that a type can be indexed *)
10299
tco_constraint_array_index_assign: bool;
@@ -321,7 +318,6 @@ val set :
321318
?so_naming_sqlite_path:string ->
322319
?tco_language_feature_logging:bool ->
323320
?tco_timeout:int ->
324-
?tco_disallow_invalid_arraykey:bool ->
325321
?tco_constraint_array_index:bool ->
326322
?tco_constraint_array_index_assign:bool ->
327323
?tco_constraint_method_call:bool ->

hphp/hack/src/options/typecheckerOptions.ml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ let migration_flags_all = List.fold_right ~init:SSet.empty ~f:SSet.add []
8989

9090
let timeout t = t.GlobalOptions.tco_timeout
9191

92-
let disallow_invalid_arraykey t = t.GlobalOptions.tco_disallow_invalid_arraykey
93-
9492
let constraint_array_index t = t.GlobalOptions.tco_constraint_array_index
9593

9694
let constraint_array_index_assign t =

hphp/hack/src/oxidized/gen/global_options.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// This source code is licensed under the MIT license found in the
44
// LICENSE file in the "hack" directory of this source tree.
55
//
6-
// @generated SignedSource<<09d7a09f844f0189eb598083b89bbc6e>>
6+
// @generated SignedSource<<5184475c9d375c70536f0d2c0622536d>>
77
//
88
// To regenerate this file, run:
99
// buck run @fbcode//mode/dev-nosan-lg fbcode//hphp/hack/src:oxidized_regen
@@ -189,9 +189,6 @@ pub struct GlobalOptions {
189189
pub tco_language_feature_logging: bool,
190190
/// If non-zero, give up type checking a class or function after this many seconds
191191
pub tco_timeout: isize,
192-
/// Flag to disallow using values that get casted to array keys at runtime;
193-
/// like bools, floats, or null; as array keys.
194-
pub tco_disallow_invalid_arraykey: bool,
195192
/// Flag to enable the constraint solver to infer that a type can be indexed
196193
pub tco_constraint_array_index: bool,
197194
/// Flag to enable the constraint solver to infer that a type can be indexed then assigned

hphp/hack/src/oxidized/manual/global_options_impl.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ impl Default for GlobalOptions {
5353
tco_log_inference_constraints: false,
5454
tco_language_feature_logging: false,
5555
tco_timeout: 0,
56-
tco_disallow_invalid_arraykey: false, // true in ocaml, true in .hhconfig
5756
tco_constraint_array_index: true,
5857
tco_constraint_array_index_assign: false,
5958
tco_constraint_method_call: false,

hphp/hack/src/typing/tast_check/invalid_index_check.ml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@ open Hh_prelude
1111
open Aast
1212
open Typing_defs
1313
module Env = Tast_env
14-
module TCO = TypecheckerOptions
1514
module MakeType = Typing_make_type
1615
module SN = Naming_special_names
1716
open String.Replace_polymorphic_compare
1817

19-
let should_enforce env = TCO.disallow_invalid_arraykey (Env.get_tcopt env)
20-
2118
let equiv_ak_inter_dyn env ty_expect =
2219
let r = get_reason ty_expect in
2320
let ak_dyn =
@@ -60,7 +57,6 @@ let rec array_get ~array_pos ~expr_pos ~index_pos env array_ty index_ty =
6057
)
6158
(* If the key is not even an arraykey, we've already produced an error *)
6259
|| (not (Env.can_subtype env ty_have (MakeType.arraykey Reason.none)))
63-
&& should_enforce env
6460
(* Keytype of arraykey&dynamic happens when you assign a dynamic into a dict,
6561
but the above coercion doesn't work. *)
6662
|| equiv_ak_inter_dyn env ty_expect

hphp/hack/src/typing/typing_array_access.ml

Lines changed: 58 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -187,70 +187,67 @@ let widen_for_array_get ~lhs_of_null_coalesce ~expr_pos index_expr env ty =
187187
* being a subtype of arraykey
188188
*)
189189
let check_arraykey_index error env pos container_ty index_ty =
190-
if TypecheckerOptions.disallow_invalid_arraykey (Env.get_tcopt env) then (
191-
let (env, container_ty) = Env.expand_type env container_ty in
192-
let reason =
193-
match get_node container_ty with
194-
| Tclass ((_, cn), _, _) -> Reason.index_class cn
195-
| _ -> Reason.index_array
196-
in
197-
let info_of_type ty = (get_pos ty, lazy (Typing_print.error env ty)) in
198-
let container_info = info_of_type container_ty in
199-
let index_info = info_of_type index_ty in
200-
let ty_arraykey = MakeType.arraykey (Reason.idx_dict pos) in
201-
(* If we have an error in coercion here, we will add a `Hole` indicating the
202-
actual and expected type. The `Hole` may then be used in a codemod to
203-
add a call to `UNSAFE_CAST` so we need to consider what type we expect.
204-
There is a somewhat common pattern in older parts of www to do something like:
190+
let (env, container_ty) = Env.expand_type env container_ty in
191+
let reason =
192+
match get_node container_ty with
193+
| Tclass ((_, cn), _, _) -> Reason.index_class cn
194+
| _ -> Reason.index_array
195+
in
196+
let info_of_type ty = (get_pos ty, lazy (Typing_print.error env ty)) in
197+
let container_info = info_of_type container_ty in
198+
let index_info = info_of_type index_ty in
199+
let ty_arraykey = MakeType.arraykey (Reason.idx_dict pos) in
200+
(* If we have an error in coercion here, we will add a `Hole` indicating the
201+
actual and expected type. The `Hole` may then be used in a codemod to
202+
add a call to `UNSAFE_CAST` so we need to consider what type we expect.
203+
There is a somewhat common pattern in older parts of www to do something like:
205204
206-
```
207-
function keyset_issue(?string $x): keyset<string> {
208-
$xs = keyset<string>[];
209-
...
210-
/* HH_FIXME[4435] keyset values must be arraykeys */
211-
$xs[] = $x;
212-
return Keyset\filter_nulls($xs);
213-
}
214-
```
215-
(even though it is impossible for keysets to contain nulls).
205+
```
206+
function keyset_issue(?string $x): keyset<string> {
207+
$xs = keyset<string>[];
208+
...
209+
/* HH_FIXME[4435] keyset values must be arraykeys */
210+
$xs[] = $x;
211+
return Keyset\filter_nulls($xs);
212+
}
213+
```
214+
(even though it is impossible for keysets to contain nulls).
216215
217-
If we were to add an expected type of 'arraykey' here it would be
218-
correct but adding an `UNSAFE_CAST<?string,arraykey>($x)` means we
219-
get cascading errors; here, we now have the wrong return type.
216+
If we were to add an expected type of 'arraykey' here it would be
217+
correct but adding an `UNSAFE_CAST<?string,arraykey>($x)` means we
218+
get cascading errors; here, we now have the wrong return type.
220219
221-
To try and prevent this, if this is an optional type where the nonnull
222-
part can be coerced to arraykey, we prefer that type as our expected type.
223-
*)
224-
let base_error = error pos container_info index_info in
225-
let (ty_actual, is_option) =
226-
match deref index_ty with
227-
| (_, Toption inner_ty) -> (inner_ty, true)
228-
| _ -> (index_ty, false)
229-
in
230-
let (env, e1) =
231-
Typing_coercion.coerce_type
232-
~coerce_for_op:true
233-
pos
234-
reason
235-
env
236-
ty_actual
237-
ty_arraykey
238-
Enforced
239-
@@ Typing_error.Callback.always base_error
240-
in
241-
let (ty_mismatch, e2) =
242-
match e1 with
243-
| None when is_option ->
244-
(Error (index_ty, ty_actual), Some (Typing_error.primary base_error))
245-
| None -> (Ok index_ty, None)
246-
| Some _ -> (Error (index_ty, ty_arraykey), None)
247-
in
248-
Option.(
249-
iter ~f:(Typing_error_utils.add_typing_error ~env)
250-
@@ merge e1 e2 ~f:Typing_error.both);
251-
(env, ty_mismatch)
252-
) else
253-
(env, Ok index_ty)
220+
To try and prevent this, if this is an optional type where the nonnull
221+
part can be coerced to arraykey, we prefer that type as our expected type.
222+
*)
223+
let base_error = error pos container_info index_info in
224+
let (ty_actual, is_option) =
225+
match deref index_ty with
226+
| (_, Toption inner_ty) -> (inner_ty, true)
227+
| _ -> (index_ty, false)
228+
in
229+
let (env, e1) =
230+
Typing_coercion.coerce_type
231+
~coerce_for_op:true
232+
pos
233+
reason
234+
env
235+
ty_actual
236+
ty_arraykey
237+
Enforced
238+
@@ Typing_error.Callback.always base_error
239+
in
240+
let (ty_mismatch, e2) =
241+
match e1 with
242+
| None when is_option ->
243+
(Error (index_ty, ty_actual), Some (Typing_error.primary base_error))
244+
| None -> (Ok index_ty, None)
245+
| Some _ -> (Error (index_ty, ty_arraykey), None)
246+
in
247+
Option.(
248+
iter ~f:(Typing_error_utils.add_typing_error ~env)
249+
@@ merge e1 e2 ~f:Typing_error.both);
250+
(env, ty_mismatch)
254251

255252
let check_arraykey_index_read =
256253
let mk_err pos (container_pos, container_ty_name) (key_pos, key_ty_name) =

hphp/hack/src/typing/typing_subtype.ml

Lines changed: 61 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -6865,70 +6865,67 @@ end = struct
68656865
* being a subtype of arraykey
68666866
*)
68676867
let check_arraykey_index error env pos container_ty index_ty =
6868-
if TypecheckerOptions.disallow_invalid_arraykey (Env.get_tcopt env) then (
6869-
let (env, container_ty) = Env.expand_type env container_ty in
6870-
let reason =
6871-
match get_node container_ty with
6872-
| Tclass ((_, cn), _, _) -> Reason.index_class cn
6873-
| _ -> Reason.index_array
6874-
in
6875-
let info_of_type ty = (get_pos ty, lazy (Typing_print.error env ty)) in
6876-
let container_info = info_of_type container_ty in
6877-
let index_info = info_of_type index_ty in
6878-
let ty_arraykey = MakeType.arraykey (Reason.idx_dict pos) in
6879-
(* If we have an error in coercion here, we will add a `Hole` indicating the
6880-
actual and expected type. The `Hole` may then be used in a codemod to
6881-
add a call to `UNSAFE_CAST` so we need to consider what type we expect.
6882-
There is a somewhat common pattern in older parts of www to do something like:
6883-
6884-
```
6885-
function keyset_issue(?string $x): keyset<string> {
6886-
$xs = keyset<string>[];
6887-
...
6888-
/* HH_FIXME[4435] keyset values must be arraykeys */
6889-
$xs[] = $x;
6890-
return Keyset\filter_nulls($xs);
6891-
}
6892-
```
6893-
(even though it is impossible for keysets to contain nulls).
6894-
6895-
If we were to add an expected type of 'arraykey' here it would be
6896-
correct but adding an `UNSAFE_CAST<?string,arraykey>($x)` means we
6897-
get cascading errors; here, we now have the wrong return type.
6898-
6899-
To try and prevent this, if this is an optional type where the nonnull
6900-
part can be coerced to arraykey, we prefer that type as our expected type.
6901-
*)
6902-
let base_error = error pos container_info index_info in
6903-
let (ty_actual, is_option) =
6904-
match deref index_ty with
6905-
| (_, Toption inner_ty) -> (inner_ty, true)
6906-
| _ -> (index_ty, false)
6907-
in
6908-
let (env, e1) =
6909-
Typing_coercion.coerce_type
6910-
~coerce_for_op:true
6911-
pos
6912-
reason
6913-
env
6914-
ty_actual
6915-
ty_arraykey
6916-
Enforced
6917-
@@ Typing_error.Callback.always base_error
6918-
in
6919-
let (ty_mismatch, e2) =
6920-
match e1 with
6921-
| None when is_option ->
6922-
(Error (index_ty, ty_actual), Some (Typing_error.primary base_error))
6923-
| None -> (Ok index_ty, None)
6924-
| Some _ -> (Error (index_ty, ty_arraykey), None)
6925-
in
6926-
Option.(
6927-
iter ~f:(Typing_error_utils.add_typing_error ~env)
6928-
@@ merge e1 e2 ~f:Typing_error.both);
6929-
(env, ty_mismatch)
6930-
) else
6931-
(env, Ok index_ty)
6868+
let (env, container_ty) = Env.expand_type env container_ty in
6869+
let reason =
6870+
match get_node container_ty with
6871+
| Tclass ((_, cn), _, _) -> Reason.index_class cn
6872+
| _ -> Reason.index_array
6873+
in
6874+
let info_of_type ty = (get_pos ty, lazy (Typing_print.error env ty)) in
6875+
let container_info = info_of_type container_ty in
6876+
let index_info = info_of_type index_ty in
6877+
let ty_arraykey = MakeType.arraykey (Reason.idx_dict pos) in
6878+
(* If we have an error in coercion here, we will add a `Hole` indicating the
6879+
actual and expected type. The `Hole` may then be used in a codemod to
6880+
add a call to `UNSAFE_CAST` so we need to consider what type we expect.
6881+
There is a somewhat common pattern in older parts of www to do something like:
6882+
6883+
```
6884+
function keyset_issue(?string $x): keyset<string> {
6885+
$xs = keyset<string>[];
6886+
...
6887+
/* HH_FIXME[4435] keyset values must be arraykeys */
6888+
$xs[] = $x;
6889+
return Keyset\filter_nulls($xs);
6890+
}
6891+
```
6892+
(even though it is impossible for keysets to contain nulls).
6893+
6894+
If we were to add an expected type of 'arraykey' here it would be
6895+
correct but adding an `UNSAFE_CAST<?string,arraykey>($x)` means we
6896+
get cascading errors; here, we now have the wrong return type.
6897+
6898+
To try and prevent this, if this is an optional type where the nonnull
6899+
part can be coerced to arraykey, we prefer that type as our expected type.
6900+
*)
6901+
let base_error = error pos container_info index_info in
6902+
let (ty_actual, is_option) =
6903+
match deref index_ty with
6904+
| (_, Toption inner_ty) -> (inner_ty, true)
6905+
| _ -> (index_ty, false)
6906+
in
6907+
let (env, e1) =
6908+
Typing_coercion.coerce_type
6909+
~coerce_for_op:true
6910+
pos
6911+
reason
6912+
env
6913+
ty_actual
6914+
ty_arraykey
6915+
Enforced
6916+
@@ Typing_error.Callback.always base_error
6917+
in
6918+
let (ty_mismatch, e2) =
6919+
match e1 with
6920+
| None when is_option ->
6921+
(Error (index_ty, ty_actual), Some (Typing_error.primary base_error))
6922+
| None -> (Ok index_ty, None)
6923+
| Some _ -> (Error (index_ty, ty_arraykey), None)
6924+
in
6925+
Option.(
6926+
iter ~f:(Typing_error_utils.add_typing_error ~env)
6927+
@@ merge e1 e2 ~f:Typing_error.both);
6928+
(env, ty_mismatch)
69326929

69336930
let check_arraykey_index_write =
69346931
let mk_err pos (container_pos, container_ty_name) (key_pos, key_ty_name) =

hphp/hack/src/utils/hh_config/hh_config.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,6 @@ impl HhConfig {
344344
tco_log_inference_constraints: default.tco_log_inference_constraints,
345345
tco_language_feature_logging: default.tco_language_feature_logging,
346346
tco_timeout: hhconfig.get_int_or("timeout", default.tco_timeout)?,
347-
tco_disallow_invalid_arraykey: hhconfig.get_bool_or(
348-
"disallow_invalid_arraykey",
349-
default.tco_disallow_invalid_arraykey,
350-
)?,
351347
tco_constraint_array_index: hhconfig
352348
.get_bool_or("constraint_array_index", default.tco_constraint_array_index)?,
353349
tco_constraint_array_index_assign: hhconfig.get_bool_or(

0 commit comments

Comments
 (0)