Module Shared_ast.Scope

Functions handling the code item structures of shared_ast, in particular the scopes

Traversal functions

val map_exprs_in_lets : ?typ: (Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos -> Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos) -> f:('expr1 -> 'expr2 Shared_ast__.Definitions.boxed) -> varf:('expr1 Var.t -> 'expr2 Var.t) -> ('expr1, 'expr1 Shared_ast__.Definitions.scope_let, 'expr1) Shared_ast__.Definitions.bound_list -> ('expr2, 'expr2 Shared_ast__.Definitions.scope_let, 'expr2) Shared_ast__.Definitions.bound_list Bindlib.box

Usage map_exprs_in_lets ~f:(fun e -> ...) ~varf:(fun var -> ...) scope_body_expr, where e is the right-hand-side of a scope let or the result of the scope body, and var represents the left-hand-side variable of a scope let. ~varf is usually the identity function or Var.translate when the map sends the expression to a new flavor of the shared AST. If ~reset_types is activated, then the resulting types in the scope let left-hand-sides will be reset to TAny.

val map_exprs : ?typ: (Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos -> Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos) -> f:('expr1 -> 'expr2 Shared_ast__.Definitions.boxed) -> varf:('expr1 Var.t -> 'expr2 Var.t) -> ('expr1, 'expr1 Shared_ast__.Definitions.code_item, (Shared_ast__.Definitions.code_export_kind * 'expr1) list) Shared_ast__.Definitions.bound_list -> ('expr2, 'expr2 Shared_ast__.Definitions.code_item, (Shared_ast__.Definitions.code_export_kind * 'expr2) list) Shared_ast__.Definitions.bound_list Bindlib.box

This is the main map visitor for all the expressions inside all the scopes of the program.

val map_exports : ((('a1, 'a1, 'm1) Shared_ast__.Definitions.base_gexpr, 'm1 Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> (('a2, 'a2, 'm2) Shared_ast__.Definitions.base_gexpr, 'm2 Shared_ast__.Definitions.mark) Catala_utils.Mark.ed Shared_ast__.Definitions.boxed) -> (Shared_ast__.Definitions.code_export_kind * (('a1, 'a1, 'm1) Shared_ast__.Definitions.base_gexpr, 'm1 Shared_ast__.Definitions.mark) Catala_utils.Mark.ed) list -> (Shared_ast__.Definitions.code_export_kind * (('a2, 'a2, 'm2) Shared_ast__.Definitions.base_gexpr, 'm2 Shared_ast__.Definitions.mark) Catala_utils.Mark.ed) list Bindlib.box

Helper function to handle the code_export list terminator when manually mapping on code_item_list

val fold_exprs : f: ('acc -> 'expr -> Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos -> 'acc) -> init:'acc -> ('expr, 'expr Shared_ast__.Definitions.code_item, (Shared_ast__.Definitions.code_export_kind * 'expr) list) Shared_ast__.Definitions.bound_list -> 'acc

Conversions

val to_expr : Shared_ast__.Definitions.decl_ctx -> (('a Shared_ast__.Definitions.any, 'a Shared_ast__.Definitions.any, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed Shared_ast__.Definitions.scope_body -> (('a, 'a, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed

Usage: to_expr ctx body scope_position where scope_position corresponds to the line of the scope declaration for instance.

val unfold_body_expr : Shared_ast__.Definitions.decl_ctx -> ('e, 'e Shared_ast__.Definitions.scope_let, 'e) Shared_ast__.Definitions.bound_list -> 'e Shared_ast__.Definitions.boxed
val unfold : Shared_ast__.Definitions.decl_ctx -> ('e, 'e Shared_ast__.Definitions.code_item, (Shared_ast__.Definitions.code_export_kind * 'e) list) Shared_ast__.Definitions.bound_list -> Shared_ast__.Definitions.ScopeName.t -> 'e Shared_ast__.Definitions.boxed
val typ : _ Shared_ast__.Definitions.scope_body -> Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos

builds the arrow type for the specified scope

val input_type : Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos -> Runtime_ocaml.Runtime.io_input Catala_utils.Mark.pos -> Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos

Returns the correct input type for scope input variables: this is typ for non-reentrant variables, but for reentrant variables, it is nested in a TDefault, which only applies to the return type on functions. Note that this doesn't take thunking into account (thunking is added during the scopelang->dcalc translation)

val empty_input_struct_dcalc : Shared_ast__.Definitions.decl_ctx -> Shared_ast__.Definitions.StructName.t -> 'm Shared_ast__.Definitions.mark -> ((< defaultTerms : Shared_ast__.Definitions.yes.. >, < defaultTerms : Shared_ast__.Definitions.yes.. >, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed

See empty_input_struct_lcalc.

val empty_input_struct_lcalc : Shared_ast__.Definitions.decl_ctx -> Shared_ast__.Definitions.StructName.t -> 'm Shared_ast__.Definitions.mark -> ((< polymorphic : Shared_ast__.Definitions.yes.. >, < polymorphic : Shared_ast__.Definitions.yes.. >, 'm) Shared_ast__.Definitions.base_gexpr Bindlib.box, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed

Assuming the given scope doesn't require any input, generate the minimal argument to call it. The scope may have context variables, that will be passed as None. The type will be initialised in the given mark: it is only used for position and as witness

Analysis and tests

val free_vars_body_expr : ('e, 'e Shared_ast__.Definitions.scope_let, 'e) Shared_ast__.Definitions.bound_list -> 'e Var.Set.t
val free_vars_item : 'e Shared_ast__.Definitions.code_item -> 'e Var.Set.t
val free_vars : ('e, 'e Shared_ast__.Definitions.code_item, (Shared_ast__.Definitions.code_export_kind * 'e) list) Shared_ast__.Definitions.bound_list -> 'e Var.Set.t
val get_mark_witness : ((_, _, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed Shared_ast__.Definitions.scope_body -> 'm Shared_ast__.Definitions.mark option