Forráskód Böngészése

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 éve
szülő
commit
7321f188b8

+ 1 - 1
src/compiler/args.ml

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

+ 2 - 4
src/compiler/server.ml

@@ -503,10 +503,8 @@ let after_arg_parsing 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 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
 
+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 *)
 
 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;
 		begin try
 			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();
 		end
 	| _ ->
@@ -414,7 +414,7 @@ class call_dispatcher
 	(p : pos)
 =
 	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)
 

+ 2 - 2
src/typing/matcher.ml

@@ -1510,7 +1510,7 @@ module TexprConverter = struct
 								begin match with_type,finiteness with
 								| WithType.NoValue,Infinite when toplevel -> 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
 								end
 							| Some e ->
@@ -1623,7 +1623,7 @@ module TexprConverter = struct
 						| None ->
 							if toplevel then
 								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)
 							else
 								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
 
 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
 	| TLocal {v_extra = None} | TArray _ | TField _ | TIdent _ ->
 		()
 	| 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 =
 	| 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 ->
 					if is_java_rest then
 						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
 						| 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 ->
 							t :: loop [] tl is_rest
 					end
@@ -402,7 +403,7 @@ let rec load_instance' ctx (t,p) allow_no_params =
 					let t,pt = load_param t in
 					if is_rest then
 						t :: loop tl [] true
-					else if ctx.com.display.dms_error_policy = EPIgnore then
+					else if ignore_error ctx.com then
 						[]
 					else
 						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
 			delay ctx PForce (fun () -> DisplayToplevel.handle_unresolved_identifier ctx name p true);
 			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
 		else
 			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
 	if fctx.is_abstract_member then add_class_field_flag cf CfImpl;
 	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 rec get_overload overl = match overl with
 				| [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;
 	let e = match e with
 		| 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
 				   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
@@ -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
 		   would turn Dynamic returns to Void returns. *)
 		| 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 -> ())
 	end;
 	let rec loop e =

+ 2 - 1
src/typing/typeloadParse.ml

@@ -273,7 +273,8 @@ let handle_parser_result com p result =
 			| EPShow ->
 				if is_diagnostics com then add_diagnostics_message com msg p DKParserError Error
 				else typing_error msg p
-			| EPIgnore -> ()
+			| EPIgnore ->
+				com.has_error <- true
 	in
 	match result with
 		| 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
 			unify_min_raise ctx el
 		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
 			else begin
 				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();
 	}
 
-	#if false // @see https://github.com/HaxeFoundation/haxe/issues/8596#issuecomment-518815594
 	function testDisplayModuleRecache() {
 		vfs.putContent("HelloWorld.hx", getTemplate("HelloWorld.hx"));
 		var args = ["--main", "HelloWorld", "--interp"];
@@ -126,9 +125,7 @@ class ServerTests extends TestCase {
 		runHaxe(args);
 		assertSkipping("HelloWorld");
 	}
-	#end
 
-	#if false // @see https://github.com/HaxeFoundation/haxe/issues/8596#issuecomment-518815594
 	function testMutuallyDependent() {
 		vfs.putContent("MutuallyDependent1.hx", getTemplate("MutuallyDependent1.hx"));
 		vfs.putContent("MutuallyDependent2.hx", getTemplate("MutuallyDependent2.hx"));
@@ -140,7 +137,28 @@ class ServerTests extends TestCase {
 		runHaxe(args);
 		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() {
 		vfs.putContent("HelloWorld.hx", getTemplate("HelloWorld.hx"));