Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
803b2c5
Extend `open`.
objmagic Apr 9, 2017
b9b4160
Merge branch 'trunk' into open-struct-final
objmagic Nov 19, 2017
52b9780
Fix problem after merge.
objmagic Nov 21, 2017
6822a05
remove hack.
objmagic Nov 21, 2017
7956bc7
Add tests.
objmagic Nov 21, 2017
20e94eb
Improve tests.
objmagic Nov 23, 2017
4dde10b
Fix leaked signature.
objmagic Nov 24, 2017
96ebd28
Add tests.
objmagic Nov 24, 2017
81cef41
Correct `open` for module sig.
objmagic Dec 1, 2017
632fd78
remove a whitespace
objmagic Dec 1, 2017
95cd814
Merge branch 'trunk' into open-struct-3
objmagic Dec 1, 2017
63e127c
Add Change entry.
objmagic Dec 2, 2017
db4a598
Do not use stack
objmagic Jan 18, 2018
9703a92
add comments, use protect_refs, etc
objmagic Jan 21, 2018
58e49b3
Merge branch 'trunk' into open-struct-3
objmagic Jan 21, 2018
d52c171
Add Alain and Florian as reviewers.
objmagic Jan 21, 2018
fc99647
save progress
objmagic Jan 30, 2018
a2bbf15
save
objmagic Feb 21, 2018
ee9e433
work.
objmagic Mar 10, 2018
9fc3c6b
tast_mapper should map env in od
objmagic Mar 18, 2018
fb8710d
Merge branch 'trunk' into open-struct-3-let
objmagic Mar 18, 2018
75d66d3
merge cont
objmagic Mar 18, 2018
c7334a4
fix type_open_
objmagic Mar 18, 2018
b3d830d
printast for Pexp_open
objmagic Mar 18, 2018
ab97d5e
Pexp_open working
objmagic Mar 20, 2018
a2745c1
add tests
objmagic Mar 21, 2018
67abcbf
Merge branch 'trunk' into open-struct-3
objmagic Mar 21, 2018
9a9860c
Merge branch 'trunk' into open-struct-3
objmagic Mar 25, 2018
d56579a
remove unused file
objmagic Mar 25, 2018
ca36b0d
clean up and and more tests.
objmagic Mar 25, 2018
1ad2061
some clean-ups
objmagic Mar 26, 2018
6856b39
style and minor improv
objmagic Mar 28, 2018
c3e4845
Ppat_open only accepts id.
objmagic Mar 29, 2018
39a17ea
minor
objmagic Mar 29, 2018
97e9cb0
save progress
objmagic Mar 29, 2018
7566875
Merge branch 'trunk' into open-struct-3
objmagic Mar 29, 2018
0be2af4
use extract, clean-ups
objmagic Apr 1, 2018
76760bd
comment for `assert false`
objmagic Apr 1, 2018
b8a0d8f
protect mod_ident_counter
objmagic Apr 1, 2018
20b2f0f
rm comment
objmagic Apr 1, 2018
f061df1
no need to adapt to GPR#556
objmagic Apr 3, 2018
8ecdac8
remove a TODO
objmagic Apr 3, 2018
ef9c107
update parsing tests.
objmagic Apr 3, 2018
1b2349f
no need for Invalid_open
objmagic Apr 3, 2018
ef514bb
update tests
objmagic Apr 8, 2018
33bebad
style
objmagic Apr 8, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ Working version
(Nicolás Ojeda Bär, review by Gabriel Radanne, Damien Doligez, Gabriel
Scherer)

- GPR#1506: Extending `open` to accept arbitrary module expression
(Runhang Li, review by Alain Frisch, Florian Angeletti, Jeremy Yallop)

- GPR#1546: Allow empty variants
(Runhang Li, review by Gabriel Radanne and Jacques Garrigue)

