Skip to content

Commit a3d1953

Browse files
authored
flambda-backend: Fix Translcore to look for allocations in exclaves (#1495)
1 parent 0ea8b04 commit a3d1953

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

lambda/translcore.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ let may_allocate_in_region lam =
145145
let rec loop_region lam =
146146
shallow_iter ~tail:(function
147147
| Lexclave body -> loop body
148-
| _ -> ()
149-
) ~non_tail:(fun _ -> ()) lam
148+
| lam -> loop_region lam
149+
) ~non_tail:(fun lam -> loop_region lam) lam
150150
and loop = function
151151
| Lvar _ | Lmutvar _ | Lconst _ -> ()
152152

testsuite/tests/typing-local/regions.ml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
(* TEST
2+
include ocamlcommon
23
* native *)
34

45
external local_stack_offset : unit -> int = "caml_local_stack_offset"
@@ -246,4 +247,30 @@ let () =
246247
create_and_ignore ();
247248
check_empty "mode-crossed region"
248249

250+
let[@inline never] allocate_in_exclave a =
251+
(* This needs to be a [while] so that we're allowed to have an [exclave_] *)
252+
while
253+
let pair = local_ opaque_identity (a, a) in
254+
let b, _ = pair in
255+
let b : int = b in
256+
exclave_ (
257+
(* This should allocate in the function's region - in particular, the
258+
function needs to have one *)
259+
let pair = local_ opaque_identity (b, b) in
260+
let c, _ = pair in
261+
c = 42)
262+
do
263+
()
264+
done
265+
266+
let () =
267+
let () =
268+
(* Temporarily disable this test for flambda1 until it's fixed there *)
269+
if not Config.flambda then
270+
allocate_in_exclave 1
271+
in
272+
(* If [allocate_in_exclave] had its region elided, the allocation will have
273+
happened in our region instead *)
274+
check_empty "allocation from exclave"
275+
249276
let () = Gc.compact ()

testsuite/tests/typing-local/regions.reference

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@
2727
dynamic/partial overapply: OK
2828
method overapply: OK
2929
mode-crossed region: OK
30+
allocation from exclave: OK

0 commit comments

Comments
 (0)