Skip to content

Commit

Permalink
Add -D fail-fast (#11609)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
kLabz authored Mar 21, 2024
1 parent 3b0c8f4 commit 1423a5f
Show file tree
Hide file tree
Showing 24 changed files with 89 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src-json/define.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 12 additions & 4 deletions src/compiler/compilationContext.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
5 changes: 3 additions & 2 deletions src/compiler/compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 7 additions & 2 deletions src/compiler/messageReporting.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/context/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/core/define.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/misc/projects/Issue6065/compile-fast-fail.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
compile-fail.hxml
-D fail-fast
8 changes: 8 additions & 0 deletions tests/misc/projects/Issue6065/compile-fast-fail.hxml.stderr
Original file line number Diff line number Diff line change
@@ -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 changes: 2 additions & 0 deletions tests/misc/projects/Issue6065/indent-fast-fail.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
indent-fail.hxml
-D fail-fast
7 changes: 7 additions & 0 deletions tests/misc/projects/Issue6065/indent-fast-fail.hxml.stderr
Original file line number Diff line number Diff line change
@@ -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 changes: 2 additions & 0 deletions tests/misc/projects/Issue6065/pretty-fast-fail.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pretty-fail.hxml
-D fail-fast
20 changes: 20 additions & 0 deletions tests/misc/projects/Issue6065/pretty-fast-fail.hxml.stderr
Original file line number Diff line number Diff line change
@@ -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 changes: 2 additions & 0 deletions tests/misc/projects/Issue8019/compile-fast-fail.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
compile-fail.hxml
-D fail-fast
2 changes: 2 additions & 0 deletions tests/misc/projects/Issue8019/compile-fast-fail.hxml.stderr
Original file line number Diff line number Diff line change
@@ -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 changes: 2 additions & 0 deletions tests/misc/projects/Issue8019/compile3-fast-fail.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
compile3-fail.hxml
-D fail-fast
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Macro2.hx:8: characters 18-19 : Module "" does not have a valid name. Module name must not be empty.
2 changes: 2 additions & 0 deletions tests/misc/projects/issue5002/compile-fast-fail.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
compile-fail.hxml
-D fail-fast
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Main.hx:1: characters 1-8 : "0" is not a valid field name.
2 changes: 2 additions & 0 deletions tests/misc/projects/issue5002/compile2-fast-fail.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
compile2-fail.hxml
-D fail-fast
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Main2.hx:6: characters 3-32 : "0_variable" is not a valid variable name.
2 changes: 2 additions & 0 deletions tests/misc/projects/issue5002/compile3-fast-fail.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
compile3-fail.hxml
-D fail-fast
Original file line number Diff line number Diff line change
@@ -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 changes: 2 additions & 0 deletions tests/misc/projects/issue5002/compile4-fast-fail.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
compile4-fail.hxml
-D fail-fast
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Main4.hx:3: characters 7-9 : Variable names starting with a dollar are not allowed: "$i"

0 comments on commit 1423a5f

Please sign in to comment.