Browse Source

cache context in any dms_full_typing mode that has no errors

I try this every year, maybe 2022 is finally the year it works...
Simon Krajewski 3 years ago
parent
commit
7321f188b8

+ 1 - 1
src/compiler/args.ml

@@ -366,7 +366,7 @@ let parse_args com =
 				actx.force_typing <- true;
 				actx.force_typing <- true;
 				actx.config_macros <- (Printf.sprintf "include('%s', true, null, null, true)" cl) :: actx.config_macros;
 				actx.config_macros <- (Printf.sprintf "include('%s', true, null, null, true)" cl) :: actx.config_macros;
 			end
 			end
-		with Failure _ when com.display.dms_error_policy = EPIgnore ->
+		with Failure _ when ignore_error com ->
 			()
 			()
 		end
 		end
 	in
 	in

+ 2 - 4
src/compiler/server.ml

@@ -503,10 +503,8 @@ let after_arg_parsing sctx ctx =
 		()
 		()
 
 
 let after_compilation sctx ctx =
 let after_compilation sctx ctx =
-	(* if not (has_error ctx) then *)
-		(* maybe_cache_context sctx ctx.com *)
-	(* TODO: not yet, trying to get parity first *)
-	()
+	if not (has_error ctx) then
+		maybe_cache_context sctx ctx.com
 
 
 let mk_length_prefixed_communication allow_nonblock chin chout =
 let mk_length_prefixed_communication allow_nonblock chin chout =
 	let sin = Unix.descr_of_in_channel chin in
 	let sin = Unix.descr_of_in_channel chin in

+ 6 - 0
src/context/common.ml

