|
|
@@ -223,12 +223,14 @@ let get_changed_directories sctx com =
|
|
|
let get_changed_directories sctx com =
|
|
|
Timer.time com.Common.timer_ctx ["server";"module cache";"changed dirs"] (get_changed_directories sctx) com
|
|
|
|
|
|
-let full_typing com m_extra =
|
|
|
- com.is_macro_context
|
|
|
- || com.display.dms_full_typing
|
|
|
- || Define.defined com.defines Define.DisableHxbCache
|
|
|
- || Define.defined com.defines Define.DisableHxbOptimizations
|
|
|
- || DisplayPosition.display_position#is_in_file (Path.UniqueKey.lazy_key m_extra.m_file)
|
|
|
+let get_typing_mode com m_extra =
|
|
|
+ let full_typing = com.is_macro_context
|
|
|
+ || com.display.dms_full_typing
|
|
|
+ || Define.defined com.defines Define.DisableHxbCache
|
|
|
+ || Define.defined com.defines Define.DisableHxbOptimizations
|
|
|
+ || DisplayPosition.display_position#is_in_file (Path.UniqueKey.lazy_key m_extra.m_file)
|
|
|
+ in
|
|
|
+ if full_typing then FullTyping else AllowPartialTyping
|
|
|
|
|
|
(* Checks if module [m] can be reused from the cache and returns None in that case. Otherwise, returns
|
|
|
[Some m'] where [m'] is the module responsible for [m] not being reusable. *)
|
|
|
@@ -331,7 +333,7 @@ let check_module sctx com m_path m_extra p =
|
|
|
try
|
|
|
check_module_path();
|
|
|
if not (has_policy NoFileSystemCheck) || Path.file_extension (Path.UniqueKey.lazy_path m_extra.m_file) <> "hx" then check_file();
|
|
|
- if full_typing com m_extra then check_dependencies();
|
|
|
+ if (get_typing_mode com m_extra) = FullTyping then check_dependencies();
|
|
|
None
|
|
|
with
|
|
|
| Dirty reason ->
|
|
|
@@ -390,17 +392,19 @@ let check_module sctx com m_path m_extra p =
|
|
|
end;
|
|
|
state
|
|
|
|
|
|
-let get_hxb_module com cc path =
|
|
|
+let get_hxb_module com cc path typing_mode =
|
|
|
try
|
|
|
let mc = cc#get_hxb_module path in
|
|
|
- if not (full_typing com mc.mc_extra) then begin
|
|
|
- mc.mc_extra.m_cache_state <- MSGood;
|
|
|
- BinaryModule mc
|
|
|
- end else
|
|
|
- begin match mc.mc_extra.m_cache_state with
|
|
|
- | MSBad reason -> BadModule reason
|
|
|
- | _ -> BinaryModule mc
|
|
|
- end
|
|
|
+ match get_typing_mode com mc.mc_extra with
|
|
|
+ | AllowPartialTyping ->
|
|
|
+ mc.mc_extra.m_cache_state <- MSGood;
|
|
|
+ BinaryModule mc
|
|
|
+ | FullTyping ->
|
|
|
+ begin match mc.mc_extra.m_cache_state with
|
|
|
+ | MSBad reason when typing_mode = AllowPartialTyping -> BadBinaryModule (mc, reason)
|
|
|
+ | MSBad reason -> BadModule reason
|
|
|
+ | _ -> BinaryModule mc
|
|
|
+ end
|
|
|
with Not_found ->
|
|
|
NoModule
|
|
|
|
|
|
@@ -425,18 +429,36 @@ class hxb_reader_api_server
|
|
|
method add_module (m : module_def) =
|
|
|
com.module_lut#add m.m_path m
|
|
|
|
|
|
- method resolve_type (pack : string list) (mname : string) (tname : string) =
|
|
|
+ method resolve_type (pack : string list) (mname : string) (tname : string) full_restore =
|
|
|
let path = (pack,mname) in
|
|
|
- let m = self#resolve_module path in
|
|
|
+ let m = self#resolve_module path full_restore in
|
|
|
List.find (fun t -> snd (t_path t) = tname) m.m_types
|
|
|
|
|
|
- method resolve_module (path : path) =
|
|
|
- match self#find_module path with
|
|
|
+ method resolve_module (path : path) full_restore =
|
|
|
+ match self#find_module path full_restore with
|
|
|
| GoodModule m ->
|
|
|
m
|
|
|
| BinaryModule mc ->
|
|
|
let reader = new HxbReader.hxb_reader path com.hxb_reader_stats (if Common.defined com Define.HxbTimes then Some com.timer_ctx else None) in
|
|
|
- let full_restore = full_typing com mc.mc_extra in
|
|
|
+ let typing_mode = get_typing_mode com mc.mc_extra in
|
|
|
+ let f_next chunks until =
|
|
|
+ let macro = if com.is_macro_context then " (macro)" else "" in
|
|
|
+ let f = reader#read_chunks_until (self :> HxbReaderApi.hxb_reader_api) chunks until in
|
|
|
+ Timer.time com.timer_ctx ["server";"module cache";"hxb read" ^ macro;"until " ^ (string_of_chunk_kind until)] f typing_mode
|
|
|
+ in
|
|
|
+
|
|
|
+ let m,chunks = f_next mc.mc_chunks EOT in
|
|
|
+
|
|
|
+ (* We try to avoid reading expressions as much as possible, so we only do this for
|
|
|
+ our current display file if we're in display mode. *)
|
|
|
+ (match typing_mode with
|
|
|
+ | FullTyping -> ignore(f_next chunks EOM)
|
|
|
+ | AllowPartialTyping -> delay PConnectField (fun () -> ignore(f_next chunks EOF)));
|
|
|
+ incr stats.s_modules_restored;
|
|
|
+ m
|
|
|
+ | BadBinaryModule (mc, reason) ->
|
|
|
+ let reader = new HxbReader.hxb_reader path com.hxb_reader_stats (if Common.defined com Define.HxbTimes then Some com.timer_ctx else None) in
|
|
|
+ let typing_mode = get_typing_mode com mc.mc_extra in
|
|
|
let f_next chunks until =
|
|
|
let macro = if com.is_macro_context then " (macro)" else "" in
|
|
|
let f = reader#read_chunks_until (self :> HxbReaderApi.hxb_reader_api) chunks until in
|
|
|
@@ -444,11 +466,13 @@ class hxb_reader_api_server
|
|
|
in
|
|
|
|
|
|
let m,chunks = f_next mc.mc_chunks EOT in
|
|
|
+ m.m_extra.m_cache_state <- MSBad reason;
|
|
|
|
|
|
(* We try to avoid reading expressions as much as possible, so we only do this for
|
|
|
our current display file if we're in display mode. *)
|
|
|
- if full_restore then ignore(f_next chunks EOM)
|
|
|
- else delay PConnectField (fun () -> ignore(f_next chunks EOF));
|
|
|
+ (match typing_mode with
|
|
|
+ | FullTyping -> ignore(f_next chunks EOM)
|
|
|
+ | AllowPartialTyping -> delay PConnectField (fun () -> ignore(f_next chunks EOF)));
|
|
|
incr stats.s_modules_restored;
|
|
|
m
|
|
|
| BadModule reason ->
|
|
|
@@ -456,10 +480,10 @@ class hxb_reader_api_server
|
|
|
| NoModule ->
|
|
|
die (Printf.sprintf "Unexpected NoModule %s" (s_type_path path)) __LOC__
|
|
|
|
|
|
- method find_module (m_path : path) =
|
|
|
+ method find_module (m_path : path) typing_mode =
|
|
|
try
|
|
|
GoodModule (com.module_lut#find m_path)
|
|
|
- with Not_found -> get_hxb_module com cc m_path
|
|
|
+ with Not_found -> get_hxb_module com cc m_path typing_mode
|
|
|
|
|
|
method basic_types =
|
|
|
com.basic
|
|
|
@@ -491,7 +515,16 @@ let handle_cache_bound_objects com cbol =
|
|
|
let rec add_modules sctx com delay (m : module_def) (from_binary : bool) (p : pos) =
|
|
|
let own_sign = CommonCache.get_cache_sign com in
|
|
|
let rec add_modules tabs m0 m =
|
|
|
- if m.m_extra.m_added < com.compilation_step then begin
|
|
|
+ if m.m_extra.m_cache_state <> MSGood then begin
|
|
|
+ (match m.m_extra.m_cache_state with
|
|
|
+ | MSBad reason when com.display.dms_full_typing ->
|
|
|
+ failwith (Printf.sprintf "Unexpected bad module %s (%s)" (s_type_path m.m_path) (Printer.s_module_skip_reason reason))
|
|
|
+ | MSBad reason ->
|
|
|
+ com.warning WIgnoredBadModule com.warning_options (Printf.sprintf "Ignored bad module %s (%s)" (s_type_path m.m_path) (Printer.s_module_skip_reason reason)) p
|
|
|
+ | _ -> ()
|
|
|
+ );
|
|
|
+ com.module_lut#remove m.m_path
|
|
|
+ end else if m.m_extra.m_added < com.compilation_step then begin
|
|
|
m.m_extra.m_added <- com.compilation_step;
|
|
|
(match m0.m_extra.m_kind, m.m_extra.m_kind with
|
|
|
| MCode, MMacro | MMacro, MCode ->
|
|
|
@@ -507,26 +540,31 @@ let rec add_modules sctx com delay (m : module_def) (from_binary : bool) (p : po
|
|
|
if not from_binary || m != m then
|
|
|
com.module_lut#add m.m_path m;
|
|
|
handle_cache_bound_objects com m.m_extra.m_cache_bound_objects;
|
|
|
- let full_restore = full_typing com m.m_extra in
|
|
|
+ let typing_mode = get_typing_mode com m.m_extra in
|
|
|
PMap.iter (fun _ mdep ->
|
|
|
let mpath = mdep.md_path in
|
|
|
if mdep.md_sign = own_sign then begin
|
|
|
let m2 = try
|
|
|
- com.module_lut#find mpath
|
|
|
+ Some (com.module_lut#find mpath)
|
|
|
with Not_found ->
|
|
|
match type_module sctx com delay mpath p with
|
|
|
| GoodModule m ->
|
|
|
- m
|
|
|
+ Some m
|
|
|
| BinaryModule mc ->
|
|
|
failwith (Printf.sprintf "Unexpectedly found unresolved binary module %s as a dependency of %s" (s_type_path mpath) (s_type_path m0.m_path))
|
|
|
| NoModule ->
|
|
|
failwith (Printf.sprintf "Unexpectedly could not find module %s as a dependency of %s" (s_type_path mpath) (s_type_path m0.m_path))
|
|
|
+ | BadBinaryModule (_, reason) | BadModule reason when typing_mode = AllowPartialTyping ->
|
|
|
+ com.warning WIgnoredBadModule com.warning_options (Printf.sprintf "Ignored bad dependency %s (%s) of %s" (s_type_path m.m_path) (Printer.s_module_skip_reason reason) (s_type_path m0.m_path)) p;
|
|
|
+ None
|
|
|
+ | BadBinaryModule (_, reason) ->
|
|
|
+ failwith (Printf.sprintf "Unexpected bad hxb module %s (%s) as a dependency of %s" (s_type_path mpath) (Printer.s_module_skip_reason reason) (s_type_path m0.m_path))
|
|
|
| BadModule reason ->
|
|
|
failwith (Printf.sprintf "Unexpected bad module %s (%s) as a dependency of %s" (s_type_path mpath) (Printer.s_module_skip_reason reason) (s_type_path m0.m_path))
|
|
|
in
|
|
|
- add_modules (tabs ^ " ") m0 m2
|
|
|
+ Option.may (fun m2 -> add_modules (tabs ^ " ") m0 m2) m2
|
|
|
end
|
|
|
- ) (if full_restore then m.m_extra.m_deps else Option.default m.m_extra.m_deps m.m_extra.m_display_deps)
|
|
|
+ ) (if typing_mode = FullTyping then m.m_extra.m_deps else Option.default m.m_extra.m_deps m.m_extra.m_display_deps)
|
|
|
)
|
|
|
end
|
|
|
in
|
|
|
@@ -555,7 +593,7 @@ and type_module sctx com delay mpath p =
|
|
|
| MSBad reason -> BadModule reason
|
|
|
| _ -> GoodModule m
|
|
|
end;
|
|
|
- with Not_found -> get_hxb_module com cc m_path
|
|
|
+ with Not_found -> get_hxb_module com cc m_path FullTyping
|
|
|
in
|
|
|
(* Should not raise anything! *)
|
|
|
let m = match find_module_in_cache cc mpath p with
|
|
|
@@ -574,7 +612,7 @@ and type_module sctx com delay mpath p =
|
|
|
begin match check_module sctx mpath mc.mc_extra p with
|
|
|
| None ->
|
|
|
let reader = new HxbReader.hxb_reader mpath com.hxb_reader_stats (if Common.defined com Define.HxbTimes then Some com.timer_ctx else None) in
|
|
|
- let full_restore = full_typing com mc.mc_extra in
|
|
|
+ let typing_mode = get_typing_mode com mc.mc_extra in
|
|
|
let api = match com.hxb_reader_api with
|
|
|
| Some api ->
|
|
|
api
|
|
|
@@ -585,20 +623,24 @@ and type_module sctx com delay mpath p =
|
|
|
in
|
|
|
let f_next chunks until =
|
|
|
let macro = if com.is_macro_context then " (macro)" else "" in
|
|
|
- Timer.time com.timer_ctx ["server";"module cache";"hxb read" ^ macro;"until " ^ (string_of_chunk_kind until)] (reader#read_chunks_until api chunks until) full_restore
|
|
|
+ Timer.time com.timer_ctx ["server";"module cache";"hxb read" ^ macro;"until " ^ (string_of_chunk_kind until)] (reader#read_chunks_until api chunks until) typing_mode
|
|
|
in
|
|
|
|
|
|
let m,chunks = f_next mc.mc_chunks EOT in
|
|
|
|
|
|
(* We try to avoid reading expressions as much as possible, so we only do this for
|
|
|
our current display file if we're in display mode. *)
|
|
|
- if full_restore then ignore(f_next chunks EOM)
|
|
|
- else delay PConnectField (fun () -> ignore(f_next chunks EOF));
|
|
|
+ (match typing_mode with
|
|
|
+ | FullTyping -> ignore(f_next chunks EOM)
|
|
|
+ | AllowPartialTyping -> delay PConnectField (fun () -> ignore(f_next chunks EOF)));
|
|
|
incr stats.s_modules_restored;
|
|
|
add_modules true m;
|
|
|
| Some reason ->
|
|
|
skip mpath reason
|
|
|
end
|
|
|
+ | BadBinaryModule (_, reason) ->
|
|
|
+ (* A BadModule state here means that the module is already invalidated in the cache, e.g. from server/invalidate. *)
|
|
|
+ skip mpath reason
|
|
|
| BadModule reason ->
|
|
|
(* A BadModule state here means that the module is already invalidated in the cache, e.g. from server/invalidate. *)
|
|
|
skip mpath reason
|