Skip to content

Commit f2a5b93

Browse files
flambda-backend: Convert Jane Syntax to use attributes for many syntactic categories (#1412)
* Use attributes to encode modular syntax for expressions * Convert types to use attributes * Convert module types to use attributes * Switch pattern modular syntax to use attributes * Add tests for pprintast * Fix ocamlprof * remove some unnecessary module paths * Update ocaml/parsing/jane_syntax_parsing.ml Co-authored-by: Antal Spector-Zabusky <[email protected]> * Update ocaml/parsing/jane_syntax_parsing.ml Co-authored-by: Antal Spector-Zabusky <[email protected]> * Update ocaml/parsing/jane_syntax_parsing.ml Co-authored-by: Antal Spector-Zabusky <[email protected]> * Respond to review * respond to more review comments * Update ocaml/parsing/jane_syntax_parsing.mli Co-authored-by: Antal Spector-Zabusky <[email protected]> * edit test according to review * Whitespace artistry * Update ocaml/parsing/parser.mly Co-authored-by: Antal Spector-Zabusky <[email protected]> * Update ocaml/typing/parmatch.ml Co-authored-by: Antal Spector-Zabusky <[email protected]> * more review responding --------- Co-authored-by: Antal Spector-Zabusky <[email protected]>
1 parent 1e2d5c5 commit f2a5b93

34 files changed

+8236
-8057
lines changed

.depend

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,19 +450,20 @@ parsing/jane_syntax.cmi : \
450450
parsing/parsetree.cmi \
451451
parsing/longident.cmi \
452452
parsing/location.cmi \
453+
parsing/jane_syntax_parsing.cmi \
453454
parsing/asttypes.cmi
454455
parsing/jane_syntax_parsing.cmo : \
455456
parsing/parsetree.cmi \
457+
utils/misc.cmi \
456458
parsing/location.cmi \
457459
utils/language_extension.cmi \
458-
parsing/asttypes.cmi \
459460
parsing/ast_helper.cmi \
460461
parsing/jane_syntax_parsing.cmi
461462
parsing/jane_syntax_parsing.cmx : \
462463
parsing/parsetree.cmi \
464+
utils/misc.cmx \
463465
parsing/location.cmx \
464466
utils/language_extension.cmx \
465-
parsing/asttypes.cmi \
466467
parsing/ast_helper.cmx \
467468
parsing/jane_syntax_parsing.cmi
468469
parsing/jane_syntax_parsing.cmi : \
@@ -2079,6 +2080,7 @@ typing/untypeast.cmo : \
20792080
parsing/parsetree.cmi \
20802081
parsing/longident.cmi \
20812082
parsing/location.cmi \
2083+
parsing/jane_syntax_parsing.cmi \
20822084
parsing/jane_syntax.cmi \
20832085
typing/ident.cmi \
20842086
typing/env.cmi \
@@ -2091,6 +2093,7 @@ typing/untypeast.cmx : \
20912093
parsing/parsetree.cmi \
20922094
parsing/longident.cmx \
20932095
parsing/location.cmx \
2096+
parsing/jane_syntax_parsing.cmx \
20942097
parsing/jane_syntax.cmx \
20952098
typing/ident.cmx \
20962099
typing/env.cmx \

boot/menhir/parser.ml

Lines changed: 7254 additions & 7399 deletions
Large diffs are not rendered by default.

ocamldoc/odoc_sig.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,7 +1556,8 @@ module Analyser =
15561556
and analyse_module_type_kind
15571557
?(erased = Name.Map.empty) env current_module_name module_type sig_module_type =
15581558
match Jane_syntax.Module_type.of_ast module_type with
1559-
| Some (Jmty_strengthen _) -> failwith "strengthen not implemented yet"
1559+
| Some (Jmty_strengthen _, _attrs) ->
1560+
failwith "strengthen not implemented yet"
15601561
| None ->
15611562
match module_type.Parsetree.pmty_desc with
15621563
Parsetree.Pmty_ident longident ->
@@ -1657,7 +1658,8 @@ module Analyser =
16571658
and analyse_module_kind
16581659
?(erased = Name.Map.empty) env current_module_name module_type sig_module_type =
16591660
match Jane_syntax.Module_type.of_ast module_type with
1660-
| Some (Jmty_strengthen _) -> failwith "strengthen not implemented yet"
1661+
| Some (Jmty_strengthen _, _attrs) ->
1662+
failwith "strengthen not implemented yet"
16611663
| None ->
16621664
match module_type.Parsetree.pmty_desc with
16631665
| Parsetree.Pmty_ident _longident ->

parsing/ast_invariants.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ let iterator =
9090
end;
9191
let loc = exp.pexp_loc in
9292
match Jane_syntax.Expression.of_ast exp with
93-
| Some jexp -> jexpr self exp.pexp_loc jexp
93+
| Some (jexp, _attrs) -> jexpr self exp.pexp_loc jexp
9494
| None ->
9595
match exp.pexp_desc with
9696
| Pexp_tuple ([] | [_]) -> invalid_tuple loc

parsing/ast_iterator.ml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,12 @@ module T = struct
122122
let iter sub ({ptyp_desc = desc; ptyp_loc = loc; ptyp_attributes = attrs}
123123
as typ) =
124124
sub.location sub loc;
125-
sub.attributes sub attrs;
126125
match Jane_syntax.Core_type.of_ast typ with
127-
| Some jtyp -> sub.typ_jane_syntax sub jtyp
126+
| Some (jtyp, attrs) ->
127+
sub.attributes sub attrs;
128+
sub.typ_jane_syntax sub jtyp
128129
| None ->
130+
sub.attributes sub attrs;
129131
match desc with
130132
| Ptyp_any
131133
| Ptyp_var _ -> ()
@@ -260,10 +262,12 @@ module MT = struct
260262
let iter sub
261263
({pmty_desc = desc; pmty_loc = loc; pmty_attributes = attrs} as mty) =
262264
sub.location sub loc;
263-
sub.attributes sub attrs;
264265
match Jane_syntax.Module_type.of_ast mty with
265-
| Some jmty -> sub.module_type_jane_syntax sub jmty
266+
| Some (jmty, attrs) ->
267+
sub.attributes sub attrs;
268+
sub.module_type_jane_syntax sub jmty
266269
| None ->
270+
sub.attributes sub attrs;
267271
match desc with
268272
| Pmty_ident s -> iter_loc sub s
269273
| Pmty_alias s -> iter_loc sub s
@@ -429,10 +433,12 @@ module E = struct
429433
let iter sub
430434
({pexp_loc = loc; pexp_desc = desc; pexp_attributes = attrs} as expr)=
431435
sub.location sub loc;
432-
sub.attributes sub attrs;
433436
match Jane_syntax.Expression.of_ast expr with
434-
| Some jexp -> sub.expr_jane_syntax sub jexp
437+
| Some (jexp, attrs) ->
438+
sub.attributes sub attrs;
439+
sub.expr_jane_syntax sub jexp
435440
| None ->
441+
sub.attributes sub attrs;
436442
match desc with
437443
| Pexp_ident x -> iter_loc sub x
438444
| Pexp_constant _ -> ()
@@ -529,10 +535,12 @@ module P = struct
529535
let iter sub
530536
({ppat_desc = desc; ppat_loc = loc; ppat_attributes = attrs} as pat) =
531537
sub.location sub loc;
532-
sub.attributes sub attrs;
533538
match Jane_syntax.Pattern.of_ast pat with
534-
| Some jpat -> sub.pat_jane_syntax sub jpat
539+
| Some (jpat, attrs) ->
540+
sub.attributes sub attrs;
541+
sub.pat_jane_syntax sub jpat
535542
| None ->
543+
sub.attributes sub attrs;
536544
match desc with
537545
| Ppat_any -> ()
538546
| Ppat_var s -> iter_loc sub s

parsing/ast_mapper.ml

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,15 @@ module T = struct
146146
as typ) =
147147
let open Typ in
148148
let loc = sub.location sub loc in
149-
let attrs = sub.attributes sub attrs in
150149
match Jane_syntax.Core_type.of_ast typ with
151-
| Some jtyp -> begin
152-
Jane_syntax_parsing.Core_type.wrap_desc ~loc ~attrs @@
150+
| Some (jtyp, attrs) -> begin
151+
let attrs = sub.attributes sub attrs in
152+
Jane_syntax_parsing.AST.wrap_desc Core_type ~loc ~attrs @@
153153
match sub.typ_jane_syntax sub jtyp with
154154
| _ -> .
155155
end
156156
| None ->
157+
let attrs = sub.attributes sub attrs in
157158
match desc with
158159
| Ptyp_any -> any ~loc ~attrs ()
159160
| Ptyp_var s -> var ~loc ~attrs s
@@ -298,14 +299,15 @@ module MT = struct
298299
({pmty_desc = desc; pmty_loc = loc; pmty_attributes = attrs} as mty) =
299300
let open Mty in
300301
let loc = sub.location sub loc in
301-
let attrs = sub.attributes sub attrs in
302302
match Jane_syntax.Module_type.of_ast mty with
303-
| Some jmty -> begin
304-
Jane_syntax_parsing.Module_type.wrap_desc ~loc ~attrs @@
303+
| Some (jmty, attrs) -> begin
304+
let attrs = sub.attributes sub attrs in
305+
Jane_syntax_parsing.AST.wrap_desc Module_type ~loc ~attrs @@
305306
match sub.module_type_jane_syntax sub jmty with
306307
| Jmty_strengthen smty -> Jane_syntax.Strengthen.mty_of ~loc smty
307308
end
308309
| None ->
310+
let attrs = sub.attributes sub attrs in
309311
match desc with
310312
| Pmty_ident s -> ident ~loc ~attrs (map_loc sub s)
311313
| Pmty_alias s -> alias ~loc ~attrs (map_loc sub s)
@@ -352,7 +354,7 @@ module MT = struct
352354
let loc = sub.location sub loc in
353355
match Jane_syntax.Signature_item.of_ast sigi with
354356
| Some jsigi -> begin
355-
Jane_syntax_parsing.Signature_item.wrap_desc ~loc ~attrs:[] @@
357+
Jane_syntax_parsing.AST.wrap_desc Signature_item ~loc ~attrs:[] @@
356358
match sub.signature_item_jane_syntax sub jsigi with
357359
| Jsig_include_functor incl ->
358360
Jane_syntax.Include_functor.sig_item_of ~loc incl
@@ -432,7 +434,7 @@ module M = struct
432434
let loc = sub.location sub loc in
433435
match Jane_syntax.Structure_item.of_ast stri with
434436
| Some jstri -> begin
435-
Jane_syntax_parsing.Structure_item.wrap_desc ~loc ~attrs:[] @@
437+
Jane_syntax_parsing.AST.wrap_desc Structure_item ~loc ~attrs:[] @@
436438
match sub.structure_item_jane_syntax sub jstri with
437439
| Jstr_include_functor incl ->
438440
Jane_syntax.Include_functor.str_item_of ~loc incl
@@ -507,15 +509,16 @@ module E = struct
507509
({pexp_loc = loc; pexp_desc = desc; pexp_attributes = attrs} as exp) =
508510
let open Exp in
509511
let loc = sub.location sub loc in
510-
let attrs = sub.attributes sub attrs in
511512
match Jane_syntax.Expression.of_ast exp with
512-
| Some jexp -> begin
513-
Jane_syntax_parsing.Expression.wrap_desc ~loc ~attrs @@
513+
| Some (jexp, attrs) -> begin
514+
let attrs = sub.attributes sub attrs in
515+
Jane_syntax_parsing.AST.wrap_desc Expression ~loc ~attrs @@
514516
match sub.expr_jane_syntax sub jexp with
515517
| Jexp_comprehension c -> Jane_syntax.Comprehensions.expr_of ~loc c
516518
| Jexp_immutable_array i -> Jane_syntax.Immutable_arrays.expr_of ~loc i
517519
end
518520
| None ->
521+
let attrs = sub.attributes sub attrs in
519522
match desc with
520523
| Pexp_ident x -> ident ~loc ~attrs (map_loc sub x)
521524
| Pexp_constant x -> constant ~loc ~attrs (sub.constant sub x)
@@ -617,14 +620,15 @@ module P = struct
617620
({ppat_desc = desc; ppat_loc = loc; ppat_attributes = attrs} as pat) =
618621
let open Pat in
619622
let loc = sub.location sub loc in
620-
let attrs = sub.attributes sub attrs in
621623
match Jane_syntax.Pattern.of_ast pat with
622-
| Some jpat -> begin
623-
Jane_syntax_parsing.Pattern.wrap_desc ~loc ~attrs @@
624+
| Some (jpat, attrs) -> begin
625+
let attrs = sub.attributes sub attrs in
626+
Jane_syntax_parsing.AST.wrap_desc Pattern ~loc ~attrs @@
624627
match sub.pat_jane_syntax sub jpat with
625628
| Jpat_immutable_array i -> Jane_syntax.Immutable_arrays.pat_of ~loc i
626629
end
627630
| None ->
631+
let attrs = sub.attributes sub attrs in
628632
match desc with
629633
| Ppat_any -> any ~loc ~attrs ()
630634
| Ppat_var s -> var ~loc ~attrs (map_loc sub s)

