Skip to content

Commit e3deedb

Browse files
authored
flambda-backend: Factor out kernel of Language_extension used by Jane Syntax (#1509)
* Make Jane Syntax depend on less of `Language_extension` * Add new module to compilerlibs * Fix broken dependencies * improve comments * Remove dependency of [Jane_syntax_parsing] on a binding that isn't available in upstream ocaml * Adapt comments from review: implicitly functorize over a smaller number of bindings * co-locate extension names
1 parent eea5150 commit e3deedb

File tree

11 files changed

+212
-104
lines changed

11 files changed

+212
-104
lines changed

.depend

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,20 @@ utils/int_replace_polymorphic_compare.cmx : \
129129
utils/int_replace_polymorphic_compare.cmi :
130130
utils/language_extension.cmo : \
131131
utils/misc.cmi \
132+
utils/language_extension_kernel.cmi \
132133
utils/language_extension.cmi
133134
utils/language_extension.cmx : \
134135
utils/misc.cmx \
136+
utils/language_extension_kernel.cmx \
135137
utils/language_extension.cmi
136-
utils/language_extension.cmi :
138+
utils/language_extension.cmi : \
139+
utils/language_extension_kernel.cmi
140+
utils/language_extension_kernel.cmo : \
141+
utils/language_extension_kernel.cmi
142+
utils/language_extension_kernel.cmx : \
143+
utils/language_extension_kernel.cmi
144+
utils/language_extension_kernel.cmi :
145+
utils/language_extension_kernel_intf.cmi :
137146
utils/lazy_backtrack.cmo : \
138147
utils/lazy_backtrack.cmi
139148
utils/lazy_backtrack.cmx : \
@@ -315,7 +324,6 @@ parsing/ast_mapper.cmo : \
315324
parsing/longident.cmi \
316325
parsing/location.cmi \
317326
utils/load_path.cmi \
318-
parsing/jane_syntax_parsing.cmi \
319327
parsing/jane_syntax.cmi \
320328
utils/config.cmi \
321329
utils/clflags.cmi \
@@ -328,7 +336,6 @@ parsing/ast_mapper.cmx : \
328336
parsing/longident.cmx \
329337
parsing/location.cmx \
330338
utils/load_path.cmx \
331-
parsing/jane_syntax_parsing.cmx \
332339
parsing/jane_syntax.cmx \
333340
utils/config.cmx \
334341
utils/clflags.cmx \
@@ -450,19 +457,18 @@ parsing/jane_syntax.cmi : \
450457
parsing/parsetree.cmi \
451458
parsing/longident.cmi \
452459
parsing/location.cmi \
453-
parsing/jane_syntax_parsing.cmi \
454460
parsing/asttypes.cmi
455461
parsing/jane_syntax_parsing.cmo : \
456462
parsing/parsetree.cmi \
457-
utils/misc.cmi \
458463
parsing/location.cmi \
464+
utils/language_extension_kernel.cmi \
459465
utils/language_extension.cmi \
460466
parsing/ast_helper.cmi \
461467
parsing/jane_syntax_parsing.cmi
462468
parsing/jane_syntax_parsing.cmx : \
463469
parsing/parsetree.cmi \
464-
utils/misc.cmx \
465470
parsing/location.cmx \
471+
utils/language_extension_kernel.cmx \
466472
utils/language_extension.cmx \
467473
parsing/ast_helper.cmx \
468474
parsing/jane_syntax_parsing.cmi
@@ -534,6 +540,7 @@ parsing/parser.cmo : \
534540
parsing/parsetree.cmi \
535541
parsing/longident.cmi \
536542
parsing/location.cmi \
543+
utils/language_extension.cmi \
537544
parsing/jane_syntax_parsing.cmi \
538545
parsing/jane_syntax.cmi \
539546
parsing/docstrings.cmi \
@@ -548,6 +555,7 @@ parsing/parser.cmx : \
548555
parsing/parsetree.cmi \
549556
parsing/longident.cmx \
550557
parsing/location.cmx \
558+
utils/language_extension.cmx \
551559
parsing/jane_syntax_parsing.cmx \
552560
parsing/jane_syntax.cmx \
553561
parsing/docstrings.cmx \
@@ -1663,6 +1671,7 @@ typing/typedecl.cmo : \
16631671
parsing/longident.cmi \
16641672
parsing/location.cmi \
16651673
typing/layouts.cmi \
1674+
parsing/jane_syntax.cmi \
16661675
typing/includecore.cmi \
16671676
typing/ident.cmi \
16681677
typing/errortrace.cmi \
@@ -1696,6 +1705,7 @@ typing/typedecl.cmx : \
16961705
parsing/longident.cmx \
16971706
parsing/location.cmx \
16981707
typing/layouts.cmx \
1708+
parsing/jane_syntax.cmx \
16991709
typing/includecore.cmx \
17001710
typing/ident.cmx \
17011711
typing/errortrace.cmx \
@@ -2088,7 +2098,6 @@ typing/untypeast.cmo : \
20882098
parsing/parsetree.cmi \
20892099
parsing/longident.cmi \
20902100
parsing/location.cmi \
2091-
parsing/jane_syntax_parsing.cmi \
20922101
parsing/jane_syntax.cmi \
20932102
typing/ident.cmi \
20942103
typing/env.cmi \
@@ -2101,7 +2110,6 @@ typing/untypeast.cmx : \
21012110
parsing/parsetree.cmi \
21022111
parsing/longident.cmx \
21032112
parsing/location.cmx \
2104-
parsing/jane_syntax_parsing.cmx \
21052113
parsing/jane_syntax.cmx \
21062114
typing/ident.cmx \
21072115
typing/env.cmx \

compilerlibs/Makefile.compilerlibs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ UTILS = \
3535
utils/load_path.cmo \
3636
utils/clflags.cmo \
3737
utils/debug.cmo \
38+
utils/language_extension_kernel.cmo \
3839
utils/language_extension.cmo \
3940
utils/profile.cmo \
4041
utils/terminfo.cmo \
@@ -53,7 +54,7 @@ UTILS = \
5354
utils/lazy_backtrack.cmo \
5455
utils/diffing.cmo \
5556
utils/diffing_with_keys.cmo
56-
UTILS_CMI =
57+
UTILS_CMI = \
5758

5859
PARSING = \
5960
parsing/location.cmo \

dune

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@
5858
debug profile terminfo ccomp warnings consistbl strongly_connected_components
5959
targetint load_path int_replace_polymorphic_compare domainstate binutils
6060
local_store target_system compilation_unit import_info linkage_name symbol
61-
lazy_backtrack diffing diffing_with_keys language_extension
61+
lazy_backtrack diffing diffing_with_keys
62+
language_extension_kernel language_extension
6263

6364
;; PARSING
6465
location longident docstrings syntaxerr ast_helper camlinternalMenhirLib

otherlibs/dynlink/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ COMPILERLIBS_SOURCES=\
8282
utils/load_path.ml \
8383
utils/clflags.ml \
8484
utils/debug.ml \
85+
utils/language_extension_kernel.ml \
8586
utils/language_extension.ml \
8687
utils/profile.ml \
8788
utils/consistbl.ml \

otherlibs/dynlink/dune

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
arg_helper
3333
clflags
3434
debug
35+
language_extension_kernel
3536
language_extension
3637
profile
3738
consistbl
@@ -111,6 +112,7 @@
111112
(copy_files ../../utils/arg_helper.ml)
112113
(copy_files ../../utils/clflags.ml)
113114
(copy_files ../../utils/debug.ml)
115+
(copy_files ../../utils/language_extension_kernel.ml)
114116
(copy_files ../../utils/language_extension.ml)
115117
(copy_files ../../utils/profile.ml)
116118
(copy_files ../../utils/consistbl.ml)
@@ -168,6 +170,7 @@
168170
(copy_files ../../utils/arg_helper.mli)
169171
(copy_files ../../utils/clflags.mli)
170172
(copy_files ../../utils/debug.mli)
173+
(copy_files ../../utils/language_extension_kernel.mli)
171174
(copy_files ../../utils/language_extension.mli)
172175
(copy_files ../../utils/profile.mli)
173176
(copy_files ../../utils/consistbl.mli)
@@ -267,6 +270,7 @@
267270
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Profile.cmo
268271
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Clflags.cmo
269272
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Debug.cmo
273+
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Language_extension_kernel.cmo
270274
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Language_extension.cmo
271275
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Terminfo.cmo
272276
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Location.cmo
@@ -339,6 +343,7 @@
339343
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Profile.cmx
340344
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Clflags.cmx
341345
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Debug.cmx
346+
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Language_extension_kernel.cmx
342347
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Language_extension.cmx
343348
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Terminfo.cmx
344349
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Location.cmx

parsing/jane_syntax_parsing.ml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@
7979

8080
open Parsetree
8181

82+
(** We carefully regulate which bindings we import from [Language_extension]
83+
to ensure that we can import this file into the Jane Street internal
84+
repo with no changes.
85+
*)
86+
module Language_extension = struct
87+
include Language_extension_kernel
88+
include (
89+
Language_extension
90+
: Language_extension_kernel.Language_extension_for_jane_syntax)
91+
end
92+
8293
(******************************************************************************)
8394

8495
module Feature : sig
@@ -777,7 +788,7 @@ module Make_ast (AST : AST_internal) : AST with type ast = AST.ast = struct
777788
let make_entire_jane_syntax ~loc feature ast =
778789
AST.with_location
779790
(make_jane_syntax feature []
780-
(Ast_helper.with_default_loc (Location.ghostify loc) ast))
791+
(Ast_helper.with_default_loc { loc with loc_ghost = true } ast))
781792
loc
782793

