Skip to content

Commit bc1d15a

Browse files
authored
flambda-backend: Remove ast_desc and ast_info from jane-syntax (#1488)
* Remove ast_desc and ast_info from jane-syntax * Remove optional parameters from jane-syntax
1 parent be57ed6 commit bc1d15a

File tree

9 files changed

+6544
-6773
lines changed

9 files changed

+6544
-6773
lines changed

boot/menhir/parser.ml

Lines changed: 6408 additions & 6477 deletions
Large diffs are not rendered by default.

parsing/ast_mapper.ml

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,10 @@ module T = struct
154154
match Jane_syntax.Core_type.of_ast typ with
155155
| Some (jtyp, attrs) -> begin
156156
let attrs = sub.attributes sub attrs in
157-
Jane_syntax_parsing.Core_type.wrap_desc ~loc ~info:attrs @@
158-
match sub.typ_jane_syntax sub jtyp with
159-
| _ -> .
157+
let typ = match sub.typ_jane_syntax sub jtyp with
158+
| _ -> .
159+
in
160+
{ typ with ptyp_attributes = attrs @ typ.ptyp_attributes }
160161
end
161162
| None ->
162163
let attrs = sub.attributes sub attrs in
@@ -254,16 +255,14 @@ module T = struct
254255
let name = map_loc sub pext_name in
255256
match Jane_syntax.Extension_constructor.of_ast ext with
256257
| Some (jext, attrs) -> begin
257-
let attrs = sub.attributes sub attrs in
258-
Jane_syntax_parsing.Extension_constructor.wrap_desc
259-
~loc ~info:(attrs, name) @@
258+
let _attrs = sub.attributes sub attrs in
260259
match sub.extension_constructor_jane_syntax sub jext with
261260
| _ -> .
262261
end
263262
| None ->
264263
let attrs = sub.attributes sub pext_attributes in
265264
Te.constructor ~loc ~attrs
266-
(map_loc sub pext_name)
265+
name
267266
(map_extension_constructor_kind sub pext_kind)
268267

269268
end
@@ -321,9 +320,8 @@ module MT = struct
321320
match Jane_syntax.Module_type.of_ast mty with
322321
| Some (jmty, attrs) -> begin
323322
let attrs = sub.attributes sub attrs in
324-
Jane_syntax_parsing.Module_type.wrap_desc ~loc ~info:attrs @@
325323
match sub.module_type_jane_syntax sub jmty with
326-
| Jmty_strengthen smty -> Jane_syntax.Strengthen.mty_of ~loc smty
324+
| Jmty_strengthen smty -> Jane_syntax.Strengthen.mty_of ~loc ~attrs smty
327325
end
328326
| None ->
329327
let attrs = sub.attributes sub attrs in
@@ -373,7 +371,6 @@ module MT = struct
373371
let loc = sub.location sub loc in
374372
match Jane_syntax.Signature_item.of_ast sigi with
375373
| Some jsigi -> begin
376-
Jane_syntax_parsing.Signature_item.wrap_desc ~loc ~info:() @@
377374
match sub.signature_item_jane_syntax sub jsigi with
378375
| Jsig_include_functor incl ->
379376
Jane_syntax.Include_functor.sig_item_of ~loc incl
@@ -453,7 +450,6 @@ module M = struct
453450
let loc = sub.location sub loc in
454451
match Jane_syntax.Structure_item.of_ast stri with
455452
| Some jstri -> begin
456-
Jane_syntax_parsing.Structure_item.wrap_desc ~loc ~info:() @@
457453
match sub.structure_item_jane_syntax sub jstri with
458454
| Jstr_include_functor incl ->
459455
Jane_syntax.Include_functor.str_item_of ~loc incl
@@ -540,8 +536,8 @@ module E = struct
540536
match Jane_syntax.Expression.of_ast exp with
541537
| Some (jexp, attrs) -> begin
542538
let attrs = sub.attributes sub attrs in
543-
Jane_syntax_parsing.Expression.wrap_desc ~loc ~info:attrs
544-
(Jane_syntax.Expression.expr_of ~loc (sub.expr_jane_syntax sub jexp))
539+
Jane_syntax.Expression.expr_of ~loc ~attrs
540+
(sub.expr_jane_syntax sub jexp)
545541
end
546542
| None ->
547543
let attrs = sub.attributes sub attrs in
@@ -658,8 +654,7 @@ module P = struct
658654
match Jane_syntax.Pattern.of_ast pat with
659655
| Some (jpat, attrs) -> begin
660656
let attrs = sub.attributes sub attrs in
661-
Jane_syntax_parsing.Pattern.wrap_desc ~loc ~info:attrs @@
662-
Jane_syntax.Pattern.pat_of ~loc (sub.pat_jane_syntax sub jpat)
657+
Jane_syntax.Pattern.pat_of ~loc ~attrs (sub.pat_jane_syntax sub jpat)
663658
end
664659
| None ->
665660
let attrs = sub.attributes sub attrs in

parsing/jane_syntax.ml

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ open Jane_syntax_parsing
4141
future syntax features to remember to do this wrapping.
4242
*)
4343

