Skip to content

Commit 7ac42ab

Browse files
flambda-backend: Don't substitute into exclaves in simplif.ml (#1448)
Co-authored-by: Mark Shinwell <mshinwell@pm.me>
1 parent a03de20 commit 7ac42ab

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lambda/simplif.ml

+4-1
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,10 @@ let simplify_lets lam =
492492
| Lregion (l, _) ->
493493
count bv l
494494
| Lexclave l ->
495-
count bv l
495+
(* Not safe in general to move code into an exclave, so block
496+
single-use optimizations by treating them the same as lambdas
497+
and loops *)
498+
count Ident.Map.empty l
496499

497500
and count_default bv sw = match sw.sw_failaction with
498501
| None -> ()

testsuite/tests/typing-local/exclave.ml

+19
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,22 @@ val bar : 'a -> string = <fun>
192192
- : string = "Some of 5"
193193
|}]
194194

195+
(* Ensure that Alias bindings are not substituted by Simplif (PR1448) *)
196+
type 'a glob = Glob of ('a[@global])
197+
198+
let[@inline never] return_local a = [%local] (Glob a)
199+
200+
let f () =
201+
let (Glob x) = return_local 1 in
202+
[%exclave]
203+
(let (_ : _) = return_local 99 in
204+
assert (x = 1))
205+
;;
206+
f ();;
207+
[%%expect{|
208+
type 'a glob = Glob of global_ 'a
209+
val return_local : 'a -> local_ 'a glob = <fun>
210+
val f : unit -> local_ unit = <fun>
211+
- : unit = ()
212+
|}]
213+

0 commit comments

Comments
 (0)