Skip to content

Commit 620b011

Browse files
lukemaurermshinwell
andcommitted
Don't substitute into exclaves in simplif.ml (#1448)
Co-authored-by: Mark Shinwell <mshinwell@pm.me>
1 parent d65f752 commit 620b011

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

ocaml/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 -> ()

ocaml/testsuite/tests/typing-local/exclave.ml

+19
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,22 @@ val bar : 'a -> string = <fun>
199199
- : string = "Some of 5"
200200
|}]
201201

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

0 commit comments

Comments
 (0)