Skip to content

Commit 90b7bc9

Browse files
authored
flambda-backend: Support type directed disambiguation better for exclave_ (#2746)
* regression test * Support type directed disambiguation for exclave and update test output * kick ci
1 parent c9c7afc commit 90b7bc9

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

testsuite/tests/typing-local/local.ml

+15
Original file line numberDiff line numberDiff line change
@@ -2967,6 +2967,21 @@ let () = foo_f (local_ (fun M_constructor -> ()))
29672967
[%%expect{|
29682968
|}]
29692969
2970+
let _ret () : M.t -> unit = (fun M_constructor -> ())
2971+
[%%expect{|
2972+
val _ret : unit -> M.t -> unit = <fun>
2973+
|}]
2974+
2975+
let _ret () : M.t -> unit = local_ (fun M_constructor -> ())
2976+
[%%expect{|
2977+
val _ret : unit -> local_ (M.t -> unit) = <fun>
2978+
|}]
2979+
2980+
let _ret () : M.t -> unit = exclave_ (fun M_constructor -> ())
2981+
[%%expect{|
2982+
val _ret : unit -> local_ (M.t -> unit) = <fun>
2983+
|}]
2984+
29702985
type r = {global_ x : string; y : string}
29712986
29722987
let foo () =

typing/typecore.ml

+10-3
Original file line numberDiff line numberDiff line change
@@ -4663,13 +4663,21 @@ let unify_exp ?sdesc_for_hint env exp expected_ty =
46634663
with Error(loc, env, Expr_type_clash(err, tfc, None)) ->
46644664
raise (Error(loc, env, Expr_type_clash(err, tfc, sdesc_for_hint)))
46654665

4666+
let is_exclave_extension_node = function
4667+
| "extension.exclave" | "ocaml.exclave" | "exclave" -> true
4668+
| _ -> false
4669+
46664670
(* If [is_inferred e] is true, [e] will be typechecked without using
46674671
the "expected type" provided by the context. *)
46684672

46694673
let rec is_inferred sexp =
46704674
match Jane_syntax.Expression.of_ast sexp with
46714675
| Some (jexp, _attrs) -> is_inferred_jane_syntax jexp
46724676
| None -> match sexp.pexp_desc with
4677+
| Pexp_apply
4678+
({ pexp_desc = Pexp_extension({ txt }, PStr []) },
4679+
[Nolabel, sbody]) when is_exclave_extension_node txt ->
4680+
is_inferred sbody
46734681
| Pexp_ident _ | Pexp_apply _ | Pexp_field _ | Pexp_constraint _
46744682
| Pexp_coerce _ | Pexp_send _ | Pexp_new _ -> true
46754683
| Pexp_sequence (_, e) | Pexp_open (_, e) -> is_inferred e
@@ -5345,9 +5353,8 @@ and type_expect_
53455353
in
53465354
{exp with exp_loc = loc}
53475355
| Pexp_apply
5348-
({ pexp_desc = Pexp_extension({
5349-
txt = "extension.exclave" | "ocaml.exclave" | "exclave" as txt}, PStr []) },
5350-
[Nolabel, sbody]) ->
5356+
({ pexp_desc = Pexp_extension({ txt }, PStr []) },
5357+
[Nolabel, sbody]) when is_exclave_extension_node txt ->
53515358
if (txt = "extension.exclave") && not (Language_extension.is_enabled Mode) then
53525359
raise (Typetexp.Error (loc, Env.empty, Unsupported_extension Mode));
53535360
begin

0 commit comments

Comments
 (0)