44-
module With_attributes = With_attributes
45-
4644
(** List and array comprehensions *)
4745
module Comprehensions = struct
4846
let feature : Feature.t = Language_extension Comprehensions
@@ -94,9 +92,7 @@ module Comprehensions = struct
9492
v}
9593
*)
9694

97-
let comprehension_expr names x =
98-
Expression.wrap_desc ~info:[] ~loc:x.pexp_loc @@
99-
Expression.make_jane_syntax feature names x
95+
let comprehension_expr names x = Expression.make_jane_syntax feature names x
10096

10197
(** First, we define how to go from the nice AST to the OCaml AST; this is
10298
the [expr_of_...] family of expressions, culminating in
@@ -143,9 +139,9 @@ module Comprehensions = struct
143139
clauses
144140
(comprehension_expr ["body"] body)))
145141

146-
let expr_of ~loc cexpr =
142+
let expr_of ~loc ~attrs cexpr =
147143
(* See Note [Wrapping with make_entire_jane_syntax] *)
148-
Expression.make_entire_jane_syntax ~loc feature (fun () ->
144+
let expr = Expression.make_entire_jane_syntax ~loc feature (fun () ->
149145
match cexpr with
150146
| Cexp_list_comprehension comp ->
151147
expr_of_comprehension ~type_:["list"] comp
@@ -157,6 +153,8 @@ module Comprehensions = struct
157153
| Immutable -> "immutable"
158154
]
159155
comp)
156+
in
157+
{ expr with pexp_attributes = expr.pexp_attributes @ attrs }
160158

161159
(** Then, we define how to go from the OCaml AST to the nice AST; this is
162160
the [..._of_expr] family of expressions, culminating in
@@ -286,22 +284,22 @@ module Immutable_arrays = struct
286284

287285
let feature : Feature.t = Language_extension Immutable_arrays
288286

289-
let expr_of ~loc = function
287+
let expr_of ~loc ~attrs = function
290288
| Iaexp_immutable_array elts ->
291289
(* See Note [Wrapping with make_entire_jane_syntax] *)
292290
Expression.make_entire_jane_syntax ~loc feature (fun () ->
293-
Ast_helper.Exp.array elts)
291+
Ast_helper.Exp.array ~attrs elts)
294292

295293
(* Returns remaining unconsumed attributes *)
296294
let of_expr expr = match expr.pexp_desc with
297295
| Pexp_array elts -> Iaexp_immutable_array elts, expr.pexp_attributes
298296
| _ -> failwith "Malformed immutable array expression"
299297

300-
let pat_of ~loc = function
298+
let pat_of ~loc ~attrs = function
301299
| Iapat_immutable_array elts ->
302300
(* See Note [Wrapping with make_entire_jane_syntax] *)
303301
Pattern.make_entire_jane_syntax ~loc feature (fun () ->
304-
Ast_helper.Pat.array elts)
302+
Ast_helper.Pat.array ~attrs elts)
305303

