浏览代码

[hxb] Continue display dependencies rework

Rudy Ges 9 月之前
父节点
当前提交
672bf046b1

+ 2 - 1
src/compiler/compilationCache.ml

@@ -104,7 +104,8 @@ class context_cache (index : int) (sign : Digest.t) = object(self)
 				mc_min_chunks = HxbWriter.get_chunks min_writer;
 				mc_min_chunks = HxbWriter.get_chunks min_writer;
 				mc_extra = { m.m_extra with
 				mc_extra = { m.m_extra with
 					m_cache_state = MSGood;
 					m_cache_state = MSGood;
-					m_sig_deps = Some (HxbWriter.get_dependencies min_writer)
+					m_sig_deps = Some (HxbWriter.get_dependencies min_writer);
+					m_all_deps = PMap.fold (fun mdep acc -> (mdep.md_path, mdep.md_sign) :: acc) (HxbWriter.get_dependencies writer) [];
 				}
 				}
 			}
 			}
 
 

+ 1 - 1
src/compiler/hxb/hxbWriter.ml

@@ -870,7 +870,7 @@ module HxbWriter = struct
 	(* References *)
 	(* References *)
 
 
 	let maybe_add_sig_dep writer m =
 	let maybe_add_sig_dep writer m =
-		if writer.minimal && m.m_path <> writer.current_module.m_path && not (List.exists (fun m' -> m'.m_path = m.m_path) writer.deps) then
+		if m.m_path <> writer.current_module.m_path && not (List.exists (fun m' -> m'.m_path = m.m_path) writer.deps) then
 			writer.deps <- m :: writer.deps
 			writer.deps <- m :: writer.deps
 
 
 	let write_class_ref writer (c : tclass) =
 	let write_class_ref writer (c : tclass) =

+ 19 - 6
src/compiler/server.ml

@@ -447,7 +447,8 @@ class hxb_reader_api_server
 				else Minimal
 				else Minimal
 			in
 			in
 			let f_next chunks until =
 			let f_next chunks until =
-				let t_hxb = Timer.timer ["server";"module cache";"hxb read";"until " ^ (string_of_chunk_kind until)] in
+				let macro = if com.is_macro_context then " (macro)" else "" in
+				let t_hxb = Timer.timer ["server";"module cache";"hxb read" ^ macro;"until " ^ (string_of_chunk_kind until)] in
 				let r = reader#read_chunks_until (self :> HxbReaderApi.hxb_reader_api) chunks until restore_level in
 				let r = reader#read_chunks_until (self :> HxbReaderApi.hxb_reader_api) chunks until restore_level in
 				t_hxb();
 				t_hxb();
 				r
 				r
@@ -460,7 +461,8 @@ class hxb_reader_api_server
 			(* We try to avoid reading expressions as much as possible, so we only do this for
 			(* 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. *)
 				 our current display file if we're in display mode. *)
 			if restore_level <> Minimal then ignore(f_next chunks EOM)
 			if restore_level <> Minimal then ignore(f_next chunks EOM)
-			else delay (fun () -> ignore(f_next chunks EOF));
+			else if DisplayPosition.display_position#is_display_dependency m.m_path m.m_extra.m_sign then
+				delay (fun () -> ignore(f_next chunks EOF));
 			m
 			m
 		| BadModule reason ->
 		| BadModule reason ->
 			die (Printf.sprintf "Unexpected BadModule %s (%s)" (s_type_path path) (Printer.s_module_skip_reason reason)) __LOC__
 			die (Printf.sprintf "Unexpected BadModule %s (%s)" (s_type_path path) (Printer.s_module_skip_reason reason)) __LOC__
@@ -579,18 +581,25 @@ and type_module sctx com delay mpath p =
 			   in the cache. The true cache state will be known after check_module. *)
 			   in the cache. The true cache state will be known after check_module. *)
 			begin match check_module sctx mpath m.m_extra p with
 			begin match check_module sctx mpath m.m_extra p with
 				| None ->
 				| None ->
