Skip to content

Commit 5fdb4b7

Browse files
Michael Thomasfacebook-github-bot
authored andcommitted
Refactor error evaluation
Summary: Error evaluation is the defunctionalized version of the callback-hell that was error messages. Unfortunately, it is still very complex with lots of _similar_ types corresponding to different subsets of a `User_error.t`. This diff takes a first step at reducing the complexity by making subsequent refactors more error resistant by introducing named record types rather than using tuples and eliminating the completely unused `User_error_flags.t` component. Reviewed By: madgen Differential Revision: D72396317 fbshipit-source-id: 3d7a1d25f144f74c125142f111a642fa31b7ebcf
1 parent 8230cf1 commit 5fdb4b7

29 files changed

+1211
-2512
lines changed

hphp/hack/src/client/clientLsp.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,6 @@ let ide_diagnostics_to_lsp_diagnostics
11641164
explanation = _;
11651165
custom_msgs;
11661166
is_fixmed = _;
1167-
flags = _;
11681167
quickfixes = _;
11691168
function_pos = _;
11701169
} =

hphp/hack/src/errors/contextual_error_formatter.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ let to_string
213213
explanation = _;
214214
custom_msgs;
215215
quickfixes = _;
216-
flags = _;
217216
is_fixmed = _;
218217
function_pos = _;
219218
} =

hphp/hack/src/errors/dune

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@
5252
render
5353
message
5454
quickfix
55-
user_error
56-
user_error_flags)
55+
user_error)
5756
(libraries
5857
core_kernel
5958
classish_positions

hphp/hack/src/errors/errors.ml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ let try_with_result (f1 : unit -> 'res) (f2 : 'res -> error -> 'res) : 'res =
195195
explanation;
196196
quickfixes;
197197
custom_msgs;
198-
flags;
199198
function_pos;
200199
is_fixmed = _;
201200
} ->
@@ -220,7 +219,6 @@ let try_with_result (f1 : unit -> 'res) (f2 : 'res -> error -> 'res) : 'res =
220219
explanation
221220
~quickfixes
222221
~custom_msgs
223-
~flags
224222
?function_pos
225223

226224
let try_with_result_pure ~fail f g =
@@ -324,7 +322,6 @@ let compare_internal (x : ('a, 'b) User_error.t) (y : ('a, 'b) User_error.t) :
324322
custom_msgs = _;
325323
quickfixes = _;
326324
is_fixmed = _;
327-
flags = _;
328325
function_pos = _;
329326
} =
330327
x
@@ -339,7 +336,6 @@ let compare_internal (x : ('a, 'b) User_error.t) (y : ('a, 'b) User_error.t) :
339336
custom_msgs = _;
340337
quickfixes = _;
341338
is_fixmed = _;
342-
flags = _;
343339
function_pos = _;
344340
} =
345341
y
@@ -705,7 +701,6 @@ let add_error_with_fixme_error error explanation ~fixme_pos =
705701
explanation = _;
706702
quickfixes;
707703
custom_msgs;
708-
flags;
709704
function_pos;
710705
is_fixmed = _;
711706
} =
@@ -721,7 +716,6 @@ let add_error_with_fixme_error error explanation ~fixme_pos =
721716
Explanation.empty
722717
~quickfixes
723718
~custom_msgs
724-
~flags
725719
?function_pos
726720

727721
let add_applied_fixme error =
@@ -836,7 +830,6 @@ let add_error (error : error) =
836830
explanation;
837831
quickfixes;
838832
custom_msgs;
839-
flags;
840833
function_pos;
841834
is_fixmed = _;
842835
} =
@@ -852,7 +845,6 @@ let add_error (error : error) =
852845
explanation
853846
~quickfixes
854847
~custom_msgs
855-
~flags
856848
?function_pos
857849
in
858850

@@ -1352,7 +1344,6 @@ let convert_errors_to_string ?(include_filename = false) (errors : error list) :
13521344
explanation = _;
13531345
quickfixes = _;
13541346
is_fixmed = _;
1355-
flags = _;
13561347
function_pos = _;
13571348
} =
13581349
err

hphp/hack/src/errors/fmt_plain.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ impl<'a> std::fmt::Display for FmtPlain<'a> {
2626
custom_msgs,
2727
quickfixes: _,
2828
is_fixmed: _,
29-
flags: _,
3029
function_pos: _,
3130
},
3231
ctx,

hphp/hack/src/errors/fmt_raw.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ impl<'a> std::fmt::Display for FmtRaw<'a> {
3030
custom_msgs,
3131
quickfixes: _,
3232
is_fixmed: _,
33-
flags: _,
3433
function_pos: _,
3534
},
3635
ctx,

hphp/hack/src/errors/highlighted_error_formatter.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,6 @@ let to_string (error : Errors.finalized_error) : string =
571571
custom_msgs;
572572
explanation = _;
573573
quickfixes = _;
574-
flags = _;
575574
is_fixmed = _;
576575
function_pos = _;
577576
} =

hphp/hack/src/errors/raw_error_formatter.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ let to_string (error : Errors.finalized_error) : string =
5656
quickfixes = _;
5757
custom_msgs = _;
5858
is_fixmed = _;
59-
flags = _;
6059
function_pos = _;
6160
} =
6261
error

