Browse Source

Move the logic behind Define.get_signature to define.json (#12251)

* Move the logic behind Define.get_signature to define.json

* Compute signature from sanitized defines

* Update usage of hxb.stats define

* Set more defines as signature neutral

* Set DisableParallelism as signature neutral
Rudy Ges 2 months ago
parent
commit
7a2742bc37
4 changed files with 49 additions and 10 deletions
  1. 29 0
      src-json/define.json
  2. 1 1
      src/context/commonCache.ml
  3. 4 7
      src/core/define.ml
  4. 15 2
      src/prebuild.ml

+ 29 - 0
src-json/define.json

@@ -20,6 +20,7 @@
 		"name": "AnalyzerTimes",
 		"name": "AnalyzerTimes",
 		"define": "times.analyzer",
 		"define": "times.analyzer",
 		"deprecatedDefine": "analyzer-times",
 		"deprecatedDefine": "analyzer-times",
+		"signatureNeutral": true,
 		"doc": "Record detailed timers for the analyzer",
 		"doc": "Record detailed timers for the analyzer",
 		"params": ["level: 0 | 1 | 2"]
 		"params": ["level: 0 | 1 | 2"]
 	},
 	},
@@ -60,6 +61,7 @@
 	{
 	{
 		"name": "DceDebug",
 		"name": "DceDebug",
 		"define": "dce-debug",
 		"define": "dce-debug",
+		"signatureNeutral": true,
 		"doc": "Show DCE log.",
 		"doc": "Show DCE log.",
 		"links": ["https://haxe.org/manual/cr-dce.html"]
 		"links": ["https://haxe.org/manual/cr-dce.html"]
 	},
 	},