+					(* TODO: does this help at all? *)
+					(* let is_display_file = DisplayPosition.display_position#is_in_file (Path.UniqueKey.lazy_key m.m_extra.m_file) in *)
+					(* if is_display_file then DisplayPosition.display_position#set_display_module m.m_path m.m_extra; *)
+
 					add_modules false m;
 					add_modules false m;
 				| Some reason ->
 				| Some reason ->
 					skip m.m_path reason
 					skip m.m_path reason
 			end
 			end
 		| BinaryModule mc ->
 		| BinaryModule mc ->
+			let is_display_file = DisplayPosition.display_position#is_in_file (Path.UniqueKey.lazy_key mc.mc_extra.m_file) in
+			if is_display_file then DisplayPosition.display_position#set_display_module mc.mc_path mc.mc_extra;
+
 			(* Similarly, we only know that a binary module wasn't explicitly tainted. Decode it only after
 			(* Similarly, we only know that a binary module wasn't explicitly tainted. Decode it only after
 			   checking dependencies. This means that the actual decoding never has any reason to fail. *)
 			   checking dependencies. This means that the actual decoding never has any reason to fail. *)
 			begin match check_module sctx mpath mc.mc_extra p with
 			begin match check_module sctx mpath mc.mc_extra p with
 				| None ->
 				| None ->
 					let reader = new HxbReader.hxb_reader mpath com.hxb_reader_stats (Some cc#get_string_pool_arr) (Common.defined com Define.HxbTimes) in
 					let reader = new HxbReader.hxb_reader mpath com.hxb_reader_stats (Some cc#get_string_pool_arr) (Common.defined com Define.HxbTimes) in
 					let restore_level:HxbReader.restore_level =
 					let restore_level:HxbReader.restore_level =
-						if com.display.dms_full_typing then Full
+						if com.is_macro_context || com.display.dms_full_typing then Full
 						else if DisplayPosition.display_position#is_in_file (Path.UniqueKey.lazy_key mc.mc_extra.m_file) then DisplayFile
 						else if DisplayPosition.display_position#is_in_file (Path.UniqueKey.lazy_key mc.mc_extra.m_file) then DisplayFile
 						else Minimal
 						else Minimal
 					in
 					in
@@ -603,19 +612,23 @@ and type_module sctx com delay mpath p =
 							api
 							api
 					in
 					in
 					let f_next chunks until =
 					let f_next chunks until =
-						let t_hxb = Timer.timer ["server";"module cache";"hxb read";"until " ^ (string_of_chunk_kind until)] in
+						let macro = if com.is_macro_context then " (macro)" else "" in
+						let t_hxb = Timer.timer ["server";"module cache";"hxb read" ^ macro;"until " ^ (string_of_chunk_kind until)] in
 						let r = reader#read_chunks_until api chunks until restore_level in
 						let r = reader#read_chunks_until api chunks until restore_level in
 						t_hxb();
 						t_hxb();
 						r
 						r
 					in
 					in
+
 					let m,chunks = f_next (match restore_level with
 					let m,chunks = f_next (match restore_level with
 						| Full | DisplayFile -> mc.mc_chunks
 						| Full | DisplayFile -> mc.mc_chunks
 						| Minimal -> mc.mc_min_chunks
 						| Minimal -> mc.mc_min_chunks
 					) EOT in
 					) EOT in
+
 					(* We try to avoid reading expressions as much as possible, so we only do this for
 					(* 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. *)
 					   our current display file if we're in display mode. *)
-					if restore_level <> Minimal then ignore(f_next chunks EOM)
-					else delay (fun () -> ignore(f_next chunks EOF));
+          if restore_level <> Minimal then ignore(f_next chunks EOM)
+          else if DisplayPosition.display_position#is_display_dependency m.m_path m.m_extra.m_sign then
+            delay (fun () -> ignore(f_next chunks EOF));
 					add_modules true m;
 					add_modules true m;
 				| Some reason ->
 				| Some reason ->
 					skip mpath reason
 					skip mpath reason

+ 10 - 0
src/core/display/displayPosition.ml

@@ -10,6 +10,7 @@ class display_position_container =
 	object (self)
 	object (self)
 		(** Current display position *)
 		(** Current display position *)
 		val mutable pos = null_pos
 		val mutable pos = null_pos
+		val mutable display_module : (path * TType.module_def_extra) option = None
 		val mutable file_key = None
 		val mutable file_key = None
 		val mutable file_keys = []
 		val mutable file_keys = []
 		(**
 		(**
@@ -26,6 +27,14 @@ class display_position_container =
 			file_key <- None;
 			file_key <- None;
 			file_keys <- if p.pfile = DisplayProcessingGlobals.file_input_marker then [] else [Path.UniqueKey.create p.pfile]
 			file_keys <- if p.pfile = DisplayProcessingGlobals.file_input_marker then [] else [Path.UniqueKey.create p.pfile]
 
 
+		method set_display_module path mc_extra =
+			display_module <- Some (path, mc_extra)
+
+		method is_display_dependency path sign = match display_module with
+			(* That one is tricky.. usually when it's not set it's because it's being retyped *)
+			| None -> true
+			| Some m' -> List.mem (path,sign) (snd m').m_all_deps
+
 		method set_files files =
 		method set_files files =
 			file_keys <- files
 			file_keys <- files
 
 
@@ -52,6 +61,7 @@ class display_position_container =
 		*)
 		*)
 		method reset =
 		method reset =
 			pos <- null_pos;
 			pos <- null_pos;
+			display_module <- None;
 			file_key <- None;
 			file_key <- None;
 			file_keys <- []
 			file_keys <- []
 		(**
 		(**

+ 1 - 0
src/core/tFunctions.ml

@@ -185,6 +185,7 @@ let module_extra file sign time kind added policy =
 		m_processed = 0;
 		m_processed = 0;
 		m_deps = PMap.empty;
 		m_deps = PMap.empty;
 		m_sig_deps = None;
 		m_sig_deps = None;
+		m_all_deps = [];
 		m_kind = kind;
 		m_kind = kind;
 		m_cache_bound_objects = DynArray.create ();
 		m_cache_bound_objects = DynArray.create ();
 		m_features = Hashtbl.create 0;
 		m_features = Hashtbl.create 0;

+ 1 - 0
src/core/tType.ml

@@ -444,6 +444,7 @@ and module_def_extra = {
 	mutable m_processed : int;
 	mutable m_processed : int;
 	mutable m_deps : (int,module_dep) PMap.t;
 	mutable m_deps : (int,module_dep) PMap.t;
 	mutable m_sig_deps : (int,module_dep) PMap.t option;
 	mutable m_sig_deps : (int,module_dep) PMap.t option;
+	mutable m_all_deps : (path * Digest.t) list;
 	mutable m_kind : module_kind;
 	mutable m_kind : module_kind;
 	mutable m_cache_bound_objects : cache_bound_object DynArray.t;
 	mutable m_cache_bound_objects : cache_bound_object DynArray.t;
 	mutable m_features : (string,bool) Hashtbl.t;
 	mutable m_features : (string,bool) Hashtbl.t;