Просмотр исходного кода

Add -D fail-fast (#11609)

* Add -D fail-fast

* [tests] add some tests for -D fast-fail

* [tests] more tests for -D fast-fail

* [tests] fix file names

* Keep same signature with or without -D fail-fast
Rudy Ges 1 год назад
Родитель
Сommit
1423a5f2dd
24 измененных файлов с 89 добавлено и 9 удалено
  1. 5 0
      src-json/define.json
  2. 12 4
      src/compiler/compilationContext.ml
  3. 3 2
      src/compiler/compiler.ml
  4. 7 2
      src/compiler/messageReporting.ml
  5. 1 0
      src/context/common.ml
  6. 1 1
      src/core/define.ml
  7. 2 0
      tests/misc/projects/Issue6065/compile-fast-fail.hxml
  8. 8 0
      tests/misc/projects/Issue6065/compile-fast-fail.hxml.stderr
  9. 2 0
      tests/misc/projects/Issue6065/indent-fast-fail.hxml
  10. 7 0
      tests/misc/projects/Issue6065/indent-fast-fail.hxml.stderr
  11. 2 0
      tests/misc/projects/Issue6065/pretty-fast-fail.hxml
  12. 20 0
      tests/misc/projects/Issue6065/pretty-fast-fail.hxml.stderr
  13. 2 0
      tests/misc/projects/Issue8019/compile-fast-fail.hxml
  14. 2 0
      tests/misc/projects/Issue8019/compile-fast-fail.hxml.stderr
  15. 2 0
      tests/misc/projects/Issue8019/compile3-fast-fail.hxml
  16. 1 0
      tests/misc/projects/Issue8019/compile3-fast-fail.hxml.stderr
  17. 2 0
      tests/misc/projects/issue5002/compile-fast-fail.hxml
  18. 1 0
      tests/misc/projects/issue5002/compile-fast-fail.hxml.stderr
  19. 2 0
      tests/misc/projects/issue5002/compile2-fast-fail.hxml
  20. 1 0
      tests/misc/projects/issue5002/compile2-fast-fail.hxml.stderr
  21. 2 0
      tests/misc/projects/issue5002/compile3-fast-fail.hxml
  22. 1 0
      tests/misc/projects/issue5002/compile3-fast-fail.hxml.stderr
  23. 2 0
      tests/misc/projects/issue5002/compile4-fast-fail.hxml
  24. 1 0
      tests/misc/projects/issue5002/compile4-fast-fail.hxml.stderr

+ 5 - 0
src-json/define.json

@@ -160,6 +160,11 @@
 		"doc": "Record per-method execution times in macro/interp mode. Implies eval-stack.",
 		"platforms": ["eval"]
 	},
+	{
+		"name": "FailFast",
+		"define": "fail-fast",
+		"doc": "Abort compilation when first error occurs."
+	},
 	{
 		"name": "FilterTimes",
 		"define": "filter-times",

+ 12 - 4
src/compiler/compilationContext.ml

@@ -80,16 +80,24 @@ let message ctx msg =
 	ctx.messages <- msg :: ctx.messages
 
 let error ctx ?(depth=0) ?(from_macro = false) msg p =
-	message ctx (make_compiler_message ~from_macro msg p depth DKCompilerMessage Error);
-	ctx.has_error <- true
+	message ctx (make_compiler_message ~from_macro msg p depth DKCompilerMessage Error)
+
+let after_error ctx =
+	ctx.has_error <- true;
+	if Common.fail_fast ctx.com then raise Abort
 
 let error_ext ctx (err : Error.error) =
 	Error.recurse_error (fun depth err ->
 		error ~depth ~from_macro:err.err_from_macro ctx (Error.error_msg err.err_message) err.err_pos
-	) err
+	) err;
+	after_error ctx
+
+let error ctx ?(depth=0) ?(from_macro = false) msg p =
+	error ctx ~depth ~from_macro msg p;
+	after_error ctx
 
 let create_native_lib file extern kind = {
 	lib_file = file;
 	lib_extern = extern;
 	lib_kind = kind;
-}
+}

