Selaa lähdekoodia

[server] generalize cache-bound object handling

see #7851
Simon Krajewski 1 vuosi sitten
vanhempi
commit
580cacd45d
4 muutettua tiedostoa jossa 19 lisäystä ja 5 poistoa
  1. 10 2
      src/compiler/server.ml
  2. 1 1
      src/core/tFunctions.ml
  3. 5 1
      src/core/tType.ml
  4. 3 1
      src/macro/macroApi.ml

+ 10 - 2
src/compiler/server.ml

@@ -395,6 +395,14 @@ let check_module sctx ctx m p =
 	end;
 	state
 
+let handle_cache_bound_objects com cbol =
+	List.iter (function
+		| Resource(name,data) ->
+			Hashtbl.replace com.resources name data
+		| IncludeFile(file,position) ->
+			com.include_files <- (file,position) :: com.include_files
+	) cbol
+
 (* Adds module [m] and all its dependencies (recursively) from the cache to the current compilation
    context. *)
 let add_modules sctx ctx m p =
@@ -404,7 +412,7 @@ let add_modules sctx ctx m p =
 			(match m0.m_extra.m_kind, m.m_extra.m_kind with
 			| MCode, MMacro | MMacro, MCode ->
 				(* this was just a dependency to check : do not add to the context *)
-				PMap.iter (Hashtbl.replace com.resources) m.m_extra.m_binded_res;
+				handle_cache_bound_objects com m.m_extra.m_cache_bound_objects;
 			| _ ->
 				m.m_extra.m_added <- ctx.com.compilation_step;
 				ServerMessage.reusing com tabs m;
@@ -412,7 +420,7 @@ let add_modules sctx ctx m p =
 					(t_infos t).mt_restore()
 				) m.m_types;
 				TypeloadModule.ModuleLevel.add_module ctx m p;
-				PMap.iter (Hashtbl.replace com.resources) m.m_extra.m_binded_res;
+				handle_cache_bound_objects com m.m_extra.m_cache_bound_objects;
 				PMap.iter (fun _ (sign,mpath) ->
 					let m2 = (com.cs#get_context sign)#find_module mpath in
 					add_modules (tabs ^ "  ") m0 m2

+ 1 - 1
src/core/tFunctions.ml

@@ -166,7 +166,7 @@ let module_extra file sign time kind policy =
 		m_processed = 0;
 		m_deps = PMap.empty;
 		m_kind = kind;
-		m_binded_res = PMap.empty;
+		m_cache_bound_objects = [];
 		m_if_feature = [];
 		m_features = Hashtbl.create 0;
 		m_check_policy = policy;

+ 5 - 1
src/core/tType.ml

@@ -52,6 +52,10 @@ type type_param_host =
 	| TPHAnonField
 	| TPHLocal
 
+type cache_bound_object =
+	| Resource of string * string
+	| IncludeFile of string * string
+
 type t =
 	| TMono of tmono
 	| TEnum of tenum * tparams
@@ -403,7 +407,7 @@ and module_def_extra = {
 	mutable m_processed : int;
 	mutable m_deps : (int,(string (* sign *) * path)) PMap.t;
 	mutable m_kind : module_kind;
-	mutable m_binded_res : (string, string) PMap.t;
+	mutable m_cache_bound_objects : cache_bound_object list;
 	mutable m_if_feature : (string * class_field_ref) list;
 	mutable m_features : (string,bool) Hashtbl.t;
 }

+ 3 - 1
src/macro/macroApi.ml

@@ -2088,7 +2088,7 @@ let macro_api ccom get_api =
 			if name = "" then failwith "Empty resource name";
 			Hashtbl.replace (ccom()).resources name data;
 			let m = (get_api()).current_module() in
-			m.m_extra.m_binded_res <- PMap.add name data m.m_extra.m_binded_res;
+			m.m_extra.m_cache_bound_objects <- (Resource(name,data)) :: m.m_extra.m_cache_bound_objects;
 			vnull
 		);
 		"get_resources", vfun0 (fun() ->
@@ -2301,6 +2301,8 @@ let macro_api ccom get_api =
 					failwith ("unable to find file for inclusion: " ^ file)
 			in
 			(ccom()).include_files <- (file, position) :: (ccom()).include_files;
+			let m = (get_api()).current_module() in
+			m.m_extra.m_cache_bound_objects <- (IncludeFile(file,position)) :: m.m_extra.m_cache_bound_objects;
 			vnull
 		);
 		(* Compilation server *)