Skip to content

Commit 44cd2fc

Browse files
authored
flambda-backend: Fix uncaught Unify exception in filter_arrow (#1820)
* fix uncaught unify exception in filter_arrow * add related testcase * simplify testcase * call link_type after constrain_type_layout * reduce testcase further * simplify error message * change link_type call order for moregen --------- Co-authored-by: Alan Chang <alanechang@janestreet.com>
1 parent 3552db6 commit 44cd2fc

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

testsuite/tests/typing-layouts/basics_alpha.ml

+3-2
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ Error: Signature mismatch:
654654
val x : ('a : immediate). 'a
655655
is not included in
656656
val x : string
657-
The type string is not compatible with the type string
657+
The type ('a : immediate) is not compatible with the type string
658658
string has layout value, which is not a sublayout of immediate.
659659
|}];;
660660

@@ -691,7 +691,8 @@ Error: Signature mismatch:
691691
val x : ('a : immediate). 'a t
692692
is not included in
693693
val x : string
694-
The type string t = string is not compatible with the type string
694+
The type 'a t = ('a : immediate) is not compatible with the type
695+
string
695696
string has layout value, which is not a sublayout of immediate.
696697
|}]
697698

testsuite/tests/typing-layouts/basics_beta.ml

+18-2
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ Error: Signature mismatch:
486486
val x : ('a : immediate). 'a
487487
is not included in
488488
val x : string
489-
The type string is not compatible with the type string
489+
The type ('a : immediate) is not compatible with the type string
490490
string has layout value, which is not a sublayout of immediate.
491491
|}];;
492492

@@ -523,7 +523,8 @@ Error: Signature mismatch:
523523
val x : ('a : immediate). 'a t
524524
is not included in
525525
val x : string
526-
The type string t = string is not compatible with the type string
526+
The type 'a t = ('a : immediate) is not compatible with the type
527+
string
527528
string has layout value, which is not a sublayout of immediate.
528529
|}]
529530

@@ -1320,3 +1321,18 @@ Line 3, characters 15-40:
13201321
^^^^^^^^^^^^^^^^^^^^^^^^^
13211322
Error: Type 'a has layout value, which is not a sublayout of immediate.
13221323
|}]
1324+
1325+
(****************************************************)
1326+
(* Test 35: check bad layout error in filter_arrow *)
1327+
1328+
type ('a : immediate) t35 = 'a
1329+
let f35 : 'a t35 = fun () -> ()
1330+
1331+
[%%expect {|
1332+
type ('a : immediate) t35 = 'a
1333+
Line 2, characters 19-31:
1334+
2 | let f35 : 'a t35 = fun () -> ()
1335+
^^^^^^^^^^^^
1336+
Error:
1337+
'a -> 'b has layout value, which is not a sublayout of immediate.
1338+
|}]

typing/ctype.ml

+13-5
Original file line numberDiff line numberDiff line change
@@ -3857,8 +3857,16 @@ let filter_arrow env t l ~force_tpoly =
38573857
match get_desc t with
38583858
Tvar { layout } ->
38593859
let t', arrow_desc = function_type (get_level t) in
3860+
begin match constrain_type_layout env t' layout with
3861+
| Ok _ -> ()
3862+
| Error err ->
3863+
raise (Filter_arrow_failed
3864+
(Unification_error
3865+
(expand_to_unification_error
3866+
env
3867+
[Bad_layout (t',err)])))
3868+
end;
38603869
link_type t t';
3861-
constrain_type_layout_exn env Unify t' layout;
38623870
arrow_desc
38633871
| Tarrow((l', arg_mode, ret_mode), ty_arg, ty_ret, _) ->
38643872
if l = l' || !Clflags.classic && l = Nolabel && not (is_optional l')
@@ -4363,8 +4371,8 @@ let rec moregen inst_nongen variance type_pairs env t1 t2 =
43634371
moregen_occur env (get_level t1) t2;
43644372
update_scope_for Moregen (get_scope t1) t2;
43654373
occur_for Moregen env t1 t2;
4366-
link_type t1 t2;
4367-
constrain_type_layout_exn env Moregen t2 layout
4374+
constrain_type_layout_exn env Moregen t2 layout;
4375+
link_type t1 t2
43684376
| (Tconstr (p1, [], _), Tconstr (p2, [], _)) when Path.same p1 p2 ->
43694377
()
43704378
| _ ->
@@ -4379,8 +4387,8 @@ let rec moregen inst_nongen variance type_pairs env t1 t2 =
43794387
(Tvar { layout }, _) when may_instantiate inst_nongen t1' ->
43804388
moregen_occur env (get_level t1') t2;
43814389
update_scope_for Moregen (get_scope t1') t2;
4382-
link_type t1' t2;
4383-
constrain_type_layout_exn env Moregen t2 layout
4390+
constrain_type_layout_exn env Moregen t2 layout;
4391+
link_type t1' t2
43844392
| (Tarrow ((l1,a1,r1), t1, u1, _),
43854393
Tarrow ((l2,a2,r2), t2, u2, _)) when
43864394
(l1 = l2

0 commit comments

Comments
 (0)