783794
(** Generically lift our custom ASTs for our novel syntax from OCaml ASTs. *)

tools/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ OCAMLPROF=config.cmo build_path_prefix_map.cmo misc.cmo identifiable.cmo \
8686
numbers.cmo arg_helper.cmo clflags.cmo debug.cmo terminfo.cmo \
8787
warnings.cmo location.cmo longident.cmo docstrings.cmo \
8888
syntaxerr.cmo ast_helper.cmo \
89-
language_extension.cmo jane_syntax_parsing.cmo jane_syntax.cmo \
89+
language_extension_kernel.cmo language_extension.cmo \
90+
jane_syntax_parsing.cmo jane_syntax.cmo \
9091
ast_iterator.cmo builtin_attributes.cmo \
9192
camlinternalMenhirLib.cmo parser.cmo \
9293
pprintast.cmo \
@@ -99,7 +100,8 @@ opt.opt: profiling.cmx
99100

100101
OCAMLCP = config.cmo build_path_prefix_map.cmo misc.cmo profile.cmo \
101102
warnings.cmo identifiable.cmo numbers.cmo arg_helper.cmo \
102-
language_extension.cmo clflags.cmo local_store.cmo \
103+
language_extension_kernel.cmo language_extension.cmo \
104+
clflags.cmo local_store.cmo \
103105
terminfo.cmo location.cmo load_path.cmo ccomp.cmo compenv.cmo \
104106
main_args.cmo
105107

