Skip to content

Commit bf5ffb2

Browse files
authored
[Super errors] add needed patch for better unification errors (#1919)
* [Super errors] add needed patch for better unification errors * New super_type_expansion function * Fix patch typo
1 parent dfe959f commit bf5ffb2

File tree

4 files changed

+97
-1
lines changed

4 files changed

+97
-1
lines changed

vendor/ocaml/bytecomp/translcore.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ let primitive_is_ccall = function
617617
let assert_failed exp =
618618
let (fname, line, char) =
619619
Location.get_pos_info exp.exp_loc.Location.loc_start in
620-
#if undefined BS_NO_COMPILER_PATH then
620+
#if undefined BS_NO_COMPILER_PATCH then
621621
let fname =
622622
if not !Location.absname then Filename.basename fname else fname
623623
in

vendor/ocaml/typing/printtyp.ml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,6 +1429,7 @@ let rec trace_same_names = function
14291429
type_same_name t1 t2; type_same_name t1' t2'; trace_same_names rem
14301430
| _ -> ()
14311431

1432+
#if defined BS_NO_COMPILER_PATCH then
14321433
let unification_error unif tr txt1 ppf txt2 =
14331434
reset ();
14341435
trace_same_names tr;
@@ -1457,6 +1458,87 @@ let unification_error unif tr txt1 ppf txt2 =
14571458
with exn ->
14581459
print_labels := true;
14591460
raise exn
1461+
#else
1462+
let super_type_expansion ~tag t ppf t' =
1463+
if same_path t t' then begin
1464+
Format.pp_open_tag ppf tag;
1465+
type_expr ppf t;
1466+
Format.pp_close_tag ppf ();
1467+
end else begin
1468+
let t' = if proxy t == proxy t' then unalias t' else t' in
1469+
fprintf ppf "@[<2>";
1470+
Format.pp_open_tag ppf tag;
1471+
fprintf ppf "%a" type_expr t;
1472+
Format.pp_close_tag ppf ();
1473+
fprintf ppf "@ @{<dim>(defined as@}@ ";
1474+
Format.pp_open_tag ppf tag;
1475+
fprintf ppf "%a" type_expr t';
1476+
Format.pp_close_tag ppf ();
1477+
fprintf ppf "@{<dim>)@}";
1478+
fprintf ppf "@]";
1479+
end
1480+
1481+
let super_trace ppf =
1482+
let rec super_trace first_report ppf = function
1483+
| (t1, t1') :: (t2, t2') :: rem ->
1484+
fprintf ppf
1485+
"@,@,@[<v 2>";
1486+
if first_report then
1487+
fprintf ppf "The incompatible parts:@,"
1488+
else begin
1489+
fprintf ppf "Further expanded:@,"
1490+
end;
1491+
fprintf ppf
1492+
"@[<v>\
1493+
@[%a@]@,\
1494+
vs@,\
1495+
@[%a@]\
1496+
%a\
1497+
@]"
1498+
(super_type_expansion ~tag:"error" t1) t1'
1499+
(super_type_expansion ~tag:"info" t2) t2'
1500+
(super_trace false) rem;
1501+
fprintf ppf "@]"
1502+
| _ -> ()
1503+
in super_trace true ppf
1504+
1505+
let unification_error unif tr txt1 ppf txt2 = begin
1506+
reset ();
1507+
trace_same_names tr;
1508+
let tr = List.map (fun (t, t') -> (t, hide_variant_name t')) tr in
1509+
let mis = mismatch unif tr in
1510+
match tr with
1511+
| [] | _ :: [] -> assert false
1512+
| t1 :: t2 :: tr ->
1513+
try
1514+
let tr = filter_trace (mis = None) tr in
1515+
let t1, t1' = may_prepare_expansion (tr = []) t1
1516+
and t2, t2' = may_prepare_expansion (tr = []) t2 in
1517+
print_labels := not !Clflags.classic;
1518+
let tr = List.map prepare_expansion tr in
1519+
fprintf ppf
1520+
"@[<v 0>\
1521+
@[<v 2>\
1522+
%t@,\
1523+
@[<2>%a@]\
1524+
@]@,\
1525+
@[<v 2>\
1526+
%t@,\
1527+
@[<2>%a@]\
1528+
@]\
1529+
%a\
1530+
%t\
1531+
@]"
1532+
txt1 (super_type_expansion ~tag:"error" t1) t1'
1533+
txt2 (super_type_expansion ~tag:"info" t2) t2'
1534+
super_trace tr
1535+
(explanation unif mis);
1536+
print_labels := true
1537+
with exn ->
1538+
print_labels := true;
1539+
raise exn
1540+
end
1541+
#end
14601542

14611543
let report_unification_error ppf env ?(unif=true)
14621544
tr txt1 txt2 =

vendor/ocaml/utils/misc.ml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,9 @@ module Color = struct
376376
| BG of color (* background *)
377377
| Bold
378378
| Reset
379+
#if undefined BS_NO_COMPILER_PATCH then
380+
| Dim
381+
#end
379382

380383
let ansi_of_color = function
381384
| Black -> "0"
@@ -392,6 +395,9 @@ module Color = struct
392395
| BG c -> "4" ^ ansi_of_color c
393396
| Bold -> "1"
394397
| Reset -> "0"
398+
#if undefined BS_NO_COMPILER_PATCH then
399+
| Dim -> "2"
400+
#end
395401

396402
let ansi_of_style_l l =
397403
let s = match l with
@@ -423,6 +429,11 @@ module Color = struct
423429
| "error" -> (!cur_styles).error
424430
| "warning" -> (!cur_styles).warning
425431
| "loc" -> (!cur_styles).loc
432+
#if undefined BS_NO_COMPILER_PATCH then
433+
| "info" -> [Bold; FG Yellow]
434+
| "dim" -> [Dim]
435+
| "filename" -> [FG Cyan]
436+
#end
426437
| _ -> raise Not_found
427438

428439
let color_enabled = ref true

vendor/ocaml/utils/misc.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ module Color : sig
188188
| BG of color (* background *)
189189
| Bold
190190
| Reset
191+
#if undefined BS_NO_COMPILER_PATCH then
192+
| Dim
193+
#end
191194

192195
val ansi_of_style_l : style list -> string
193196
(* ANSI escape sequence for the given style *)

0 commit comments

Comments
 (0)