11type type_expr =
22 | Tuple of tuple
33 | Arrow of arrow
4+ | Constr of constr
45 | Atomic of Types .type_expr Stddiff .atomic_modification
56
67and tuple = (Types. type_expr, type_expr) Stddiff.List. t
@@ -23,6 +24,16 @@ and arg_label_diff = {
2324
2425and arg_optional = Added_opt_arg | Removed_opt_arg
2526
27+ and constr = {
28+ path : (Path .t , Path .t Stddiff .atomic_modification ) Stddiff .maybe_changed ;
29+ args :
30+ ( Types .type_expr list ,
31+ ( Types .type_expr list ,
32+ (Types .type_expr , type_expr ) Stddiff.List .t )
33+ Stddiff .entry )
34+ Stddiff .maybe_changed ;
35+ }
36+
2637type type_modification = {
2738 type_kind : (Types .type_decl_kind , type_kind ) Stddiff .maybe_changed ;
2839 type_privacy : (Asttypes .private_flag , type_privacy ) Stddiff .maybe_changed ;
@@ -32,7 +43,9 @@ type type_modification = {
3243 Stddiff .maybe_changed ;
3344 type_params :
3445 ( Types .type_expr list ,
35- (Types .type_expr , type_expr ) Stddiff.List .t )
46+ ( Types .type_expr list ,
47+ (Types .type_expr , type_expr ) Stddiff.List .t )
48+ Stddiff .entry )
3649 Stddiff .maybe_changed ;
3750}
3851
@@ -174,6 +187,10 @@ let rec type_expr ~typing_env ?(ref_params = []) ?(cur_params = []) reference
174187 match arrow with
175188 | Stddiff. Same _ -> Stddiff. Same reference
176189 | Changed change -> Changed (Arrow change))
190+ | Tconstr (ref_path , ref_args , _ ), Tconstr (cur_path , cur_args , _ ) ->
191+ expand_and_diff_tconstr ~typing_env ~ref_params ~cur_params
192+ ~reference: (reference, ref_path, ref_args)
193+ ~current: (current, cur_path, cur_args)
177194 | _ ->
178195 let normed_ref, normed_cur =
179196 Normalize. type_params_arity ~reference: ref_params ~current: cur_params
@@ -191,6 +208,62 @@ let rec type_expr ~typing_env ?(ref_params = []) ?(cur_params = []) reference
191208 current = expand_alias_types ~typing_env ~type_expr: current;
192209 })
193210
211+ and expand_and_diff_tconstr ~typing_env ~ref_params ~cur_params ~reference
212+ ~current =
213+ let ref_expr, ref_path, ref_args = reference in
214+ let cur_expr, cur_path, cur_args = current in
215+ let expanded_ref =
216+ Option. value
217+ (Typing_env. fully_expand_tconstr ~typing_env ~path: ref_path ~args: ref_args)
218+ ~default: ref_expr
219+ in
220+ let expanded_cur =
221+ Option. value
222+ (Typing_env. fully_expand_tconstr ~typing_env ~path: cur_path ~args: cur_args)
223+ ~default: cur_expr
224+ in
225+ match (Types. get_desc expanded_ref, Types. get_desc expanded_cur) with
226+ | Tconstr (ref_path , ref_args , _ ), Tconstr (cur_path , cur_args , _ ) -> (
227+ let constr =
228+ constr ~typing_env ~ref_params ~cur_params
229+ ~reference: (ref_path, ref_args) ~current: (cur_path, cur_args)
230+ in
231+ match constr with
232+ | Stddiff. Same _ -> Stddiff. Same cur_expr
233+ | Changed change -> Changed change)
234+ | _ , _ -> (
235+ let diff =
236+ type_expr ~typing_env ~ref_params ~cur_params expanded_ref expanded_cur
237+ in
238+ match diff with
239+ | Same _ -> Same cur_expr
240+ | Changed change -> Changed change)
241+
242+ and constr ~typing_env ~ref_params ~cur_params ~reference ~current =
243+ let open Stddiff in
244+ let ref_path, ref_args = reference in
245+ let cur_path, cur_args = current in
246+ let path =
247+ if String. equal (Path. name ref_path) (Path. name cur_path) then Same ref_path
248+ else Changed { reference = ref_path; current = cur_path }
249+ in
250+ let args =
251+ match (ref_args, cur_args) with
252+ | [] , _ :: _ -> Changed (Added cur_args)
253+ | _ :: _ , [] -> Changed (Removed ref_args)
254+ | _ -> (
255+ let type_exprs =
256+ type_exprs ~typing_env ~ref_params ~cur_params ~reference: ref_args
257+ ~current: cur_args
258+ in
259+ match type_exprs with
260+ | Same same_params -> Same same_params
261+ | Changed change -> Changed (Modified change))
262+ in
263+ match (path, args) with
264+ | Same _ , Same _ -> Same current
265+ | _ -> Changed (Constr { path; args })
266+
194267and type_exprs ~typing_env ~ref_params ~cur_params ~reference ~current =
195268 Stddiff.List. diff
196269 ~diff_one: (fun ref cur ->
@@ -393,7 +466,16 @@ and cstr ~typing_env ~ref_params ~cur_params reference current =
393466
394467and type_params ~reference ~current =
395468 let open Stddiff in
396- List. diff ~diff_one: (fun t1 _ -> Same t1) ~reference ~current
469+ match (reference, current) with
470+ | [] , _ :: _ -> Changed (Added current)
471+ | _ :: _ , [] -> Changed (Removed reference)
472+ | _ -> (
473+ let params_diff =
474+ List. diff ~diff_one: (fun t1 _ -> Same t1) ~reference ~current
475+ in
476+ match params_diff with
477+ | Same same_params -> Same same_params
478+ | Changed change -> Changed (Modified change))
397479
398480and type_privacy ~reference ~current =
399481 match (reference, current) with
0 commit comments