Skip to content

Commit 29d08cb

Browse files
committed
Revert "more hints about what types we are looking at"
This reverts commit 55476b9.
1 parent 1093261 commit 29d08cb

File tree

10 files changed

+97
-206
lines changed

10 files changed

+97
-206
lines changed

compiler/ml/ctype.ml

Lines changed: 45 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ open Btype
5353
*)
5454

5555
(**** Errors ****)
56-
type type_pairs = (type_expr * type_expr) list
5756

58-
exception Unify of type_pairs
57+
exception Unify of (type_expr * type_expr) list
5958

6059
exception Tags of label * label
6160

@@ -101,20 +100,11 @@ type subtype_context =
101100
issues: Record_coercion.record_field_subtype_violation list;
102101
}
103102

104-
type subtype_type_position =
105-
| RecordField of {
106-
field_name: string;
107-
left_record_name: Path.t;
108-
right_record_name: Path.t;
109-
}
110-
| TupleElement of {index: int}
111-
112103
exception
113104
Subtype of
114-
type_pairs
115-
* type_pairs
105+
(type_expr * type_expr) list
106+
* (type_expr * type_expr) list
116107
* subtype_context option
117-
* subtype_type_position option
118108

119109
exception Cannot_expand
120110

@@ -123,7 +113,7 @@ exception Cannot_apply
123113
exception Recursive_abbrev
124114

125115
(* GADT: recursive abbrevs can appear as a result of local constraints *)
126-
exception Unification_recursive_abbrev of type_pairs
116+
exception Unification_recursive_abbrev of (type_expr * type_expr) list
127117

128118
(**** Type level management ****)
129119

@@ -3589,15 +3579,15 @@ let enlarge_type env ty =
35893579

35903580
let subtypes = TypePairs.create 17
35913581

3592-
let subtype_error ?type_position ?ctx env trace =
3593-
raise (Subtype (expand_trace env (List.rev trace), [], ctx, type_position))
3582+
let subtype_error ?ctx env trace =
3583+
raise (Subtype (expand_trace env (List.rev trace), [], ctx))
35943584

35953585
let extract_concrete_typedecl_opt env t =
35963586
match extract_concrete_typedecl env t with
35973587
| v -> Some v
35983588
| exception Not_found -> None
35993589