@@ -357,6 +357,12 @@ type context = {
 
 
 exception Abort of string * pos
 exception Abort of string * pos
 
 
+let ignore_error com =
+	let b = com.display.dms_error_policy = EPIgnore in
+	if b then
+		if b then com.has_error <- true;
+	b
+
 (* Defines *)
 (* Defines *)
 
 
 module Define = Define
 module Define = Define

+ 2 - 2
src/typing/callUnification.ml

@@ -364,7 +364,7 @@ let unify_field_call ctx fa el_typed el p inline =
 		if overload_kind = OverloadProper then maybe_check_access cf;
 		if overload_kind = OverloadProper then maybe_check_access cf;
 		begin try
 		begin try
 			commit_delayed_display (attempt_call cf false)
 			commit_delayed_display (attempt_call cf false)
-		with Error _ when ctx.com.display.dms_error_policy = EPIgnore ->
+		with Error _ when Common.ignore_error ctx.com ->
 			fail_fun();
 			fail_fun();
 		end
 		end
 	| _ ->
 	| _ ->
@@ -414,7 +414,7 @@ class call_dispatcher
 	(p : pos)
 	(p : pos)
 =
 =
 	let is_set = match mode with MSet _ -> true | _ -> false in
 	let is_set = match mode with MSet _ -> true | _ -> false in
-	let check_assign () = if is_set && ctx.com.display.dms_error_policy <> EPIgnore then invalid_assign p in
+	let check_assign () = if is_set && not (Common.ignore_error ctx.com) then invalid_assign p in
 
 
 object(self)
 object(self)
 
 

+ 2 - 2
src/typing/matcher.ml

@@ -1510,7 +1510,7 @@ module TexprConverter = struct
 								begin match with_type,finiteness with
 								begin match with_type,finiteness with
 								| WithType.NoValue,Infinite when toplevel -> None
 								| WithType.NoValue,Infinite when toplevel -> None
 								| _,CompileTimeFinite when unmatched = [] -> None
 								| _,CompileTimeFinite when unmatched = [] -> None
-								| _ when ctx.com.display.DisplayMode.dms_error_policy = DisplayMode.EPIgnore -> None
+								| _ when ignore_error ctx.com -> None
 								| _ -> report_not_exhaustive !v_lookup e_subject unmatched
 								| _ -> report_not_exhaustive !v_lookup e_subject unmatched
 								end
 								end
 							| Some e ->
 							| Some e ->
@@ -1623,7 +1623,7 @@ module TexprConverter = struct
 						| None ->
 						| None ->
 							if toplevel then
 							if toplevel then
 								loop dt_rec params dt2
 								loop dt_rec params dt2
-							else if ctx.com.display.DisplayMode.dms_error_policy = DisplayMode.EPIgnore then
+							else if ignore_error ctx.com then
 								Some (mk (TConst TNull) (mk_mono()) dt2.dt_pos)
 								Some (mk (TConst TNull) (mk_mono()) dt2.dt_pos)
 							else
 							else
 								report_not_exhaustive !v_lookup e [(ConConst TNull,dt.dt_pos),dt.dt_pos]
 								report_not_exhaustive !v_lookup e [(ConConst TNull,dt.dt_pos),dt.dt_pos]

+ 4 - 3
src/typing/operators.ml

@@ -79,15 +79,16 @@ module BinopResult = struct
 end
 end
 
 
 let check_assign ctx e =
 let check_assign ctx e =
-	if ctx.com.display.dms_error_policy <> EPIgnore then match e.eexpr with
-	| TLocal v when has_var_flag v VFinal ->
+	match e.eexpr with
+	| TLocal v when has_var_flag v VFinal && not (Common.ignore_error ctx.com) ->
 		typing_error "Cannot assign to final" e.epos
 		typing_error "Cannot assign to final" e.epos
 	| TLocal {v_extra = None} | TArray _ | TField _ | TIdent _ ->
 	| TLocal {v_extra = None} | TArray _ | TField _ | TIdent _ ->
 		()
 		()
 	| TConst TThis | TTypeExpr _ when ctx.untyped ->
 	| TConst TThis | TTypeExpr _ when ctx.untyped ->
 		()
 		()
 	| _ ->
 	| _ ->
-		invalid_assign e.epos
+		if not (Common.ignore_error ctx.com) then
+			invalid_assign e.epos
 
 
 type type_class =
 type type_class =
 	| KInt
 	| KInt

+ 6 - 5
src/typing/typeload.ml

@@ -390,11 +390,12 @@ let rec load_instance' ctx (t,p) allow_no_params =
 				| [],({ttp_type=t;ttp_default=def}) :: tl ->
 				| [],({ttp_type=t;ttp_default=def}) :: tl ->
 					if is_java_rest then
 					if is_java_rest then
 						t_dynamic :: loop [] tl is_rest
 						t_dynamic :: loop [] tl is_rest
-					else if ctx.com.display.dms_error_policy = EPIgnore then
-						t :: loop [] tl is_rest
 					else begin match def with
 					else begin match def with
 						| None ->
 						| None ->
-							typing_error ("Not enough type parameters for " ^ s_type_path path) p
+							if ignore_error ctx.com then
+								t :: loop [] tl is_rest
+							else
+								typing_error ("Not enough type parameters for " ^ s_type_path path) p
 						| Some t ->
 						| Some t ->
 							t :: loop [] tl is_rest
 							t :: loop [] tl is_rest
 					end
 					end
@@ -402,7 +403,7 @@ let rec load_instance' ctx (t,p) allow_no_params =
 					let t,pt = load_param t in
 					let t,pt = load_param t in
 					if is_rest then
 					if is_rest then
 						t :: loop tl [] true
 						t :: loop tl [] true
-					else if ctx.com.display.dms_error_policy = EPIgnore then
+					else if ignore_error ctx.com then
 						[]
 						[]
 					else
 					else
 						typing_error ("Too many type parameters for " ^ s_type_path path) pt
 						typing_error ("Too many type parameters for " ^ s_type_path path) pt
@@ -630,7 +631,7 @@ and load_complex_type ctx allow_display (t,pn) =
 		if Diagnostics.error_in_diagnostics_run ctx.com p then begin
 		if Diagnostics.error_in_diagnostics_run ctx.com p then begin
 			delay ctx PForce (fun () -> DisplayToplevel.handle_unresolved_identifier ctx name p true);
 			delay ctx PForce (fun () -> DisplayToplevel.handle_unresolved_identifier ctx name p true);
 			t_dynamic
 			t_dynamic
-		end else if ctx.com.display.dms_error_policy = EPIgnore && not (DisplayPosition.display_position#enclosed_in pn) then
+		end else if ignore_error ctx.com && not (DisplayPosition.display_position#enclosed_in pn) then
 			t_dynamic
 			t_dynamic
 		else
 		else
 			raise exc
 			raise exc

+ 1 - 3
src/typing/typeloadFields.ml

@@ -1433,9 +1433,7 @@ let create_property (ctx,cctx,fctx) c f (get,set,t,eo) p =
 	} in
 	} in
 	if fctx.is_abstract_member then add_class_field_flag cf CfImpl;
 	if fctx.is_abstract_member then add_class_field_flag cf CfImpl;
 	let check_method m t is_getter =
 	let check_method m t is_getter =
-		if ctx.com.display.dms_error_policy = EPIgnore then
-			()
-		else try
+		try
 			let overloads = find_accessor m in
 			let overloads = find_accessor m in
 			let rec get_overload overl = match overl with
 			let rec get_overload overl = match overl with
 				| [tf] ->
 				| [tf] ->

+ 1 - 2
src/typing/typeloadFunction.ml

@@ -59,7 +59,7 @@ let type_function ctx (args : function_arguments) ret fmode e do_display p =
 	args#bring_into_context;
 	args#bring_into_context;
 	let e = match e with
 	let e = match e with
 		| None ->
 		| None ->
-			if ctx.com.display.dms_error_policy = EPIgnore then
+			if ignore_error ctx.com then
 				(* when we don't care because we're in display mode, just act like
 				(* when we don't care because we're in display mode, just act like
 				   the function has an empty block body. this is fine even if function
 				   the function has an empty block body. this is fine even if function
 				   defines a return type, because returns aren't checked in this mode
 				   defines a return type, because returns aren't checked in this mode
@@ -104,7 +104,6 @@ let type_function ctx (args : function_arguments) ret fmode e do_display p =
 		   can _not_ use type_iseq to avoid the Void check above because that
 		   can _not_ use type_iseq to avoid the Void check above because that
 		   would turn Dynamic returns to Void returns. *)
 		   would turn Dynamic returns to Void returns. *)
 		| TMono t when not (has_return e) -> ignore(link t ret ctx.t.tvoid)
 		| TMono t when not (has_return e) -> ignore(link t ret ctx.t.tvoid)
-		| _ when ctx.com.display.dms_error_policy = EPIgnore -> ()
 		| _ -> (try TypeloadCheck.return_flow ctx e with Exit -> ())
 		| _ -> (try TypeloadCheck.return_flow ctx e with Exit -> ())
 	end;
 	end;
 	let rec loop e =
 	let rec loop e =

+ 2 - 1
src/typing/typeloadParse.ml

@@ -273,7 +273,8 @@ let handle_parser_result com p result =
 			| EPShow ->
 			| EPShow ->
 				if is_diagnostics com then add_diagnostics_message com msg p DKParserError Error
 				if is_diagnostics com then add_diagnostics_message com msg p DKParserError Error
 				else typing_error msg p
 				else typing_error msg p
-			| EPIgnore -> ()
+			| EPIgnore ->
+				com.has_error <- true
 	in
 	in
 	match result with
 	match result with
 		| ParseSuccess(data,is_display_file,pdi) ->
 		| ParseSuccess(data,is_display_file,pdi) ->

+ 1 - 1
src/typing/typer.ml

@@ -1377,7 +1377,7 @@ and type_array_decl ctx el with_type p =
 		let t = try
 		let t = try
 			unify_min_raise ctx el
 			unify_min_raise ctx el
 		with Error (Unify l,p) ->
 		with Error (Unify l,p) ->
-			if !allow_array_dynamic || ctx.untyped || ctx.com.display.dms_error_policy = EPIgnore then
+			if !allow_array_dynamic || ctx.untyped || ignore_error ctx.com then
 				t_dynamic
 				t_dynamic
 			else begin
 			else begin
 				display_error ctx "Arrays of mixed types are only allowed if the type is forced to Array<Dynamic>" p;
 				display_error ctx "Arrays of mixed types are only allowed if the type is forced to Array<Dynamic>" p;

+ 22 - 4
tests/server/src/cases/ServerTests.hx

@@ -105,7 +105,6 @@ class ServerTests extends TestCase {
 		assertSuccess();
 		assertSuccess();
 	}
 	}
 
 
