Skip to content

Commit

Permalink
cache context in any dms_full_typing mode that has no errors
Browse files Browse the repository at this point in the history
I try this every year, maybe 2022 is finally the year it works...
  • Loading branch information
Simn committed Mar 20, 2022
1 parent 793d63d commit 7321f18
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/compiler/args.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions src/compiler/server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/context/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/typing/callUnification.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
| _ ->
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions src/typing/matcher.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down Expand Up @@ -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]
Expand Down
7 changes: 4 additions & 3 deletions src/typing/operators.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions src/typing/typeload.ml
Original file line number Diff line number Diff line change
Expand Up @@ -390,19 +390,20 @@ 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
| t :: tl,[] ->
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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions src/typing/typeloadFields.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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] ->
Expand Down
3 changes: 1 addition & 2 deletions src/typing/typeloadFunction.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand Down
3 changes: 2 additions & 1 deletion src/typing/typeloadParse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down
2 changes: 1 addition & 1 deletion src/typing/typer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 22 additions & 4 deletions tests/server/src/cases/ServerTests.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand All @@ -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"));
Expand All @@ -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"));
Expand Down

0 comments on commit 7321f18

Please sign in to comment.