306304
(* Returns remaining unconsumed attributes *)
307305
let of_pat pat = match pat.ppat_desc with
@@ -351,10 +349,10 @@ module Strengthen = struct
351349
the [(module M)] is a [Pmty_alias]. This isn't syntax we can write, but
352350
[(module M)] can be the inferred type for [M], so this should be fine. *)
353351

354-
let mty_of ~loc { mty; mod_id } =
352+
let mty_of ~loc ~attrs { mty; mod_id } =
355353
(* See Note [Wrapping with make_entire_jane_syntax] *)
356354
Module_type.make_entire_jane_syntax ~loc feature (fun () ->
357-
Ast_helper.Mty.functor_ (Named (Location.mknoloc None, mty))
355+
Ast_helper.Mty.functor_ ~attrs (Named (Location.mknoloc None, mty))
358356
(Ast_helper.Mty.alias mod_id))
359357

360358
(* Returns remaining unconsumed attributes *)
@@ -404,15 +402,15 @@ module Unboxed_constants = struct
404402
| Float (x, suffix) -> Pconst_float (x, suffix)
405403
| Integer (x, suffix) -> Pconst_integer (x, Some suffix)
406404

407-
let expr_of ~loc t =
405+
let expr_of ~loc ~attrs t =
408406
let constant = constant_of t in
409407
Expression.make_entire_jane_syntax ~loc feature (fun () ->
410-
Ast_helper.Exp.constant constant)
408+
Ast_helper.Exp.constant ~attrs constant)
411409

412-
let pat_of ~loc t =
410+
let pat_of ~loc ~attrs t =
413411
let constant = constant_of t in
414412
Pattern.make_entire_jane_syntax ~loc feature (fun () ->
415-
Ast_helper.Pat.constant constant)
413+
Ast_helper.Pat.constant ~attrs constant)
416414
end
417415

418416
(******************************************************************************)
@@ -463,10 +461,10 @@ module Expression = struct
463461

464462
let of_ast = Expression.make_of_ast ~of_ast_internal
465463

466-
let expr_of ~loc = function
467-
| Jexp_comprehension x -> Comprehensions.expr_of ~loc x
468-
| Jexp_immutable_array x -> Immutable_arrays.expr_of ~loc x
469-
| Jexp_unboxed_constant x -> Unboxed_constants.expr_of ~loc x
464+
let expr_of ~loc ~attrs = function
465+
| Jexp_comprehension x -> Comprehensions.expr_of ~loc ~attrs x
466+
| Jexp_immutable_array x -> Immutable_arrays.expr_of ~loc ~attrs x
467+
| Jexp_unboxed_constant x -> Unboxed_constants.expr_of ~loc ~attrs x
470468
end
471469

472470
module Pattern = struct
@@ -485,9 +483,9 @@ module Pattern = struct
485483

486484
let of_ast = Pattern.make_of_ast ~of_ast_internal
487485

488-
let pat_of ~loc = function
489-
| Jpat_immutable_array x -> Immutable_arrays.pat_of ~loc x
490-
| Jpat_unboxed_constant x -> Unboxed_constants.pat_of ~loc x
486+
let pat_of ~loc ~attrs = function
487+
| Jpat_immutable_array x -> Immutable_arrays.pat_of ~loc ~attrs x
488+
| Jpat_unboxed_constant x -> Unboxed_constants.pat_of ~loc ~attrs x
491489
end
492490

493491
module Module_type = struct

parsing/jane_syntax.mli

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,6 @@
2323
(*********************************************)
2424
(* Individual features *)
2525

26-
(** An AST desc together with its attributes, including the attributes that
27-
signal that the AST should be interpreted as a Jane Syntax AST.
28-
*)
29-
module With_attributes : sig
30-
type 'desc t = 'desc Jane_syntax_parsing.With_attributes.t = private
31-
{ jane_syntax_attributes : Parsetree.attributes
32-
; desc : 'desc
33-
}
34-
end
35-
3626
(** The ASTs for list and array comprehensions *)
3727
module Comprehensions : sig
3828
type iterator =
@@ -72,7 +62,8 @@ module Comprehensions : sig
7262
(only allowed with [-extension immutable_arrays]) *)
7363

