@@ -89,6 +89,24 @@ type cltype = {
8989 ctdiff : Types .class_type_declaration Stddiff .atomic_entry ;
9090}
9191
92+ type extcstr = {
93+ ecname : string ;
94+ ectname : string ;
95+ ecexn : bool ;
96+ ecdiff : (Types .extension_constructor , extcstr_modification ) Stddiff .entry ;
97+ }
98+
99+ and extcstr_modification = {
100+ extcstr_params :
101+ ( Types .type_expr list ,
102+ ( Types .type_expr list ,
103+ (Types .type_expr , type_expr ) Stddiff.List .t )
104+ Stddiff .entry )
105+ Stddiff .maybe_changed ;
106+ extcstr_private : (Asttypes .private_flag , type_privacy ) Stddiff .maybe_changed ;
107+ extcstr_args : (Types .constructor_arguments , cstr_args ) Stddiff .maybe_changed ;
108+ }
109+
92110type module_ = {
93111 mname : string ;
94112 mdiff : (Types .module_declaration , signature_modification ) Stddiff .entry ;
@@ -108,6 +126,7 @@ and sig_item =
108126 | Modtype of modtype
109127 | Class of class_
110128 | Classtype of cltype
129+ | Extcstr of extcstr
111130
112131let extract_items items =
113132 List. fold_left
@@ -137,6 +156,12 @@ let extract_items items =
137156 else
138157 Sig_item_map. add ~name: (Ident. name id) Sig_item_map. Classtype
139158 class_type_decl tbl
159+ | Sig_typext (id , typext , status , Exported) ->
160+ let exn = match status with Text_exception -> true | _ -> false in
161+ Sig_item_map. add
162+ ~name: (Path. name typext.ext_type_path)
163+ (Sig_item_map. Extcstr (Ident. name id))
164+ (typext, exn ) tbl
140165 | _ -> tbl)
141166 Sig_item_map. empty items
142167
@@ -443,7 +468,16 @@ and variant_type ~typing_env ~ref_params ~cur_params ~ref_constructor_lst
443468 ~reference: ref_cstrs ~current: cur_cstrs
444469
445470and cstr ~typing_env ~ref_params ~cur_params reference current =
446- match (reference.cd_args, current.cd_args) with
471+ let diff =
472+ cstr_args ~typing_env ~ref_params ~cur_params ~reference: reference.cd_args
473+ ~current: current.cd_args
474+ in
475+ match diff with
476+ | Stddiff. Same _ -> Same reference
477+ | Changed change -> Changed change
478+
479+ and cstr_args ~typing_env ~ref_params ~cur_params ~reference ~current =
480+ match (reference, current) with
447481 | Cstr_tuple ref_type_exprs , Cstr_tuple cur_type_exprs -> (
448482 let type_exprs =
449483 type_exprs ~typing_env ~ref_params ~cur_params ~reference: ref_type_exprs
@@ -459,10 +493,7 @@ and cstr ~typing_env ~ref_params ~cur_params reference current =
459493 in
460494 if String_map. is_empty label_map.changed_map then Same reference
461495 else Changed (Record_cstr label_map)
462- | _ ->
463- Changed
464- (Atomic_cstr
465- { reference = reference.cd_args; current = current.cd_args })
496+ | _ -> Changed (Atomic_cstr { reference; current })
466497
467498and type_params ~reference ~current =
468499 let open Stddiff in
@@ -553,6 +584,64 @@ let class_type_item ~typing_env ~name
553584 { reference = ref_class_type; current = curr_class_type };
554585 }))
555586
587+ let extension_constructors ~typing_env ~type_name ~name ~reference ~current =
588+ let ref_exn, ref_extcstr = reference in
589+ let cur_exn, cur_extcstr = current in
590+ let ecexn =
591+ match (ref_exn, cur_exn) with
592+ | true , true | false , false -> ref_exn
593+ | _ -> false
594+ in
595+ let extcstr_params =
596+ type_params ~reference: ref_extcstr.Types. ext_type_params
597+ ~current: cur_extcstr.Types. ext_type_params
598+ in
599+ let extcstr_private =
600+ type_privacy ~reference: ref_extcstr.ext_private
601+ ~current: cur_extcstr.ext_private
602+ in
603+ let extcstr_args =
604+ cstr_args ~typing_env ~ref_params: ref_extcstr.ext_type_params
605+ ~cur_params: cur_extcstr.ext_type_params ~reference: ref_extcstr.ext_args
606+ ~current: cur_extcstr.ext_args
607+ in
608+ match { extcstr_params; extcstr_private; extcstr_args } with
609+ | {
610+ extcstr_params = Same _ | Changed _;
611+ extcstr_private = Same _;
612+ extcstr_args = Same _;
613+ } ->
614+ None
615+ | diff ->
616+ Some
617+ (Extcstr
618+ { ecname = name; ectname = type_name; ecexn; ecdiff = Modified diff })
619+
620+ let extcstr_item ~typing_env ~type_name ~name ~reference ~current =
621+ match (reference, current) with
622+ | None , None -> None
623+ | None , Some (curr_extcstr , curr_exn ) ->
624+ Some
625+ (Extcstr
626+ {
627+ ecname = name;
628+ ectname = type_name;
629+ ecexn = curr_exn;
630+ ecdiff = Added curr_extcstr;
631+ })
632+ | Some (ref_extcstr , ref_exn ), None ->
633+ Some
634+ (Extcstr
635+ {
636+ ecname = name;
637+ ectname = type_name;
638+ ecexn = ref_exn;
639+ ecdiff = Removed ref_extcstr;
640+ })
641+ | Some (ref_extcstr , ref_exn ), Some (cur_extcstr , cur_exn ) ->
642+ extension_constructors ~typing_env ~type_name ~name
643+ ~reference: (ref_exn, ref_extcstr) ~current: (cur_exn, cur_extcstr)
644+
556645let rec items ~reference ~current ~typing_env =
557646 let ref_items = extract_items reference in
558647 let curr_items = extract_items current in
@@ -565,6 +654,9 @@ let rec items ~reference ~current ~typing_env =
565654 | Type -> type_item ~typing_env ~name ~reference ~current
566655 | Class -> class_item ~typing_env ~name ~reference ~current
567656 | Classtype -> class_type_item ~typing_env ~name ~reference ~current
657+ | Extcstr extcstr_name ->
658+ extcstr_item ~typing_env ~name: extcstr_name ~type_name: name ~reference
659+ ~current
568660 in
569661 Sig_item_map. diff ~diff_item: { diff_item } ref_items curr_items
570662
0 commit comments