follow type aliases

This commit is contained in:
Jeremie Dimino 2013-04-26 14:14:11 +01:00
parent c1bb8be73f
commit c1ec47d83e
1 changed files with 12 additions and 20 deletions

View File

@ -373,7 +373,7 @@ let () =
(* Rewrite Async.Std.Defered.t expressions to
Async_core.Thread_safe.block_on_async_exn (fun () -> <expr>). *)
let async_rewrite = {
Hashtbl.add rewrite_rules (Longident.parse "Async_core.Ivar.Deferred.t") {
required_values = [longident_async_core_thread_safe_block_on_async_exn];
rewrite = (fun loc e -> {
Parsetree.pexp_desc =
@ -385,10 +385,7 @@ let () =
Parsetree.pexp_loc = loc;
});
enabled = UTop.auto_run_async;
} in
Hashtbl.add rewrite_rules (Longident.parse "Async_core.Deferred.t") async_rewrite;
Hashtbl.add rewrite_rules (Longident.parse "Async.Std.Deferred.t") async_rewrite
}
(* Returns whether the argument is a toplevel expression. *)
let is_eval = function
@ -416,18 +413,7 @@ let rec rule_of_type typ =
match typ.Types.desc with
| Types.Tlink typ ->
rule_of_type typ
| Types.Tconstr (path, _, _) ->
if is_persistent_path path then
try
Some (Hashtbl.find rewrite_rules (longident_of_path path))
with Not_found ->
rule_of_alias path
else
rule_of_alias path
| _ ->
None
and rule_of_alias path =
| Types.Tconstr (path, _, _) -> begin
match try Some (Env.find_type path !Toploop.toplevel_env) with Not_found -> None with
| Some {
Types.type_kind = Types.Type_abstract;
@ -435,6 +421,12 @@ and rule_of_alias path =
Types.type_manifest = Some typ;
} ->
rule_of_type typ
| _ ->
try
Some (Hashtbl.find rewrite_rules (longident_of_path path))
with Not_found ->
None
end
| _ ->
None