7464
val expr_of :
75-
loc:Location.t -> expression -> Parsetree.expression_desc With_attributes.t
65+
loc:Location.t -> attrs:Parsetree.attributes ->
66+
expression -> Parsetree.expression
7667
end
7768

7869
(** The ASTs for immutable arrays. When we merge this upstream, we'll merge
@@ -88,10 +79,11 @@ module Immutable_arrays : sig
8879
(** [: P1; ...; Pn :] **)
8980

9081
val expr_of :
91-
loc:Location.t -> expression -> Parsetree.expression_desc With_attributes.t
92-
82+
loc:Location.t -> attrs:Parsetree.attributes ->
83+
expression -> Parsetree.expression
9384
val pat_of :
94-
loc:Location.t -> pattern -> Parsetree.pattern_desc With_attributes.t
85+
loc:Location.t -> attrs:Parsetree.attributes ->
86+
pattern -> Parsetree.pattern
9587
end
9688

9789
(** The ASTs for [include functor]. When we merge this upstream, we'll merge
@@ -104,10 +96,8 @@ module Include_functor : sig
10496
type structure_item =
10597
| Ifstr_include_functor of Parsetree.include_declaration
10698

107-
val sig_item_of :
108-
loc:Location.t -> signature_item -> Parsetree.signature_item_desc
109-
val str_item_of :
110-
loc:Location.t -> structure_item -> Parsetree.structure_item_desc
99+
val sig_item_of : loc:Location.t -> signature_item -> Parsetree.signature_item
100+
val str_item_of : loc:Location.t -> structure_item -> Parsetree.structure_item
111101
end
112102

113103
(** The ASTs for module type strengthening. *)
@@ -116,9 +106,8 @@ module Strengthen : sig
116106
{ mty : Parsetree.module_type; mod_id : Longident.t Location.loc }
117107

118108
val mty_of :
119-
loc:Location.t
120-
-> module_type
121-
-> Parsetree.module_type_desc With_attributes.t
109+
loc:Location.t -> attrs:Parsetree.attributes ->
110+
module_type -> Parsetree.module_type
122111
end
123112

124113
(** The ASTs for unboxed literals, like #4.0 *)
@@ -131,10 +120,12 @@ module Unboxed_constants : sig
131120
type pattern = t
132121

133122
val expr_of :
134-
loc:Location.t -> expression -> Parsetree.expression_desc With_attributes.t
123+
loc:Location.t -> attrs:Parsetree.attributes ->
124+
expression -> Parsetree.expression
135125

136126
val pat_of :
137-
loc:Location.t -> pattern -> Parsetree.pattern_desc With_attributes.t
127+
loc:Location.t -> attrs:Parsetree.attributes ->
128+
pattern -> Parsetree.pattern
138129
end
139130

140131
(******************************************)
@@ -244,7 +235,7 @@ module Expression : sig
244235
and type ast := Parsetree.expression
245236

246237
val expr_of :
247-
loc:Location.t -> t -> Parsetree.expression_desc With_attributes.t
238+
loc:Location.t -> attrs:Parsetree.attributes -> t -> Parsetree.expression
248239
end
249240

250241
(** Novel syntax in patterns *)
@@ -258,7 +249,7 @@ module Pattern : sig
258249
and type ast := Parsetree.pattern
259250

260251
val pat_of :
261-
loc:Location.t -> t -> Parsetree.pattern_desc With_attributes.t
252+
loc:Location.t -> attrs:Parsetree.attributes -> t -> Parsetree.pattern
262253
end
263254

264255
(** Novel syntax in module types *)
@@ -287,6 +278,7 @@ module Structure_item : sig
287278
include AST with type t := t and type ast := Parsetree.structure_item
288279
end
289280

281+
(** Novel syntax in extension constructors *)
290282
module Extension_constructor : sig
291283
type t = |
292284

0 commit comments

Comments
 (0)