3600-
let rec subtype_rec ?type_position env trace t1 t2 cstrs =
3590+
let rec subtype_rec env trace t1 t2 cstrs =
36013591
let t1 = repr t1 in
36023592
let t2 = repr t2 in
36033593
if t1 == t2 then cstrs
@@ -3608,16 +3598,14 @@ let rec subtype_rec ?type_position env trace t1 t2 cstrs =
36083598
with Not_found -> (
36093599
TypePairs.add subtypes (t1, t2) ();
36103600
match (t1.desc, t2.desc) with
3611-
| Tvar _, _ | _, Tvar _ ->
3612-
(trace, t1, t2, !univar_pairs, None, type_position) :: cstrs
3601+
| Tvar _, _ | _, Tvar _ -> (trace, t1, t2, !univar_pairs, None) :: cstrs
36133602
| Tarrow (l1, t1, u1, _, _), Tarrow (l2, t2, u2, _, _)
36143603
when Asttypes.Noloc.same_arg_label l1 l2 ->
36153604
let cstrs = subtype_rec env ((t2, t1) :: trace) t2 t1 cstrs in
36163605
subtype_rec env ((u1, u2) :: trace) u1 u2 cstrs
36173606
| Ttuple tl1, Ttuple tl2 ->
3618-
subtype_list
3619-
~make_type_position:(fun i -> Some (TupleElement {index = i}))
3620-
env trace tl1 tl2 cstrs
3607+
(* TODO(subtype-errors) Tuple as context *)
3608+
subtype_list env trace tl1 tl2 cstrs
36213609
| Tconstr (p1, [], _), Tconstr (p2, [], _) when Path.same p1 p2 -> cstrs
36223610
| Tconstr (p1, _tl1, _abbrev1), _
36233611
when generic_abbrev env p1 && safe_abbrev env t1 ->
@@ -3643,15 +3631,13 @@ let rec subtype_rec ?type_position env trace t1 t2 cstrs =
36433631
newty2 t1.level (Ttuple [t1]),
36443632
newty2 t2.level (Ttuple [t2]),
36453633
!univar_pairs,
3646-
None,
3647-
type_position )
3634+
None )
36483635
:: cstrs
36493636
else subtype_rec env ((t1, t2) :: trace) t1 t2 cstrs
36503637
else if cn then subtype_rec env ((t2, t1) :: trace) t2 t1 cstrs
36513638
else cstrs)
36523639
cstrs decl.type_variance (List.combine tl1 tl2)
3653-
with Not_found ->
3654-
(trace, t1, t2, !univar_pairs, None, type_position) :: cstrs)
3640+
with Not_found -> (trace, t1, t2, !univar_pairs, None) :: cstrs)
36553641
| Tconstr (p1, _, _), _ when generic_private_abbrev env p1 ->
36563642
subtype_rec env trace (expand_abbrev_opt env t1) t2 cstrs
36573643
| Tconstr (p1, [], _), Tconstr (p2, [], _)
@@ -3678,8 +3664,7 @@ let rec subtype_rec ?type_position env trace t1 t2 cstrs =
36783664
!univar_pairs,
36793665
Some
36803666
(Primitive_coercion_target_variant_not_unboxed
3681-
{variant_name = p; primitive = path}),
3682-
type_position )
3667+
{variant_name = p; primitive = path}) )
36833668
:: cstrs
36843669
| Some (p, constructors, true) ->
36853670
if
@@ -3693,17 +3678,11 @@ let rec subtype_rec ?type_position env trace t1 t2 cstrs =
36933678
!univar_pairs,
36943679
Some
36953680
(Primitive_coercion_target_variant_no_catch_all
3696-
{variant_name = p; primitive = path}),
3697-
type_position )
3681+
{variant_name = p; primitive = path}) )
36983682
:: cstrs
36993683
| None ->
37003684
(* Unclear when this case actually happens. *)
3701-
( trace,
3702-
t1,
3703-
t2,
3704-
!univar_pairs,
3705-
Some (Generic {errorCode = "VCPMMVD"}),
3706-
type_position )
3685+
(trace, t1, t2, !univar_pairs, Some (Generic {errorCode = "VCPMMVD"}))
37073686
:: cstrs)
37083687
| Tconstr (_, [], _), Tconstr (path, [], _)
37093688
when Variant_coercion.can_coerce_primitive path
@@ -3729,11 +3708,11 @@ let rec subtype_rec ?type_position env trace t1 t2 cstrs =
37293708
!univar_pairs,
37303709
Some
37313710
(Variant_constructor_runtime_representation_mismatch
3732-
{issues = runtime_representation_issues; variant_name = p}),
3733-
type_position )
3711+
{issues = runtime_representation_issues; variant_name = p})
3712+
)
37343713
:: cstrs
37353714
else cstrs
3736-
| None -> (trace, t1, t2, !univar_pairs, None, type_position) :: cstrs)
3715+
| None -> (trace, t1, t2, !univar_pairs, None) :: cstrs)
37373716
| Tconstr (_, [], _), Tconstr (_, [], _) -> (
37383717
(* type coercion for variants and records *)
37393718
match
@@ -3743,7 +3722,7 @@ let rec subtype_rec ?type_position env trace t1 t2 cstrs =
37433722
(p2, _, {type_kind = Type_variant c2; type_attributes = t2attrs}) )
37443723
-> (
37453724
match
3746-
Variant_coercion.variant_configuration_can_be_coerced t1attrs
3725+
Variant_coercion.variant_configuration_can_be_coerced2 t1attrs
37473726
t2attrs
37483727
with
37493728
| Error issue ->
@@ -3753,8 +3732,7 @@ let rec subtype_rec ?type_position env trace t1 t2 cstrs =
37533732
!univar_pairs,
37543733
Some
37553734
(Variant_configurations_mismatch
3756-
{left_variant_name = p1; right_variant_name = p2; issue}),
3757-
type_position )
3735+
{left_variant_name = p1; right_variant_name = p2; issue}) )
37583736
:: cstrs
37593737
| Ok () ->
37603738
let c1_len = List.length c1 in
@@ -3782,8 +3760,7 @@ let rec subtype_rec ?type_position env trace t1 t2 cstrs =
37823760
issue =
37833761
Incompatible_constructor_count
37843762
{constructor_names = incompatible_constructor_names};
3785-
}),
3786-
type_position )
3763+
}) )
37873764
:: cstrs
37883765
else
37893766
let constructor_map = Hashtbl.create c1_len in
@@ -3845,7 +3822,7 @@ let rec subtype_rec ?type_position env trace t1 t2 cstrs =
38453822
| _ -> Some [ (* TODO(subtype-errors) *) ])
38463823
in
38473824
if field_subtype_violations = [] then cstrs
3848-
else (trace, t1, t2, !univar_pairs, None, type_position) :: cstrs)
3825+
else (trace, t1, t2, !univar_pairs, None) :: cstrs)
38493826
| ( (p1, _, {type_kind = Type_record (fields1, repr1)}),
38503827
(p2, _, {type_kind = Type_record (fields2, repr2)}) ) ->
38513828
(* TODO(subtype-errors) Record representation *)
@@ -3873,24 +3850,10 @@ let rec subtype_rec ?type_position env trace t1 t2 cstrs =
38733850
left_record_name = p1;
38743851
right_record_name = p2;
38753852
issues = violations;
3876-
}),
3877-
type_position )
3853+
}) )
38783854
:: cstrs
3879-
else
3880-
subtype_list
3881-
~make_type_position:(fun i ->
3882-
match List.nth_opt fields1 i with
3883-
| None -> None
3884-
| Some field ->
3885-
Some
3886-
(RecordField
3887-
{
3888-
field_name = field.ld_id.name;
3889-
left_record_name = p1;
3890-
right_record_name = p2;
3891-
}))
3892-
env trace tl1 tl2 cstrs
3893-
else (trace, t1, t2, !univar_pairs, None, type_position) :: cstrs
3855+
else subtype_list env trace tl1 tl2 cstrs
3856+
else (trace, t1, t2, !univar_pairs, None) :: cstrs
38943857
| (p1, _, {type_kind = tk1}), (p2, _, {type_kind = tk2}) ->
38953858
( trace,
38963859
t1,
@@ -3903,22 +3866,19 @@ let rec subtype_rec ?type_position env trace t1 t2 cstrs =
39033866
right_typename = p2;
39043867
left_type_kind = tk1;
39053868
right_type_kind = tk2;
3906-
}),
3907-
type_position )
3869+
}) )
39083870
:: cstrs
3909-
| exception Not_found ->
3910-
(trace, t1, t2, !univar_pairs, None, type_position) :: cstrs)
3871+
| exception Not_found -> (trace, t1, t2, !univar_pairs, None) :: cstrs)
39113872
(* | (_, Tconstr(p2, _, _)) when generic_private_abbrev false env p2 ->
39123873
subtype_rec env trace t1 (expand_abbrev_opt env t2) cstrs *)
39133874
| Tobject (f1, _), Tobject (f2, _)
39143875
when is_Tvar (object_row f1) && is_Tvar (object_row f2) ->
39153876
(* Same row variable implies same object. *)
3916-
(trace, t1, t2, !univar_pairs, None, type_position) :: cstrs
3877+
(trace, t1, t2, !univar_pairs, None) :: cstrs
39173878
| Tobject (f1, _), Tobject (f2, _) -> subtype_fields env trace f1 f2 cstrs
39183879
| Tvariant row1, Tvariant row2 -> (
39193880
try subtype_row env trace row1 row2 cstrs
3920-
with Exit ->
3921-
(trace, t1, t2, !univar_pairs, None, type_position) :: cstrs)
3881+
with Exit -> (trace, t1, t2, !univar_pairs, None) :: cstrs)
39223882
| Tvariant {row_closed = true; row_fields}, Tconstr (_, [], _)
39233883
when extract_concrete_typedecl_opt env t2
39243884
|> Variant_coercion.type_is_variant -> (
@@ -3932,9 +3892,8 @@ let rec subtype_rec ?type_position env trace t1 t2 cstrs =
39323892
~variant_constructors ~type_attributes
39333893
with
39343894
| Ok _ -> cstrs
3935-
| Error _ ->
3936-
(trace, t1, t2, !univar_pairs, None, type_position) :: cstrs)
3937-
| _ -> (trace, t1, t2, !univar_pairs, None, type_position) :: cstrs)
3895+
| Error _ -> (trace, t1, t2, !univar_pairs, None) :: cstrs)
3896+
| _ -> (trace, t1, t2, !univar_pairs, None) :: cstrs)
39383897
| Tvariant v, _ when !variant_is_subtype env (row_repr v) t2 -> cstrs
39393898
| Tpoly (u1, []), Tpoly (u2, []) -> subtype_rec env trace u1 u2 cstrs
39403899
| Tpoly (u1, tl1), Tpoly (u2, []) ->
@@ -3944,8 +3903,7 @@ let rec subtype_rec ?type_position env trace t1 t2 cstrs =
39443903
try
39453904
enter_poly env univar_pairs u1 tl1 u2 tl2 (fun t1 t2 ->
39463905
subtype_rec env trace t1 t2 cstrs)
3947-
with Unify _ ->
3948-
(trace, t1, t2, !univar_pairs, None, type_position) :: cstrs)
3906+
with Unify _ -> (trace, t1, t2, !univar_pairs, None) :: cstrs)
39493907
| Tpackage (p1, nl1, tl1), Tpackage (p2, nl2, tl2) -> (
39503908
try
39513909
let ntl1 = complete_type_list env nl2 t1.level (Mty_ident p1) nl1 tl1
@@ -3956,49 +3914,32 @@ let rec subtype_rec ?type_position env trace t1 t2 cstrs =
39563914
let cstrs' =
39573915
List.map
39583916
(fun (n2, t2) ->
3959-
( trace,
3960-
List.assoc n2 ntl1,
3961-
t2,
3962-
!univar_pairs,
3963-
None,
3964-
type_position ))
3917+
(trace, List.assoc n2 ntl1, t2, !univar_pairs, None))
39653918
ntl2
39663919
in
39673920
if eq_package_path env p1 p2 then cstrs' @ cstrs
39683921
else
39693922
(* need to check module subtyping *)
39703923
let snap = Btype.snapshot () in
39713924
try
3972-
List.iter (fun (_, t1, t2, _, _, _) -> unify env t1 t2) cstrs';
3925+
List.iter (fun (_, t1, t2, _, _) -> unify env t1 t2) cstrs';
39733926
if !package_subtype env p1 nl1 tl1 p2 nl2 tl2 then (
39743927
Btype.backtrack snap;
39753928
cstrs' @ cstrs)
39763929
else raise (Unify [])
39773930
with Unify _ ->
39783931
Btype.backtrack snap;
39793932
raise Not_found
3980-
with Not_found ->
3981-
(trace, t1, t2, !univar_pairs, None, type_position) :: cstrs)
3982-
| _, _ -> (trace, t1, t2, !univar_pairs, None, type_position) :: cstrs)
3983-
3984-
and subtype_list ?make_type_position env trace tl1 tl2 cstrs =
3985-
if List.length tl1 <> List.length tl2 then
3986-
(* TODO(subtype-errors): Not the same length error *)
3987-
subtype_error env trace;
3988-
let idx = ref 0 in
3933+
with Not_found -> (trace, t1, t2, !univar_pairs, None) :: cstrs)
3934+
| _, _ -> (trace, t1, t2, !univar_pairs, None) :: cstrs)
3935+
3936+
and subtype_list env trace tl1 tl2 cstrs =
3937+
if List.length tl1 <> List.length tl2 then subtype_error env trace;
39893938
List.fold_left2
3990-
(fun cstrs t1 t2 ->
3991-
let index = !idx in
3992-
incr idx;
3993-
let type_position =
3994-
match make_type_position with
3995-
| Some f -> f index
3996-
| None -> None
3997-
in
3998-
subtype_rec ?type_position env ((t1, t2) :: trace) t1 t2 cstrs)
3939+
(fun cstrs t1 t2 -> subtype_rec env ((t1, t2) :: trace) t1 t2 cstrs)
39993940
cstrs tl1 tl2
40003941

