From a1d6cd662c4d8e7d2e40ae1665d0ac26045a7f8b Mon Sep 17 00:00:00 2001 From: Simon Krajewski Date: Thu, 1 Feb 2024 08:25:04 +0100 Subject: [PATCH] in_call_args & in_overload_call_args --- src/context/typecore.ml | 10 +++++----- src/typing/callUnification.ml | 14 +++++++------- src/typing/typeloadModule.ml | 4 ++-- src/typing/typerDisplay.ml | 8 ++++---- src/typing/typerEntry.ml | 4 ++-- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/context/typecore.ml b/src/context/typecore.ml index bd53225d9e9..cd3d645a921 100644 --- a/src/context/typecore.ml +++ b/src/context/typecore.ml @@ -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 = { @@ -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; @@ -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 = diff --git a/src/typing/callUnification.ml b/src/typing/callUnification.ml index 8f6079f728d..090a15171b3 100644 --- a/src/typing/callUnification.ml +++ b/src/typing/callUnification.ml @@ -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 @@ -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. diff --git a/src/typing/typeloadModule.ml b/src/typing/typeloadModule.ml index 9e4f09395a5..45501448356 100644 --- a/src/typing/typeloadModule.ml +++ b/src/typing/typeloadModule.ml @@ -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; } diff --git a/src/typing/typerDisplay.ml b/src/typing/typerDisplay.ml index 86cafc48f9b..6c9ea406c4e 100644 --- a/src/typing/typerDisplay.ml +++ b/src/typing/typerDisplay.ml @@ -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) @@ -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 -> diff --git a/src/typing/typerEntry.ml b/src/typing/typerEntry.ml index 2f6c31260b2..d9893ef62e2 100644 --- a/src/typing/typerEntry.ml +++ b/src/typing/typerEntry.ml @@ -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; @@ -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