Expand Down
8 changes: 4 additions & 4 deletions bytecomp/translclass.ml
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ let rec build_object_init cl_table obj params inh_init obj_init cl =
build_object_init cl_table obj (vals @ params) inh_init obj_init cl
in
(inh_init, Translcore.transl_let rec_flag defs obj_init)
| Tcl_open (_, _, _, _, cl)
| Tcl_open (_, cl)
| Tcl_constraint (cl, _, _, _, _) ->
build_object_init cl_table obj params inh_init obj_init cl

Expand Down Expand Up @@ -387,7 +387,7 @@ let rec build_class_init cla cstr super inh_init cl_init msubst top cl =
Lsequence(mkappl (oo_prim "narrow", narrow_args),
cl_init))
end
| Tcl_open (_, _, _, _, cl) ->
| Tcl_open (_, cl) ->
build_class_init cla cstr super inh_init cl_init msubst top cl

let rec build_class_lets cl =
Expand All @@ -407,7 +407,7 @@ let rec get_class_meths cl =
| Tcl_fun (_, _, _, cl, _)
| Tcl_let (_, _, _, cl)
| Tcl_apply (cl, _)
| Tcl_open (_, _, _, _, cl)
| Tcl_open (_, cl)
| Tcl_constraint (cl, _, _, _, _) -> get_class_meths cl

