<commit_before>module RegionPoset = SkelPoset.Make(struct
  type t = Type.region_param
  let compare = Pervasives.compare
end)

module FullRegions = Set.Make(struct
  type t = Type.region_param
  let compare = Pervasives.compare
end)

type t = {
  full_regions: FullRegions.t;
  regions: RegionPoset.t
}

let empty = {
  regions = RegionPoset.empty;
  full_regions = FullRegions.empty;
}

let union bnds1 bnds2 = {
  full_regions = FullRegions.union bnds1.full_regions bnds2.full_regions;
  regions = RegionPoset.union bnds1.regions bnds2.regions;
}

let subst sbst bnds = {
  full_regions = FullRegions.fold (fun r s -> FullRegions.add (sbst.Type.region_param r) s) bnds.full_regions FullRegions.empty;
  regions = RegionPoset.map sbst.Type.region_param bnds.regions;
}

let garbage_collect pos neg bnds =
  {
    full_regions = FullRegions.filter (fun r -> List.mem r pos) bnds.full_regions;
    regions = RegionPoset.garbage_collect pos neg bnds.regions;
  }

let add_full_region r bnds =
  (* REMOVE FULL REGIONS FROM bnds.regions *)
  {bnds with full_regions = FullRegions.add r bnds.full_regions}

let add_region_constraint r1 r2 bnds =
  if FullRegions.mem r1 bnds.full_regions then
    let new_full_regions = r2 :: RegionPoset.get_succ r2 bnds.regions in
    List.fold_right add_full_region new_full_regions bnds
  else
    {bnds with regions = RegionPoset.add_edge r1 r2 bnds.regions}

let print ~non_poly bnds ppf =
  Print.print ppf "%t; FULL: %t"
    (RegionPoset.print (Type.print_region_param ~non_poly) bnds.regions)
    (Print.sequence "," (Type.print_region_param ~non_poly) (FullRegions.elements bnds.full_regions))<commit_msg>Moving region constraints to the simpler poset<commit_after>module RegionPoset = Poset.Make(struct
  type t = Type.region_param
  let compare = Pervasives.compare
  let print = Type.print_region_param ~non_poly:Trio.empty
end)

module FullRegions = Set.Make(struct
  type t = Type.region_param
  let compare = Pervasives.compare
end)

type t = {
  full_regions: FullRegions.t;
  regions: RegionPoset.t
}

let empty = {
  regions = RegionPoset.empty;
  full_regions = FullRegions.empty;
}

let union bnds1 bnds2 = {
  full_regions = FullRegions.union bnds1.full_regions bnds2.full_regions;
  regions = RegionPoset.merge bnds1.regions bnds2.regions;
}

let subst sbst bnds = {
  full_regions = FullRegions.fold (fun r s -> FullRegions.add (sbst.Type.region_param r) s) bnds.full_regions FullRegions.empty;
  regions = RegionPoset.map sbst.Type.region_param bnds.regions;
}

let garbage_collect pos neg bnds =
  {
    full_regions = FullRegions.filter (fun r -> List.mem r pos) bnds.full_regions;
    regions = RegionPoset.filter (fun x y -> List.mem x neg && List.mem y pos && not (FullRegions.mem y bnds.full_regions)) bnds.regions;
  }

let add_full_region r bnds =
  let new_full_regions = r :: RegionPoset.get_succ r bnds.regions in
  {bnds with full_regions = List.fold_right FullRegions.add new_full_regions bnds.full_regions}

let add_region_constraint r1 r2 bnds =
  if FullRegions.mem r1 bnds.full_regions then
    let new_full_regions = r2 :: RegionPoset.get_succ r2 bnds.regions in
    {bnds with full_regions = List.fold_right FullRegions.add new_full_regions bnds.full_regions}
  else
    {bnds with regions = RegionPoset.add r1 r2 bnds.regions}

let print ~non_poly bnds ppf =
  Print.print ppf "%t; FULL: %t"
    (RegionPoset.print bnds.regions)
    (Print.sequence "," (Type.print_region_param ~non_poly) (FullRegions.elements bnds.full_regions))
{'fraction_non_alphanumeric': 0.08815977175463624, 'fraction_numerical': 0.007417974322396576, 'mean_word_length': 4.288084464555053, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2006711', 'n_tokens_mistral': 1350, 'n_tokens_neox': 1290, 'n_words': 312}