Fix a few remaining renaming glitches

This commit is contained in:
Louis Gesbert 2024-09-02 12:15:14 +02:00
parent cb88cb07a1
commit 634de675a2
18 changed files with 153 additions and 159 deletions

View File

@ -1,6 +1,18 @@
# Reformatting commits to be skipped when running 'git blame' # Reformatting commits to be skipped when running 'git blame'
# Use `git config --global blame.ignoreRevsFile .git-blame-ignore-revs` to use it # Use `git config --global blame.ignoreRevsFile .git-blame-ignore-revs` to use it
# Add new reformatting commits at the top # Add new reformatting commits at the top
6a062921f15c5b70e42fefee0f28d249d4289e34
5d61963a93a0b735d9419b43ef05c676f5169d9a
1b6da0b5720e9168aca1452e9ed40ad7e0bd737a
840530163284da2d664f8e3e8a1ff89830132a1d
dc1b725e9b9d34db3bef5da28c20a4e489b304d9
79e0dcecdaa9ae129330ba371b627d6842d48dbc
75bf76826486a96c0b4110a6758a561781d49145
619cafebb8028ea9cc3bd49ed9334c9c39a1e6d3
1ae955b50443edb123de4b612bc8c85935567c59
d4198f52b47670a0ace3f65fed91ea28543a3488
cf89204a4b0dcdc37554b9206bdc03c9a0d21fa8
c4715ea86efa12cfdfd5b230c48f32a2cdb9552d
2708fa53b23bde545e7378a660cdb99e8671f1de 2708fa53b23bde545e7378a660cdb99e8671f1de
a79acd1fa8b701a5688c7fa985c7064cd6d81acf a79acd1fa8b701a5688c7fa985c7064cd6d81acf

View File

@ -36,6 +36,10 @@ authors:
family-names: Banuls family-names: Banuls
- given-name: Aminata - given-name: Aminata
family-names: Boiguillé family-names: Boiguillé
- given-name: Vincent
family-names: Botbol
affiliation: "INRIA"
email: vincent.botbol@inria.fr
repository-code: "https://github.com/CatalaLang/catala" repository-code: "https://github.com/CatalaLang/catala"
url: "https://catala-lang.org/" url: "https://catala-lang.org/"
abstract: >- abstract: >-
@ -43,5 +47,5 @@ abstract: >-
faithful-by-construction algorithms from faithful-by-construction algorithms from
legislative texts. legislative texts.
license: Apache-2.0 license: Apache-2.0
version: 0.8.0 version: 0.10.0
date-released: "2022-03-08" date-released: "2022-03-08"

View File

@ -134,8 +134,8 @@ let renaming =
Renaming.program () Renaming.program ()
~reserved:ocaml_keywords ~reserved:ocaml_keywords
(* TODO: add catala runtime built-ins as reserved as well ? *) (* TODO: add catala runtime built-ins as reserved as well ? *)
~reset_context_for_closed_terms:true ~skip_constant_binders:true ~skip_constant_binders:true ~constant_binder_name:(Some "_")
~constant_binder_name:(Some "_") ~namespaced_fields_constrs:true ~namespaced_fields_constrs:true
let format_struct_name (fmt : Format.formatter) (v : StructName.t) : unit = let format_struct_name (fmt : Format.formatter) (v : StructName.t) : unit =
(match StructName.path v with (match StructName.path v with

View File

@ -625,7 +625,6 @@ let program_to_graph
{ {
Renaming.reserved = []; Renaming.reserved = [];
sanitize_varname = String.to_snake_case; sanitize_varname = String.to_snake_case;
reset_context_for_closed_terms = false;
skip_constant_binders = false; skip_constant_binders = false;
constant_binder_name = None; constant_binder_name = None;
}) })

View File

