Skip to content

Commit

Permalink
Bugfix for application mode crossing (#1451)
Browse files Browse the repository at this point in the history
  • Loading branch information
stedolan authored Jun 6, 2023
1 parent 059ce3c commit 4584a80
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
11 changes: 11 additions & 0 deletions ocaml/testsuite/tests/typing-local/regions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -234,5 +234,16 @@ let () =
check (!obj#local_ret "!" 5);
check_empty "method overapply"

type t = { x : int } [@@unboxed]
let[@inline never] create_local () =
let local_ _extra = opaque_identity (Some (opaque_identity ())) in
local_ { x = opaque_identity 0 }
let create_and_ignore () =
let x = create_local () in
ignore (Sys.opaque_identity x : t)

let () =
create_and_ignore ();
check_empty "mode-crossed region"

let () = Gc.compact ()
1 change: 1 addition & 0 deletions ocaml/testsuite/tests/typing-local/regions.reference
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@
static/partial overapply: OK
dynamic/partial overapply: OK
method overapply: OK
mode-crossed region: OK
11 changes: 6 additions & 5 deletions ocaml/typing/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4445,13 +4445,12 @@ and type_expect_
| _ ->
(rt, funct), sargs
in
let (args, ty_res, mode_res, position) =
let (args, ty_res, ap_mode, position) =
type_application env loc expected_mode position funct funct_mode sargs rt
in

rue {
exp_desc = Texp_apply(funct, args, position,
Value_mode.regional_to_global_alloc mode_res);
exp_desc = Texp_apply(funct, args, position, ap_mode);
exp_loc = loc; exp_extra = [];
exp_type = ty_res;
exp_attributes = sexp.pexp_attributes;
Expand Down Expand Up @@ -6448,6 +6447,7 @@ and type_application env app_loc expected_mode position funct funct_mode sargs r
end_def ();
generalize_structure ty_res
end;
let ap_mode = mres in
let mode_res =
mode_cross_to_global env ty_res (Value_mode.of_alloc mres)
in
Expand All @@ -6458,7 +6458,7 @@ and type_application env app_loc expected_mode position funct funct_mode sargs r
in
let exp = type_expect env marg sarg (mk_expected ty_arg) in
check_partial_application ~statement:false exp;
([Nolabel, Arg exp], ty_res, mode_res, position)
([Nolabel, Arg exp], ty_res, ap_mode, position)
| _ ->
let ty = funct.exp_type in
let ignore_labels =
Expand Down Expand Up @@ -6499,12 +6499,13 @@ and type_application env app_loc expected_mode position funct funct_mode sargs r
end_def () ;
generalize_structure ty_ret
end;
let ap_mode = mode_ret in
let mode_ret =
mode_cross_to_global env ty_ret (Value_mode.of_alloc mode_ret)
in
submode ~loc:app_loc ~env ~reason:(Application ty_ret)
mode_ret expected_mode;
args, ty_ret, mode_ret, position
args, ty_ret, ap_mode, position

and type_construct env (expected_mode : expected_mode) loc lid sarg
ty_expected_explained attrs =
Expand Down

0 comments on commit 4584a80

Please sign in to comment.