فهرست منبع

[macro] Remove CompilationServer.setModuleCheckPolicy options (#11615)

* [macro] Remove CompilationServer.addModuleCheckPolicy

* [std] remove more special #if display cases

* [macro] Add back some module check policies through CompilationServer.setModuleFileSystemCheckPolicy

* Naming

* Revert renaming

* Rename fix
Rudy Ges 1 سال پیش
والد
کامیت
0bdc03a89d

+ 0 - 5
src/compiler/compilationCache.ml

@@ -310,8 +310,3 @@ class cache = object(self)
 end
 
 type t = cache
-
-type context_options =
-	| NormalContext
-	| MacroContext
-	| NormalAndMacroContext

+ 4 - 4
src/compiler/server.ml

@@ -291,7 +291,7 @@ let check_module sctx com m_path m_extra p =
 				end
 		in
 		let has_policy policy = List.mem policy m_extra.m_check_policy || match policy with
-			| NoCheckShadowing | NoCheckFileTimeModification when !ServerConfig.do_not_check_modules && !Parser.display_mode <> DMNone -> true
+			| NoFileSystemCheck when !ServerConfig.do_not_check_modules && !Parser.display_mode <> DMNone -> true
 			| _ -> false
 		in
 		let check_file () =
@@ -325,9 +325,9 @@ let check_module sctx com m_path m_extra p =
 		in
 		let check () =
 			try
-				if not (has_policy NoCheckShadowing) then check_module_path();
-				if not (has_policy NoCheckFileTimeModification) || Path.file_extension (Path.UniqueKey.lazy_path m_extra.m_file) <> "hx" then check_file();
-				if not (has_policy NoCheckDependencies) then check_dependencies();
+				check_module_path();
+				if not (has_policy NoFileSystemCheck) || Path.file_extension (Path.UniqueKey.lazy_path m_extra.m_file) <> "hx" then check_file();
+				check_dependencies();
 				None
 			with
 			| Dirty reason ->

+ 2 - 3
src/core/tType.ml

@@ -26,10 +26,9 @@ and method_kind =
 	| MethMacro
 
 type module_check_policy =
-	| NoCheckFileTimeModification
+	| NoFileSystemCheck
+	| CheckFileModificationTime
 	| CheckFileContentModification
-	| NoCheckDependencies
-	| NoCheckShadowing
 
 type module_tainting_reason =
 	| CheckDisplayFile

+ 3 - 3
src/macro/macroApi.ml

@@ -56,7 +56,7 @@ type 'value compiler_api = {
 	add_global_metadata : string -> string -> (bool * bool * bool) -> pos -> unit;
 	register_define : string -> Define.user_define -> unit;
 	register_metadata : string -> Meta.user_meta -> unit;
-	add_module_check_policy : string list -> int list -> bool -> int -> unit;
+	add_module_check_policy : string list -> int list -> bool -> unit;
 	decode_expr : 'value -> Ast.expr;
 	encode_expr : Ast.expr -> 'value;
 	encode_ctype : Ast.type_hint -> 'value;
@@ -2292,10 +2292,10 @@ let macro_api ccom get_api =
 			vnull
 		);
 		(* Compilation server *)
-		"server_add_module_check_policy", vfun4 (fun filter policy recursive context_options ->
+		"server_add_module_check_policy", vfun3 (fun filter policy recursive ->
 			let filter = List.map decode_string (decode_array filter) in
 			let policy = List.map decode_int (decode_array policy) in
-			(get_api()).add_module_check_policy filter policy (decode_bool recursive) (decode_int context_options);
+			(get_api()).add_module_check_policy filter policy (decode_bool recursive);
 			vnull
 		);
 		"server_invalidate_files", vfun1 (fun a ->

+ 5 - 10
src/typing/macroContext.ml

@@ -257,7 +257,7 @@ let make_macro_com_api com mcom p =
 				com.global_metadata <- (ExtString.String.nsplit s1 ".",m,config) :: com.global_metadata;
 			) meta;
 		);
-		add_module_check_policy = (fun sl il b i ->
+		add_module_check_policy = (fun sl il b ->
 			Interp.exc_string "unsupported"
 		);
 		register_define = (fun s data -> Define.register_user_define com.user_defines s data);
@@ -526,20 +526,15 @@ let make_macro_api ctx mctx p =
 				ctx.com.global_metadata <- (ExtString.String.nsplit s1 ".",m,config) :: ctx.com.global_metadata;
 			) meta;
 		);
