Browse Source

[std] add haxe.macro.CompilationServer.invalidateModule()

Rudy Ges 7 months ago
parent
commit
90a0af0e1a
3 changed files with 29 additions and 3 deletions
  1. 15 3
      src/compiler/compilationCache.ml
  2. 5 0
      src/macro/macroApi.ml
  3. 9 0
      std/haxe/macro/CompilationServer.hx

+ 15 - 3
src/compiler/compilationCache.ml

@@ -234,15 +234,27 @@ class cache = object(self)
 			) cc#get_modules acc
 		) contexts []
 
+	method taint_module m_path reason =
+		Hashtbl.iter (fun _ cc ->
+			Hashtbl.iter (fun _ m ->
+				if m.m_path = m_path then m.m_extra.m_cache_state <- MSBad (Tainted reason)
+			) cc#get_modules;
+			Hashtbl.iter (fun _ mc ->
+				if mc.HxbData.mc_path = m_path then
+					mc.HxbData.mc_extra.m_cache_state <- match reason, mc.mc_extra.m_cache_state with
+					| CheckDisplayFile, (MSBad _ as state) -> state
+					| _ -> MSBad (Tainted reason)
+			) cc#get_hxb
+		) contexts
+
 	method taint_modules file_key reason =
 		Hashtbl.iter (fun _ cc ->
 			Hashtbl.iter (fun _ m ->
 				if Path.UniqueKey.lazy_key m.m_extra.m_file = file_key then m.m_extra.m_cache_state <- MSBad (Tainted reason)
 			) cc#get_modules;
-			let open HxbData in
 			Hashtbl.iter (fun _ mc ->
-				if Path.UniqueKey.lazy_key mc.mc_extra.m_file = file_key then
-					mc.mc_extra.m_cache_state <- match reason, mc.mc_extra.m_cache_state with
+				if Path.UniqueKey.lazy_key mc.HxbData.mc_extra.m_file = file_key then
+					mc.HxbData.mc_extra.m_cache_state <- match reason, mc.HxbData.mc_extra.m_cache_state with
 					| CheckDisplayFile, (MSBad _ as state) -> state
 					| _ -> MSBad (Tainted reason)
 			) cc#get_hxb

+ 5 - 0
src/macro/macroApi.ml

@@ -2323,6 +2323,11 @@ let macro_api ccom get_api =
 			(get_api()).add_module_check_policy filter policy (decode_bool recursive);
 			vnull
 		);
+		"server_invalidate_module", vfun1 (fun p ->
+			let mpath = parse_path (decode_string p) in
+			(ccom()).cs#taint_module mpath ServerInvalidate;
+			vnull
+		);
 		"server_invalidate_files", vfun1 (fun a ->
 			let com = ccom() in
 			let cs = com.cs in

+ 9 - 0
std/haxe/macro/CompilationServer.hx

@@ -69,6 +69,15 @@ class CompilationServer {
 		});
 	}
 
+	/**
+		TODO: apply some restrictions
+
+		Invalidates a module, removing it from the cache.
+	**/
+	static public function invalidateModule(path:String) {
+		@:privateAccess Compiler.load("server_invalidate_module", 1)(path);
+	}
+
 	/**
 		Invalidates all files given in `filePaths`, removing them from the cache.
 	**/