4001-
and subtype_fields ?type_position env trace ty1 ty2 cstrs =
3942+
and subtype_fields env trace ty1 ty2 cstrs =
40023943
(* Assume that either rest1 or rest2 is not Tvar *)
40033944
let fields1, rest1 = flatten_fields ty1 in
40043945
let fields2, rest2 = flatten_fields ty2 in
@@ -4012,8 +3953,7 @@ and subtype_fields ?type_position env trace ty1 ty2 cstrs =
40123953
build_fields (repr ty1).level miss1 rest1,
40133954
rest2,
40143955
!univar_pairs,
4015-
None,
4016-
type_position )
3956+
None )
40173957
:: cstrs
40183958
in
40193959
let cstrs =
@@ -4023,8 +3963,7 @@ and subtype_fields ?type_position env trace ty1 ty2 cstrs =
40233963
rest1,
40243964
build_fields (repr ty2).level miss2 (newvar ()),
40253965
!univar_pairs,
4026-
None,
4027-
type_position )
3966+
None )
40283967
:: cstrs
40293968
in
40303969
List.fold_left
@@ -4081,15 +4020,14 @@ let subtype env ty1 ty2 =
40814020
| () ->
40824021
List.iter
40834022
(function
4084-
| trace0, t1, t2, pairs, ctx, type_position -> (
4023+
| trace0, t1, t2, pairs, ctx -> (
40854024
try unify_pairs (ref env) t1 t2 pairs
40864025
with Unify trace ->
40874026
raise
40884027
(Subtype
40894028
( expand_trace env (List.rev trace0),
40904029
List.tl (List.tl trace),
4091-
ctx,
4092-
type_position ))))
4030+
ctx ))))
40934031
(List.rev cstrs)
40944032