utils/language_extension.ml

Lines changed: 8 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
include Language_extension_kernel
2+
13
(* operations we want on every extension level *)
24
module type Extension_level = sig
35
type t
@@ -18,7 +20,7 @@ module Unit = struct
1820
end
1921

2022
module Maturity = struct
21-
type t = Stable | Beta | Alpha
23+
type t = maturity = Stable | Beta | Alpha
2224

2325
let compare t1 t2 =
2426
let rank = function
@@ -39,34 +41,6 @@ module Maturity = struct
3941
| Alpha -> "_alpha"
4042
end
4143

42-
type maturity = Maturity.t = Stable | Beta | Alpha
43-
44-
(* Remember to update [all] when changing this type. *)
45-
type _ t =
46-
| Comprehensions : unit t
47-
| Local : unit t
48-
| Include_functor : unit t
49-
| Polymorphic_parameters : unit t
50-
| Immutable_arrays : unit t
51-
| Module_strengthening : unit t
52-
| Layouts : Maturity.t t
53-
54-
type exist =
55-
Pack : _ t -> exist
56-
57-
let all : exist list =
58-
[ Pack Comprehensions
59-
; Pack Local
60-
; Pack Include_functor
61-
; Pack Polymorphic_parameters
62-
; Pack Immutable_arrays
63-
; Pack Module_strengthening
64-
; Pack Layouts
65-
]
66-
67-
type extn_pair =
68-
| Pair : 'a t * 'a -> extn_pair
69-
7044
let get_level_ops : type a. a t -> (module Extension_level with type t = a) =
7145
function
7246
| Comprehensions -> (module Unit)
@@ -77,47 +51,17 @@ let get_level_ops : type a. a t -> (module Extension_level with type t = a) =
7751
| Module_strengthening -> (module Unit)
7852
| Layouts -> (module Maturity)
7953

