Skip to content

Commit bdec230

Browse files
fix the issue with instance_prim
1 parent 65754bb commit bdec230

File tree

4 files changed

+29
-28
lines changed

4 files changed

+29
-28
lines changed

typing/ctype.ml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1806,14 +1806,14 @@ let instance_prim_mode (desc : Primitive.description) ty =
18061806
let finalret = prim_mode (Some mode_l) (Some mode_y) desc.prim_native_repr_res in
18071807
instance_prim_locals desc.prim_native_repr_args
18081808
mode_l mode_y (Alloc.disallow_right Alloc.legacy) finalret ty,
1809-
Some mode_l
1809+
Some mode_l, Some mode_y
18101810
else
1811-
ty, None
1811+
ty, None, None
18121812

18131813
let instance_prim (desc : Primitive.description) ty =
18141814
let ty, sort = instance_prim_layout desc ty in
1815-
let ty, mode = instance_prim_mode desc ty in
1816-
ty, mode, sort
1815+
let ty, mode_l, mode_y = instance_prim_mode desc ty in
1816+
ty, mode_l, mode_y, sort
18171817

18181818
(**** Instantiation with parameter substitution ****)
18191819

typing/ctype.mli

+2-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ val prim_mode :
229229
* (Mode.allowed * 'r) Mode.Yielding.t
230230
val instance_prim:
231231
Primitive.description -> type_expr ->
232-
type_expr * Mode.Locality.lr option * Jkind.Sort.t option
232+
type_expr * Mode.Locality.lr option
233+
* Mode.Yielding.lr option * Jkind.Sort.t option
233234

234235
(** Given (a @ m1 -> b -> c) @ m0, where [m0] and [m1] are modes expressed by
235236
user-syntax, [curry_mode m0 m1] gives the mode we implicitly interpret b->c

typing/includecore.ml

+22-22
Original file line numberDiff line numberDiff line change
@@ -191,37 +191,37 @@ let value_descriptions ~loc env name
191191
| Val_prim p1 -> begin
192192
match vd2.val_kind with
193193
| Val_prim p2 -> begin
194-
let ty1_global, _, _ = Ctype.instance_prim p1 vd1.val_type in
195-
let ty2_global =
196-
let ty2, mode2, _ = Ctype.instance_prim p2 vd2.val_type in
197-
Option.iter
198-
(fun m -> Mode.Locality.submode_exn m Mode.Locality.global)
199-
mode2;
200-
ty2
201-
in
202-
(try Ctype.moregeneral env true ty1_global ty2_global
203-
with Ctype.Moregen err -> raise (Dont_match (Type err)));
204-
let ty1_local, _, _ = Ctype.instance_prim p1 vd1.val_type in
205-
let ty2_local =
206-
let ty2, mode2, _ = Ctype.instance_prim p2 vd2.val_type in
207-
Option.iter
208-
(fun m -> Mode.Locality.submode_exn Mode.Locality.local m)
209-
mode2;
210-
ty2
211-
in
212-
(try Ctype.moregeneral env true ty1_local ty2_local
213-
with Ctype.Moregen err -> raise (Dont_match (Type err)));
194+
let restrict_locality = [
195+
(fun m -> Mode.Locality.submode_exn m Mode.Locality.global);
196+
(fun m -> Mode.Locality.submode_exn Mode.Locality.local m)
197+
] in
198+
let restrict_yielding = [
199+
(fun m -> Mode.Yielding.submode_exn m Mode.Yielding.unyielding);
200+
(fun m -> Mode.Yielding.submode_exn Mode.Yielding.yielding m)
201+
] in
202+
List.iter (fun restrict_loc ->
203+
List.iter (fun restrict_yield ->
204+
let ty1, _, _, _ = Ctype.instance_prim p1 vd1.val_type in
205+
let ty2, mode_l2, mode_y2, _ = Ctype.instance_prim p2 vd2.val_type in
206+
Option.iter restrict_loc mode_l2;
207+
Option.iter restrict_yield mode_y2;
208+
try
209+
Ctype.moregeneral env true ty1 ty2
210+
with Ctype.Moregen err ->
211+
raise (Dont_match (Type err))
212+
) restrict_yielding
213+
) restrict_locality;
214214
match primitive_descriptions p1 p2 with
215215
| None -> Tcoerce_none
216216
| Some err -> raise (Dont_match (Primitive_mismatch err))
217217
end
218218
| _ ->
219-
let ty1, mode1, sort1 = Ctype.instance_prim p1 vd1.val_type in
219+
let ty1, mode_l1, _, sort1 = Ctype.instance_prim p1 vd1.val_type in
220220
(try Ctype.moregeneral env true ty1 vd2.val_type
221221
with Ctype.Moregen err -> raise (Dont_match (Type err)));
222222
let pc =
223223
{pc_desc = p1; pc_type = vd2.Types.val_type;
224-
pc_poly_mode = Option.map Mode.Locality.disallow_right mode1;
224+
pc_poly_mode = Option.map Mode.Locality.disallow_right mode_l1;
225225
pc_poly_sort=sort1;
226226
pc_env = env; pc_loc = vd1.Types.val_loc; } in
227227
Tcoerce_primitive pc

typing/typecore.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7132,7 +7132,7 @@ and type_ident env ?(recarg=Rejected) lid =
71327132
let val_type, kind =
71337133
match desc.val_kind with
71347134
| Val_prim prim ->
7135-
let ty, mode, sort = instance_prim prim desc.val_type in
7135+
let ty, mode, _, sort = instance_prim prim desc.val_type in
71367136
let ty = instance ty in
71377137
begin match prim.prim_native_repr_res, mode with
71387138
(* if the locality of returned value of the primitive is poly

0 commit comments

Comments
 (0)