@@ -298,6 +298,17 @@ let monomorphize_data_types map = object(self)
298298 TQualified chosen_lid
299299 end )#visit_typ () t
300300
301+ (* We need to renormalize entries in the map for the Checker module. For
302+ instance, the map might contain `t (u v) -> t0` and `u v -> u0`, but at
303+ this stage, we will have a type error when trying to compare `t (u v)` and
304+ `t u0`, since the latter does not appear in the map. *)
305+ method private renormalize_entry (n , ts , cgs ) chosen_lid =
306+ (* We do this on the fly to make sure that types that appear in ts have
307+ themselves been renormalized. *)
308+ let ts' = List. map resolve_deep ts in
309+ if not (Hashtbl. mem state (n, ts', cgs)) then
310+ Hashtbl. add state (n, ts', cgs) (Black , chosen_lid)
311+
301312 (* Compute the name of a given node in the graph. *)
302313 method private lid_of (n : node ) =
303314 let lid, ts, cgs = n in
@@ -340,6 +351,7 @@ let monomorphize_data_types map = object(self)
340351 (* For tuples, we immediately know how to generate a definition. *)
341352 let fields = List. mapi (fun i arg -> Some (self#field_at i), (arg, false )) args in
342353 self#record (DType (chosen_lid, [ Common. Private ] @ flag, 0 , 0 , Flat fields));
354+ self#renormalize_entry n chosen_lid;
343355 Hashtbl. replace state n (Black , chosen_lid)
344356 end else begin
345357 (* This specific node has not been visited yet. *)
@@ -352,6 +364,7 @@ let monomorphize_data_types map = object(self)
352364 begin match Hashtbl. find map lid with
353365 | exception Not_found ->
354366 (* Unknown, external non-polymorphic lid, e.g. Prims.int *)
367+ self#renormalize_entry n chosen_lid;
355368 Hashtbl. replace state n (Black , chosen_lid)
356369 | flags , ((Variant _ | Flat _ | Union _ ) as def ) when under_ref && not (Hashtbl. mem seen_declarations lid) ->
357370 (* Because this looks up a definition in the global map, the
@@ -382,10 +395,12 @@ let monomorphize_data_types map = object(self)
382395 let branches = List. map (fun (cons , fields ) -> cons, subst fields) branches in
383396 let branches = self#visit_branches_t under_ref branches in
384397 self#record (DType (chosen_lid, flag @ flags, 0 , 0 , Variant branches));
398+ self#renormalize_entry n chosen_lid;
385399 Hashtbl. replace state n (Black , chosen_lid)
386400 | flags , Flat fields ->
387401 let fields = self#visit_fields_t_opt under_ref (subst fields) in
388402 self#record (DType (chosen_lid, flag @ flags, 0 , 0 , Flat fields));
403+ self#renormalize_entry n chosen_lid;
389404 Hashtbl. replace state n (Black , chosen_lid)
390405 | flags , Union fields ->
391406 let fields = List. map (fun (f , t ) ->
@@ -394,13 +409,16 @@ let monomorphize_data_types map = object(self)
394409 f, t
395410 ) fields in
396411 self#record (DType (chosen_lid, flag @ flags, 0 , 0 , Union fields));
412+ self#renormalize_entry n chosen_lid;
397413 Hashtbl. replace state n (Black , chosen_lid)
398414 | flags , Abbrev t ->
399415 let t = DeBruijn. subst_tn args t in
400416 let t = self#visit_typ under_ref t in
401417 self#record (DType (chosen_lid, flag @ flags, 0 , 0 , Abbrev t));
418+ self#renormalize_entry n chosen_lid;
402419 Hashtbl. replace state n (Black , chosen_lid)
403420 | _ ->
421+ self#renormalize_entry n chosen_lid;
404422 Hashtbl. replace state n (Black , chosen_lid)
405423 end
406424 end ;
0 commit comments