Skip to content

Commit 6543e9d

Browse files
committed
Rework implementation
Allow redefining when not loaded, but invalidate previous cached module (if any)
1 parent ba54ffc commit 6543e9d

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed

src/compiler/server.ml

-8
Original file line numberDiff line numberDiff line change
@@ -779,16 +779,8 @@ let do_connect ip port args =
779779
process();
780780
if !has_error then exit 1
781781

782-
let find_good_module_extra sctx com path =
783-
let cc = CommonCache.get_cache com in
784-
let m_extra = cc#find_module_extra path in
785-
match check_module sctx com path m_extra null_pos with
786-
| None -> m_extra
787-
| Some _ -> raise Not_found
788-
789782
let enable_cache_mode sctx =
790783
type_module_hook := type_module sctx;
791-
find_module_extra_hook := find_good_module_extra sctx;
792784
ServerCompilationContext.ensure_macro_setup sctx;
793785
TypeloadParse.parse_hook := parse_file sctx.cs
794786

src/typing/macroContext.ml

+9-9
Original file line numberDiff line numberDiff line change
@@ -465,12 +465,13 @@ let make_macro_api ctx mctx p =
465465
in
466466
let add is_macro ctx =
467467
try
468-
let m_extra = !TypeloadCacheHook.find_module_extra_hook ctx.com mpath in
469-
let pos = { pfile = (Path.UniqueKey.lazy_path m_extra.m_file); pmin = 0; pmax = 0 } in
468+
let m = ctx.com.module_lut#find mpath in
469+
let pos = { pfile = (Path.UniqueKey.lazy_path m.m_extra.m_file); pmin = 0; pmax = 0 } in
470470
raise_typing_error_ext (make_error ~sub:[
471471
make_error ~depth:1 (Custom "Previously defined here") pos
472472
] (Custom (Printf.sprintf "Cannot redefine module %s" (s_type_path mpath))) p);
473473
with Not_found ->
474+
ctx.com.cs#taint_module mpath ServerInvalidate;
474475
let mdep = Option.map_default (fun s -> TypeloadModule.load_module ~origin:MDepFromMacro ctx (parse_path s) pos) ctx.m.curmod mdep in
475476
let mnew = TypeloadModule.type_module ctx.com ctx.g ~dont_check_path:(has_native_meta) mpath (ctx.com.file_keys#generate_virtual mpath ctx.com.compilation_step) [tdef,pos] pos in
476477
mnew.m_extra.m_kind <- if is_macro then MMacro else MFake;
@@ -500,17 +501,16 @@ let make_macro_api ctx mctx p =
500501
let types = imports @ usings @ types in
501502
let mpath = Ast.parse_path m in
502503
begin try
503-
let m = try Some (ctx.com.module_lut#find mpath) with Not_found -> None in
504-
if Option.is_some m && Option.get m == ctx.m.curmod then
505-
ignore(TypeloadModule.type_types_into_module ctx.com ctx.g ctx.m.curmod types pos)
506-
else begin
507-
let m_extra = match m with Some m -> m.m_extra | None -> !TypeloadCacheHook.find_module_extra_hook ctx.com mpath in
508-
let pos = { pfile = (Path.UniqueKey.lazy_path m_extra.m_file); pmin = 0; pmax = 0 } in
504+
let m = ctx.com.module_lut#find mpath in
505+
if m != ctx.m.curmod then begin
506+
let pos = { pfile = (Path.UniqueKey.lazy_path m.m_extra.m_file); pmin = 0; pmax = 0 } in
509507
raise_typing_error_ext (make_error ~sub:[
510508
make_error ~depth:1 (Custom "Previously defined here") pos
511509
] (Custom (Printf.sprintf "Cannot redefine module %s" (s_type_path mpath))) p);
512-
end
510+
end else
511+
ignore(TypeloadModule.type_types_into_module ctx.com ctx.g ctx.m.curmod types pos)
513512
with Not_found ->
513+
ctx.com.cs#taint_module mpath ServerInvalidate;
514514
let mnew = TypeloadModule.type_module ctx.com ctx.g mpath (ctx.com.file_keys#generate_virtual mpath ctx.com.compilation_step) types pos in
515515
mnew.m_extra.m_kind <- MFake;
516516
add_dependency mnew ctx.m.curmod MDepFromMacro;

src/typing/typeloadCacheHook.ml

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ type find_module_result =
1010
| BinaryModule of HxbData.module_cache
1111
| NoModule
1212

13-
let find_module_extra_hook : (Common.context -> path -> module_def_extra) ref = ref (fun com mpath -> (com.module_lut#find mpath).m_extra)
1413
let type_module_hook : (Common.context -> (typer_pass -> (unit -> unit) -> unit) -> path -> pos -> find_module_result) ref = ref (fun _ _ _ _ -> NoModule)
1514

1615
let fake_modules = Hashtbl.create 0

0 commit comments

Comments
 (0)