-	#if false // @see https://github.com/HaxeFoundation/haxe/issues/8596#issuecomment-518815594
 	function testDisplayModuleRecache() {
 	function testDisplayModuleRecache() {
 		vfs.putContent("HelloWorld.hx", getTemplate("HelloWorld.hx"));
 		vfs.putContent("HelloWorld.hx", getTemplate("HelloWorld.hx"));
 		var args = ["--main", "HelloWorld", "--interp"];
 		var args = ["--main", "HelloWorld", "--interp"];
@@ -126,9 +125,7 @@ class ServerTests extends TestCase {
 		runHaxe(args);
 		runHaxe(args);
 		assertSkipping("HelloWorld");
 		assertSkipping("HelloWorld");
 	}
 	}
-	#end
 
 
-	#if false // @see https://github.com/HaxeFoundation/haxe/issues/8596#issuecomment-518815594
 	function testMutuallyDependent() {
 	function testMutuallyDependent() {
 		vfs.putContent("MutuallyDependent1.hx", getTemplate("MutuallyDependent1.hx"));
 		vfs.putContent("MutuallyDependent1.hx", getTemplate("MutuallyDependent1.hx"));
 		vfs.putContent("MutuallyDependent2.hx", getTemplate("MutuallyDependent2.hx"));
 		vfs.putContent("MutuallyDependent2.hx", getTemplate("MutuallyDependent2.hx"));
@@ -140,7 +137,28 @@ class ServerTests extends TestCase {
 		runHaxe(args);
 		runHaxe(args);
 		assertSuccess();
 		assertSuccess();
 	}
 	}
-	#end
+
+	function testDiagnosticsRecache() {
+		vfs.putContent("HelloWorld.hx", getTemplate("HelloWorld.hx"));
+		var args = ["--main", "HelloWorld", "--interp"];
+		runHaxe(args);
+		runHaxe(args);
+		assertReuse("HelloWorld");
+	 	runHaxeJson([], ServerMethods.Invalidate, {file: new FsPath("HelloWorld.hx")});
+	 	runHaxe(args);
+	 	assertSkipping("HelloWorld");
+		runHaxe(args.concat(["--display", "HelloWorld.hx@0@diagnostics"]));
+		runHaxe(args);
+		assertReuse("HelloWorld");
+	}
+
+	function testDiagnosticsRecache2() {
+		vfs.putContent("HelloWorld.hx", getTemplate("HelloWorld.hx"));
+		var args = ["--main", "HelloWorld", "--interp"];
+		runHaxe(args.concat(["--display", "HelloWorld.hx@0@diagnostics"]));
+		runHaxe(args);
+		assertReuse("HelloWorld");
+	}
 
 
 	function testSyntaxCache() {
 	function testSyntaxCache() {
 		vfs.putContent("HelloWorld.hx", getTemplate("HelloWorld.hx"));
 		vfs.putContent("HelloWorld.hx", getTemplate("HelloWorld.hx"));