parsing/depend.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ let handle_extension ext =
9797

9898
let rec add_type bv ty =
9999
match Jane_syntax.Core_type.of_ast ty with
100-
| Some jty -> add_type_jst bv jty
100+
| Some (jty, _attrs) -> add_type_jst bv jty
101101
| None ->
102102
match ty.ptyp_desc with
103103
Ptyp_any -> ()
@@ -173,7 +173,7 @@ let pattern_bv = ref String.Map.empty
173173

174174
let rec add_pattern bv pat =
175175
match Jane_syntax.Pattern.of_ast pat with
176-
| Some jpat -> add_pattern_jane_syntax bv jpat
176+
| Some (jpat, _attrs) -> add_pattern_jane_syntax bv jpat
177177
| None ->
178178
match pat.ppat_desc with
179179
Ppat_any -> ()
@@ -212,7 +212,7 @@ let add_pattern bv pat =
212212

213213
let rec add_expr bv exp =
214214
match Jane_syntax.Expression.of_ast exp with
215-
| Some jexp -> add_expr_jane_syntax bv jexp
215+
| Some (jexp, _attrs) -> add_expr_jane_syntax bv jexp
216216
| None ->
217217
match exp.pexp_desc with
218218
Pexp_ident l -> add bv l
@@ -347,7 +347,7 @@ and add_binding_op bv bv' pbop =
347347

348348
and add_modtype bv mty =
349349
match Jane_syntax.Module_type.of_ast mty with
350-
| Some jmty -> add_modtype_jane_syntax bv jmty
350+
| Some (jmty, _attrs) -> add_modtype_jane_syntax bv jmty
351351
| None ->
352352
match mty.pmty_desc with
353353
Pmty_ident l -> add bv l
@@ -397,7 +397,7 @@ and add_module_alias bv l =
397397

398398
and add_modtype_binding bv mty =
399399
match Jane_syntax.Module_type.of_ast mty with
400-
| Some jmty -> add_modtype_jane_syntax_binding bv jmty
400+
| Some (jmty, _attrs) -> add_modtype_jane_syntax_binding bv jmty
401401
| None ->
402402
match mty.pmty_desc with
403403
Pmty_alias l ->

0 commit comments

Comments
 (0)