54+
type extn_pair = Exist_pair.t = Pair : 'a t * 'a -> extn_pair
55+
type exist = Exist.t = Pack : _ t -> exist
56+
8057
(**********************************)
8158
(* string conversions *)
8259

83-
let to_string : type a. a t -> string = function
84-
| Comprehensions -> "comprehensions"
85-
| Local -> "local"
86-
| Include_functor -> "include_functor"
87-
| Polymorphic_parameters -> "polymorphic_parameters"
88-
| Immutable_arrays -> "immutable_arrays"
89-
| Module_strengthening -> "module_strengthening"
90-
| Layouts -> "layouts"
91-
92-
(* converts full extension names, like "layouts_alpha" to a pair of
93-
an extension and its setting *)
94-
let pair_of_string extn_name : extn_pair option =
95-
match String.lowercase_ascii extn_name with
96-
| "comprehensions" -> Some (Pair (Comprehensions, ()))
97-
| "local" -> Some (Pair (Local, ()))
98-
| "include_functor" -> Some (Pair (Include_functor, ()))
99-
| "polymorphic_parameters" -> Some (Pair (Polymorphic_parameters, ()))
100-
| "immutable_arrays" -> Some (Pair (Immutable_arrays, ()))
101-
| "module_strengthening" -> Some (Pair (Module_strengthening, ()))
102-
| "layouts" -> Some (Pair (Layouts, (Stable : Maturity.t)))
103-
| "layouts_beta" -> Some (Pair (Layouts, (Beta : Maturity.t)))
104-
| "layouts_alpha" -> Some (Pair (Layouts, (Alpha : Maturity.t)))
105-
| _ -> None
106-
10760
let pair_of_string_exn extn_name = match pair_of_string extn_name with
10861
| Some pair -> pair
10962
| None ->
11063
raise (Arg.Bad(Printf.sprintf "Extension %s is not known" extn_name))
11164

112-
let of_string extn_name =
113-
let pack (Pair (extn, _) : extn_pair) = Pack extn in
114-
Option.map pack (pair_of_string extn_name)
115-
116-
let maturity_to_string = function
117-
| Alpha -> "alpha"
118-
| Beta -> "beta"
119-
| Stable -> "stable"
120-
12165
(************************************)
12266
(* equality *)
12367

@@ -137,25 +81,6 @@ let equal a b = Option.is_some (equal_t a b)
13781
(*****************************)
13882
(* extension universes *)
13983

140-
(* We'll do this in a more principled way later. *)
141-
(* CR layouts: Note that layouts is only "mostly" erasable, because of annoying
142-
interactions with the pre-layouts [@@immediate] attribute like:
143-
144-
type ('a : immediate) t = 'a [@@immediate]
145-
146-
But we've decided to punt on this issue in the short term.
147-
*)
148-
let is_erasable : type a. a t -> bool = function
149-
| Local
150-
| Layouts ->
151-
true
152-
| Comprehensions
153-
| Include_functor
154-
| Polymorphic_parameters
155-
| Immutable_arrays
156-
| Module_strengthening ->
157-
false
158-
15984
module Universe : sig
16085
val is_allowed : 'a t -> bool
16186
val check : 'a t -> unit
@@ -304,7 +229,7 @@ let enable_maximal () =
304229
let (module Ops) = get_level_ops extn in
305230
Pair (extn, Ops.max_value)
306231
in
307-
extensions := List.map maximal_pair all
232+
extensions := List.map maximal_pair Exist.all
308233

309234
let restrict_to_erasable_extensions () =
310235
let changed = Universe.set Only_erasable in
@@ -340,9 +265,7 @@ let is_enabled extn =
340265

341266

342267
module Exist = struct
343-
type 'a extn = 'a t
344-
type t = exist =
345-
| Pack : 'a extn -> t
268+
include Exist
346269

347270
let to_command_line_strings (Pack extn) =
348271
let (module Ops) = get_level_ops extn in
@@ -358,6 +281,4 @@ module Exist = struct
358281

359282
let is_erasable : t -> bool = function
360283
| Pack extn -> is_erasable extn
361-
362-
let all = all
363284
end

0 commit comments

Comments
 (0)