Skip to content

Commit

Permalink
Fix a few remaining renaming glitches
Browse files Browse the repository at this point in the history
  • Loading branch information
AltGr committed Sep 4, 2024
1 parent cb88cb0 commit 634de67
Show file tree
Hide file tree
Showing 18 changed files with 153 additions and 159 deletions.
12 changes: 12 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# Reformatting commits to be skipped when running 'git blame'
# Use `git config --global blame.ignoreRevsFile .git-blame-ignore-revs` to use it
# Add new reformatting commits at the top
6a062921f15c5b70e42fefee0f28d249d4289e34
5d61963a93a0b735d9419b43ef05c676f5169d9a
1b6da0b5720e9168aca1452e9ed40ad7e0bd737a
840530163284da2d664f8e3e8a1ff89830132a1d
dc1b725e9b9d34db3bef5da28c20a4e489b304d9
79e0dcecdaa9ae129330ba371b627d6842d48dbc
75bf76826486a96c0b4110a6758a561781d49145
619cafebb8028ea9cc3bd49ed9334c9c39a1e6d3
1ae955b50443edb123de4b612bc8c85935567c59
d4198f52b47670a0ace3f65fed91ea28543a3488
cf89204a4b0dcdc37554b9206bdc03c9a0d21fa8
c4715ea86efa12cfdfd5b230c48f32a2cdb9552d

2708fa53b23bde545e7378a660cdb99e8671f1de
a79acd1fa8b701a5688c7fa985c7064cd6d81acf
Expand Down
6 changes: 5 additions & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ authors:
family-names: Banuls
- given-name: Aminata
family-names: Boiguillé
- given-name: Vincent
family-names: Botbol
affiliation: "INRIA"
email: [email protected]
repository-code: "https://github.com/CatalaLang/catala"
url: "https://catala-lang.org/"
abstract: >-
Catala is a domain-specific language for deriving
faithful-by-construction algorithms from
legislative texts.
license: Apache-2.0
version: 0.8.0
version: 0.10.0
date-released: "2022-03-08"
4 changes: 2 additions & 2 deletions compiler/lcalc/to_ocaml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ let renaming =
Renaming.program ()
~reserved:ocaml_keywords
(* TODO: add catala runtime built-ins as reserved as well ? *)
~reset_context_for_closed_terms:true ~skip_constant_binders:true
~constant_binder_name:(Some "_") ~namespaced_fields_constrs:true
~skip_constant_binders:true ~constant_binder_name:(Some "_")
~namespaced_fields_constrs:true