@@ -71,16 +73,19 @@
 	{
 	{
 		"name": "DisableHxbCache",
 		"name": "DisableHxbCache",
 		"define": "disable-hxb-cache",
 		"define": "disable-hxb-cache",
+		"signatureNeutral": true,
 		"doc": "Use in-memory cache instead of hxb powered cache."
 		"doc": "Use in-memory cache instead of hxb powered cache."
 	},
 	},
 	{
 	{
 		"name": "DisableHxbOptimizations",
 		"name": "DisableHxbOptimizations",
 		"define": "disable-hxb-optimizations",
 		"define": "disable-hxb-optimizations",
+		"signatureNeutral": true,
 		"doc": "Disable shortcuts used by hxb cache to speed up display requests."
 		"doc": "Disable shortcuts used by hxb cache to speed up display requests."
 	},
 	},
 	{
 	{
 		"name": "DisableParallelism",
 		"name": "DisableParallelism",
 		"define": "disable-parallelism",
 		"define": "disable-parallelism",
+		"signatureNeutral": true,
 		"doc": "Disable all uses of parallelism in the compiler."
 		"doc": "Disable all uses of parallelism in the compiler."
 	},
 	},
 	{
 	{
@@ -92,12 +97,14 @@
 	{
 	{
 		"name": "Display",
 		"name": "Display",
 		"define": "display",
 		"define": "display",
+		"signatureNeutral": true,
 		"doc": "Activated during completion.",
 		"doc": "Activated during completion.",
 		"links": ["https://haxe.org/manual/cr-completion.html"]
 		"links": ["https://haxe.org/manual/cr-completion.html"]
 	},
 	},
 	{
 	{
 		"name": "DisplayStdin",
 		"name": "DisplayStdin",
 		"define": "display-stdin",
 		"define": "display-stdin",
+		"signatureNeutral": true,
 		"doc": "Read the contents of a file specified in `--display` from standard input."
 		"doc": "Read the contents of a file specified in `--display` from standard input."
 	},
 	},
 	{
 	{
@@ -114,12 +121,14 @@
 	{
 	{
 		"name": "Dump",
 		"name": "Dump",
 		"define": "dump",
 		"define": "dump",
+		"signatureNeutral": true,
 		"doc": "Dump typed AST in dump subdirectory using specified mode or non-prettified default.",
 		"doc": "Dump typed AST in dump subdirectory using specified mode or non-prettified default.",
 		"params": ["mode: pretty | record | position | legacy"]
 		"params": ["mode: pretty | record | position | legacy"]
 	},
 	},
 	{
 	{
 		"name": "DumpStage",
 		"name": "DumpStage",
 		"define": "dump.stage",
 		"define": "dump.stage",
+		"signatureNeutral": true,
 		"doc": "The compiler stage after which to generate the dump",
 		"doc": "The compiler stage after which to generate the dump",
 		"params": ["stage: typing | casting | inlining | analyzing | dce"],
 		"params": ["stage: typing | casting | inlining | analyzing | dce"],
 		"default": "dce"
 		"default": "dce"
@@ -127,6 +136,7 @@
 	{
 	{
 		"name": "DumpPath",
 		"name": "DumpPath",
 		"define": "dump-path",
 		"define": "dump-path",
+		"signatureNeutral": true,
 		"doc": "Path to generate dumps to (default: \"dump\").",
 		"doc": "Path to generate dumps to (default: \"dump\").",
 		"default": "dump",
 		"default": "dump",
 		"params": ["path"]
 		"params": ["path"]
@@ -134,11 +144,13 @@
 	{
 	{
 		"name": "DumpDependencies",
 		"name": "DumpDependencies",
 		"define": "dump-dependencies",
 		"define": "dump-dependencies",
+		"signatureNeutral": true,
 		"doc": "Dump the classes dependencies in a dump subdirectory."
 		"doc": "Dump the classes dependencies in a dump subdirectory."
 	},
 	},
 	{
 	{
 		"name": "DumpIgnoreVarIds",
 		"name": "DumpIgnoreVarIds",
 		"define": "dump-ignore-var-ids",
 		"define": "dump-ignore-var-ids",
+		"signatureNeutral": true,
 		"doc": "Remove variable IDs from non-pretty dumps (helps with diff).",
 		"doc": "Remove variable IDs from non-pretty dumps (helps with diff).",
 		"default": "1"
 		"default": "1"
 	},
 	},
@@ -186,18 +198,21 @@
 		"name": "EvalTimes",
 		"name": "EvalTimes",
 		"define": "times.eval",
 		"define": "times.eval",
 		"deprecatedDefine": "eval-times",
 		"deprecatedDefine": "eval-times",
+		"signatureNeutral": true,
 		"doc": "Record per-method execution times in macro/interp mode. Implies eval-stack.",
 		"doc": "Record per-method execution times in macro/interp mode. Implies eval-stack.",
 		"platforms": ["eval"]
 		"platforms": ["eval"]
 	},
 	},
 	{
 	{
 		"name": "FailFast",
 		"name": "FailFast",
 		"define": "fail-fast",
 		"define": "fail-fast",
+		"signatureNeutral": true,
 		"doc": "Abort compilation when first error occurs."
 		"doc": "Abort compilation when first error occurs."
 	},
 	},
 	{
 	{
 		"name": "FilterTimes",
 		"name": "FilterTimes",
 		"define": "times.filter",
 		"define": "times.filter",
 		"deprecatedDefine": "filter-times",
 		"deprecatedDefine": "filter-times",
+		"signatureNeutral": true,
 		"doc": "Record per-filter execution times upon --times."
 		"doc": "Record per-filter execution times upon --times."
 	},
 	},
 	{
 	{
@@ -316,8 +331,15 @@
 		"name": "HxbTimes",
 		"name": "HxbTimes",
 		"define": "times.hxb",
 		"define": "times.hxb",
 		"deprecatedDefine": "hxb-times",
 		"deprecatedDefine": "hxb-times",
+		"signatureNeutral": true,
 		"doc": "Display hxb timing when used with `--times`."
 		"doc": "Display hxb timing when used with `--times`."
 	},
 	},
+	{
+		"name": "HxbStats",
+		"define": "hxb.stats",
+		"signatureNeutral": true,
+		"doc": "Display some hxb related stats (only with compilation server)."
+	},
 	{
 	{
 		"name": "HxcppApiLevel",
 		"name": "HxcppApiLevel",
 		"define": "hxcpp-api-level",
 		"define": "hxcpp-api-level",
@@ -555,6 +577,7 @@
 		"name": "MacroTimes",
 		"name": "MacroTimes",
 		"define": "times.macro",
 		"define": "times.macro",
 		"deprecatedDefine": "macro-times",
 		"deprecatedDefine": "macro-times",
+		"signatureNeutral": true,
 		"doc": "Display per-macro timing when used with `--times`."
 		"doc": "Display per-macro timing when used with `--times`."
 	},
 	},
 	{
 	{
@@ -587,6 +610,7 @@
 	{
 	{
 		"name": "NoCompilation",
 		"name": "NoCompilation",
 		"define": "no-compilation",
 		"define": "no-compilation",
+		"signatureNeutral": true,
 		"doc": "Disable final compilation.",
 		"doc": "Disable final compilation.",
 		"platforms": ["cpp", "hl"]
 		"platforms": ["cpp", "hl"]
 	},
 	},
@@ -848,6 +872,7 @@
 	{
 	{
 		"name": "MessageReporting",
 		"name": "MessageReporting",
 		"define": "message.reporting",
 		"define": "message.reporting",
+		"signatureNeutral": true,
 		"doc": "Select message reporting mode for compiler output. (default: pretty)",
 		"doc": "Select message reporting mode for compiler output. (default: pretty)",
 		"default": "pretty",
 		"default": "pretty",
 		"params": ["mode: classic | pretty | indent"]
 		"params": ["mode: classic | pretty | indent"]
@@ -855,21 +880,25 @@
 	{
 	{
 		"name": "MessageNoColor",
 		"name": "MessageNoColor",
 		"define": "message.no-color",
 		"define": "message.no-color",
+		"signatureNeutral": true,
 		"doc": "Disable ANSI color codes in message reporting."
 		"doc": "Disable ANSI color codes in message reporting."
 	},
 	},
 	{
 	{
 		"name": "MessageAbsolutePositions",
 		"name": "MessageAbsolutePositions",
 		"define": "message.absolute-positions",
 		"define": "message.absolute-positions",
+		"signatureNeutral": true,
 		"doc": "Use absolute character positions instead of line/columns for message reporting."
 		"doc": "Use absolute character positions instead of line/columns for message reporting."
 	},
 	},
 	{
 	{
 		"name": "MessageLogFile",
 		"name": "MessageLogFile",
 		"define": "message.log-file",
 		"define": "message.log-file",
+		"signatureNeutral": true,
 		"doc": "Path to a text file to write message reporting to, in addition to regular output."
 		"doc": "Path to a text file to write message reporting to, in addition to regular output."
 	},
 	},
 	{
 	{
 		"name": "MessageLogFormat",
 		"name": "MessageLogFormat",
 		"define": "message.log-format",
 		"define": "message.log-format",
+		"signatureNeutral": true,
 		"doc": "Select message reporting mode for message log file. (default: indent)",
 		"doc": "Select message reporting mode for message log file. (default: indent)",
 		"default": "indent",
 		"default": "indent",
 		"params": ["format: classic | pretty | indent"]
 		"params": ["format: classic | pretty | indent"]

+ 1 - 1
src/context/commonCache.ml

@@ -122,7 +122,7 @@ let rec cache_context cs com =
 		| None -> ()
 		| None -> ()
 		| Some com -> cache_context cs com
 		| Some com -> cache_context cs com
 	end;
 	end;
-	if Define.raw_defined com.defines "hxb.stats" then
+	if Define.defined com.defines HxbStats then
 		HxbReader.dump_stats (platform_name com.platform) com.hxb_reader_stats
 		HxbReader.dump_stats (platform_name com.platform) com.hxb_reader_stats
 
 
 let maybe_add_context_sign cs com desc =
 let maybe_add_context_sign cs com desc =

+ 4 - 7
src/core/define.ml

@@ -155,16 +155,13 @@ let get_signature def =
 	| None ->
 	| None ->
 		let defines = PMap.foldi (fun k v acc ->
 		let defines = PMap.foldi (fun k v acc ->
 			(* don't make much difference between these special compilation flags *)
 			(* don't make much difference between these special compilation flags *)
-			match String.concat "_" (ExtString.String.nsplit k "-") with
+			let sanitized = String.concat "_" (ExtString.String.nsplit k "-") in
 			(* If we add something here that might be used in conditional compilation it should be added to
 			(* If we add something here that might be used in conditional compilation it should be added to
-			   Parser.parse_macro_ident as well (issue #5682).
-			   Note that we should removed flags like use_rtti_doc here.
+			   Grammar.parse_macro_ident as well (issue #5682).
 			*)
 			*)
-			| "display" | "use_rtti_doc" | "macro_times" | "display_details" | "no_copt" | "display_stdin" | "disable-hxb-cache" | "hxb.stats" | "fail_fast"
-			| "message.reporting" | "message.log_file" | "message.log_format" | "message.no_color"
-			| "dump" | "dump_dependencies" | "dump_ignore_var_ids" -> acc
-			| _ -> (k ^ "=" ^ v) :: acc
+			if DefineList.is_signature_neutral sanitized then acc else (sanitized ^ "=" ^ v) :: acc
 		) def.values [] in
 		) def.values [] in
+		let defines = Ast.remove_duplicates (fun a b -> a != b) defines in
 		let str = String.concat "@" (List.sort compare defines) in
 		let str = String.concat "@" (List.sort compare defines) in
 		let s = Digest.string str in
 		let s = Digest.string str in
 		def.defines_signature <- Some s;
 		def.defines_signature <- Some s;

+ 15 - 2
src/prebuild.ml

@@ -115,6 +115,7 @@ type parsed_define = {
 	d_deprecated : string option;
 	d_deprecated : string option;
 	d_deprecated_define : string option;
 	d_deprecated_define : string option;
 	d_default : string option;
 	d_default : string option;
+	d_signature_neutral : bool option;
 }
 }
 let parse_define json =
 let parse_define json =
 	let fields = match json with
 	let fields = match json with
@@ -131,6 +132,7 @@ let parse_define json =
 		d_deprecated = get_optional_field2 "deprecated" as_string fields;
 		d_deprecated = get_optional_field2 "deprecated" as_string fields;
 		d_deprecated_define = get_optional_field2 "deprecatedDefine" as_string fields;
 		d_deprecated_define = get_optional_field2 "deprecatedDefine" as_string fields;
 		d_default = get_optional_field2 "default" as_string fields;
 		d_default = get_optional_field2 "default" as_string fields;
+		d_signature_neutral = get_optional_field2 "signatureNeutral" as_bool fields;
 	}
 	}
 
 
 let parse_meta json =
 let parse_meta json =
@@ -204,6 +206,7 @@ let gen_option f = function
 let gen_define_info defines =
 let gen_define_info defines =
 	let deprecations = DynArray.create() in
 	let deprecations = DynArray.create() in
 	let default_values = DynArray.create() in
 	let default_values = DynArray.create() in
+	let sig_neutral = DynArray.create() in
 	let define_str = List.map (function
 	let define_str = List.map (function
 		def ->
 		def ->
 			let platforms_str = gen_platforms def.d_platforms in
 			let platforms_str = gen_platforms def.d_platforms in
@@ -233,12 +236,16 @@ let gen_define_info defines =
 					DynArray.add default_values (Printf.sprintf "\t(%S,%S)" define x);
 					DynArray.add default_values (Printf.sprintf "\t(%S,%S)" define x);
 					[Printf.sprintf "DefaultValue(%s)" quoted]
 					[Printf.sprintf "DefaultValue(%s)" quoted]
 			in
 			in
+			(match def.d_signature_neutral with
+				| Some true -> DynArray.add sig_neutral (Printf.sprintf "| %S" (convert_define define))
+				| _ -> ());
 			"\t| " ^ def.d_name ^ " -> \"" ^ define ^ "\",(" ^ (Printf.sprintf "%S" def.d_doc) ^ ",[" ^ (String.concat "; " (platforms_str @ params_str @ links_str @ deprecated @ default)) ^ "])"
 			"\t| " ^ def.d_name ^ " -> \"" ^ define ^ "\",(" ^ (Printf.sprintf "%S" def.d_doc) ^ ",[" ^ (String.concat "; " (platforms_str @ params_str @ links_str @ deprecated @ default)) ^ "])"
 	) defines in
 	) defines in
 	(
 	(
 		String.concat "\n" define_str,
 		String.concat "\n" define_str,
 		String.concat "\n" (DynArray.to_list deprecations),
 		String.concat "\n" (DynArray.to_list deprecations),
-		String.concat ";\n" (DynArray.to_list default_values)
+		String.concat ";\n" (DynArray.to_list default_values),
+		String.concat " " (DynArray.to_list sig_neutral)
 	)
 	)
 
 
 let gen_meta_type metas =
 let gen_meta_type metas =
@@ -379,10 +386,16 @@ match Array.to_list (Sys.argv) with
 		Printf.printf "type strict_defined =\n";
 		Printf.printf "type strict_defined =\n";
 		Printf.printf "%s" (gen_define_type defines);
 		Printf.printf "%s" (gen_define_type defines);
 		Printf.printf "\n\t| Last\n\t| Custom of string\n\n";
 		Printf.printf "\n\t| Last\n\t| Custom of string\n\n";
-		let infos,deprecations,default_values = gen_define_info defines in
+		let infos,deprecations,default_values,sig_neutral = gen_define_info defines in
 		Printf.printf "let infos = function\n";
 		Printf.printf "let infos = function\n";
 		Printf.printf "%s" infos;
 		Printf.printf "%s" infos;
 		Printf.printf "\n\t| Last -> die \"\" __LOC__\n\t| Custom s -> s,(\"\",[])\n";
 		Printf.printf "\n\t| Last -> die \"\" __LOC__\n\t| Custom s -> s,(\"\",[])\n";
+		if sig_neutral = "" then
+			Printf.printf "let is_signature_neutral _ = false\n"
+		else begin
+			Printf.printf "let is_signature_neutral = function\n";
+			Printf.printf "\t%s -> true\n\t| _ -> false\n" sig_neutral;
+		end;
 		Printf.printf "\nlet deprecated_defines = [\n%s\n]\n" deprecations;
 		Printf.printf "\nlet deprecated_defines = [\n%s\n]\n" deprecations;
 		Printf.printf "\nlet default_values = [\n%s\n]\n" default_values;
 		Printf.printf "\nlet default_values = [\n%s\n]\n" default_values;
 	| [_; "meta"; meta_path]->
 	| [_; "meta"; meta_path]->