40954033
(*******************)

compiler/ml/ctype.mli

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
open Asttypes
1919
open Types
2020

21-
type type_pairs = (type_expr * type_expr) list
22-
2321
type subtype_context =
2422
| Generic of {errorCode: string}
2523
| Primitive_coercion_target_variant_not_unboxed of {
@@ -51,26 +49,17 @@ type subtype_context =
5149
issues: Record_coercion.record_field_subtype_violation list;
5250
}
5351

54-
type subtype_type_position =
55-
| RecordField of {
56-
field_name: string;
57-
left_record_name: Path.t;
58-
right_record_name: Path.t;
59-
}
60-
| TupleElement of {index: int}
61-
62-
exception Unify of type_pairs
52+
exception Unify of (type_expr * type_expr) list
6353
exception Tags of label * label
6454
exception
6555
Subtype of
66-
type_pairs
67-
* type_pairs
56+
(type_expr * type_expr) list
57+
* (type_expr * type_expr) list
6858
* subtype_context option
69-
* subtype_type_position option
7059
exception Cannot_expand
7160
exception Cannot_apply
7261
exception Recursive_abbrev
73-
exception Unification_recursive_abbrev of type_pairs
62+
exception Unification_recursive_abbrev of (type_expr * type_expr) list
7463

7564
val init_def : int -> unit
7665
(* Set the initial variable level *)

0 commit comments

Comments
 (0)