let format_struct_name (fmt : Format.formatter) (v : StructName.t) : unit =
(match StructName.path v with
Expand Down
1 change: 0 additions & 1 deletion compiler/plugins/explain.ml
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,6 @@ let program_to_graph
{
Renaming.reserved = [];
sanitize_varname = String.to_snake_case;
reset_context_for_closed_terms = false;
skip_constant_binders = false;
constant_binder_name = None;
})
Expand Down
119 changes: 52 additions & 67 deletions compiler/scalc/from_lcalc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ and translate_expr (ctxt : 'm ctxt) (expr : 'm L.expr) :
let exceptions_stmts, new_exceptions, ren_ctx =
translate_expr_list ctxt exceptions
in
let ctxt = { ctxt with ren_ctx } in
let eposl, vposdefs, ctxt =
List.fold_left
(fun (eposl, vposdefs, ctxt) exc ->
Expand All @@ -225,11 +226,9 @@ and translate_expr (ctxt : 'm ctxt) (expr : 'm L.expr) :
ctxt )
else
let arr_var_name, ctxt =
fresh_var ~pos { ctxt with ren_ctx } ctxt.context_name
in
let pos_arr_var_name, ctxt =
fresh_var ~pos { ctxt with ren_ctx } "pos_list"
fresh_var ~pos ctxt ("exc_" ^ ctxt.context_name)
in
let pos_arr_var_name, ctxt = fresh_var ~pos ctxt "pos_list" in
let stmts =
stmts
++ RevBlock.make
Expand Down Expand Up @@ -475,7 +474,7 @@ and translate_statements (ctxt : 'm ctxt) (block_expr : 'm L.expr) :
{ ctxt with inside_definition_of = None }
vars_tau
in
let new_body, _ren_ctx = translate_statements ctxt body in
let new_body, ren_ctx = translate_statements ctxt body in
( [
( A.SInnerFuncDef
{
Expand All @@ -497,10 +496,9 @@ and translate_statements (ctxt : 'm ctxt) (block_expr : 'm L.expr) :
},
binder_pos );
],
ctxt.ren_ctx )
ren_ctx )
| EMatch { e = e1; cases; name } ->
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 ctxt = { ctxt with ren_ctx } in
let e1_stmts, switch_var, ctxt =
Expand All @@ -514,63 +512,45 @@ and translate_statements (ctxt : 'm ctxt) (block_expr : 'm L.expr) :
v,
ctxt )
in
let new_cases =
let new_cases, ren_ctx =
EnumConstructor.Map.fold
(fun _ arg new_args ->
(fun _ arg (new_args, ren_ctx) ->
match Mark.remove arg with
| 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);
let var = vars.(0) in
let scalc_var, ctxt =
register_fresh_var ctxt var ~pos:(Expr.pos arg)
in
let new_arg, _ren_ctx = translate_statements ctxt body in
{
A.case_block = new_arg;
payload_var_name = scalc_var;
payload_var_typ = typ;
}
:: new_args
( {
A.case_block = new_arg;
payload_var_name = scalc_var;
payload_var_typ = typ;
}
:: new_args,
ctxt.ren_ctx )
| _ -> assert false)
cases []
cases ([], ctxt.ren_ctx)
in
let new_args = List.rev new_cases in
let ctxt = { ctxt with ren_ctx } in
let tail =
if ctxt.config.keep_special_ops then
let tmp_var = A.VarName.fresh ("match_arg", pos) in
[
( A.SLocalInit
{
name = tmp_var, pos;
typ = Expr.maybe_ty (Mark.get e1);
expr = new_e1;
},
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 );
]
[
( A.SSwitch
{
switch_var;
switch_var_typ = typ;
enum_name = name;
switch_cases = List.rev new_cases;
},
Expr.pos block_expr );
]
in
RevBlock.rebuild e1_stmts ~tail, ren_ctx
RevBlock.rebuild e1_stmts ~tail, ctxt.ren_ctx
| EIfThenElse { cond; etrue; efalse } ->
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_false, _ = translate_statements ctxt efalse in
( RevBlock.rebuild cond_stmts
Expand Down Expand Up @@ -808,20 +788,25 @@ let translate_program ~(config : translation_config) (p : 'm L.program) :
~f:(fun (ctxt, rev_items) code_item var ->
match code_item with
| 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
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
in
let new_scope_body =
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
in
let func_id, ctxt1 = register_fresh_func ctxt1 var ~pos:input_pos in
( ctxt1,
let func_id, outer_ctx =
register_fresh_func outer_ctx var ~pos:input_pos
in
( outer_ctx,
A.SScope
{
Ast.scope_body_name = name;
Expand All @@ -841,32 +826,32 @@ let translate_program ~(config : translation_config) (p : 'm L.program) :
:: rev_items )
| Topdef (name, topdef_ty, _vis, (EAbs abs, m)) ->
(* Toplevel function def *)
let (block, expr, _ren_ctx), args_id =
let args_a, expr, ctxt = unmbind ctxt abs.binder in
let (block, expr, _ren_ctx_inner), args_id =
let args_a, expr, ctxt_inner = unmbind ctxt abs.binder in
let args = Array.to_list args_a in
let rargs_id, ctxt =
let rargs_id, ctxt_inner =
List.fold_left2
(fun (rargs_id, ctxt) v ty ->
(fun (rargs_id, ctxt_inner) v ty ->
let pos = Mark.get ty in
let id, ctxt = register_fresh_var ctxt v ~pos in
((id, pos), ty) :: rargs_id, ctxt)
([], ctxt) args abs.tys
let id, ctxt_inner = register_fresh_var ctxt_inner v ~pos in
((id, pos), ty) :: rargs_id, ctxt_inner)
([], ctxt_inner) args abs.tys
in
let ctxt =
let ctxt_inner =
{
ctxt with
ctxt_inner with
context_name = Mark.remove (TopdefName.get_info name);
}
in
translate_expr ctxt expr, List.rev rargs_id
translate_expr ctxt_inner expr, List.rev rargs_id
in
let body_block =
RevBlock.rebuild block ~tail:[A.SReturn expr, Mark.get expr]
in
let func_id, ctxt =
let func_id, ctxt_outer =
register_fresh_func ctxt var ~pos:(Expr.mark_pos m)
in
( ctxt,
( ctxt_outer,
A.SFunc
{
var = func_id;
Expand All @@ -884,7 +869,7 @@ let translate_program ~(config : translation_config) (p : 'm L.program) :
:: rev_items )
| Topdef (name, topdef_ty, _vis, expr) ->
(* Toplevel constant def *)
let block, expr, _ren_ctx =
let block, expr, _ren_ctx_inner =
let ctxt =
{
ctxt with
Expand Down
4 changes: 2 additions & 2 deletions compiler/scalc/to_c.ml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ let renaming =
Renaming.program ()
~reserved:c_keywords
(* TODO: add catala runtime built-ins as reserved as well ? *)
~reset_context_for_closed_terms:false ~skip_constant_binders:true
~constant_binder_name:None ~namespaced_fields_constrs:false
~skip_constant_binders:true ~constant_binder_name:None
~namespaced_fields_constrs:false

module TypMap = Map.Make (struct
type t = naked_typ
Expand Down
6 changes: 3 additions & 3 deletions compiler/scalc/to_python.ml
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ let renaming =
Renaming.program ()
~reserved:python_keywords
(* TODO: add catala runtime built-ins as reserved as well ? *)
~reset_context_for_closed_terms:false ~skip_constant_binders:false
~constant_binder_name:None ~namespaced_fields_constrs:true
~f_struct:String.to_camel_case ~f_enum:String.to_camel_case
~skip_constant_binders:false ~constant_binder_name:None
~namespaced_fields_constrs:true ~f_struct:String.to_camel_case
~f_enum:String.to_camel_case

let typ_needs_parens (e : typ) : bool =
match Mark.remove e with TArrow _ | TArray _ -> true | _ -> false
Expand Down
Loading

0 comments on commit 634de67

Please sign in to comment.