Skip to content

Commit 58fd6c5

Browse files
committed
AST cleanup: first class expression and patterns for records with optional fields.
1 parent 6cc7343 commit 58fd6c5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+397
-341
lines changed

analysis/reanalyze/src/Arnold.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,8 @@ module Compile = struct
947947
|> List.map
948948
(fun
949949
( _desc,
950-
(recordLabelDefinition : Typedtree.record_label_definition) )
950+
(recordLabelDefinition : Typedtree.record_label_definition),
951+
_ )
951952
->
952953
match recordLabelDefinition with
953954
| Kept _typeExpr -> None

analysis/reanalyze/src/DeadValue.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ let rec collectExpr super self (e : Typedtree.expression) =
192192
DeadType.addTypeReference ~posTo ~posFrom:locFrom.loc_start
193193
| Texp_record {fields} ->
194194
fields
195-
|> Array.iter (fun (_, record_label_definition) ->
195+
|> Array.iter (fun (_, record_label_definition, _) ->
196196
match record_label_definition with
197197
| Typedtree.Overridden (_, ({exp_loc} as e)) when exp_loc.loc_ghost
198198
->
@@ -219,7 +219,7 @@ let collectPattern : _ -> _ -> Typedtree.pattern -> Typedtree.pattern =
219219
(match pat.pat_desc with
220220
| Typedtree.Tpat_record (cases, _clodsedFlag) ->
221221
cases
222-
|> List.iter (fun (_loc, {Types.lbl_loc = {loc_start = posTo}}, _pat) ->
222+
|> List.iter (fun (_loc, {Types.lbl_loc = {loc_start = posTo}}, _pat, _) ->
223223
if !Config.analyzeTypes then
224224
DeadType.addTypeReference ~posFrom ~posTo)
225225
| _ -> ());

analysis/reanalyze/src/SideEffects.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ and exprOptNoSideEffects eo =
7575
| None -> true
7676
| Some e -> e |> exprNoSideEffects
7777

78-
and fieldNoSideEffects ((_ld, rld) : _ * Typedtree.record_label_definition) =
78+
and fieldNoSideEffects
79+
((_ld, rld, _) : _ * Typedtree.record_label_definition * _) =
7980
match rld with
8081
| Kept _typeExpr -> true
8182
| Overridden (_lid, e) -> e |> exprNoSideEffects

analysis/src/CompletionExpressions.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ let rec traverseExpr (exp : Parsetree.expression) ~exprPath ~pos
6060
let fieldWithCursor = ref None in
6161
let fieldWithExprHole = ref None in
6262
fields
63-
|> List.iter (fun (fname, exp) ->
63+
|> List.iter (fun (fname, exp, _) ->
6464
match
6565
( fname.Location.txt,
6666
exp.Parsetree.pexp_loc |> CursorPosition.classifyLoc ~pos )
@@ -72,7 +72,7 @@ let rec traverseExpr (exp : Parsetree.expression) ~exprPath ~pos
7272
| _ -> ());
7373
let seenFields =
7474
fields
75-
|> List.filter_map (fun (fieldName, _f) ->
75+
|> List.filter_map (fun (fieldName, _f, _) ->
7676
match fieldName with
7777
| {Location.txt = Longident.Lident fieldName} -> Some fieldName
7878
| _ -> None)

analysis/src/CompletionFrontEnd.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
473473
?contextPath p
474474
| Ppat_record (fields, _) ->
475475
fields
476-
|> List.iter (fun (fname, p) ->
476+
|> List.iter (fun (fname, p, _) ->
477477
match fname with
478478
| {Location.txt = Longident.Lident fname} ->
479479
scopePattern
@@ -879,7 +879,8 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
879879
Pstr_eval
880880
( {
881881
pexp_desc =
882-
Pexp_record (({txt = Lident "from"}, fromExpr) :: _, _);
882+
Pexp_record
883+
(({txt = Lident "from"}, fromExpr, _) :: _, _);
883884
},
884885
_ );
885886
};

analysis/src/CompletionPatterns.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ and traversePattern (pat : Parsetree.pattern) ~patternPath ~locHasCursor
112112
let fieldWithCursor = ref None in
113113
let fieldWithPatHole = ref None in
114114
fields
115-
|> List.iter (fun (fname, f) ->
115+
|> List.iter (fun (fname, f, _) ->
116116
match
117117
( fname.Location.txt,
118118
f.Parsetree.ppat_loc
@@ -125,7 +125,7 @@ and traversePattern (pat : Parsetree.pattern) ~patternPath ~locHasCursor
125125
| _ -> ());
126126
let seenFields =
127127
fields
128-
|> List.filter_map (fun (fieldName, _f) ->
128+
|> List.filter_map (fun (fieldName, _f, _) ->
129129
match fieldName with
130130
| {Location.txt = Longident.Lident fieldName} -> Some fieldName
131131
| _ -> None)

analysis/src/DumpAst.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ let rec printPattern pattern ~pos ~indentation =
104104
^ addIndentation (indentation + 1)
105105
^ "fields:\n"
106106
^ (fields
107-
|> List.map (fun ((Location.{txt} as loc), pat) ->
107+
|> List.map (fun ((Location.{txt} as loc), pat, _) ->
108108
addIndentation (indentation + 2)
109109
^ (loc |> printLocDenominatorLoc ~pos)
110110
^ (Utils.flattenLongIdent txt |> ident |> str)
@@ -245,7 +245,7 @@ and printExprItem expr ~pos ~indentation =
245245
^ addIndentation (indentation + 1)
246246
^ "fields:\n"
247247
^ (fields
248-
|> List.map (fun ((Location.{txt} as loc), expr) ->
248+
|> List.map (fun ((Location.{txt} as loc), expr, _) ->
249249
addIndentation (indentation + 2)
250250
^ (loc |> printLocDenominatorLoc ~pos)
251251
^ (Utils.flattenLongIdent txt |> ident |> str)

analysis/src/Hint.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ let inlay ~path ~pos ~maxLength ~debug =
4444
match pat.ppat_desc with
4545
| Ppat_tuple pl -> pl |> List.iter processPattern
4646
| Ppat_record (fields, _) ->
47-
fields |> List.iter (fun (_, p) -> processPattern p)
47+
fields |> List.iter (fun (_, p, _) -> processPattern p)
4848
| Ppat_array fields -> fields |> List.iter processPattern
4949
| Ppat_var {loc} -> push loc Type
5050
| _ -> ()

analysis/src/ProcessCmt.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ let rec forStructureItem ~env ~(exported : Exported.t) item =
459459
pats |> List.iter (fun p -> handlePattern [] p)
460460
| Tpat_or (p, _, _) -> handlePattern [] p
461461
| Tpat_record (items, _) ->
462-
items |> List.iter (fun (_, _, p) -> handlePattern [] p)
462+
items |> List.iter (fun (_, _, p, _) -> handlePattern [] p)
463463
| Tpat_lazy p -> handlePattern [] p
464464
| Tpat_variant (_, Some p, _) -> handlePattern [] p
465465
| Tpat_variant (_, None, _) | Tpat_any | Tpat_constant _ -> ()

analysis/src/ProcessExtra.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ let addForRecord ~env ~extra ~recordType items =
237237
| Tconstr (path, _args, _memo) ->
238238
let t = getTypeAtPath ~env path in
239239
items
240-
|> List.iter (fun ({Asttypes.txt; loc}, _, _) ->
240+
|> List.iter (fun ({Asttypes.txt; loc}, _, _, _) ->
241241
(* let name = Longident.last(txt); *)
242242
let name = handleConstructor txt in
243243
let nameLoc = Utils.endOfLocation loc (String.length name) in
@@ -394,9 +394,9 @@ let expr ~env ~(extra : extra) (iter : Tast_iterator.iterator)
394394
| Texp_record {fields} ->
395395
addForRecord ~env ~extra ~recordType:expression.exp_type
396396
(fields |> Array.to_list
397-
|> Utils.filterMap (fun (desc, item) ->
397+
|> Utils.filterMap (fun (desc, item, opt) ->
398398
match item with
399-
| Typedtree.Overridden (loc, _) -> Some (loc, desc, ())
399+
| Typedtree.Overridden (loc, _) -> Some (loc, desc, (), opt)
400400
| _ -> None))
401401
| Texp_constant constant ->
402402
addLocItem extra expression.exp_loc (Constant constant)

0 commit comments

Comments
 (0)