123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102(* This file is part of the Catala compiler, a specification language for tax
and social benefits computation rules. Copyright (C) 2024 Inria, contributor:
Louis Gesbert <louis.gesbert@inria.fr>
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License. *)typet=intletmix(h1:t)(h2:t):t=Hashtbl.hash(h1,h2)letraw=Hashtbl.hashmoduleOp=structlet(%)=mixlet(!)=rawendopenOpletoptionf=functionNone->!`None|Somex->!`Some%fxletlisthfl=List.fold_left(funaccx->acc%hfx)!`ListEmptylletmapfold_funkhvhmap=fold_fun(funkvacc->acclxor(khk%vhv))map!`HashMapDelimmoduleFlags:sigtypenonrect=privatetvalpass:(t->'a)->monomorphize_types:bool->'avalof_t:int->tend=structtypenonrect=tletpassk~monomorphize_types=(* Should not affect the call convention or actual interfaces: include,
optimize, check_invariants, typed *)!(monomorphize_types:bool)(* % (\* The following may not affect the call convention, but we want it set in
* an homogeneous way *\)
* !(Global.options.trace <> None : bool) *)%!(Global.options.max_prec_digits:int)|>kletof_tt=tendtypefull={catala_version:t;flags_hash:Flags.t;contents:t}letfinaliset=Flags.pass(funflags_hash->{catala_version=!(Version.v:string);flags_hash;contents=t})letto_stringfull=Printf.sprintf"CM0|%08x|%08x|%08x"full.catala_version(full.flags_hash:>int)full.contents(* Putting color inside the hash makes them much easier to differentiate at a
glance *)letformatppffull=letopenOcolor_typesinletpcolorcolfx=Format.pp_open_stagppfOcolor_format.(Ocolor_style_tag(Fg(C24col)));fx;Format.pp_close_stagppf()inlettag=pcolor{r24=172;g24=172;b24=172}inletautoi={r24=128+(imod128);g24=128+((ilsr10)mod128);b24=128+((ilsr20)mod128);}inletphashh=letcol=autohinpcolorcol(Format.fprintfppf"%08x")hintag(Format.pp_print_stringppf)"CM0|";phashfull.catala_version;tag(Format.pp_print_stringppf)"|";phash(full.flags_hash:>int);tag(Format.pp_print_stringppf)"|";phashfull.contentsletof_strings=tryScanf.sscanfs"CM0|%08x|%08x|%08x"(funcatala_versionflags_hashcontents->{catala_version;flags_hash=Flags.of_tflags_hash;contents})withScanf.Scan_failure_->failwith"Hash.of_string"letexternal_placeholder="*external*"