-		MacroApi.add_module_check_policy = (fun sl il b i ->
+		MacroApi.add_module_check_policy = (fun sl il b ->
 			let add ctx =
 				ctx.g.module_check_policies <- (List.fold_left (fun acc s -> (ExtString.String.nsplit s ".",List.map Obj.magic il,b) :: acc) ctx.g.module_check_policies sl);
 				ctx.com.module_lut#iter (fun _ m -> m.m_extra.m_check_policy <- TypeloadModule.get_policy ctx.g m.m_path);
 			in
-			let add_macro ctx = match ctx.g.macros with
+			add ctx;
+			match ctx.g.macros with
 				| None -> ()
-				| Some(_,mctx) -> add mctx;
-			in
-			let open CompilationCache in
-			match Obj.magic i with
-			| NormalContext -> add ctx
-			| MacroContext -> add_macro ctx
-			| NormalAndMacroContext -> add ctx; add_macro ctx;
+				| Some(_,mctx) -> add mctx
 		);
 		MacroApi.with_imports = (fun imports usings f ->
 			let restore_resolution = ctx.m.import_resolution#save in

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

@@ -28,47 +28,18 @@ enum abstract ModuleCheckPolicy(Int) {
 	/**
 		Disables file modification checks, avoiding some filesystem operations.
 	**/
-	var NoCheckFileTimeModification = 0;
+	var NoFileSystemCheck = 0;
 
 	/**
-		If a file is modified, also checks if its content changed. This check
-		is not free, but useful when .hx files are auto-generated.
-	**/
-	var CheckFileContentModification = 1;
-
-	/**
-		Disables dependency checks of the module.
-
-		This should only be used for modules that don't depend on any module that
-		might change. It is effectively a promise to the compiler that the module
-		is unaffected by changes made to other modules. If that promise is broken,
-		the compiler is sad and things probably stop working.
+		Default behavior: check last modification time.
 	**/
-	var NoCheckDependencies = 2;
-
-	/**
-		Disables file shadowing checks. Shadowing can occur when a new file
-		is added to a class-path that has higher priority than the class-path
-		of the current module file.
-	**/
-	var NoCheckShadowing = 3;
-}
+	var CheckFileModificationTime = 1;
 
-enum abstract ContextOptions(Int) {
 	/**
-		Affects only the normal context.
-	**/
-	var NormalContext = 0;
-
-	/**
-		Affects only the macro context.
-	**/
-	var MacroContext = 1;
-
-	/**
-		Affects the normal and macro contexts.
+		If a file is modified, also checks if its content changed. This check
+		is not free, but useful when .hx files are auto-generated.
 	**/
-	var NormalAndMacroContext = 2;
+	var CheckFileContentModification = 2;
 }
 
 /**
@@ -76,7 +47,7 @@ enum abstract ContextOptions(Int) {
 	`--macro server.field(args)`.
 **/
 class CompilationServer {
-	#if (macro || display)
+	#if macro
 	/**
 		Sets the `ModuleCheckPolicy` of all files whose dot-path matches an
 		element of `pathFilters`.
@@ -89,16 +60,12 @@ class CompilationServer {
 		everything (if `recursive = true`) or only top-level types (if
 		`recursive = false`).
 
-		The argument `contextOptions` determines which context (normal, macro
-		or both) this affects.
-
 		If a call to this function is added to the compilation parameters, the
 		compilation server should be restarted to ensure it takes effect.
 	**/
-	static public function setModuleCheckPolicy(pathFilters:Array<String>, policy:Array<ModuleCheckPolicy>, ?recursive = true,
-			?contextOptions:ContextOptions = NormalContext) {
+	static public function setModuleCheckPolicy(pathFilters:Array<String>, policy:Array<ModuleCheckPolicy>, ?recursive = true) {
 		Context.onAfterInitMacros(() -> {
-			@:privateAccess Compiler.load("server_add_module_check_policy", 4)(pathFilters, policy, recursive, contextOptions);
+			@:privateAccess Compiler.load("server_add_module_check_policy", 4)(pathFilters, policy, recursive);
 		});
 	}
 

+ 1 - 1
std/haxe/macro/ExampleJSGenerator.hx

@@ -256,7 +256,7 @@ class ExampleJSGenerator {
 		sys.io.File.saveContent(api.outputFile, buf.toString());
 	}
 
-	#if (macro || display)
+	#if macro
 	public static function use() {
 		Compiler.setCustomJSGenerator(function(api) new ExampleJSGenerator(api).generate());
 	}

+ 1 - 1
std/haxe/macro/Format.hx

@@ -29,7 +29,7 @@ import haxe.macro.Context;
 	The actual macro implemented for Std.format
 **/
 class Format {
-	#if (macro || display)
+	#if macro
 	public static function format(estr:Expr) {
 		var str = switch (estr.expr) {
 			case EConst(c): switch (c) {