| Attached Files | lazy_subst.diff [^] (13,259 bytes) 2013-02-07 06:24 [Show Content] [Hide Content]Index: debugger/envaux.ml
===================================================================
--- debugger/envaux.ml (révision 12778)
+++ debugger/envaux.ml (copie de travail)
@@ -48,7 +48,7 @@
Env.add_type id (Subst.type_declaration subst desc) (env_from_summary s subst)
| Env_exception(s, id, desc) ->
Env.add_exception id (Subst.exception_declaration subst desc) (env_from_summary s subst)
- | Env_module(s, id, desc) ->
+ | Env_module(s, id, lazy desc) ->
Env.add_module id (Subst.modtype subst desc) (env_from_summary s subst)
| Env_modtype(s, id, desc) ->
Env.add_modtype id (Subst.modtype_declaration subst desc) (env_from_summary s subst)
Index: boot/ocamldep
===================================================================
Impossible d'afficher : fichier considéré comme binaire.
svn:mime-type = application/octet-stream
Index: boot/ocamllex
===================================================================
Impossible d'afficher : fichier considéré comme binaire.
svn:mime-type = application/octet-stream
Index: boot/ocamlc
===================================================================
Impossible d'afficher : fichier considéré comme binaire.
svn:mime-type = application/octet-stream
Index: typing/typemod.ml
===================================================================
--- typing/typemod.ml (révision 12778)
+++ typing/typemod.ml (copie de travail)
@@ -67,9 +67,15 @@
(* Compute the environment after opening a module *)
let type_open ?toplevel env loc lid =
- let (path, mty) = Typetexp.find_module env loc lid.txt in
+ let (path, (subst, mty)) = Typetexp.find_module_and_subst env loc lid.txt in
+ let subst, mty =
+ (* applying the substitution anyway in the cheap case where scrape is going
+ to look at the identifiers *)
+ match mty with
+ | Mty_ident _ -> Subst.identity, Subst.modtype subst mty
+ | _ -> subst, mty in
let sg = extract_sig_open env loc mty in
- path, Env.open_signature ~loc ?toplevel path sg env
+ path, Env.open_signature_and_subst ~loc ?toplevel path (subst, sg) env
(* Record a module type *)
let rm node =
Index: typing/typetexp.ml
===================================================================
--- typing/typetexp.ml (révision 12778)
+++ typing/typetexp.ml (copie de travail)
@@ -101,6 +101,8 @@
find_component Env.lookup_value (fun lid -> Unbound_value lid)
let find_module =
find_component Env.lookup_module (fun lid -> Unbound_module lid)
+let find_module_and_subst =
+ find_component Env.lookup_module_and_subst (fun lid -> Unbound_module lid)
let find_modtype =
find_component Env.lookup_modtype (fun lid -> Unbound_modtype lid)
let find_class_type =
Index: typing/env.ml
===================================================================
--- typing/env.ml (révision 12778)
+++ typing/env.ml (copie de travail)
@@ -65,6 +65,7 @@
val force : ('a -> 'b) -> ('a,'b) t -> 'b
val create : 'a -> ('a,'b) t
+ val map : ('thunk -> 'a) -> ('done_ -> 'a) -> ('thunk, 'done_) t -> 'a
end = struct
@@ -75,6 +76,11 @@
| Raise of exn
| Thunk of 'a
+ let map thunk done_ = function
+ | { contents = Done d } -> done_ d
+ | { contents = Raise e } -> raise e
+ | { contents = Thunk t } -> thunk t
+
let force f x =
match !x with
Done x -> x
@@ -100,7 +106,7 @@
| Env_value of summary * Ident.t * value_description
| Env_type of summary * Ident.t * type_declaration
| Env_exception of summary * Ident.t * exception_declaration
- | Env_module of summary * Ident.t * module_type
+ | Env_module of summary * Ident.t * module_type Lazy.t
| Env_modtype of summary * Ident.t * modtype_declaration
| Env_class of summary * Ident.t * class_declaration
| Env_cltype of summary * Ident.t * class_type_declaration
@@ -148,7 +154,7 @@
labels: (Path.t * label_description) EnvTbl.t;
constrs_by_path: (Path.t * (constructor_description list)) EnvTbl.t;
types: (Path.t * type_declaration) EnvTbl.t;
- modules: (Path.t * module_type) EnvTbl.t;
+ modules: (Path.t * module_type Lazy.t) EnvTbl.t;
modtypes: (Path.t * modtype_declaration) EnvTbl.t;
components: (Path.t * module_components) EnvTbl.t;
classes: (Path.t * class_declaration) EnvTbl.t;
@@ -160,7 +166,7 @@
}
and module_components =
- (t * Subst.t * Path.t * Types.module_type, module_components_repr) EnvLazy.t
+ (t * Subst.t * Path.t * Types.module_type Lazy.t, module_components_repr) EnvLazy.t
and module_components_repr =
Structure_comps of structure_components
@@ -231,10 +237,10 @@
let components_of_module' =
ref ((fun env sub path mty -> assert false) :
- t -> Subst.t -> Path.t -> module_type -> module_components)
+ t -> Subst.t -> Path.t -> module_type Lazy.t -> module_components)
let components_of_module_maker' =
ref ((fun (env, sub, path, mty) -> assert false) :
- t * Subst.t * Path.t * module_type -> module_components_repr)
+ t * Subst.t * Path.t * module_type Lazy.t -> module_components_repr)
let components_of_functor_appl' =
ref ((fun f p1 p2 -> assert false) :
functor_components -> Path.t -> Path.t -> module_components)
@@ -284,7 +290,7 @@
let comps =
!components_of_module' empty Subst.identity
(Pident(Ident.create_persistent name))
- (Mty_signature sign) in
+ (lazy (Mty_signature sign)) in
let ps = { ps_name = name;
ps_sig = sign;
ps_comps = comps;
@@ -438,7 +444,7 @@
match path with
Pident id ->
begin try
- let (p, data) = EnvTbl.find_same id env.modules
+ let (p, lazy data) = EnvTbl.find_same id env.modules
in data
with Not_found ->
if Ident.persistent id then
@@ -495,7 +501,8 @@
match lid with
Lident s ->
begin try
- EnvTbl.find_name s env.modules
+ let (p, lazy data) = EnvTbl.find_name s env.modules in
+ p, data
with Not_found ->
if s = !current_unit then raise Not_found;
let ps = find_pers_struct s in
@@ -523,6 +530,24 @@
raise Not_found
end
+(* [lookup_module_and_subs lid env] returns a [(subst, mty)] such that
+ [assert (lookup_module lid env) = Subst.modtype subst mty] *)
+let lookup_module_and_subst lid env =
+ match lid with
+ | Ldot(l, s) ->
+ let (p, descr) = lookup_module_descr l env in
+ begin match EnvLazy.force !components_of_module_maker' descr with
+ Structure_comps c ->
+ let (data, pos) = Tbl.find s c.comp_modules in
+ Pdot(p, s, pos), (EnvLazy.map (fun x -> x) (fun ty -> Subst.identity, ty) data)
+ | Functor_comps f ->
+ raise Not_found
+ end
+ | Lident _
+ | Lapply _ ->
+ let a, b = lookup_module lid env in
+ a, (Subst.identity, b)
+
let lookup proj1 proj2 lid env =
match lid with
Lident s ->
@@ -793,7 +818,7 @@
let rec components_of_module env sub path mty =
EnvLazy.create (env, sub, path, mty)
-and components_of_module_maker (env, sub, path, mty) =
+and components_of_module_maker (env, sub, path, lazy mty) =
(match scrape_modtype mty env with
Mty_signature sg ->
let c =
@@ -851,7 +876,7 @@
let mty' = EnvLazy.create (sub, mty) in
c.comp_modules <-
Tbl.add (Ident.name id) (mty', !pos) c.comp_modules;
- let comps = components_of_module !env sub path mty in
+ let comps = components_of_module !env sub path (lazy mty) in
c.comp_components <-
Tbl.add (Ident.name id) (comps, !pos) c.comp_components;
env := store_module id path mty !env;
@@ -1004,13 +1029,15 @@
Datarepr.exception_descr path decl) env.constrs;
summary = Env_exception(env.summary, id, decl) }
-and store_module id path mty env =
+and store_module_lazy id path (mty : module_type Lazy.t) env =
{ env with
modules = EnvTbl.add id (path, mty) env.modules;
components =
EnvTbl.add id (path, components_of_module env Subst.identity path mty)
env.components;
summary = Env_module(env.summary, id, mty) }
+and store_module id path (mty : module_type) env =
+ store_module_lazy id path (lazy mty) env
and store_modtype id path info env =
{ env with
@@ -1035,8 +1062,9 @@
with Not_found ->
let p = Papply(p1, p2) in
let mty =
- Subst.modtype (Subst.add_module f.fcomp_param p2 Subst.identity)
- f.fcomp_res in
+ lazy (
+ Subst.modtype (Subst.add_module f.fcomp_param p2 Subst.identity)
+ f.fcomp_res) in
let comps = components_of_module f.fcomp_env f.fcomp_subst p mty in
Hashtbl.add f.fcomp_cache p2 comps;
comps
@@ -1115,9 +1143,9 @@
(* Open a signature path *)
-let open_signature root sg env =
+let open_signature root (sub, sg) env =
(* First build the paths and substitution *)
- let (pl, sub) = prefix_idents root 0 Subst.identity sg in
+ let (pl, sub) = prefix_idents root 0 sub sg in
(* Then enter the components in the environment after substitution *)
let newenv =
List.fold_left2
@@ -1134,7 +1162,7 @@
store_exception (Ident.hide id) p
(Subst.exception_declaration sub decl) env
| Sig_module(id, mty, _) ->
- store_module (Ident.hide id) p (Subst.modtype sub mty) env
+ store_module_lazy (Ident.hide id) p (lazy (Subst.modtype sub mty)) env
| Sig_modtype(id, decl) ->
store_modtype (Ident.hide id) p
(Subst.modtype_declaration sub decl) env
@@ -1151,7 +1179,7 @@
let open_pers_signature name env =
let ps = find_pers_struct name in
- open_signature (Pident(Ident.create_persistent name)) ps.ps_sig env
+ open_signature (Pident(Ident.create_persistent name)) (Subst.identity, ps.ps_sig) env
let open_signature ?(loc = Location.none) ?(toplevel = false) root sg env =
if not toplevel && not loc.Location.loc_ghost && Warnings.is_active (Warnings.Unused_open "")
@@ -1166,6 +1194,12 @@
end
else open_signature root sg env
+let open_signature_and_subst ?loc ?toplevel root sg env =
+ open_signature ?loc ?toplevel root sg env
+
+let open_signature ?loc ?toplevel root sg env =
+ open_signature ?loc ?toplevel root (Subst.identity, sg) env
+
(* Read a signature from a file *)
let read_signature modname filename =
@@ -1205,7 +1239,7 @@
will also return its crc *)
let comps =
components_of_module empty Subst.identity
- (Pident(Ident.create_persistent modname)) (Mty_signature sg) in
+ (Pident(Ident.create_persistent modname)) (lazy (Mty_signature sg)) in
let ps =
{ ps_name = modname;
ps_sig = sg;
@@ -1253,7 +1287,7 @@
| None ->
let acc =
ident_tbl_fold
- (fun id (p, data) acc -> f (Ident.name id) p data acc)
+ (fun id (p, lazy data) acc -> f (Ident.name id) p data acc)
env.modules
acc
in
Index: typing/typetexp.mli
===================================================================
--- typing/typetexp.mli (révision 12778)
+++ typing/typetexp.mli (copie de travail)
@@ -90,6 +90,8 @@
Env.t -> Location.t -> Longident.t -> Path.t * Types.class_declaration
val find_module:
Env.t -> Location.t -> Longident.t -> Path.t * Types.module_type
+val find_module_and_subst:
+ Env.t -> Location.t -> Longident.t -> Path.t * (Subst.t * Types.module_type)
val find_modtype:
Env.t -> Location.t -> Longident.t -> Path.t * Types.modtype_declaration
val find_class_type:
Index: typing/env.mli
===================================================================
--- typing/env.mli (révision 12778)
+++ typing/env.mli (copie de travail)
@@ -21,7 +21,7 @@
| Env_value of summary * Ident.t * value_description
| Env_type of summary * Ident.t * type_declaration
| Env_exception of summary * Ident.t * exception_declaration
- | Env_module of summary * Ident.t * module_type
+ | Env_module of summary * Ident.t * module_type Lazy.t
| Env_modtype of summary * Ident.t * modtype_declaration
| Env_class of summary * Ident.t * class_declaration
| Env_cltype of summary * Ident.t * class_type_declaration
@@ -66,6 +66,7 @@
val lookup_label: Longident.t -> t -> Path.t * label_description
val lookup_type: Longident.t -> t -> Path.t * type_declaration
val lookup_module: Longident.t -> t -> Path.t * module_type
+val lookup_module_and_subst: Longident.t -> t -> Path.t * (Subst.t * module_type)
val lookup_modtype: Longident.t -> t -> Path.t * modtype_declaration
val lookup_class: Longident.t -> t -> Path.t * class_declaration
val lookup_cltype: Longident.t -> t -> Path.t * class_type_declaration
@@ -91,6 +92,7 @@
(* Insertion of all fields of a signature, relative to the given path.
Used to implement open. *)
+val open_signature_and_subst: ?loc:Location.t -> ?toplevel:bool -> Path.t -> Subst.t * signature -> t -> t
val open_signature: ?loc:Location.t -> ?toplevel:bool -> Path.t -> signature -> t -> t
val open_pers_signature: string -> t -> t
lazy-subst2.diff [^] (16,693 bytes) 2013-02-20 15:18 [Show Content] [Hide Content]Index: boot/ocamldep
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: boot/ocamllex
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: boot/ocamlc
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: typing/typemod.ml
===================================================================
--- typing/typemod.ml (revision 13290)
+++ typing/typemod.ml (working copy)
@@ -65,9 +65,15 @@
(* Compute the environment after opening a module *)
let type_open ?toplevel env loc lid =
- let (path, mty) = Typetexp.find_module env loc lid.txt in
+ let (path, (subst, mty)) = Typetexp.find_module_and_subst env loc lid.txt in
+ let subst, mty =
+ (* applying the substitution anyway in the cheap case where scrape is
+ going to look at the identifiers *)
+ match mty with
+ | Mty_ident _ -> Subst.identity, Subst.modtype subst mty
+ | _ -> subst, mty in
let sg = extract_sig_open env loc mty in
- path, Env.open_signature ~loc ?toplevel path sg env
+ path, Env.open_signature_with_subst ~loc ?toplevel path (subst, sg) env
(* Record a module type *)
let rm node =
Index: typing/typetexp.ml
===================================================================
--- typing/typetexp.ml (revision 13290)
+++ typing/typetexp.ml (working copy)
@@ -105,6 +105,8 @@
find_component Env.lookup_value (fun lid -> Unbound_value lid)
let find_module =
find_component Env.lookup_module (fun lid -> Unbound_module lid)
+let find_module_and_subst =
+ find_component Env.lookup_module_and_subst (fun lid -> Unbound_module lid)
let find_modtype =
find_component Env.lookup_modtype (fun lid -> Unbound_modtype lid)
let find_class_type =
Index: typing/env.ml
===================================================================
--- typing/env.ml (revision 13290)
+++ typing/env.ml (working copy)
@@ -51,8 +51,6 @@
(string * Location.t * string, (constructor_usage -> unit)) Hashtbl.t
= Hashtbl.create 16
-let prefixed_sg = Hashtbl.create 113
-
type error =
| Illegal_renaming of string * string
| Inconsistent_import of string * string * string
@@ -65,7 +63,9 @@
val force : ('a -> 'b) -> ('a,'b) t -> 'b
val create : 'a -> ('a,'b) t
+ val create_val : 'b -> (_, 'b) t
val is_val : ('a,'b) t -> bool
+ val map : ('thunk -> 'a) -> ('done_ -> 'a) -> ('thunk, 'done_) t -> 'a
end = struct
@@ -96,15 +96,30 @@
let x = ref (Thunk x) in
x
+ let map thunk done_ = function
+ | { contents = Done d } -> done_ d
+ | { contents = Raise e } -> raise e
+ | { contents = Thunk t } -> thunk t
+
+ let create_val x =
+ ref (Done x)
+
end
+type lazy_module_type =
+ (Subst.t * module_type, module_type) EnvLazy.t
+type maybe_lazy_signature_item =
+ | Computed of signature_item
+ | Lazy_sig_module of Ident.t * lazy_module_type * rec_status
+let prefixed_sg = Hashtbl.create 113
+
type summary =
Env_empty
| Env_value of summary * Ident.t * value_description
| Env_type of summary * Ident.t * type_declaration
| Env_exception of summary * Ident.t * exception_declaration
- | Env_module of summary * Ident.t * module_type
+ | Env_module of summary * Ident.t * lazy_module_type
| Env_modtype of summary * Ident.t * modtype_declaration
| Env_class of summary * Ident.t * class_declaration
| Env_cltype of summary * Ident.t * class_type_declaration
@@ -161,7 +176,7 @@
constrs: constructor_description EnvTbl.t;
labels: label_description EnvTbl.t;
types: (Path.t * (type_declaration * type_descriptions)) EnvTbl.t;
- modules: (Path.t * module_type) EnvTbl.t;
+ modules: (Path.t * lazy_module_type) EnvTbl.t;
modtypes: (Path.t * modtype_declaration) EnvTbl.t;
components: (Path.t * module_components) EnvTbl.t;
classes: (Path.t * class_declaration) EnvTbl.t;
@@ -173,7 +188,7 @@
}
and module_components =
- (t * Subst.t * Path.t * Types.module_type, module_components_repr) EnvLazy.t
+ (t * Subst.t * Path.t * lazy_module_type, module_components_repr) EnvLazy.t
and module_components_repr =
Structure_comps of structure_components
@@ -203,6 +218,7 @@
}
let subst_modtype_maker (subst, mty) = Subst.modtype subst mty
+let force_lazy_module_type envlazy = EnvLazy.force subst_modtype_maker envlazy
let empty = {
values = EnvTbl.empty; constrs = EnvTbl.empty;
@@ -245,10 +261,10 @@
let components_of_module' =
ref ((fun env sub path mty -> assert false) :
- t -> Subst.t -> Path.t -> module_type -> module_components)
+ t -> Subst.t -> Path.t -> lazy_module_type -> module_components)
let components_of_module_maker' =
ref ((fun (env, sub, path, mty) -> assert false) :
- t * Subst.t * Path.t * module_type -> module_components_repr)
+ t * Subst.t * Path.t * lazy_module_type -> module_components_repr)
let components_of_functor_appl' =
ref ((fun f p1 p2 -> assert false) :
functor_components -> Path.t -> Path.t -> module_components)
@@ -298,7 +314,7 @@
let comps =
!components_of_module' empty Subst.identity
(Pident(Ident.create_persistent name))
- (Mty_signature sign) in
+ (EnvLazy.create_val (Mty_signature sign)) in
let ps = { ps_name = name;
ps_sig = sign;
ps_comps = comps;
@@ -464,7 +480,7 @@
Pident id ->
begin try
let (p, data) = EnvTbl.find_same id env.modules
- in data
+ in force_lazy_module_type data
with Not_found ->
if Ident.persistent id then
let ps = find_pers_struct (Ident.name id) in
@@ -477,7 +493,7 @@
with
Structure_comps c ->
let (data, pos) = Tbl.find s c.comp_modules in
- EnvLazy.force subst_modtype_maker data
+ force_lazy_module_type data
| Functor_comps f ->
raise Not_found
end
@@ -520,7 +536,8 @@
match lid with
Lident s ->
begin try
- EnvTbl.find_name s env.modules
+ let (p, data) = EnvTbl.find_name s env.modules in
+ p, force_lazy_module_type data
with Not_found ->
if s = !current_unit then raise Not_found;
let ps = find_pers_struct s in
@@ -564,6 +581,27 @@
| Lapply(l1, l2) ->
raise Not_found
+(* [lookup_module_and_subst lid env] returns a [(subst, mty)] such that
+ [assert (lookup_module lid env = Subst.modtype subst mty)] *)
+let lookup_module_and_subst lid env =
+ match lid with
+ | Ldot(l, s) ->
+ let (p, descr) = lookup_module_descr l env in
+ begin match EnvLazy.force !components_of_module_maker' descr with
+ Structure_comps c ->
+ let (data, pos) = Tbl.find s c.comp_modules in
+ let data =
+ EnvLazy.map (fun x -> x) (fun ty -> Subst.identity, ty) data
+ in
+ Pdot(p, s, pos), data
+ | Functor_comps f ->
+ raise Not_found
+ end
+ | Lident _
+ | Lapply _ ->
+ let a, b = lookup_module lid env in
+ a, (Subst.identity, b)
+
let lookup_simple proj1 proj2 lid env =
match lid with
Lident s ->
@@ -923,19 +961,31 @@
(fun item ->
match item with
| Sig_value(id, decl) ->
+ Computed (
Sig_value (id, Subst.value_description sub decl)
+ )
| Sig_type(id, decl, x) ->
+ Computed (
Sig_type(id, Subst.type_declaration sub decl, x)
+ )
| Sig_exception(id, decl) ->
+ Computed (
Sig_exception (id, Subst.exception_declaration sub decl)
+ )
| Sig_module(id, mty, x) ->
- Sig_module(id, Subst.modtype sub mty,x)
+ Lazy_sig_module (id, EnvLazy.create (sub, mty), x)
| Sig_modtype(id, decl) ->
+ Computed (
Sig_modtype(id, Subst.modtype_declaration sub decl)
+ )
| Sig_class(id, decl, x) ->
+ Computed (
Sig_class(id, Subst.class_declaration sub decl, x)
+ )
| Sig_class_type(id, decl, x) ->
+ Computed (
Sig_class_type(id, Subst.cltype_declaration sub decl, x)
+ )
)
sg
@@ -970,10 +1020,11 @@
try Tbl.find id tbl with Not_found -> [] in
Tbl.add id (decl :: decls) tbl
-let rec components_of_module env sub path mty =
+let rec components_of_module env sub path (mty : lazy_module_type) =
EnvLazy.create (env, sub, path, mty)
and components_of_module_maker (env, sub, path, mty) =
+ let mty = EnvLazy.force subst_modtype_maker mty in
(match scrape_modtype mty env with
Mty_signature sg ->
let c =
@@ -1025,7 +1076,7 @@
let mty' = EnvLazy.create (sub, mty) in
c.comp_modules <-
Tbl.add (Ident.name id) (mty', !pos) c.comp_modules;
- let comps = components_of_module !env sub path mty in
+ let comps = components_of_module !env sub path (EnvLazy.create_val mty) in
c.comp_components <-
Tbl.add (Ident.name id) (comps, !pos) c.comp_components;
env := store_module id path mty !env;
@@ -1165,7 +1216,7 @@
constrs = EnvTbl.add id (Datarepr.exception_descr path decl) env.constrs;
summary = Env_exception(env.summary, id, decl) }
-and store_module id path mty env =
+and store_module_lazy id path (mty : lazy_module_type) env =
{ env with
modules = EnvTbl.add id (path, mty) env.modules;
components =
@@ -1173,6 +1224,9 @@
env.components;
summary = Env_module(env.summary, id, mty) }
+and store_module id path mty env =
+ store_module_lazy id path (EnvLazy.create_val mty) env
+
and store_modtype id path info env =
{ env with
modtypes = EnvTbl.add id (path, info) env.modtypes;
@@ -1196,8 +1250,10 @@
with Not_found ->
let p = Papply(p1, p2) in
let mty =
- Subst.modtype (Subst.add_module f.fcomp_param p2 Subst.identity)
- f.fcomp_res in
+ EnvLazy.create (
+ Subst.add_module f.fcomp_param p2 Subst.identity,
+ f.fcomp_res
+ ) in
let comps = components_of_module f.fcomp_env f.fcomp_subst p mty in
Hashtbl.add f.fcomp_cache p2 comps;
comps
@@ -1273,9 +1329,9 @@
(* Open a signature path *)
-let open_signature root sg env =
+let open_signature_with_subst root (sub, sg) env =
(* First build the paths and substitution *)
- let (pl, sub, sg) = prefix_idents_and_subst root Subst.identity sg in
+ let (pl, sub, sg) = prefix_idents_and_subst root sub sg in
let sg = Lazy.force sg in
(* Then enter the components in the environment after substitution *)
@@ -1284,19 +1340,22 @@
List.fold_left2
(fun env item p ->
match item with
- Sig_value(id, decl) ->
+ | Lazy_sig_module (id, mty, x) ->
+ store_module_lazy (Ident.hide id) p mty env
+ | Computed item ->
+ match item with
+ | Sig_module _ -> assert false
+ | Sig_value(id, decl) ->
store_value (Ident.hide id) p decl env
- | Sig_type(id, decl, _) ->
+ | Sig_type(id, decl, _) ->
store_type (Ident.hide id) p decl env
- | Sig_exception(id, decl) ->
+ | Sig_exception(id, decl) ->
store_exception (Ident.hide id) p decl env
- | Sig_module(id, mty, _) ->
- store_module (Ident.hide id) p mty env
- | Sig_modtype(id, decl) ->
+ | Sig_modtype(id, decl) ->
store_modtype (Ident.hide id) p decl env
- | Sig_class(id, decl, _) ->
+ | Sig_class(id, decl, _) ->
store_class (Ident.hide id) p decl env
- | Sig_class_type(id, decl, _) ->
+ | Sig_class_type(id, decl, _) ->
store_cltype (Ident.hide id) p decl env
)
env sg pl in
@@ -1306,9 +1365,9 @@
let open_pers_signature name env =
let ps = find_pers_struct name in
- open_signature (Pident(Ident.create_persistent name)) ps.ps_sig env
+ open_signature_with_subst (Pident(Ident.create_persistent name)) (Subst.identity, ps.ps_sig) env
-let open_signature ?(loc = Location.none) ?(toplevel = false) root sg env =
+let open_signature_with_subst ?(loc = Location.none) ?(toplevel = false) root subst_sg env =
if not toplevel && not loc.Location.loc_ghost && Warnings.is_active (Warnings.Unused_open "")
then begin
let used = ref false in
@@ -1317,10 +1376,13 @@
if not !used then
Location.prerr_warning loc (Warnings.Unused_open (Path.name root))
);
- EnvTbl.with_slot used (open_signature root sg) env
+ EnvTbl.with_slot used (open_signature_with_subst root subst_sg) env
end
- else open_signature root sg env
+ else open_signature_with_subst root subst_sg env
+let open_signature ?loc ?toplevel root sg env =
+ open_signature_with_subst ?loc ?toplevel root (Subst.identity, sg) env
+
(* Read a signature from a file *)
let read_signature modname filename =
@@ -1360,7 +1422,8 @@
will also return its crc *)
let comps =
components_of_module empty Subst.identity
- (Pident(Ident.create_persistent modname)) (Mty_signature sg) in
+ (Pident(Ident.create_persistent modname))
+ (EnvLazy.create_val (Mty_signature sg)) in
let ps =
{ ps_name = modname;
ps_sig = sg;
@@ -1424,7 +1487,9 @@
| None ->
let acc =
EnvTbl.fold_name
- (fun id (p, data) acc -> f (Ident.name id) p data acc)
+ (fun id (p, data) acc ->
+ let data = force_lazy_module_type data in
+ f (Ident.name id) p data acc)
env.modules
acc
in
Index: typing/envaux.ml
===================================================================
--- typing/envaux.ml (revision 13290)
+++ typing/envaux.ml (working copy)
@@ -47,6 +47,7 @@
| Env_exception(s, id, desc) ->
Env.add_exception id (Subst.exception_declaration subst desc) (env_from_summary s subst)
| Env_module(s, id, desc) ->
+ let desc = Env.force_lazy_module_type desc in
Env.add_module id (Subst.modtype subst desc) (env_from_summary s subst)
| Env_modtype(s, id, desc) ->
Env.add_modtype id (Subst.modtype_declaration subst desc) (env_from_summary s subst)
Index: typing/typetexp.mli
===================================================================
--- typing/typetexp.mli (revision 13290)
+++ typing/typetexp.mli (working copy)
@@ -94,6 +94,8 @@
Env.t -> Location.t -> Longident.t -> Path.t * class_declaration
val find_module:
Env.t -> Location.t -> Longident.t -> Path.t * module_type
+val find_module_and_subst:
+ Env.t -> Location.t -> Longident.t -> Path.t * (Subst.t * module_type)
val find_modtype:
Env.t -> Location.t -> Longident.t -> Path.t * modtype_declaration
val find_class_type:
Index: typing/env.mli
===================================================================
--- typing/env.mli (revision 13290)
+++ typing/env.mli (working copy)
@@ -14,12 +14,15 @@
open Types
+type lazy_module_type
+val force_lazy_module_type : lazy_module_type -> module_type
+
type summary =
Env_empty
| Env_value of summary * Ident.t * value_description
| Env_type of summary * Ident.t * type_declaration
| Env_exception of summary * Ident.t * exception_declaration
- | Env_module of summary * Ident.t * module_type
+ | Env_module of summary * Ident.t * lazy_module_type
| Env_modtype of summary * Ident.t * modtype_declaration
| Env_class of summary * Ident.t * class_declaration
| Env_cltype of summary * Ident.t * class_type_declaration
@@ -73,6 +76,7 @@
Longident.t -> t -> (label_description * (unit -> unit)) list
val lookup_type: Longident.t -> t -> Path.t * type_declaration
val lookup_module: Longident.t -> t -> Path.t * module_type
+val lookup_module_and_subst: Longident.t -> t -> Path.t * (Subst.t * module_type)
val lookup_modtype: Longident.t -> t -> Path.t * modtype_declaration
val lookup_class: Longident.t -> t -> Path.t * class_declaration
val lookup_cltype: Longident.t -> t -> Path.t * class_type_declaration
@@ -98,6 +102,7 @@
Used to implement open. *)
val open_signature: ?loc:Location.t -> ?toplevel:bool -> Path.t -> signature -> t -> t
+val open_signature_with_subst: ?loc:Location.t -> ?toplevel:bool -> Path.t -> (Subst.t * signature) -> t -> t
val open_pers_signature: string -> t -> t
(* Insertion by name *)
|