(*
Expand Down Expand Up @@ -453,7 +453,7 @@ let rec transl_class_rebind obj_init cl vf =
in
check_constraint cl.cl_type;
(path, obj_init)
| Tcl_open (_, _, _, _, cl) ->
| Tcl_open (_, cl) ->
transl_class_rebind obj_init cl vf

let rec transl_class_rebind_0 self obj_init cl vf =
Expand Down
4 changes: 2 additions & 2 deletions parsing/ast_helper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,9 @@ end

module Opn = struct
let mk ?(loc = !default_loc) ?(attrs = []) ?(docs = empty_docs)
?(override = Fresh) lid =
?(override = Fresh) expr =
{
popen_lid = lid;
popen_expr = expr;
popen_override = override;
popen_loc = loc;
popen_attributes = add_docs_attrs docs attrs;
Expand Down
10 changes: 5 additions & 5 deletions parsing/ast_helper.mli
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ module Exp:
val object_: ?loc:loc -> ?attrs:attrs -> class_structure -> expression
val newtype: ?loc:loc -> ?attrs:attrs -> str -> expression -> expression
val pack: ?loc:loc -> ?attrs:attrs -> module_expr -> expression
val open_: ?loc:loc -> ?attrs:attrs -> override_flag -> lid -> expression
-> expression
val open_: ?loc:loc -> ?attrs:attrs -> override_flag -> module_expr
-> expression -> expression
val extension: ?loc:loc -> ?attrs:attrs -> extension -> expression
val unreachable: ?loc:loc -> ?attrs:attrs -> unit -> expression

Expand Down Expand Up @@ -322,7 +322,7 @@ module Mb:
module Opn:
sig
val mk: ?loc: loc -> ?attrs:attrs -> ?docs:docs ->
?override:override_flag -> lid -> open_description
?override:override_flag -> module_expr -> open_description
end

(** Includes *)
Expand Down Expand Up @@ -352,7 +352,7 @@ module Cty:
val arrow: ?loc:loc -> ?attrs:attrs -> arg_label -> core_type ->
class_type -> class_type
val extension: ?loc:loc -> ?attrs:attrs -> extension -> class_type
val open_: ?loc:loc -> ?attrs:attrs -> override_flag -> lid -> class_type
val open_: ?loc:loc -> ?attrs:attrs -> override_flag -> module_expr -> class_type
-> class_type
end

Expand Down Expand Up @@ -392,7 +392,7 @@ module Cl:
val constraint_: ?loc:loc -> ?attrs:attrs -> class_expr -> class_type ->
class_expr
val extension: ?loc:loc -> ?attrs:attrs -> extension -> class_expr
val open_: ?loc:loc -> ?attrs:attrs -> override_flag -> lid -> class_expr
val open_: ?loc:loc -> ?attrs:attrs -> override_flag -> module_expr -> class_expr
-> class_expr
end

Expand Down
7 changes: 3 additions & 4 deletions parsing/ast_invariants.ml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ let iterator =
| Ppat_construct (id, _) -> simple_longident id
| Ppat_record (fields, _) ->
List.iter (fun (id, _) -> simple_longident id) fields
| Ppat_open (id, _) -> simple_longident id
| _ -> ()
in
let expr self exp =
Expand All @@ -87,8 +88,7 @@ let iterator =
| Pexp_construct (id, _)
| Pexp_field (_, id)
| Pexp_setfield (_, id, _)
| Pexp_new id
| Pexp_open (_, id, _) -> simple_longident id
| Pexp_new id -> simple_longident id
| Pexp_record (fields, _) ->
List.iter (fun (id, _) -> simple_longident id) fields
| _ -> ()
Expand All @@ -114,8 +114,7 @@ let iterator =
| _ -> ()
in
let open_description self opn =
super.open_description self opn;
simple_longident opn.popen_lid
super.open_description self opn
in
let with_constraint self wc =
super.with_constraint self wc;
Expand Down
16 changes: 8 additions & 8 deletions parsing/ast_iterator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ module CT = struct
| Pcty_arrow (_lab, t, ct) ->
sub.typ sub t; sub.class_type sub ct
| Pcty_extension x -> sub.extension sub x
| Pcty_open (_ovf, lid, e) ->
iter_loc sub lid; sub.class_type sub e
| Pcty_open (_ovf, me, e) ->
sub.module_expr sub me; sub.class_type sub e

let iter_field sub {pctf_desc = desc; pctf_loc = loc; pctf_attributes = attrs}
=
Expand Down Expand Up @@ -372,8 +372,8 @@ module E = struct
| Pexp_object cls -> sub.class_structure sub cls
| Pexp_newtype (_s, e) -> sub.expr sub e
| Pexp_pack me -> sub.module_expr sub me
| Pexp_open (_ovf, lid, e) ->
iter_loc sub lid; sub.expr sub e
| Pexp_open (_ovf, me, e) ->
sub.module_expr sub me; sub.expr sub e
| Pexp_extension x -> sub.extension sub x
| Pexp_unreachable -> ()
end
Expand Down Expand Up @@ -434,8 +434,8 @@ module CE = struct
| Pcl_constraint (ce, ct) ->
sub.class_expr sub ce; sub.class_type sub ct
| Pcl_extension x -> sub.extension sub x
| Pcl_open (_ovf, lid, e) ->
iter_loc sub lid; sub.class_expr sub e
| Pcl_open (_ovf, me, e) ->
sub.module_expr sub me; sub.class_expr sub e

let iter_kind sub = function
| Cfk_concrete (_o, e) -> sub.expr sub e
Expand Down Expand Up @@ -535,8 +535,8 @@ let default_iterator =


open_description =
(fun this {popen_lid; popen_override = _; popen_attributes; popen_loc} ->
iter_loc this popen_lid;
(fun this {popen_expr; popen_override = _; popen_attributes; popen_loc} ->
this.module_expr this popen_expr;
this.location this popen_loc;
this.attributes this popen_attributes
);
Expand Down
16 changes: 8 additions & 8 deletions parsing/ast_mapper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ module CT = struct
| Pcty_arrow (lab, t, ct) ->
arrow ~loc ~attrs lab (sub.typ sub t) (sub.class_type sub ct)
| Pcty_extension x -> extension ~loc ~attrs (sub.extension sub x)
| Pcty_open (ovf, lid, ct) ->
open_ ~loc ~attrs ovf (map_loc sub lid) (sub.class_type sub ct)
| Pcty_open (ovf, me, ct) ->
open_ ~loc ~attrs ovf (sub.module_expr sub me) (sub.class_type sub ct)

let map_field sub {pctf_desc = desc; pctf_loc = loc; pctf_attributes = attrs}
=
Expand Down Expand Up @@ -394,8 +394,8 @@ module E = struct
| Pexp_newtype (s, e) ->
newtype ~loc ~attrs (map_loc sub s) (sub.expr sub e)
| Pexp_pack me -> pack ~loc ~attrs (sub.module_expr sub me)
| Pexp_open (ovf, lid, e) ->
open_ ~loc ~attrs ovf (map_loc sub lid) (sub.expr sub e)
| Pexp_open (ovf, me, e) ->
open_ ~loc ~attrs ovf (sub.module_expr sub me) (sub.expr sub e)
| Pexp_extension x -> extension ~loc ~attrs (sub.extension sub x)
| Pexp_unreachable -> unreachable ~loc ~attrs ()
end
Expand Down Expand Up @@ -458,8 +458,8 @@ module CE = struct
| Pcl_constraint (ce, ct) ->
constraint_ ~loc ~attrs (sub.class_expr sub ce) (sub.class_type sub ct)
| Pcl_extension x -> extension ~loc ~attrs (sub.extension sub x)
| Pcl_open (ovf, lid, ce) ->
open_ ~loc ~attrs ovf (map_loc sub lid) (sub.class_expr sub ce)
| Pcl_open (ovf, me, ce) ->
open_ ~loc ~attrs ovf (sub.module_expr sub me) (sub.class_expr sub ce)

let map_kind sub = function
| Cfk_concrete (o, e) -> Cfk_concrete (o, sub.expr sub e)
Expand Down Expand Up @@ -570,8 +570,8 @@ let default_mapper =


open_description =
(fun this {popen_lid; popen_override; popen_attributes; popen_loc} ->
Opn.mk (map_loc this popen_lid)
(fun this {popen_expr; popen_override; popen_attributes; popen_loc} ->
Opn.mk (this.module_expr this popen_expr)
~override:popen_override
~loc:(this.location this popen_loc)
~attrs:(this.attributes this popen_attributes)
Expand Down
80 changes: 48 additions & 32 deletions parsing/depend.ml
Original file line number Diff line number Diff line change
Expand Up @@ -160,32 +160,6 @@ let add_type_extension bv te =
add bv te.ptyext_path;
List.iter (add_extension_constructor bv) te.ptyext_constructors

let rec add_class_type bv cty =
match cty.pcty_desc with
Pcty_constr(l, tyl) ->
add bv l; List.iter (add_type bv) tyl
| Pcty_signature { pcsig_self = ty; pcsig_fields = fieldl } ->
add_type bv ty;
List.iter (add_class_type_field bv) fieldl
| Pcty_arrow(_, ty1, cty2) ->
add_type bv ty1; add_class_type bv cty2
| Pcty_extension e -> handle_extension e
| Pcty_open (_ovf, m, e) ->
let bv = open_module bv m.txt in add_class_type bv e

and add_class_type_field bv pctf =
match pctf.pctf_desc with
Pctf_inherit cty -> add_class_type bv cty
| Pctf_val(_, _, _, ty) -> add_type bv ty
| Pctf_method(_, _, _, ty) -> add_type bv ty
| Pctf_constraint(ty1, ty2) -> add_type bv ty1; add_type bv ty2
| Pctf_attribute _ -> ()
| Pctf_extension e -> handle_extension e

let add_class_description bv infos =
add_class_type bv infos.pci_expr

let add_class_type_declaration = add_class_description

let pattern_bv = ref StringMap.empty

Expand Down Expand Up @@ -268,7 +242,10 @@ let rec add_expr bv exp =
| Pexp_newtype (_, e) -> add_expr bv e
| Pexp_pack m -> add_module_expr bv m
| Pexp_open (_ovf, m, e) ->
let bv = open_module bv m.txt in add_expr bv e
let Node(s, m') = add_module_binding bv m in
add_names s;
let bv = StringMap.fold StringMap.add m' bv in
add_expr bv e
| Pexp_extension (({ txt = ("ocaml.extension_constructor"|
"extension_constructor"); _ },
PStr [item]) as e) ->
Expand Down Expand Up @@ -371,7 +348,10 @@ and add_sig_item (bv, m) item =
end;
(bv, m)
| Psig_open od ->
(open_module bv od.popen_lid.txt, m)
let Node (s, m') = add_module_binding bv od.popen_expr in
add_names s;
let add = StringMap.fold StringMap.add m' in
(add bv, add m)
| Psig_include incl ->
let Node (s, m') = add_modtype_binding bv incl.pincl_mod in
add_names s;
Expand All @@ -380,7 +360,7 @@ and add_sig_item (bv, m) item =
| Psig_class cdl ->
List.iter (add_class_description bv) cdl; (bv, m)
| Psig_class_type cdtl ->
List.iter (add_class_type_declaration bv) cdtl; (bv, m)
List.iter (add_class_type_declaration () bv) cdtl; (bv, m)
| Psig_attribute _ -> (bv, m)
| Psig_extension (e, _) ->
handle_extension e;
Expand Down Expand Up @@ -409,6 +389,36 @@ and add_module_expr bv modl =
| Pmod_extension e ->
handle_extension e

and add_class_type bv cty =
match cty.pcty_desc with
Pcty_constr(l, tyl) ->
add bv l; List.iter (add_type bv) tyl
| Pcty_signature { pcsig_self = ty; pcsig_fields = fieldl } ->
add_type bv ty;
List.iter (add_class_type_field bv) fieldl
| Pcty_arrow(_, ty1, cty2) ->
add_type bv ty1; add_class_type bv cty2
| Pcty_extension e -> handle_extension e
| Pcty_open (_ovf, m, e) ->
let Node(s, m') = add_module_binding bv m in
add_names s;
let bv = StringMap.fold StringMap.add m' bv in
add_class_type bv e

and add_class_type_field bv pctf =
match pctf.pctf_desc with
Pctf_inherit cty -> add_class_type bv cty
| Pctf_val(_, _, _, ty) -> add_type bv ty
| Pctf_method(_, _, _, ty) -> add_type bv ty
| Pctf_constraint(ty1, ty2) -> add_type bv ty1; add_type bv ty2
| Pctf_attribute _ -> ()
| Pctf_extension e -> handle_extension e

and add_class_description bv infos =
add_class_type bv infos.pci_expr

and add_class_type_declaration () = add_class_description

and add_structure bv item_list =
let (bv, m) = add_structure_binding bv item_list in
add_names (collect_free (make_node m));
Expand Down Expand Up @@ -452,11 +462,14 @@ and add_struct_item (bv, m) item : _ StringMap.t * _ StringMap.t =
end;
(bv, m)
| Pstr_open od ->
(open_module bv od.popen_lid.txt, m)
let Node (s, m') = add_module_binding bv od.popen_expr in
add_names s;
let add = StringMap.fold StringMap.add m' in
(add bv, add m)
| Pstr_class cdl ->
List.iter (add_class_declaration bv) cdl; (bv, m)
| Pstr_class_type cdtl ->
List.iter (add_class_type_declaration bv) cdtl; (bv, m)
List.iter (add_class_type_declaration () bv) cdtl; (bv, m)
| Pstr_include incl ->
let Node (s, m') as n = add_module_binding bv incl.pincl_mod in
if !Clflags.transparent_modules then
Expand Down Expand Up @@ -502,7 +515,10 @@ and add_class_expr bv ce =
add_class_expr bv ce; add_class_type bv ct
| Pcl_extension e -> handle_extension e
| Pcl_open (_ovf, m, e) ->
let bv = open_module bv m.txt in add_class_expr bv e
let Node(s, m') = add_module_binding bv m in
add_names s;
let bv = StringMap.fold StringMap.add m' bv in
add_class_expr bv e

and add_class_field bv pcf =
match pcf.pcf_desc with
Expand Down
Loading