+ 3 - 2
src/compiler/compiler.ml

@@ -417,8 +417,6 @@ let compile_safe ctx f =
 try
 	f ()
 with
-	| Abort ->
-		()
 	| Error.Fatal_error err ->
 		error_ext ctx err
 	| Lexer.Error (m,p) ->
@@ -454,6 +452,9 @@ with
 	| e when (try Sys.getenv "OCAMLRUNPARAM" <> "b" with _ -> true) && not Helper.is_debug_run ->
 		error ctx (Printexc.to_string e) null_pos
 
+let compile_safe ctx f =
+	try compile_safe ctx f with Abort -> ()
+
 let finalize ctx =
 	ctx.comm.flush ctx;
 	List.iter (fun lib -> lib#close) ctx.com.hxb_libs;

+ 7 - 2
src/compiler/messageReporting.ml

@@ -356,10 +356,15 @@ let display_messages ctx on_message = begin
 	let ectx = create_error_context absolute_positions in
 	ectx.max_lines <- get_max_line ectx.max_lines ctx.messages;
 
+	let error msg =
+		ctx.has_error <- true;
+		on_message MessageSeverity.Error msg
+	in
+
 	let get_formatter _ def default =
 		try get_formatter ctx.com def default
 		with | ConfigError s ->
-			error ctx s null_pos;
+			error s;
 			compiler_message_string
 	in
 
@@ -393,7 +398,7 @@ let display_messages ctx on_message = begin
 		end with
 			| Failure e | Sys_error e -> begin
 				let def = Define.get_define_key Define.MessageLogFile in
-				error ctx (Printf.sprintf "Error opening log file: %s. Logging to file disabled (-D %s)" e def) null_pos;
+				error (Printf.sprintf "Error opening log file: %s. Logging to file disabled (-D %s)" e def);
 				log_messages := false;
 			end
 	end;

+ 1 - 0
src/context/common.ml

@@ -469,6 +469,7 @@ let convert_define k =
 	String.concat "_" (ExtString.String.nsplit k "-")
 
 let is_next com = defined com HaxeNext
+let fail_fast com = defined com FailFast
 
 let external_defined ctx k =
 	Define.raw_defined ctx.defines (convert_define k)

+ 1 - 1
src/core/define.ml

@@ -152,7 +152,7 @@ let get_signature def =
 			   Parser.parse_macro_ident as well (issue #5682).
 			   Note that we should removed flags like use_rtti_doc here.
 			*)
-			| "display" | "use_rtti_doc" | "macro_times" | "display_details" | "no_copt" | "display_stdin" | "hxb.stats"
+			| "display" | "use_rtti_doc" | "macro_times" | "display_details" | "no_copt" | "display_stdin" | "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

+ 2 - 0
tests/misc/projects/Issue6065/compile-fast-fail.hxml

@@ -0,0 +1,2 @@
+compile-fail.hxml
+-D fail-fast

+ 8 - 0
tests/misc/projects/Issue6065/compile-fast-fail.hxml.stderr

@@ -0,0 +1,8 @@
+Main.hx:8: characters 9-18 : Could not find a suitable overload, reasons follow
+Main.hx:8: characters 9-18 : Overload resolution failed for () -> Void
+Main.hx:8: characters 13-17 : Too many arguments
+Main.hx:8: characters 9-18 : Overload resolution failed for (t : f.T) -> Void
+Main.hx:8: characters 13-17 : Constraint check failure for f.T
+Main.hx:8: characters 13-17 : ... String should be Int
+Main.hx:8: characters 13-17 : ... For function argument 't'
+Main.hx:8: characters 9-18 : End of overload failure reasons

+ 2 - 0
tests/misc/projects/Issue6065/indent-fast-fail.hxml

@@ -0,0 +1,2 @@
+indent-fail.hxml
+-D fail-fast

+ 7 - 0
tests/misc/projects/Issue6065/indent-fast-fail.hxml.stderr

@@ -0,0 +1,7 @@
+Main.hx:8: characters 9-18 : Could not find a suitable overload, reasons follow
+  Main.hx:8: characters 9-18 : Overload resolution failed for () -> Void
+    Main.hx:8: characters 13-17 : Too many arguments
+  Main.hx:8: characters 9-18 : Overload resolution failed for (t : f.T) -> Void
+    Main.hx:8: characters 13-17 : Constraint check failure for f.T
+      Main.hx:8: characters 13-17 : String should be Int
+      Main.hx:8: characters 13-17 : For function argument 't'

+ 2 - 0
tests/misc/projects/Issue6065/pretty-fast-fail.hxml

@@ -0,0 +1,2 @@
+pretty-fail.hxml
+-D fail-fast

+ 20 - 0
tests/misc/projects/Issue6065/pretty-fast-fail.hxml.stderr

@@ -0,0 +1,20 @@
+[ERROR] Main.hx:8: characters 9-18
+
+ 8 |         C.f("hi");
+   |         ^^^^^^^^^
+   | Could not find a suitable overload, reasons follow
+
+      | Overload resolution failed for () -> Void
+
+       8 |         C.f("hi");
+         |             ^^^^
+         | Too many arguments
+
+      | Overload resolution failed for (t : f.T) -> Void
+
+       8 |         C.f("hi");
+         |             ^^^^
+         | Constraint check failure for f.T
+         | String should be Int
+         | For function argument 't'
+

+ 2 - 0
tests/misc/projects/Issue8019/compile-fast-fail.hxml

@@ -0,0 +1,2 @@
+compile-fail.hxml
+-D fail-fast

+ 2 - 0
tests/misc/projects/Issue8019/compile-fast-fail.hxml.stderr

@@ -0,0 +1,2 @@
+Macro.hx:9: characters 18-19 : "" is not a valid package name:
+Macro.hx:9: characters 18-19 : Package name must not be empty

+ 2 - 0
tests/misc/projects/Issue8019/compile3-fast-fail.hxml

@@ -0,0 +1,2 @@
+compile3-fail.hxml
+-D fail-fast

+ 1 - 0
tests/misc/projects/Issue8019/compile3-fast-fail.hxml.stderr

@@ -0,0 +1 @@
+Macro2.hx:8: characters 18-19 : Module "" does not have a valid name. Module name must not be empty.

+ 2 - 0
tests/misc/projects/issue5002/compile-fast-fail.hxml

@@ -0,0 +1,2 @@
+compile-fail.hxml
+-D fail-fast

+ 1 - 0
tests/misc/projects/issue5002/compile-fast-fail.hxml.stderr

@@ -0,0 +1 @@
+Main.hx:1: characters 1-8 : "0" is not a valid field name.

+ 2 - 0
tests/misc/projects/issue5002/compile2-fast-fail.hxml

@@ -0,0 +1,2 @@
+compile2-fail.hxml
+-D fail-fast

+ 1 - 0
tests/misc/projects/issue5002/compile2-fast-fail.hxml.stderr

@@ -0,0 +1 @@
+Main2.hx:6: characters 3-32 : "0_variable" is not a valid variable name.

+ 2 - 0
tests/misc/projects/issue5002/compile3-fast-fail.hxml

@@ -0,0 +1,2 @@
+compile3-fail.hxml
+-D fail-fast

+ 1 - 0
tests/misc/projects/issue5002/compile3-fast-fail.hxml.stderr

@@ -0,0 +1 @@
+Main3.hx:10: characters 18-19 : Module "lowercase" does not have a valid name. Module name should start with an uppercase letter: "lowercase"

+ 2 - 0
tests/misc/projects/issue5002/compile4-fast-fail.hxml

@@ -0,0 +1,2 @@
+compile4-fail.hxml
+-D fail-fast

+ 1 - 0
tests/misc/projects/issue5002/compile4-fast-fail.hxml.stderr

@@ -0,0 +1 @@
+Main4.hx:3: characters 7-9 : Variable names starting with a dollar are not allowed: "$i"