Skip to content

Commit

Permalink
in_call_args & in_overload_call_args
Browse files Browse the repository at this point in the history
  • Loading branch information
Simn committed Feb 1, 2024
1 parent 94a52b2 commit a1d6cd6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
10 changes: 5 additions & 5 deletions src/context/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ and typer_expr = {
mutable bypass_accessor : int;
mutable with_type_stack : WithType.t list;
mutable call_argument_stack : expr list list;
mutable in_call_args : bool;
mutable in_overload_call_args : bool;
}

and typer_field = {
Expand All @@ -172,8 +174,6 @@ and typer = {
mutable allow_transform : bool;
mutable in_display : bool;
mutable macro_depth : int;
mutable in_call_args : bool;
mutable in_overload_call_args : bool;
mutable delayed_display : DisplayTypes.display_exception_kind option;
(* events *)
memory_marker : float array;
Expand Down Expand Up @@ -320,16 +320,16 @@ let raise_with_type_error ?(depth = 0) msg p =

let raise_or_display ctx l p =
if ctx.f.untyped then ()
else if ctx.in_call_args then raise (WithTypeError (make_error (Unify l) p))
else if ctx.e.in_call_args then raise (WithTypeError (make_error (Unify l) p))
else display_error_ext ctx.com (make_error (Unify l) p)

let raise_or_display_error ctx err =
if ctx.f.untyped then ()
else if ctx.in_call_args then raise (WithTypeError err)
else if ctx.e.in_call_args then raise (WithTypeError err)
else display_error_ext ctx.com err

let raise_or_display_message ctx msg p =
if ctx.in_call_args then raise_with_type_error msg p
if ctx.e.in_call_args then raise_with_type_error msg p
else display_error ctx.com msg p

let unify ctx t1 t2 p =
Expand Down
14 changes: 7 additions & 7 deletions src/typing/callUnification.ml
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ let unify_call_args ctx el args r callp inline force_inline in_overload =
end
in
let restore =
let in_call_args = ctx.in_call_args in
let in_overload_call_args = ctx.in_overload_call_args in
ctx.in_call_args <- true;
ctx.in_overload_call_args <- in_overload;
let in_call_args = ctx.e.in_call_args in
let in_overload_call_args = ctx.e.in_overload_call_args in
ctx.e.in_call_args <- true;
ctx.e.in_overload_call_args <- in_overload;
(fun () ->
ctx.in_call_args <- in_call_args;
ctx.in_overload_call_args <- in_overload_call_args;
ctx.e.in_call_args <- in_call_args;
ctx.e.in_overload_call_args <- in_overload_call_args;
)
in
let el = try loop el args with exc -> restore(); raise exc; in
Expand Down Expand Up @@ -241,7 +241,7 @@ let unify_field_call ctx fa el_typed el p inline =
else if fa.fa_field.cf_overloads <> [] then OverloadMeta
else OverloadNone
in
(* Delayed display handling works like this: If ctx.in_overload_call_args is set (via attempt_calls calling unify_call_args' below),
(* Delayed display handling works like this: If ctx.e.in_overload_call_args is set (via attempt_calls calling unify_call_args' below),
the code which normally raises eager Display exceptions (in typerDisplay.ml handle_display) instead stores them in ctx.delayed_display.
The overload handling here extracts them and associates the exception with the field call candidates. Afterwards, normal overload resolution
can take place and only then the display callback is actually committed.
Expand Down
4 changes: 2 additions & 2 deletions src/typing/typeloadModule.ml
Original file line number Diff line number Diff line change
Expand Up @@ -727,13 +727,13 @@ let create_typer_context_for_module ctx m = {
bypass_accessor = 0;
with_type_stack = [];
call_argument_stack = [];
in_call_args = false;
in_overload_call_args = false;
};
allow_inline = true;
allow_transform = true;
type_params = [];
in_display = false;
in_call_args = false;
in_overload_call_args = false;
delayed_display = None;
memory_marker = Typecore.memory_marker;
}
Expand Down
8 changes: 4 additions & 4 deletions src/typing/typerDisplay.ml
Original file line number Diff line number Diff line change
Expand Up @@ -541,9 +541,9 @@ and display_expr ctx e_ast e dk mode with_type p =
raise_fields fields (CRField(item,e.epos,iterator,keyValueIterator)) (make_subject None (DisplayPosition.display_position#with_pos p))

let handle_display ctx e_ast dk mode with_type =
let old = ctx.in_display,ctx.in_call_args in
let old = ctx.in_display,ctx.e.in_call_args in
ctx.in_display <- true;
ctx.in_call_args <- false;
ctx.e.in_call_args <- false;
let tpair t =
let ct = CompletionType.from_type (get_import_status ctx) t in
(t,ct)
Expand Down Expand Up @@ -658,9 +658,9 @@ let handle_display ctx e_ast dk mode with_type =
print_endline (Printf.sprintf "cast expr:\n%s" (s_expr_ast true "" (s_type (print_context())) e));
end;
ctx.in_display <- fst old;
ctx.in_call_args <- snd old;
ctx.e.in_call_args <- snd old;
let f () = display_expr ctx e_ast e dk mode with_type p in
if ctx.in_overload_call_args then begin
if ctx.e.in_overload_call_args then begin
try
f()
with DisplayException de ->
Expand Down
4 changes: 2 additions & 2 deletions src/typing/typerEntry.ml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ let create com macros =
bypass_accessor = 0;
with_type_stack = [];
call_argument_stack = [];
in_call_args = false;
in_overload_call_args = false;
};
is_display_file = false;
pass = PBuildModule;
Expand All @@ -77,8 +79,6 @@ let create com macros =
allow_inline = true;
allow_transform = true;
type_params = [];
in_call_args = false;
in_overload_call_args = false;
delayed_display = None;
memory_marker = Typecore.memory_marker;
} in
Expand Down

0 comments on commit a1d6cd6

Please sign in to comment.