hphp/hack/src/errors/user_error.ml

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ type ('prim_pos, 'pos) t = {
3838
quickfixes: 'prim_pos Quickfix.t list; [@hash.ignore]
3939
custom_msgs: string list;
4040
is_fixmed: bool;
41-
flags: User_error_flags.t;
4241
function_pos: 'prim_pos option;
4342
}
4443
[@@deriving eq, hash, ord, show]
@@ -52,7 +51,6 @@ let make
5251
?(is_fixmed = false)
5352
?(quickfixes = [])
5453
?(custom_msgs = [])
55-
?(flags = User_error_flags.empty)
5654
?function_pos
5755
claim
5856
reasons
@@ -66,7 +64,6 @@ let make
6664
quickfixes;
6765
custom_msgs;
6866
is_fixmed;
69-
flags;
7067
function_pos;
7168
}
7269

@@ -75,7 +72,6 @@ let make_err
7572
?is_fixmed
7673
?quickfixes
7774
?custom_msgs
78-
?flags
7975
?function_pos
8076
claim
8177
reasons
@@ -86,20 +82,18 @@ let make_err
8682
?is_fixmed
8783
?quickfixes
8884
?custom_msgs
89-
?flags
9085
?function_pos
9186
claim
9287
reasons
9388
explanation
9489

95-
let make_warning code ?is_fixmed ?quickfixes ?custom_msgs ?flags claim reasons =
90+
let make_warning code ?is_fixmed ?quickfixes ?custom_msgs claim reasons =
9691
make
9792
Warning
9893
code
9994
?is_fixmed
10095
?quickfixes
10196
?custom_msgs
102-
?flags
10397
claim
10498
reasons
10599
Explanation.empty
@@ -127,7 +121,6 @@ let to_absolute
127121
quickfixes;
128122
custom_msgs;
129123
is_fixmed;
130-
flags;
131124
function_pos;
132125
} =
133126
let pos_or_decl_to_absolute_pos pos_or_decl =
@@ -153,7 +146,6 @@ let to_absolute
153146
quickfixes;
154147
custom_msgs;
155148
is_fixmed;
156-
flags;
157149
function_pos;
158150
}
159151

@@ -179,7 +171,6 @@ let make_absolute severity code = function
179171
quickfixes = [];
180172
custom_msgs = [];
181173
is_fixmed = false;
182-
flags = User_error_flags.empty;
183174
function_pos = None;
184175
}
185176

@@ -193,7 +184,6 @@ let to_absolute_for_test
193184
quickfixes;
194185
custom_msgs;
195186
is_fixmed;
196-
flags;
197187
function_pos;
198188
} =
199189
let f (p, s) =
@@ -228,7 +218,6 @@ let to_absolute_for_test
228218
quickfixes;
229219
custom_msgs;
230220
is_fixmed;
231-
flags;
232221
function_pos;
233222
}
234223

@@ -290,7 +279,7 @@ let to_string { severity; code; claim; reasons; custom_msgs; _ } =
290279

291280
let to_json ~(human_formatter : (_ -> string) option) ~filename_to_string error
292281
=
293-
let { severity; code; claim; reasons; flags; custom_msgs; function_pos; _ } =
282+
let { severity; code; claim; reasons; custom_msgs; function_pos; _ } =
294283
error
295284
in
296285
let msgl = claim :: reasons in
@@ -310,13 +299,11 @@ let to_json ~(human_formatter : (_ -> string) option) ~filename_to_string error
310299
let custom_msgs =
311300
List.map ~f:(fun msg -> Hh_json.JSON_String msg) custom_msgs
312301
in
313-
let flags = User_error_flags.to_json flags in
314302
let human_format = Option.map ~f:(fun f -> f error) human_formatter in
315303
let obj =
316304
("severity", Hh_json.JSON_String (Severity.to_string severity))
317305
:: ("message", Hh_json.JSON_Array elts)
318306
:: ("custom_messages", Hh_json.JSON_Array custom_msgs)
319-
:: ("flags", flags)
320307
:: List.filter_opt
321308
[
322309
Option.map human_format ~f:(fun human_format ->

hphp/hack/src/errors/user_error.mli

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ type ('prim_pos, 'pos) t = {
2828
quickfixes: 'prim_pos Quickfix.t list; [@hash.ignore]
2929
custom_msgs: string list;
3030
is_fixmed: bool;
31-
flags: User_error_flags.t;
3231
function_pos: 'prim_pos option;
3332
}
3433
[@@deriving eq, hash, ord, show]
@@ -41,7 +40,6 @@ val make :
4140
?is_fixmed:bool ->
4241
?quickfixes:'a Quickfix.t list ->
4342
?custom_msgs:string list ->
44-
?flags:User_error_flags.t ->
4543
?function_pos:'a ->
4644
'a Message.t ->
4745
'b Message.t list ->
@@ -54,7 +52,6 @@ val make_err :
5452
?is_fixmed:bool ->
5553
?quickfixes:'a Quickfix.t list ->
5654
?custom_msgs:string list ->
57-
?flags:User_error_flags.t ->
5855
?function_pos:'a ->
5956
'a Message.t ->
6057
'b Message.t list ->
@@ -67,7 +64,6 @@ val make_warning :
6764
?is_fixmed:bool ->
6865
?quickfixes:'a Quickfix.t list ->
6966
?custom_msgs:string list ->
70-
?flags:User_error_flags.t ->
7167
'a Message.t ->
7268
'b Message.t list ->
7369
('a, 'b) t

0 commit comments

Comments
 (0)