Skip to content

Commit 75a359e

Browse files
committed
Factor "package" loading in first class mod and functors
1 parent 061c80d commit 75a359e

File tree

2 files changed

+11
-41
lines changed

2 files changed

+11
-41
lines changed

src/loader/cmi.ml

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -518,17 +518,8 @@ let rec read_type_expr env typ =
518518
| Tpackage(p, frags, tyl) ->
519519
let eqs = List.combine frags tyl in
520520
#endif
521-
let open TypeExpr.Package in
522-
let path = Env.Path.read_module_type env.ident_env p in
523-
let substitutions =
524-
List.map
525-
(fun (frag,typ) ->
526-
let frag = Env.Fragment.read_type frag in
527-
let typ = read_type_expr env typ in
528-
(frag, typ))
529-
eqs
530-
in
531-
Package {path; substitutions}
521+
let package = read_package env eqs p in
522+
Package package
532523
#if OCAML_VERSION<(4,13,0)
533524
| Tsubst typ -> read_type_expr env typ
534525
#else
@@ -545,7 +536,10 @@ let rec read_type_expr env typ =
545536
in
546537
let env = {env with ident_env = e'} in
547538
let ret = read_type_expr env ret_type in
548-
let package = read_package env pkg in
539+
let eqs =
540+
List.filter_map (fun (l,ty) -> Option.map (fun x -> x, ty) (Longident.unflatten l)) pkg.pack_constraints
541+
in
542+
let package = read_package env eqs pkg.pack_path in
549543
Arrow_functor(lbl, {id ; package}, ret)
550544

551545
#endif
@@ -556,14 +550,7 @@ let rec read_type_expr env typ =
556550
| Some name -> Alias(typ, name)
557551
end
558552

559-
and read_package env pkg =
560-
let pack_constraints = pkg.pack_constraints in
561-
let p = pkg.pack_path in
562-
let eqs =
563-
List.filter_map
564-
(fun (l,ty) -> Option.map (fun x -> x, ty) (Longident.unflatten l))
565-
pack_constraints
566-
in
553+
and read_package env eqs p =
567554
let open TypeExpr in
568555
let open TypeExpr.Package in
569556
let path = Env.Path.read_module_type env.ident_env p in

src/loader/cmti.ml

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,8 @@ let rec read_core_type env container ctyp =
150150
#else
151151
| Ttyp_package {pack_path; pack_fields; _} ->
152152
#endif
153-
let open TypeExpr.Package in
154-
let path = Env.Path.read_module_type env.ident_env pack_path in
155-
let substitutions =
156-
List.map
157-
(fun (frag, typ) ->
158-
let frag = Env.Fragment.read_type frag.Location.txt in
159-
let typ = read_core_type env container typ in
160-
(frag, typ))
161-
pack_fields
162-
in
163-
Package {path; substitutions}
153+
let pkg = read_package env container pack_path pack_fields in
154+
Package pkg
164155
#if OCAML_VERSION >= (5,2,0)
165156
| Ttyp_open (_p,_l,t) ->
166157
(* TODO: adjust model *)
@@ -176,19 +167,11 @@ let rec read_core_type env container ctyp =
176167
in
177168
let env = {env with ident_env = e'} in
178169
let ret = read_core_type env container ret_type in
179-
let package = read_package env container pkg in
170+
let package = read_package env container pkg.tpt_path pkg.tpt_constraints in
180171
Arrow_functor(lbl, {id ; package}, ret)
181-
(* let ctyp_desc = Ttyp_package pkg in *)
182-
(* let pkg = {ctyp with ctyp_desc} in *)
183-
(* let ctyp_desc = Ttyp_arrow (lbl, pkg, ret_type) in *)
184-
(* let ctyp = {ctyp with ctyp_desc} in *)
185-
(* (\* TODO: adjust model *\) *)
186-
(* let e' = Env.add_parameter (Identifier.Mk.root (None, ModuleName.of_ident id.txt)) id.txt (ModuleName.of_ident id.txt) env.ident_env in *)
187-
(* let env = {env with ident_env = e'} in *)
188-
(* read_core_type env container ctyp *)
189172
#endif
190173

191-
and read_package env container {tpt_path = pack_path; tpt_constraints=pack_fields; _} =
174+
and read_package env container pack_path pack_fields =
192175
let open TypeExpr.Package in
193176
let path = Env.Path.read_module_type env.ident_env pack_path in
194177
let substitutions =

0 commit comments

Comments
 (0)