Skip to content

Commit ce76e02

Browse files
authored
flambda-backend: Bugfix for type_application (#746)
The modes for the function being applied were wrong in the case of a Regional function, which can allow a heap closure to close over a stack closure.
1 parent 44f3afb commit ce76e02

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

testsuite/tests/typing-local/local.ml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,27 @@ Line 3, characters 63-64:
487487
Error: The value a is local, so cannot be used inside a closure that might escape
488488
|}]
489489

490+
(* Regression test for bug with mishandled regional function modes *)
491+
let bug4 : local_ (string -> foo:string -> unit) -> (string -> unit) =
492+
fun f -> f ~foo:"hello"
493+
[%%expect{|
494+
Line 2, characters 11-25:
495+
2 | fun f -> f ~foo:"hello"
496+
^^^^^^^^^^^^^^
497+
Error: This value escapes its region
498+
|}]
499+
500+
let bug4' () =
501+
let local_ f arg ~foo = () in
502+
let local_ perm ~foo = f ~foo in
503+
perm ~foo:"foo" "Optional"
504+
[%%expect{|
505+
Line 3, characters 25-31:
506+
3 | let local_ perm ~foo = f ~foo in
507+
^^^^^^
508+
Error: This local value escapes its region
509+
Hint: Cannot return local value without an explicit "local_" annotation
510+
|}]
490511

491512
(*
492513
* Optional arguments

typing/typecore.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5396,7 +5396,7 @@ and type_application env app_loc expected_mode position funct funct_mode sargs =
53965396
in
53975397
let ty_ret, mode_ret, args =
53985398
collect_apply_args env funct ignore_labels ty (instance ty)
5399-
(Value_mode.regional_to_global_alloc funct_mode) sargs
5399+
(Value_mode.regional_to_local_alloc funct_mode) sargs
54005400
in
54015401
let partial_app = is_partial_apply args in
54025402
let position = if partial_app then Default else position in

0 commit comments

Comments
 (0)