Module Ppxlib.Ast_builder.Make

Build Ast helpers with the location argument factorized.

Parameters

Signature

module Located : Ppxlib__.Ast_builder_intf.Located with type with_loc := a Ppxlib__.Ast_builder_intf.without_location
include module type of sig ... end
val loc : Location.t
val class_infos : virt:Ppxlib__.Import.virtual_flag ‑> params:(Ppxlib__.Import.core_type * Ppxlib__.Import.variance) list ‑> name:string Ppxlib__.Import.loc ‑> expr:'a ‑> 'a Ppxlib__.Import.class_infos
val ptyp_var : string ‑> Ppxlib__.Import.core_type
val ptyp_alias : Ppxlib__.Import.core_type ‑> string ‑> Ppxlib__.Import.core_type
val pexp_function : Ppxlib__.Import.case list ‑> Ppxlib__.Import.expression
val pexp_unreachable : Ppxlib__.Import.expression
val include_infos : 'a ‑> 'a Ppxlib__.Import.include_infos
val location : start:Ppxlib__.Import.position ‑> end_:Ppxlib__.Import.position ‑> ghost:bool ‑> Ppxlib__.Import.location
val module_declaration : name:string Ppxlib__.Import.loc ‑> type_:Ppxlib__.Import.module_type ‑> Ppxlib__.Import.module_declaration
val module_type_declaration : name:string Ppxlib__.Import.loc ‑> type_:Ppxlib__.Import.module_type option ‑> Ppxlib__.Import.module_type_declaration
val ppat_var : string Ppxlib__.Import.loc ‑> Ppxlib__.Import.pattern
val ppat_unpack : string Ppxlib__.Import.loc ‑> Ppxlib__.Import.pattern
val position : fname:string ‑> lnum:int ‑> bol:int ‑> cnum:int ‑> Ppxlib__.Import.position
val value_description : name:string Ppxlib__.Import.loc ‑> type_:Ppxlib__.Import.core_type ‑> prim:string list ‑> Ppxlib__.Import.value_description
include Ppxlib__.Ast_builder_intf.Additional_helpers with type with_loc := a Ppxlib__.Ast_builder_intf.without_location
type 'a with_loc

evar id produces a Pexp_ident _ expression, it parses its input so you can pass any dot-separated identifier, for instance: evar ~loc "Foo.bar".

pstr_value_list ~loc rf vbs = pstr_value ~loc rf vbs if vbs <> [], [] otherwise.

  • Deprecated [since 2016-10] use Nonrecursive on the P(str|sig)_type instead

unapplied_type_constr_conv is the standard way to map identifiers to conversion fonctions, for preprocessor that creates values that follow the structure of types. More precisely, path_conv path (sprintf "sexp_of_%s") is:

  • sexp_of_t if path is "t"
  • A.B.sexp_of_foo if path is "A.B.foo"
  • A.B.sexp_of_f__foo (module A1) (module A2) if path is "A.B.F(A1)(A2).foo" type_constr_conv also applies it to a list of expression, which both prevents the compiler from allocating useless closures, and almost always what is needed, since type constructors are always applied.

Tries to simplify fun v1 v2 .. -> f v1 v2 .. into f. Only works when f is a path, not an arbitrary expression as that would change the meaning of the code. This can be used either for cleaning up the generated code, or to reduce allocation if f is a local variable (the compiler won't optimize the allocation of the closure).

Eta-reduction can change the types/behavior in some corner cases that are unlikely to show up in generated code:

  • if f has optional arguments, eta-expanding f can drop them
  • because labels commute, it can change the type of an expression: $ let f ~x y = x + y let f2 = fun x -> add x;; val f : x:int -> int -> int = <fun> val f2 : int -> x:int -> int = <fun> In fact, if f does side effects before receiving all its arguments, and if the eta-expansion is partially applied, eta-reducing could change behavior.

eta_reduce_if_possible_and_nonrec is meant for the case where the resulting expression is going to be bound in a potentially recursive let-binding, where we have to keep the eta-expansion when rec_flag is Recursive to avoid a compile error.

val eta_reduce_if_possible : Ppxlib__.Import.expression ‑> Ppxlib__.Import.expression
val eta_reduce_if_possible_and_nonrec : Ppxlib__.Import.expression ‑> rec_flag:Ppxlib__.Import.rec_flag ‑> Ppxlib__.Import.expression