@ -209,6 +209,7 @@ and translate_expr (ctxt : 'm ctxt) (expr : 'm L.expr) :
let exceptions_stmts, new_exceptions, ren_ctx = let exceptions_stmts, new_exceptions, ren_ctx =
translate_expr_list ctxt exceptions translate_expr_list ctxt exceptions
in in
let ctxt = { ctxt with ren_ctx } in
let eposl, vposdefs, ctxt = let eposl, vposdefs, ctxt =
List.fold_left List.fold_left
(fun (eposl, vposdefs, ctxt) exc -> (fun (eposl, vposdefs, ctxt) exc ->
@ -225,11 +226,9 @@ and translate_expr (ctxt : 'm ctxt) (expr : 'm L.expr) :
ctxt ) ctxt )
else else
let arr_var_name, ctxt = let arr_var_name, ctxt =
fresh_var ~pos { ctxt with ren_ctx } ctxt.context_name fresh_var ~pos ctxt ("exc_" ^ ctxt.context_name)
in
let pos_arr_var_name, ctxt =
fresh_var ~pos { ctxt with ren_ctx } "pos_list"
in in
let pos_arr_var_name, ctxt = fresh_var ~pos ctxt "pos_list" in
let stmts = let stmts =
stmts stmts
++ RevBlock.make ++ RevBlock.make
@ -475,7 +474,7 @@ and translate_statements (ctxt : 'm ctxt) (block_expr : 'm L.expr) :
{ ctxt with inside_definition_of = None } { ctxt with inside_definition_of = None }
vars_tau vars_tau
in in
let new_body, _ren_ctx = translate_statements ctxt body in let new_body, ren_ctx = translate_statements ctxt body in
( [ ( [
( A.SInnerFuncDef ( A.SInnerFuncDef
{ {
@ -497,10 +496,9 @@ and translate_statements (ctxt : 'm ctxt) (block_expr : 'm L.expr) :
}, },
binder_pos ); binder_pos );
], ],
ctxt.ren_ctx ) ren_ctx )
| EMatch { e = e1; cases; name } -> | EMatch { e = e1; cases; name } ->
let typ = Expr.maybe_ty (Mark.get e1) in let typ = Expr.maybe_ty (Mark.get e1) in
let pos = Expr.pos block_expr in
let e1_stmts, new_e1, ren_ctx = translate_expr ctxt e1 in let e1_stmts, new_e1, ren_ctx = translate_expr ctxt e1 in
let ctxt = { ctxt with ren_ctx } in let ctxt = { ctxt with ren_ctx } in
let e1_stmts, switch_var, ctxt = let e1_stmts, switch_var, ctxt =
@ -514,63 +512,45 @@ and translate_statements (ctxt : 'm ctxt) (block_expr : 'm L.expr) :
v, v,
ctxt ) ctxt )
in in
let new_cases = let new_cases, ren_ctx =
EnumConstructor.Map.fold EnumConstructor.Map.fold
(fun _ arg new_args -> (fun _ arg (new_args, ren_ctx) ->
match Mark.remove arg with match Mark.remove arg with
| EAbs { binder; tys = typ :: _ } -> | EAbs { binder; tys = typ :: _ } ->
let vars, body, ctxt = unmbind ctxt binder in let vars, body, ctxt = unmbind { ctxt with ren_ctx } binder in
assert (Array.length vars = 1); assert (Array.length vars = 1);
let var = vars.(0) in let var = vars.(0) in
let scalc_var, ctxt = let scalc_var, ctxt =
register_fresh_var ctxt var ~pos:(Expr.pos arg) register_fresh_var ctxt var ~pos:(Expr.pos arg)
in in
let new_arg, _ren_ctx = translate_statements ctxt body in let new_arg, _ren_ctx = translate_statements ctxt body in
{ ( {
A.case_block = new_arg; A.case_block = new_arg;
payload_var_name = scalc_var; payload_var_name = scalc_var;
payload_var_typ = typ; payload_var_typ = typ;
} }
:: new_args :: new_args,
ctxt.ren_ctx )
| _ -> assert false) | _ -> assert false)
cases [] cases ([], ctxt.ren_ctx)
in in
let new_args = List.rev new_cases in let ctxt = { ctxt with ren_ctx } in
let tail = let tail =
if ctxt.config.keep_special_ops then [
let tmp_var = A.VarName.fresh ("match_arg", pos) in ( A.SSwitch
[ {
( A.SLocalInit switch_var;
{ switch_var_typ = typ;
name = tmp_var, pos; enum_name = name;
typ = Expr.maybe_ty (Mark.get e1); switch_cases = List.rev new_cases;
expr = new_e1; },
}, Expr.pos block_expr );
pos ); ]
( A.SSwitch
{
switch_var = tmp_var;
switch_var_typ = typ;
enum_name = name;
switch_cases = new_args;
},
pos );
]
else
[
( A.SSwitch
{
switch_var;
switch_var_typ = typ;
enum_name = name;
switch_cases = List.rev new_cases;
},
Expr.pos block_expr );
]
in in
RevBlock.rebuild e1_stmts ~tail, ren_ctx RevBlock.rebuild e1_stmts ~tail, ctxt.ren_ctx
| EIfThenElse { cond; etrue; efalse } -> | EIfThenElse { cond; etrue; efalse } ->
let cond_stmts, s_cond, ren_ctx = translate_expr ctxt cond in let cond_stmts, s_cond, ren_ctx = translate_expr ctxt cond in
let ctxt = { ctxt with ren_ctx } in
let s_e_true, _ = translate_statements ctxt etrue in let s_e_true, _ = translate_statements ctxt etrue in
let s_e_false, _ = translate_statements ctxt efalse in let s_e_false, _ = translate_statements ctxt efalse in
( RevBlock.rebuild cond_stmts ( RevBlock.rebuild cond_stmts
@ -808,20 +788,25 @@ let translate_program ~(config : translation_config) (p : 'm L.program) :
~f:(fun (ctxt, rev_items) code_item var -> ~f:(fun (ctxt, rev_items) code_item var ->
match code_item with match code_item with
| ScopeDef (name, body) -> | ScopeDef (name, body) ->
let scope_input_var, scope_body_expr, ctxt1 = let scope_input_var, scope_body_expr, outer_ctx =
unbind ctxt body.scope_body_expr unbind ctxt body.scope_body_expr
in in
let input_pos = Mark.get (ScopeName.get_info name) in let input_pos = Mark.get (ScopeName.get_info name) in
let scope_input_var_id, ctxt = let scope_input_var_id, inner_ctx =
register_fresh_var ctxt scope_input_var ~pos:input_pos register_fresh_var ctxt scope_input_var ~pos:input_pos
in in
let new_scope_body = let new_scope_body =
translate_scope_body_expr translate_scope_body_expr
{ ctxt with context_name = Mark.remove (ScopeName.get_info name) } {
inner_ctx with
context_name = Mark.remove (ScopeName.get_info name);
}
scope_body_expr scope_body_expr
in in
let func_id, ctxt1 = register_fresh_func ctxt1 var ~pos:input_pos in let func_id, outer_ctx =
( ctxt1, register_fresh_func outer_ctx var ~pos:input_pos
in
( outer_ctx,
A.SScope A.SScope
{ {
Ast.scope_body_name = name; Ast.scope_body_name = name;
@ -841,32 +826,32 @@ let translate_program ~(config : translation_config) (p : 'm L.program) :
:: rev_items ) :: rev_items )
| Topdef (name, topdef_ty, _vis, (EAbs abs, m)) -> | Topdef (name, topdef_ty, _vis, (EAbs abs, m)) ->
(* Toplevel function def *) (* Toplevel function def *)
let (block, expr, _ren_ctx), args_id = let (block, expr, _ren_ctx_inner), args_id =
let args_a, expr, ctxt = unmbind ctxt abs.binder in let args_a, expr, ctxt_inner = unmbind ctxt abs.binder in
let args = Array.to_list args_a in let args = Array.to_list args_a in
let rargs_id, ctxt = let rargs_id, ctxt_inner =
List.fold_left2 List.fold_left2
(fun (rargs_id, ctxt) v ty -> (fun (rargs_id, ctxt_inner) v ty ->
let pos = Mark.get ty in let pos = Mark.get ty in
let id, ctxt = register_fresh_var ctxt v ~pos in let id, ctxt_inner = register_fresh_var ctxt_inner v ~pos in
((id, pos), ty) :: rargs_id, ctxt) ((id, pos), ty) :: rargs_id, ctxt_inner)
([], ctxt) args abs.tys ([], ctxt_inner) args abs.tys
in in
let ctxt = let ctxt_inner =
{ {
ctxt with ctxt_inner with
context_name = Mark.remove (TopdefName.get_info name); context_name = Mark.remove (TopdefName.get_info name);
} }
in in
translate_expr ctxt expr, List.rev rargs_id translate_expr ctxt_inner expr, List.rev rargs_id
in in
let body_block = let body_block =
RevBlock.rebuild block ~tail:[A.SReturn expr, Mark.get expr] RevBlock.rebuild block ~tail:[A.SReturn expr, Mark.get expr]
in in
let func_id, ctxt = let func_id, ctxt_outer =
register_fresh_func ctxt var ~pos:(Expr.mark_pos m) register_fresh_func ctxt var ~pos:(Expr.mark_pos m)
in in
( ctxt, ( ctxt_outer,
A.SFunc A.SFunc
{ {
var = func_id; var = func_id;
@ -884,7 +869,7 @@ let translate_program ~(config : translation_config) (p : 'm L.program) :
:: rev_items ) :: rev_items )
| Topdef (name, topdef_ty, _vis, expr) -> | Topdef (name, topdef_ty, _vis, expr) ->
(* Toplevel constant def *) (* Toplevel constant def *)
let block, expr, _ren_ctx = let block, expr, _ren_ctx_inner =
let ctxt = let ctxt =
{ {
ctxt with ctxt with

View File

@ -69,8 +69,8 @@ let renaming =
Renaming.program () Renaming.program ()
~reserved:c_keywords ~reserved:c_keywords
(* TODO: add catala runtime built-ins as reserved as well ? *) (* TODO: add catala runtime built-ins as reserved as well ? *)
~reset_context_for_closed_terms:false ~skip_constant_binders:true ~skip_constant_binders:true ~constant_binder_name:None
~constant_binder_name:None ~namespaced_fields_constrs:false ~namespaced_fields_constrs:false
module TypMap = Map.Make (struct module TypMap = Map.Make (struct
type t = naked_typ type t = naked_typ

View File

@ -167,9 +167,9 @@ let renaming =
Renaming.program () Renaming.program ()
~reserved:python_keywords ~reserved:python_keywords
(* TODO: add catala runtime built-ins as reserved as well ? *) (* TODO: add catala runtime built-ins as reserved as well ? *)
~reset_context_for_closed_terms:false ~skip_constant_binders:false ~skip_constant_binders:false ~constant_binder_name:None
~constant_binder_name:None ~namespaced_fields_constrs:true ~namespaced_fields_constrs:true ~f_struct:String.to_camel_case
~f_struct:String.to_camel_case ~f_enum:String.to_camel_case ~f_enum:String.to_camel_case
let typ_needs_parens (e : typ) : bool = let typ_needs_parens (e : typ) : bool =
match Mark.remove e with TArrow _ | TArray _ -> true | _ -> false match Mark.remove e with TArrow _ | TArray _ -> true | _ -> false

View File

@ -75,7 +75,6 @@ module type BindlibCtxt = module type of Bindlib.Ctxt (DefaultBindlibCtxRename)
type config = { type config = {
reserved : string list; reserved : string list;
sanitize_varname : string -> string; sanitize_varname : string -> string;
reset_context_for_closed_terms : bool;
skip_constant_binders : bool; skip_constant_binders : bool;
constant_binder_name : string option; constant_binder_name : string option;
} }
@ -96,41 +95,37 @@ let default_config =
{ {
reserved = []; reserved = [];
sanitize_varname = Fun.id; sanitize_varname = Fun.id;
reset_context_for_closed_terms = true;
skip_constant_binders = true; skip_constant_binders = true;
constant_binder_name = None; constant_binder_name = None;
} }
let patch_binder_name fname b =
let name = fname (Bindlib.binder_name b) in
let occurs = Bindlib.binder_occur b in
let rank = Bindlib.binder_rank b in
let mkfree v = EVar v in
let subst = Bindlib.subst b in
Bindlib.raw_binder name occurs rank mkfree subst
let patch_mbinder_names fname b =
let names = Array.map fname (Bindlib.mbinder_names b) in
let occurs = Bindlib.mbinder_occurs b in
let rank = Bindlib.mbinder_rank b in
let mkfree v = EVar v in
let msubst = Bindlib.msubst b in
Bindlib.raw_mbinder names occurs rank mkfree msubst
let unbind_in ctx ?fname b = let unbind_in ctx ?fname b =
let module BindCtx = (val ctx.bindCtx) in let module BindCtx = (val ctx.bindCtx) in
match fname with let b = match fname with Some fn -> patch_binder_name fn b | None -> b in
| Some fn -> let v, e, bcontext = BindCtx.unbind_in ctx.bcontext b in
let name = fn (Bindlib.binder_name b) in v, e, { ctx with bcontext }
let v, bcontext = BindCtx.new_var_in ctx.bcontext (fun v -> EVar v) name in
let e = Bindlib.subst b (EVar v) in
v, e, { ctx with bcontext }
| None ->
let v, e, bcontext = BindCtx.unbind_in ctx.bcontext b in
v, e, { ctx with bcontext }
let unmbind_in ctx ?fname b = let unmbind_in ctx ?fname b =
let module BindCtx = (val ctx.bindCtx) in let module BindCtx = (val ctx.bindCtx) in
match fname with let b = match fname with Some fn -> patch_mbinder_names fn b | None -> b in
| Some fn -> let vs, e, bcontext = BindCtx.unmbind_in ctx.bcontext b in
let names = Array.map fn (Bindlib.mbinder_names b) in vs, e, { ctx with bcontext }
let rvs, bcontext =
Array.fold_left
(fun (rvs, bcontext) n ->
let v, bcontext = BindCtx.new_var_in bcontext (fun v -> EVar v) n in
v :: rvs, bcontext)
([], ctx.bcontext) names
in
let vs = Array.of_list (List.rev rvs) in
let e = Bindlib.msubst b (Array.map (fun v -> EVar v) vs) in
vs, e, { ctx with bcontext }
| None ->
let vs, e, bcontext = BindCtx.unmbind_in ctx.bcontext b in
vs, e, { ctx with bcontext }
let set_rewriters ?scopes ?topdefs ?structs ?fields ?enums ?constrs ctx = let set_rewriters ?scopes ?topdefs ?structs ?fields ?enums ?constrs ctx =
(fun ?(scopes = ctx.scopes) ?(topdefs = ctx.topdefs) ?(structs = ctx.structs) (fun ?(scopes = ctx.scopes) ?(topdefs = ctx.topdefs) ?(structs = ctx.structs)
@ -152,7 +147,6 @@ let get_ctx cfg =
let module BindCtx = Bindlib.Ctxt (struct let module BindCtx = Bindlib.Ctxt (struct
include DefaultBindlibCtxRename include DefaultBindlibCtxRename
let reset_context_for_closed_terms = cfg.reset_context_for_closed_terms
let skip_constant_binders = cfg.skip_constant_binders let skip_constant_binders = cfg.skip_constant_binders
let constant_binder_name = cfg.constant_binder_name let constant_binder_name = cfg.constant_binder_name
end) in end) in
@ -255,7 +249,7 @@ let code_items ctx fty (items : 'e code_item_list) =
(function EVar v -> Bindlib.box_var v | _ -> assert false) (function EVar v -> Bindlib.box_var v | _ -> assert false)
l) l)
in in
Bindlib.box_apply (fun l -> Last l) l Bindlib.box_apply (fun l -> Last l) l, ctx
| Cons (ScopeDef (name, body), next_bind) -> | Cons (ScopeDef (name, body), next_bind) ->
let scope_body = let scope_body =
let scope_input_var, scope_lets, ctx = let scope_input_var, scope_lets, ctx =
@ -287,10 +281,12 @@ let code_items ctx fty (items : 'e code_item_list) =
(* Otherwise, it is treated as a normal variable *) (* Otherwise, it is treated as a normal variable *)
unbind_in ctx ~fname:ctx.vars next_bind unbind_in ctx ~fname:ctx.vars next_bind
in in
let next_bind = Bindlib.bind_var scope_var (aux ctx next) in let next_body, ctx = aux ctx next in
Bindlib.box_apply2 let next_bind = Bindlib.bind_var scope_var next_body in
(fun body next_bind -> Cons (ScopeDef (name, body), next_bind)) ( Bindlib.box_apply2
scope_body next_bind (fun body next_bind -> Cons (ScopeDef (name, body), next_bind))
scope_body next_bind,
ctx )
| Cons (Topdef (name, ty, visibility, e), next_bind) -> | Cons (Topdef (name, ty, visibility, e), next_bind) ->
let e = expr ctx e in let e = expr ctx e in
let ty = fty ty in let ty = fty ty in
@ -306,12 +302,16 @@ let code_items ctx fty (items : 'e code_item_list) =
(* Otherwise, it is treated as a normal variable *) (* Otherwise, it is treated as a normal variable *)
unbind_in ctx ~fname:ctx.vars next_bind unbind_in ctx ~fname:ctx.vars next_bind
in in
let next_bind = Bindlib.bind_var topdef_var (aux ctx next) in let next_body, ctx = aux ctx next in
Bindlib.box_apply2 let next_bind = Bindlib.bind_var topdef_var next_body in
(fun e next_bind -> Cons (Topdef (name, ty, visibility, e), next_bind)) ( Bindlib.box_apply2
(Expr.Box.lift e) next_bind (fun e next_bind ->
Cons (Topdef (name, ty, visibility, e), next_bind))
(Expr.Box.lift e) next_bind,
ctx )
in in
Bindlib.unbox (aux ctx items) let items, ctx = aux ctx items in
Bindlib.unbox items, ctx
module PathMap = Map.Make (Uid.Path) module PathMap = Map.Make (Uid.Path)
@ -434,7 +434,6 @@ let uncap s = String.to_ascii s |> String.uncapitalize_ascii
names *) names *)
let program let program
~reserved ~reserved
~reset_context_for_closed_terms
~skip_constant_binders ~skip_constant_binders
~constant_binder_name ~constant_binder_name
~namespaced_fields_constrs ~namespaced_fields_constrs
@ -448,7 +447,6 @@ let program
{ {
reserved; reserved;
sanitize_varname = f_var; sanitize_varname = f_var;
reset_context_for_closed_terms;
skip_constant_binders; skip_constant_binders;
constant_binder_name; constant_binder_name;
} }
@ -608,7 +606,7 @@ let program
} }
in in
let decl_ctx = Program.map_decl_ctx ~f:(typ ctx) decl_ctx in let decl_ctx = Program.map_decl_ctx ~f:(typ ctx) decl_ctx in
let code_items = code_items ctx (typ ctx) p.code_items in let code_items, ctx = code_items ctx (typ ctx) p.code_items in
{ p with decl_ctx; code_items }, ctx { p with decl_ctx; code_items }, ctx
(* This first-class module wrapping is here to allow a polymorphic renaming (* This first-class module wrapping is here to allow a polymorphic renaming
@ -624,7 +622,6 @@ let apply (module R : Renaming) = R.apply
let program let program
~reserved ~reserved
~reset_context_for_closed_terms
~skip_constant_binders ~skip_constant_binders
~constant_binder_name ~constant_binder_name
~namespaced_fields_constrs ~namespaced_fields_constrs
@ -636,14 +633,14 @@ let program
() = () =
let module M = struct let module M = struct
let apply p = let apply p =
program ~reserved ~reset_context_for_closed_terms ~skip_constant_binders program ~reserved ~skip_constant_binders ~constant_binder_name
~constant_binder_name ~namespaced_fields_constrs ?f_var ?f_struct ~namespaced_fields_constrs ?f_var ?f_struct ?f_field ?f_enum ?f_constr p
?f_field ?f_enum ?f_constr p
end in end in
(module M : Renaming) (module M : Renaming)
let default = let default =
program () ~reserved:[] ~reset_context_for_closed_terms:true program () ~reserved:default_config.reserved
~skip_constant_binders:true ~constant_binder_name:(Some "_") ~f_var:Fun.id ~skip_constant_binders:default_config.skip_constant_binders
~constant_binder_name:default_config.constant_binder_name ~f_var:Fun.id
~f_struct:Fun.id ~f_field:Fun.id ~f_enum:Fun.id ~f_constr:Fun.id ~f_struct:Fun.id ~f_field:Fun.id ~f_enum:Fun.id ~f_constr:Fun.id
~namespaced_fields_constrs:true ~namespaced_fields_constrs:true

View File

@ -20,7 +20,6 @@ open Definitions
type config = { type config = {
reserved : string list; (** Use for keywords and built-ins *) reserved : string list; (** Use for keywords and built-ins *)
sanitize_varname : string -> string; (** Typically String.to_snake_case *) sanitize_varname : string -> string; (** Typically String.to_snake_case *)
reset_context_for_closed_terms : bool; (** See [Bindlib.Renaming] *)
skip_constant_binders : bool; (** See [Bindlib.Renaming] *) skip_constant_binders : bool; (** See [Bindlib.Renaming] *)
constant_binder_name : string option; (** See [Bindlib.Renaming] *) constant_binder_name : string option; (** See [Bindlib.Renaming] *)
} }
@ -73,7 +72,7 @@ val code_items :
context -> context ->
(typ -> typ) -> (typ -> typ) ->
((_ any, 'm) gexpr as 'e) code_item_list -> ((_ any, 'm) gexpr as 'e) code_item_list ->
'e code_item_list 'e code_item_list * context
type t type t
(** Enclosing of a polymorphic renaming function, to be used by [apply] *) (** Enclosing of a polymorphic renaming function, to be used by [apply] *)
@ -82,7 +81,6 @@ val apply : t -> 'e program -> 'e program * context
val program : val program :
reserved:string list -> reserved:string list ->
reset_context_for_closed_terms:bool ->
skip_constant_binders:bool -> skip_constant_binders:bool ->
constant_binder_name:string option -> constant_binder_name:string option ->
namespaced_fields_constrs:bool -> namespaced_fields_constrs:bool ->

View File

@ -100,8 +100,8 @@ const Baz* baz (const Baz_in* baz_in)
b3 = CATALA_NONE; b3 = CATALA_NONE;
} }
if (b3->code == catala_option_some) { if (b3->code == catala_option_some) {
CATALA_DEC x = b3->payload; CATALA_DEC x1 = b3->payload;
b2 = catala_some(x); b2 = catala_some(x1);
} else { } else {
CATALA_DEC b5; CATALA_DEC b5;
switch (a1->code) { switch (a1->code) {
@ -124,8 +124,8 @@ const Baz* baz (const Baz_in* baz_in)
b2 = catala_some(b5); b2 = catala_some(b5);
} }
if (b2->code == catala_option_some) { if (b2->code == catala_option_some) {
CATALA_DEC arg = b2->payload; CATALA_DEC arg1 = b2->payload;
b1 = arg; b1 = arg1;
} else { } else {
static const catala_code_position pos[1] = static const catala_code_position pos[1] =
{{"tests/backends/simple.catala_en", 12, 10, 12, 11}}; {{"tests/backends/simple.catala_en", 12, 10, 12, 11}};
@ -138,8 +138,8 @@ const Baz* baz (const Baz_in* baz_in)
c3->elements[1] = b; c3->elements[1] = b;
c2 = catala_some(c3); c2 = catala_some(c3);
if (c2->code == catala_option_some) { if (c2->code == catala_option_some) {
const CATALA_ARRAY(CATALA_DEC) arg = c2->payload; const CATALA_ARRAY(CATALA_DEC) arg2 = c2->payload;
c1 = arg; c1 = arg2;
} else { } else {
static const catala_code_position pos[1] = static const catala_code_position pos[1] =
{{"tests/backends/simple.catala_en", 13, 10, 13, 11}}; {{"tests/backends/simple.catala_en", 13, 10, 13, 11}};

View File

@ -116,11 +116,11 @@ def b(b_in:BIn):
arg = result2 arg = result2
result1 = (arg) result1 = (arg)
result = (some_name(SomeNameIn(i_in = result1))) result = (some_name(SomeNameIn(i_in = result1)))
result2 = (SomeName(o = result.o)) result3 = (SomeName(o = result.o))
if True: if True:
some_name2 = (result2) some_name2 = (result3)
else: else:
some_name2 = (result2) some_name2 = (result3)
some_name1 = (some_name2) some_name1 = (some_name2)
return B(some_name = some_name1) return B(some_name = some_name1)
``` ```

View File

@ -24,7 +24,7 @@ module S_in = struct
end end
let s (s_in: S_in.t) : S.t = let s (_: S_in.t) : S.t =
let sr: money = let sr: money =
match (Eoption.ESome (money_of_cents_string "100000")) match (Eoption.ESome (money_of_cents_string "100000"))
with with
@ -54,7 +54,7 @@ let half : integer -> decimal =
"2") "2")
let maybe : Enum1.t -> Enum1.t = let maybe : Enum1.t -> Enum1.t =
fun (x: Enum1.t) -> Enum1.Maybe () fun (_: Enum1.t) -> Enum1.Maybe ()
let () = let () =
Runtime_ocaml.Runtime.register_module "Mod_def" Runtime_ocaml.Runtime.register_module "Mod_def"

View File

@ -34,11 +34,11 @@ module Closure_scoppe1_in = struct
end end
let closure_scoppe (closure_scoppe_in: Closure_scoppe_in.t) : Closure_scoppe.t = let closure_scoppe (_: Closure_scoppe_in.t) : Closure_scoppe.t =
let scoppe: bool = false in let scoppe: bool = false in
{Closure_scoppe.scoppe = scoppe} {Closure_scoppe.scoppe = scoppe}
let closure_scoppe1 (closure_scoppe1_in: Closure_scoppe1_in.t) : Closure_scoppe1.t = let closure_scoppe1 (_: Closure_scoppe1_in.t) : Closure_scoppe1.t =
let scoppe: bool = false in let scoppe: bool = false in
{Closure_scoppe1.scoppe = scoppe} {Closure_scoppe1.scoppe = scoppe}
@ -93,17 +93,17 @@ end
let closure_scoppe2 : Obj.t -> bool -> integer -> bool = let closure_scoppe2 : Obj.t -> bool -> integer -> bool =
fun (env: Obj.t) (acc: bool) (x: integer) -> fun (_: Obj.t) (acc: bool) (x: integer) ->
o_and acc (o_gt_int_int x (integer_of_string "2")) o_and acc (o_gt_int_int x (integer_of_string "2"))
let closure_scoppe (closure_scoppe_in: Closure_scoppe_in.t) : Closure_scoppe.t = let closure_scoppe (_: Closure_scoppe_in.t) : Closure_scoppe.t =
let scoppe: bool = let scoppe: bool =
o_fold (closure_scoppe2, (o_toclosureenv ())) true o_fold (closure_scoppe2, (o_toclosureenv ())) true
([|(integer_of_string "5"); (integer_of_string "6"); (integer_of_string ([|(integer_of_string "5"); (integer_of_string "6"); (integer_of_string
"7")|]) in "7")|]) in
{Closure_scoppe.scoppe = scoppe} {Closure_scoppe.scoppe = scoppe}
let closure_scoppe1 (closure_scoppe1_in: Closure_scoppe1_in.t) : Closure_scoppe1.t = let closure_scoppe1 (_: Closure_scoppe1_in.t) : Closure_scoppe1.t =
let scoppe: bool = false in let scoppe: bool = false in
{Closure_scoppe1.scoppe = scoppe} {Closure_scoppe1.scoppe = scoppe}

View File

@ -131,16 +131,16 @@ end
let closure_assert : Obj.t -> integer -> integer = let closure_assert : Obj.t -> integer -> integer =
fun (env: Obj.t) (x: integer) -> (let env1 : unit = (o_fromclosureenv env) fun (env: Obj.t) (x: integer) -> (let _ : unit = (o_fromclosureenv env)
in in
((o_add_int_int x (integer_of_string "1")))) ((o_add_int_int x (integer_of_string "1"))))
let assert1 (assert_in: Assert_in1.t) : Assert2.t = let assert1 (_: Assert_in1.t) : Assert2.t =
let assert1: bool = let assert1: bool =
match match
(match (match
(Eoption.ESome (Eoption.ESome
(let assert1 : integer array = (let _ : integer array =
(o_map (o_map
(let assert1 : Obj.t -> integer -> integer = closure_assert (let assert1 : Obj.t -> integer -> integer = closure_assert
in in

View File

@ -64,7 +64,7 @@ let s (s_in: S_in.t) : S.t =
(let a2 : bool = (o_or a1 true) in (let a2 : bool = (o_or a1 true) in
a2))) a2)))
with with
| Eoption.ENone _1 -> (raise | Eoption.ENone _ -> (raise
(Runtime_ocaml.Runtime.Error (NoValue, [{filename="tests/name_resolution/good/let_in2.catala_en"; (Runtime_ocaml.Runtime.Error (NoValue, [{filename="tests/name_resolution/good/let_in2.catala_en";
start_line=7; start_column=18; start_line=7; start_column=18;
end_line=7; end_column=19; end_line=7; end_column=19;

View File

@ -124,7 +124,7 @@ let glob5 = glob5_init ()
let glob6 = A {"y": glob1 >= 30., "z": 123. * 17.} let glob6 = A {"y": glob1 >= 30., "z": 123. * 17.}
let S2 (_: S2_in) = let S2 (s2_in: S2_in) =
decl a1 : decimal; decl a1 : decimal;
a2 : option decimal = ESome glob3 ¤44.00 + 100.; a2 : option decimal = ESome glob3 ¤44.00 + 100.;
switch a2: switch a2:
@ -137,7 +137,7 @@ let S2 (_: S2_in) =
a = a1; a = a1;
return S2 {"a": a} return S2 {"a": a}
let S3 (_: S3_in) = let S3 (s3_in: S3_in) =
decl a1 : decimal; decl a1 : decimal;
a2 : option decimal = ESome 50. + glob4 ¤44.00 55.; a2 : option decimal = ESome 50. + glob4 ¤44.00 55.;
switch a2: switch a2:
@ -150,7 +150,7 @@ let S3 (_: S3_in) =
a = a1; a = a1;
return S3 {"a": a} return S3 {"a": a}
let S4 (_: S4_in) = let S4 (s4_in: S4_in) =
decl a1 : decimal; decl a1 : decimal;
a2 : option decimal = ESome glob5 + 1.; a2 : option decimal = ESome glob5 + 1.;
switch a2: switch a2:
@ -163,7 +163,7 @@ let S4 (_: S4_in) =
a = a1; a = a1;
return S4 {"a": a} return S4 {"a": a}
let S5 (_: S_in) = let S5 (s_in: S_in) =
decl a1 : decimal; decl a1 : decimal;
a2 : option decimal = ESome glob1 * glob1; a2 : option decimal = ESome glob1 * glob1;
switch a2: switch a2:
@ -180,8 +180,8 @@ let S5 (_: S_in) =
| ENone _ → | ENone _ →
pos : SourcePosition = <toplevel_defs:8.10-11>; pos : SourcePosition = <toplevel_defs:8.10-11>;
fatal NoValue fatal NoValue
| ESome arg → | ESome arg1
b1 = arg; b1 = arg1;
decl b : A {y: bool; z: decimal}; decl b : A {y: bool; z: decimal};
b = b1; b = b1;
return S {"a": a, "b": b} return S {"a": a, "b": b}
@ -431,8 +431,8 @@ def s5(s_in:SIn):
law_headings=["Test basic toplevel values defs"])) law_headings=["Test basic toplevel values defs"]))
raise NoValue(pos) raise NoValue(pos)
else: else:
arg = b2 arg1 = b2
b1 = (arg) b1 = (arg1)
b = (b1) b = (b1)
return S(a = a, b = b) return S(a = a, b = b)
``` ```

View File

@ -53,11 +53,10 @@ module ScopeB_in = struct
end end
let scope_a (scope_a_in: ScopeA_in.t) : ScopeA.t = let scope_a (_: ScopeA_in.t) : ScopeA.t = let a: bool = true in
let a: bool = true in {ScopeA.a = a}
{ScopeA.a = a}
let scope_b (scope_b_in: ScopeB_in.t) : ScopeB.t = let scope_b (_: ScopeB_in.t) : ScopeB.t =
let scope_a1: ScopeA.t = {ScopeA.a = ((scope_a (())).ScopeA.a)} in let scope_a1: ScopeA.t = {ScopeA.a = ((scope_a (())).ScopeA.a)} in
let a: bool = scope_a1.ScopeA.a in let a: bool = scope_a1.ScopeA.a in
{ScopeB.a = a} {ScopeB.a = a}

View File

@ -39,7 +39,7 @@ $ catala Scalc -s Foo2 -O -t
│ 5 │ output bar content integer │ 5 │ output bar content integer
│ │ ‾‾‾ │ │ ‾‾‾
└─ Test └─ Test
let Foo2 (_: Foo2_in) = let Foo2 (foo2_in: Foo2_in) =
decl bar1 : integer; decl bar1 : integer;
pos : SourcePosition = <nothing:5.10-13>; pos : SourcePosition = <nothing:5.10-13>;
fatal NoValue; fatal NoValue;