瀏覽代碼

Only enable POC with -D optimistic-display-requests, bring back some com.is_macro_context checks

Rudy Ges 10 月之前
父節點
當前提交
637d859a87

+ 5 - 0
src-json/define.json

@@ -603,6 +603,11 @@
 		"define": "old-error-format",
 		"doc": "Use Haxe 3.x zero-based column error messages instead of new one-based format."
 	},
+	{
+		"name": "OptimisticDisplayRequests",
+		"define": "optimistic-display-requests",
+		"doc": "Ignore invalidation chains during display requests."
+	},
 	{
 		"name": "PhpPrefix",
 		"define": "php-prefix",

+ 10 - 7
src/compiler/compilationCache.ml

@@ -81,7 +81,7 @@ class context_cache (index : int) (sign : Digest.t) = object(self)
 		try (Hashtbl.find modules path).m_extra
 		with Not_found -> (self#get_hxb_module path).mc_extra
 
-	method cache_hxb_module config warn anon_identification path m =
+	method cache_hxb_module ~(optimistic_display_requests:bool) config warn anon_identification path m =
 		match m.m_extra.m_kind with
 		| MImport ->
 			Hashtbl.add modules m.m_path m
@@ -90,19 +90,22 @@ class context_cache (index : int) (sign : Digest.t) = object(self)
 			HxbWriter.write_module writer m;
 
 			(* TODO: avoid running the whole writer again... *)
-			let anon_identification = new Tanon_identification.tanon_identification in
-			let min_writer = HxbWriter.create config None warn anon_identification in
-			min_writer.minimal <- true;
-			HxbWriter.write_module min_writer m;
+			let min_chunks, sig_deps = if optimistic_display_requests then begin
+				let anon_identification = new Tanon_identification.tanon_identification in
+				let min_writer = HxbWriter.create config None warn anon_identification in
+				min_writer.minimal <- true;
+				HxbWriter.write_module min_writer m;
+				HxbWriter.get_chunks min_writer, Some (HxbWriter.get_dependencies min_writer)
+			end else [], None in
 
 			Hashtbl.replace binary_cache path {
 				mc_path = path;
 				mc_id = m.m_id;
 				mc_chunks = HxbWriter.get_chunks writer;
-				mc_min_chunks = HxbWriter.get_chunks min_writer;
+				mc_min_chunks = min_chunks;
 				mc_extra = { m.m_extra with
 					m_cache_state = MSGood;
-					m_sig_deps = Some (HxbWriter.get_dependencies min_writer);
+					m_sig_deps = sig_deps;
 					m_all_deps = PMap.fold (fun mdep acc -> (mdep.md_path, mdep.md_sign) :: acc) (HxbWriter.get_dependencies writer) [];
 				}
 			}

+ 1 - 0
src/compiler/hxb/hxbReader.ml

@@ -718,6 +718,7 @@ class hxb_reader
 	(* Type instances *)
 
 	method should_lazy_wrap =
+		(* Ideally this would be enabled for more cases, but it's just not good enough yet for that *)
 		restore_level = Minimal
 
 	method resolve_ttp_ref = function

+ 18 - 5
src/compiler/server.ml

@@ -311,7 +311,9 @@ let check_module sctx com m_path m_extra p =
 		in
 		let check_dependencies () =
 			let full_restore =
-				com.display.dms_full_typing
+				com.is_macro_context
+				|| com.display.dms_full_typing
+				|| not (Define.defined com.defines Define.OptimisticDisplayRequests)
 				|| DisplayPosition.display_position#is_in_file (Path.UniqueKey.lazy_key m_extra.m_file)
 			in
 			PMap.iter (fun _ mdep ->
@@ -334,6 +336,7 @@ let check_module sctx com m_path m_extra p =
 				let full_typing =
 					com.is_macro_context
 					|| com.display.dms_full_typing
+					|| not (Define.defined com.defines Define.OptimisticDisplayRequests)
 					|| DisplayPosition.display_position#is_in_file (Path.UniqueKey.lazy_key m_extra.m_file)
 				in
 				if full_typing then check_dependencies();
@@ -398,7 +401,13 @@ let check_module sctx com m_path m_extra p =
 let get_hxb_module com cc path =
 	try
 		let mc = cc#get_hxb_module path in
-		if not com.display.dms_full_typing && not (DisplayPosition.display_position#is_in_file (Path.UniqueKey.lazy_key mc.mc_extra.m_file)) then begin
+		let full_restore =
+			com.is_macro_context
+			|| com.display.dms_full_typing
+			|| not (Define.defined com.defines Define.OptimisticDisplayRequests)
+			|| DisplayPosition.display_position#is_in_file (Path.UniqueKey.lazy_key mc.mc_extra.m_file)
+		in
+		if not full_restore then begin
 			mc.mc_extra.m_cache_state <- MSGood;
 			BinaryModule mc
 		end else
@@ -442,7 +451,8 @@ class hxb_reader_api_server
 		| BinaryModule mc ->
 			let reader = new HxbReader.hxb_reader path com.hxb_reader_stats (Some cc#get_string_pool_arr) (Common.defined com Define.HxbTimes) in
 			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 not (Define.defined com.defines Define.OptimisticDisplayRequests) then Full
 				else if DisplayPosition.display_position#is_in_file (Path.UniqueKey.lazy_key mc.mc_extra.m_file) then DisplayFile
 				else Minimal
 			in
@@ -482,7 +492,7 @@ class hxb_reader_api_server
 		i
 
 	method read_expression_eagerly (cf : tclass_field) =
-		com.display.dms_full_typing
+		com.is_macro_context || com.display.dms_full_typing || not (Define.defined com.defines Define.OptimisticDisplayRequests)
 end
 
 let handle_cache_bound_objects com cbol =
@@ -517,7 +527,9 @@ let rec add_modules sctx com delay (m : module_def) (from_binary : bool) (p : po
 					com.module_lut#add m.m_path m;
 				handle_cache_bound_objects com m.m_extra.m_cache_bound_objects;
 				let full_restore =
-					com.display.dms_full_typing
+					com.is_macro_context
+					|| com.display.dms_full_typing
+					|| not (Define.defined com.defines Define.OptimisticDisplayRequests)
 					|| DisplayPosition.display_position#is_in_file (Path.UniqueKey.lazy_key m.m_extra.m_file)
 				in
 				PMap.iter (fun _ mdep ->
@@ -601,6 +613,7 @@ and type_module sctx com delay mpath p =
 					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 =
 						if com.is_macro_context || com.display.dms_full_typing then Full
+						else if not (Define.defined com.defines Define.OptimisticDisplayRequests) then Full
 						else if DisplayPosition.display_position#is_in_file (Path.UniqueKey.lazy_key mc.mc_extra.m_file) then DisplayFile
 						else Minimal
 					in

+ 2 - 1
src/context/commonCache.ml

@@ -105,7 +105,8 @@ let rec cache_context cs com =
 			let cache_module m =
 				(* If we have a signature mismatch, look-up cache for module. Physical equality check is fine as a heuristic. *)
 				let cc = if m.m_extra.m_sign = sign then cc else cs#get_context m.m_extra.m_sign in
-				cc#cache_hxb_module config warn anon_identification m.m_path m;
+				let optimistic_display_requests = Define.defined com.defines Define.OptimisticDisplayRequests in
+				cc#cache_hxb_module ~optimistic_display_requests config warn anon_identification m.m_path m;
 			in
 			cache_module
 	in

+ 5 - 4
src/context/display/displayJson.ml

@@ -153,7 +153,6 @@ class hxb_reader_api_com
 end
 
 let find_module ~(minimal_restore : bool) com cc path =
-	(* TODO: check all this... *)
 	(new hxb_reader_api_com ~minimal_restore com cc)#find_module path
 
 type handler_context = {
@@ -348,20 +347,22 @@ let handler =
 			let path = Path.parse_path (hctx.jsonrpc#get_string_param "path") in
 			let cs = hctx.display#get_cs in
 			let cc = cs#get_context sign in
+			let minimal_restore = Define.defined hctx.com.defines Define.OptimisticDisplayRequests in
 			let m = try
-				find_module ~minimal_restore:true hctx.com cc path
+				find_module ~minimal_restore hctx.com cc path
 			with Not_found ->
 				hctx.send_error [jstring "No such module"]
 			in
-			hctx.send_result (generate_module (cc#get_hxb) (find_module ~minimal_restore:true hctx.com cc) m)
+			hctx.send_result (generate_module (cc#get_hxb) (find_module ~minimal_restore hctx.com cc) m)
 		);
 		"server/type", (fun hctx ->
 			let sign = Digest.from_hex (hctx.jsonrpc#get_string_param "signature") in
 			let path = Path.parse_path (hctx.jsonrpc#get_string_param "modulePath") in
 			let typeName = hctx.jsonrpc#get_string_param "typeName" in
 			let cc = hctx.display#get_cs#get_context sign in
+			let minimal_restore = Define.defined hctx.com.defines Define.OptimisticDisplayRequests in
 			let m = try
-				find_module ~minimal_restore:true hctx.com cc path
+				find_module ~minimal_restore hctx.com cc path
 			with Not_found ->
 				hctx.send_error [jstring "No such module"]
 			in