From e690b11d9e568bca9df22a454972c77dba672d04 Mon Sep 17 00:00:00 2001 From: Louis Gesbert Date: Mon, 30 Mar 2026 17:25:14 +0200 Subject: [PATCH] Fix Oracles for Catala's introspection (catala#974) --- impot_revenu/ocaml/oracles.ml | 100 +++++++++----------- impot_revenu/ocaml/oracles.mli | 11 +-- impot_revenu/oracles.template.ml | 150 ++++++++++++++++++++++++++++++ impot_revenu/oracles.template.mli | 80 ++++++++++++++++ 4 files changed, 279 insertions(+), 62 deletions(-) create mode 100644 impot_revenu/oracles.template.ml create mode 100644 impot_revenu/oracles.template.mli diff --git a/impot_revenu/ocaml/oracles.ml b/impot_revenu/ocaml/oracles.ml index 2b00bb7..c3f8f63 100644 --- a/impot_revenu/ocaml/oracles.ml +++ b/impot_revenu/ocaml/oracles.ml @@ -3,12 +3,14 @@ open Catala_runtime [@@@ocaml.warning "-4-26-27-32-41-42"] module DeficitAnterieur = struct - type t = { annee : integer; valeur : money } - - let embed (x : t) : runtime_value = - Struct - ( "DeficitAnterieur", - ["annee", embed_integer x.annee; "valeur", embed_money x.valeur] ) + type t = { annee: integer; valeur: money; } + let rtype = Value.Struct { + name = "Oracles.D\195\169ficitAnt\195\169rieur"; + fields = fun t -> [ + "annee", Value.embed (Value.Integer) t.annee; + "valeur", Value.embed (Value.Money) t.valeur; + ] + } end module ResultatProRataArrondiEuroBranchement = struct @@ -32,39 +34,29 @@ module ResultatProRataArrondiEuroBranchement = struct valeurs_proratisees_liste_8 : money array; valeurs_proratisees_liste_9 : money array; } - - let embed (x : t) : runtime_value = - Struct - ( "ResultatProRataArrondiEuroBranchement", - [ - "valeur_proratisee_1", embed_money x.valeur_proratisee_1; - "valeur_proratisee_2", embed_money x.valeur_proratisee_2; - "valeur_proratisee_3", embed_money x.valeur_proratisee_3; - "valeur_proratisee_4", embed_money x.valeur_proratisee_4; - "valeur_proratisee_5", embed_money x.valeur_proratisee_5; - "valeur_proratisee_6", embed_money x.valeur_proratisee_6; - "valeur_proratisee_7", embed_money x.valeur_proratisee_7; - "valeur_proratisee_8", embed_money x.valeur_proratisee_8; - "valeur_proratisee_9", embed_money x.valeur_proratisee_9; - ( "valeurs_proratisees_liste_1", - embed_array embed_money x.valeurs_proratisees_liste_1 ); - ( "valeurs_proratisees_liste_2", - embed_array embed_money x.valeurs_proratisees_liste_2 ); - ( "valeurs_proratisees_liste_3", - embed_array embed_money x.valeurs_proratisees_liste_3 ); - ( "valeurs_proratisees_liste_4", - embed_array embed_money x.valeurs_proratisees_liste_4 ); - ( "valeurs_proratisees_liste_5", - embed_array embed_money x.valeurs_proratisees_liste_5 ); - ( "valeurs_proratisees_liste_6", - embed_array embed_money x.valeurs_proratisees_liste_6 ); - ( "valeurs_proratisees_liste_7", - embed_array embed_money x.valeurs_proratisees_liste_7 ); - ( "valeurs_proratisees_liste_8", - embed_array embed_money x.valeurs_proratisees_liste_8 ); - ( "valeurs_proratisees_liste_9", - embed_array embed_money x.valeurs_proratisees_liste_9 ); - ] ) + let rtype = Value.Struct { + name = "Oracles.R\195\169sultatProRataArrondiEuroBranchement"; + fields = fun t -> [ + "valeur_proratisee_1", Value.embed (Value.Money) t.valeur_proratisee_1; + "valeur_proratisee_2", Value.embed (Value.Money) t.valeur_proratisee_2; + "valeur_proratisee_3", Value.embed (Value.Money) t.valeur_proratisee_3; + "valeur_proratisee_4", Value.embed (Value.Money) t.valeur_proratisee_4; + "valeur_proratisee_5", Value.embed (Value.Money) t.valeur_proratisee_5; + "valeur_proratisee_6", Value.embed (Value.Money) t.valeur_proratisee_6; + "valeur_proratisee_7", Value.embed (Value.Money) t.valeur_proratisee_7; + "valeur_proratisee_8", Value.embed (Value.Money) t.valeur_proratisee_8; + "valeur_proratisee_9", Value.embed (Value.Money) t.valeur_proratisee_9; + "valeurs_proratisees_liste_1", Value.embed (Value.Array(Value.embed (Value.Money))) t.valeurs_proratisees_liste_1; + "valeurs_proratisees_liste_2", Value.embed (Value.Array(Value.embed (Value.Money))) t.valeurs_proratisees_liste_2; + "valeurs_proratisees_liste_3", Value.embed (Value.Array(Value.embed (Value.Money))) t.valeurs_proratisees_liste_3; + "valeurs_proratisees_liste_4", Value.embed (Value.Array(Value.embed (Value.Money))) t.valeurs_proratisees_liste_4; + "valeurs_proratisees_liste_5", Value.embed (Value.Array(Value.embed (Value.Money))) t.valeurs_proratisees_liste_5; + "valeurs_proratisees_liste_6", Value.embed (Value.Array(Value.embed (Value.Money))) t.valeurs_proratisees_liste_6; + "valeurs_proratisees_liste_7", Value.embed (Value.Array(Value.embed (Value.Money))) t.valeurs_proratisees_liste_7; + "valeurs_proratisees_liste_8", Value.embed (Value.Array(Value.embed (Value.Money))) t.valeurs_proratisees_liste_8; + "valeurs_proratisees_liste_9", Value.embed (Value.Array(Value.embed (Value.Money))) t.valeurs_proratisees_liste_9; + ] + } end module ResultatImputation = struct @@ -72,15 +64,13 @@ module ResultatImputation = struct revenu_impute : money; deficits_anterieurs_restants : DeficitAnterieur.t array; } - - let embed (x : t) : runtime_value = - Struct - ( "ResultatImputation", - [ - "revenu_impute", embed_money x.revenu_impute; - ( "deficits_anterieurs_restants", - embed_array DeficitAnterieur.embed x.deficits_anterieurs_restants ); - ] ) + let rtype = Value.Struct { + name = "Oracles.R\195\169sultatImputation"; + fields = fun t -> [ + "revenu_impute", Value.embed (Value.Money) t.revenu_impute; + "deficits_anterieurs_restants", Value.embed (Value.Array(Value.embed (DeficitAnterieur.rtype))) t.deficits_anterieurs_restants; + ] + } end let imputation_aux_deficits_les_plus_anciens @@ -92,7 +82,7 @@ let imputation_aux_deficits_les_plus_anciens match deficits_anterieurs with | [] -> revenu_declare, [] | hd :: tl -> - if o_gt_mon_mon hd.valeur revenu_declare then + if hd.valeur > revenu_declare then ( money_of_units_int 0, { hd with valeur = o_sub_mon_mon hd.valeur revenu_declare } :: tl ) else aux (o_sub_mon_mon revenu_declare hd.valeur) tl @@ -118,7 +108,7 @@ let prorata_arrondi_euro (bases_prorata : money array) : money array = if Array.exists - (fun base -> o_lt_mon_mon base (money_of_units_int 0)) + (fun base -> base < money_of_units_int 0) bases_prorata then raise @@ -136,9 +126,9 @@ let prorata_arrondi_euro ], None )); if - (not (o_eq_mon_mon montant_a_distribuer (money_of_units_int 0))) + (not (montant_a_distribuer = money_of_units_int 0)) && Array.for_all - (fun base -> o_eq_mon_mon base (money_of_units_int 0)) + (fun base -> base = money_of_units_int 0) bases_prorata then raise @@ -182,7 +172,7 @@ let prorata_arrondi_euro let assiette_totale_rat = decimal_of_money assiette_totale_prorata in - if o_eq_rat_rat assiette_totale_rat zero then zero + if assiette_totale_rat = zero then zero else try o_mult_rat_rat @@ -203,8 +193,8 @@ let prorata_arrondi_euro in let arrondi = decimal_round brut in ( money_of_decimal arrondi, - if o_eq_rat_rat arrondi brut then Nul - else if o_gt_rat_rat arrondi brut then Haut + if arrondi = brut then Nul + else if o_gt Value.Decimal {filename=__FILE__; start_line=__LINE__; end_line=__LINE__; start_column=0; end_column=0; law_headings=[]} arrondi brut then Haut else Bas )) bases_prorata in diff --git a/impot_revenu/ocaml/oracles.mli b/impot_revenu/ocaml/oracles.mli index 761f837..1504a10 100644 --- a/impot_revenu/ocaml/oracles.mli +++ b/impot_revenu/ocaml/oracles.mli @@ -3,9 +3,8 @@ open Catala_runtime [@@@ocaml.warning "-4-26-27-32-41-42"] module DeficitAnterieur : sig - type t = { annee : integer; valeur : money } - - val embed : t -> runtime_value + type t = { annee: integer; valeur: money; } + val rtype: t Value.ty end module ResultatProRataArrondiEuroBranchement : sig @@ -29,8 +28,7 @@ module ResultatProRataArrondiEuroBranchement : sig valeurs_proratisees_liste_8 : money array; valeurs_proratisees_liste_9 : money array; } - - val embed : t -> runtime_value + val rtype: t Value.ty end module ResultatImputation : sig @@ -38,8 +36,7 @@ module ResultatImputation : sig revenu_impute : money; deficits_anterieurs_restants : DeficitAnterieur.t array; } - - val embed : t -> runtime_value + val rtype: t Value.ty end val imputation_aux_deficits_les_plus_anciens : diff --git a/impot_revenu/oracles.template.ml b/impot_revenu/oracles.template.ml new file mode 100644 index 0000000..cc94390 --- /dev/null +++ b/impot_revenu/oracles.template.ml @@ -0,0 +1,150 @@ +(* This is a template file following the expected interface and declarations to + * implement the corresponding Catala module. + * + * You should replace all `raise (Error (Impossible))` place-holders with your + * implementation and rename it to remove the ".template" suffix. *) + +[@@@ocaml.warning "-4-26-27-32-33-34-37-41-42-69"] + +open Catala_runtime + + +module DeficitAnterieur = struct + type t = { annee: integer; valeur: money; } + let rtype = Value.Struct { + name = "Oracles.D\195\169ficitAnt\195\169rieur"; + fields = fun t -> [ + "annee", Value.embed (Value.Integer) t.annee; + "valeur", Value.embed (Value.Money) t.valeur; + ] + } +end + +module ResultatProRataArrondiEuroBranchement = struct + type t = { + valeur_proratisee_1: money; + valeur_proratisee_2: money; + valeur_proratisee_3: money; + valeur_proratisee_4: money; + valeur_proratisee_5: money; + valeur_proratisee_6: money; + valeur_proratisee_7: money; + valeur_proratisee_8: money; + valeur_proratisee_9: money; + valeurs_proratisees_liste_1: money array; + valeurs_proratisees_liste_2: money array; + valeurs_proratisees_liste_3: money array; + valeurs_proratisees_liste_4: money array; + valeurs_proratisees_liste_5: money array; + valeurs_proratisees_liste_6: money array; + valeurs_proratisees_liste_7: money array; + valeurs_proratisees_liste_8: money array; + valeurs_proratisees_liste_9: money array; + } + let rtype = Value.Struct { + name = "Oracles.R\195\169sultatProRataArrondiEuroBranchement"; + fields = fun t -> [ + "valeur_proratisee_1", Value.embed (Value.Money) t.valeur_proratisee_1; + "valeur_proratisee_2", Value.embed (Value.Money) t.valeur_proratisee_2; + "valeur_proratisee_3", Value.embed (Value.Money) t.valeur_proratisee_3; + "valeur_proratisee_4", Value.embed (Value.Money) t.valeur_proratisee_4; + "valeur_proratisee_5", Value.embed (Value.Money) t.valeur_proratisee_5; + "valeur_proratisee_6", Value.embed (Value.Money) t.valeur_proratisee_6; + "valeur_proratisee_7", Value.embed (Value.Money) t.valeur_proratisee_7; + "valeur_proratisee_8", Value.embed (Value.Money) t.valeur_proratisee_8; + "valeur_proratisee_9", Value.embed (Value.Money) t.valeur_proratisee_9; + "valeurs_proratisees_liste_1", Value.embed (Value.Array(Value.embed (Value.Money))) t.valeurs_proratisees_liste_1; + "valeurs_proratisees_liste_2", Value.embed (Value.Array(Value.embed (Value.Money))) t.valeurs_proratisees_liste_2; + "valeurs_proratisees_liste_3", Value.embed (Value.Array(Value.embed (Value.Money))) t.valeurs_proratisees_liste_3; + "valeurs_proratisees_liste_4", Value.embed (Value.Array(Value.embed (Value.Money))) t.valeurs_proratisees_liste_4; + "valeurs_proratisees_liste_5", Value.embed (Value.Array(Value.embed (Value.Money))) t.valeurs_proratisees_liste_5; + "valeurs_proratisees_liste_6", Value.embed (Value.Array(Value.embed (Value.Money))) t.valeurs_proratisees_liste_6; + "valeurs_proratisees_liste_7", Value.embed (Value.Array(Value.embed (Value.Money))) t.valeurs_proratisees_liste_7; + "valeurs_proratisees_liste_8", Value.embed (Value.Array(Value.embed (Value.Money))) t.valeurs_proratisees_liste_8; + "valeurs_proratisees_liste_9", Value.embed (Value.Array(Value.embed (Value.Money))) t.valeurs_proratisees_liste_9; + ] + } +end + +module ResultatImputation = struct + type t = { + revenu_impute: money; + deficits_anterieurs_restants: DeficitAnterieur.t array; + } + let rtype = Value.Struct { + name = "Oracles.R\195\169sultatImputation"; + fields = fun t -> [ + "revenu_impute", Value.embed (Value.Money) t.revenu_impute; + "deficits_anterieurs_restants", Value.embed (Value.Array(Value.embed (DeficitAnterieur.rtype))) t.deficits_anterieurs_restants; + ] + } +end + + +(* Toplevel def loc *) +let loc : code_location array = + [|{filename="impot_revenu/oracles.catala_fr"; + start_line=29; start_column=13; end_line=29; end_column=53; + law_headings=["Imputation des déficits antérieurs"]}; + {filename="impot_revenu/oracles.catala_fr"; + start_line=73; start_column=13; end_line=73; end_column=33; + law_headings=["Calcul de pro-rata"]}; + {filename="impot_revenu/oracles.catala_fr"; + start_line=81; start_column=13; end_line=81; end_column=40; + law_headings=["Calcul de pro-rata"]}; + {filename="impot_revenu/oracles.catala_fr"; + start_line=109; start_column=13; end_line=109; end_column=45; + law_headings=["Calcul de pro-rata"]}|] + +(* Toplevel def imputation_aux_déficits_les_plus_anciens *) +let imputation_aux_deficits_les_plus_anciens : money -> + (DeficitAnterieur.t array) -> + ResultatImputation.t = + fun (_: money) (_: DeficitAnterieur.t array) -> raise + (Error (Impossible, [loc.(0)], None)) + +(* Toplevel def prorata_arrondi_euro *) +let prorata_arrondi_euro : money -> (money array) -> (money array) = + fun (_: money) (_: money array) -> raise + (Error (Impossible, [loc.(1)], None)) + +(* Toplevel def prorata_arrondi_euro_listes *) +let prorata_arrondi_euro_listes : money -> ((money array) array) -> + ((money array) array) = + fun (_: money) (_: (money array) array) -> raise + (Error (Impossible, [loc.(2)], None)) + +(* Toplevel def prorata_arrondi_euro_branchement *) +let prorata_arrondi_euro_branchement : money -> (money) Optional.t -> + (money) Optional.t -> + (money) Optional.t -> + (money) Optional.t -> + (money) Optional.t -> + (money) Optional.t -> + (money) Optional.t -> + (money) Optional.t -> + (money) Optional.t -> + (money array) -> (money array) -> + (money array) -> (money array) -> + (money array) -> (money array) -> + (money array) -> (money array) -> + (money array) -> + ResultatProRataArrondiEuroBranchement.t = + fun (_: money) (_: (money) Optional.t) (_: (money) Optional.t) + (_: (money) Optional.t) (_: (money) Optional.t) (_: (money) Optional.t) + (_: (money) Optional.t) (_: (money) Optional.t) (_: (money) Optional.t) + (_: (money) Optional.t) (_: money array) (_: money array) + (_: money array) (_: money array) (_: money array) (_: money array) + (_: money array) (_: money array) (_: money array) -> raise + (Error (Impossible, [loc.(3)], None)) + +let () = + Catala_runtime.register_module "Oracles" + [ "imputation_aux_d\195\169ficits_les_plus_anciens", + Stdlib.Obj.repr (imputation_aux_deficits_les_plus_anciens); + "prorata_arrondi_euro", Stdlib.Obj.repr (prorata_arrondi_euro); + "prorata_arrondi_euro_listes", + Stdlib.Obj.repr (prorata_arrondi_euro_listes); + "prorata_arrondi_euro_branchement", + Stdlib.Obj.repr (prorata_arrondi_euro_branchement) ] + "*external*" diff --git a/impot_revenu/oracles.template.mli b/impot_revenu/oracles.template.mli new file mode 100644 index 0000000..fb022e7 --- /dev/null +++ b/impot_revenu/oracles.template.mli @@ -0,0 +1,80 @@ +(* This is a template file following the expected interface and declarations to + * implement the corresponding Catala module. + * + * You should replace all `raise (Error (Impossible))` place-holders with your + * implementation and rename it to remove the ".template" suffix. *) + +[@@@ocaml.warning "-4-26-27-32-33-34-37-41-42-69"] + +open Catala_runtime + + +module DeficitAnterieur : sig + type t = { annee: integer; valeur: money; } + val rtype: t Value.ty +end + +module ResultatProRataArrondiEuroBranchement : sig + type t = { + valeur_proratisee_1: money; + valeur_proratisee_2: money; + valeur_proratisee_3: money; + valeur_proratisee_4: money; + valeur_proratisee_5: money; + valeur_proratisee_6: money; + valeur_proratisee_7: money; + valeur_proratisee_8: money; + valeur_proratisee_9: money; + valeurs_proratisees_liste_1: money array; + valeurs_proratisees_liste_2: money array; + valeurs_proratisees_liste_3: money array; + valeurs_proratisees_liste_4: money array; + valeurs_proratisees_liste_5: money array; + valeurs_proratisees_liste_6: money array; + valeurs_proratisees_liste_7: money array; + valeurs_proratisees_liste_8: money array; + valeurs_proratisees_liste_9: money array; + } + val rtype: t Value.ty +end + +module ResultatImputation : sig + type t = { + revenu_impute: money; + deficits_anterieurs_restants: DeficitAnterieur.t array; + } + val rtype: t Value.ty +end + + +(** Toplevel definition loc *) +val loc : code_location array + +(** Toplevel definition imputation_aux_déficits_les_plus_anciens *) +val imputation_aux_deficits_les_plus_anciens : money -> + (DeficitAnterieur.t array) -> + ResultatImputation.t + +(** Toplevel definition prorata_arrondi_euro *) +val prorata_arrondi_euro : money -> (money array) -> (money array) + +(** Toplevel definition prorata_arrondi_euro_listes *) +val prorata_arrondi_euro_listes : money -> ((money array) array) -> + ((money array) array) + +(** Toplevel definition prorata_arrondi_euro_branchement *) +val prorata_arrondi_euro_branchement : money -> (money) Optional.t -> + (money) Optional.t -> + (money) Optional.t -> + (money) Optional.t -> + (money) Optional.t -> + (money) Optional.t -> + (money) Optional.t -> + (money) Optional.t -> + (money) Optional.t -> + (money array) -> (money array) -> + (money array) -> (money array) -> + (money array) -> (money array) -> + (money array) -> (money array) -> + (money array) -> + ResultatProRataArrondiEuroBranchement.t