Skip to content

Commit 9e59dbf

Browse files
authored
Relax modes for probe (#2968)
1 parent 8e32667 commit 9e59dbf

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

ocaml/lambda/translcore.ml

+9-5
Original file line numberDiff line numberDiff line change
@@ -1116,24 +1116,28 @@ and transl_exp0 ~in_new_scope ~scopes sort e =
11161116
let assume_zero_alloc = get_assume_zero_alloc ~scopes in
11171117
let scopes = enter_value_definition ~scopes ~assume_zero_alloc funcid in
11181118
lfunction
1119-
~kind:(Curried {nlocal=0})
1119+
(* We conservatively assume that all arguments are local. This doesn't
1120+
hurt performance as probe handlers are always applied fully. *)
1121+
~kind:(Curried {nlocal=List.length param_idents})
11201122
(* CR layouts: Adjust param layouts when we allow other things in
11211123
probes. *)
1122-
~params:(List.map (fun name -> { name; layout = layout_probe_arg; attributes = Lambda.default_param_attribute; mode = alloc_heap }) param_idents)
1124+
~params:(List.map (fun name -> { name; layout = layout_probe_arg; attributes = Lambda.default_param_attribute; mode = alloc_local }) param_idents)
11231125
~return:return_layout
1124-
~body:(maybe_region_layout return_layout body)
1126+
~body:body
11251127
~loc:(of_location ~scopes exp.exp_loc)
11261128
~attr
11271129
~mode:alloc_heap
1128-
~ret_mode:alloc_heap
1130+
~ret_mode:alloc_local
1131+
(* CR zqian: the handler function doesn't have a region. However, the
1132+
[region] field is currently broken. *)
11291133
~region:true
11301134
in
11311135
let app =
11321136
{ ap_func = Lvar funcid;
11331137
ap_args = List.map (fun id -> Lvar id) arg_idents;
11341138
ap_result_layout = return_layout;
11351139
ap_region_close = Rc_normal;
1136-
ap_mode = alloc_heap;
1140+
ap_mode = alloc_local;
11371141
ap_loc = of_location e.exp_loc ~scopes;
11381142
ap_tailcall = Default_tailcall;
11391143
ap_inlined = Never_inlined;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
(* TEST
2+
flags += "-extension unique";
3+
expect;
4+
*)
5+
6+
(* probe can refer to local,nonportable,once values *)
7+
8+
let f (x @ local nonportable once) =
9+
[%probe "a" (let _ = x in ())]
10+
[%%expect{|
11+
val f : local_ once_ 'a -> unit = <fun>
12+
|}]

ocaml/typing/typecore.ml

-2
Original file line numberDiff line numberDiff line change
@@ -6296,8 +6296,6 @@ and type_expect_
62966296
| Error () -> raise (Error (loc, env, Probe_format))
62976297
| Ok { name; name_loc; enabled_at_init; arg; } ->
62986298
check_probe_name name name_loc env;
6299-
let env = Env.add_escape_lock Probe env in
6300-
let env = Env.add_share_lock Probe env in
63016299
Env.add_probe name;
63026300
let exp = type_expect env mode_legacy arg
63036301
(mk_expected Predef.type_unit) in

0 commit comments

Comments
 (0)