package ppxlib

  1. Overview
  2. Docs

Helpers taking a ~loc argument. This module is meant to be opened or aliased.

module Located : sig ... end
val pcl_constr : loc:Location.t -> Ppxlib_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_407.Parsetree.core_type list -> Migrate_parsetree.Ast_407.Parsetree.class_expr
val pcl_extension : loc:Location.t -> (string Location.loc * Migrate_parsetree.Ast_407.Parsetree.payload) -> Migrate_parsetree.Ast_407.Parsetree.class_expr
val pcf_attribute : loc:Location.t -> (string Location.loc * Migrate_parsetree.Ast_407.Parsetree.payload) -> Migrate_parsetree.Ast_407.Parsetree.class_field
val pcf_extension : loc:Location.t -> (string Location.loc * Migrate_parsetree.Ast_407.Parsetree.payload) -> Migrate_parsetree.Ast_407.Parsetree.class_field
val pcty_constr : loc:Location.t -> Ppxlib_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_407.Parsetree.core_type list -> Migrate_parsetree.Ast_407.Parsetree.class_type
val pcty_extension : loc:Location.t -> (string Location.loc * Migrate_parsetree.Ast_407.Parsetree.payload) -> Migrate_parsetree.Ast_407.Parsetree.class_type
val pctf_attribute : loc:Location.t -> (string Location.loc * Migrate_parsetree.Ast_407.Parsetree.payload) -> Migrate_parsetree.Ast_407.Parsetree.class_type_field
val pctf_extension : loc:Location.t -> (string Location.loc * Migrate_parsetree.Ast_407.Parsetree.payload) -> Migrate_parsetree.Ast_407.Parsetree.class_type_field
val ptyp_any : loc:Location.t -> Migrate_parsetree.Ast_407.Parsetree.core_type
val ptyp_var : loc:Location.t -> string -> Migrate_parsetree.Ast_407.Parsetree.core_type
val ptyp_constr : loc:Location.t -> Ppxlib_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_407.Parsetree.core_type list -> Migrate_parsetree.Ast_407.Parsetree.core_type
val ptyp_class : loc:Location.t -> Ppxlib_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_407.Parsetree.core_type list -> Migrate_parsetree.Ast_407.Parsetree.core_type
val ptyp_poly : loc:Location.t -> string Location.loc list -> Migrate_parsetree.Ast_407.Parsetree.core_type -> Migrate_parsetree.Ast_407.Parsetree.core_type
val ptyp_package : loc:Location.t -> (Ppxlib_ast__.Import.Longident.t Location.loc * (Ppxlib_ast__.Import.Longident.t Location.loc * Migrate_parsetree.Ast_407.Parsetree.core_type) list) -> Migrate_parsetree.Ast_407.Parsetree.core_type
val ptyp_extension : loc:Location.t -> (string Location.loc * Migrate_parsetree.Ast_407.Parsetree.payload) -> Migrate_parsetree.Ast_407.Parsetree.core_type
val pexp_ident : loc:Location.t -> Ppxlib_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_407.Parsetree.expression
val pexp_construct : loc:Location.t -> Ppxlib_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_407.Parsetree.expression option -> Migrate_parsetree.Ast_407.Parsetree.expression
val pexp_record : loc:Location.t -> (Ppxlib_ast__.Import.Longident.t Location.loc * Migrate_parsetree.Ast_407.Parsetree.expression) list -> Migrate_parsetree.Ast_407.Parsetree.expression option -> Migrate_parsetree.Ast_407.Parsetree.expression
val pexp_field : loc:Location.t -> Migrate_parsetree.Ast_407.Parsetree.expression -> Ppxlib_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_407.Parsetree.expression
val pexp_setfield : loc:Location.t -> Migrate_parsetree.Ast_407.Parsetree.expression -> Ppxlib_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_407.Parsetree.expression -> Migrate_parsetree.Ast_407.Parsetree.expression
val pexp_new : loc:Location.t -> Ppxlib_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_407.Parsetree.expression
val pexp_setinstvar : loc:Location.t -> string Location.loc -> Migrate_parsetree.Ast_407.Parsetree.expression -> Migrate_parsetree.Ast_407.Parsetree.expression
val pexp_override : loc:Location.t -> (string Location.loc * Migrate_parsetree.Ast_407.Parsetree.expression) list -> Migrate_parsetree.Ast_407.Parsetree.expression
val pexp_newtype : loc:Location.t -> string Location.loc -> Migrate_parsetree.Ast_407.Parsetree.expression -> Migrate_parsetree.Ast_407.Parsetree.expression
val pexp_extension : loc:Location.t -> (string Location.loc * Migrate_parsetree.Ast_407.Parsetree.payload) -> Migrate_parsetree.Ast_407.Parsetree.expression
val pexp_unreachable : loc:Location.t -> Migrate_parsetree.Ast_407.Parsetree.expression
val extension_constructor : loc:Location.t -> name:string Location.loc -> kind:Migrate_parsetree.Ast_407.Parsetree.extension_constructor_kind -> Migrate_parsetree.Ast_407.Parsetree.extension_constructor
val include_infos : loc:Location.t -> 'a -> 'a Migrate_parsetree.Ast_407.Parsetree.include_infos
val location : start:Lexing.position -> end_:Lexing.position -> ghost:bool -> Location.t
val module_binding : loc:Location.t -> name:string Location.loc -> expr:Migrate_parsetree.Ast_407.Parsetree.module_expr -> Migrate_parsetree.Ast_407.Parsetree.module_binding
val module_declaration : loc:Location.t -> name:string Location.loc -> type_:Migrate_parsetree.Ast_407.Parsetree.module_type -> Migrate_parsetree.Ast_407.Parsetree.module_declaration
val pmod_ident : loc:Location.t -> Ppxlib_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_407.Parsetree.module_expr
val pmod_extension : loc:Location.t -> (string Location.loc * Migrate_parsetree.Ast_407.Parsetree.payload) -> Migrate_parsetree.Ast_407.Parsetree.module_expr
val pmty_ident : loc:Location.t -> Ppxlib_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_407.Parsetree.module_type
val pmty_extension : loc:Location.t -> (string Location.loc * Migrate_parsetree.Ast_407.Parsetree.payload) -> Migrate_parsetree.Ast_407.Parsetree.module_type
val pmty_alias : loc:Location.t -> Ppxlib_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_407.Parsetree.module_type
val module_type_declaration : loc:Location.t -> name:string Location.loc -> type_:Migrate_parsetree.Ast_407.Parsetree.module_type option -> Migrate_parsetree.Ast_407.Parsetree.module_type_declaration
val open_description : loc:Location.t -> lid:Ppxlib_ast__.Import.Longident.t Location.loc -> override:Migrate_parsetree.Ast_407.Asttypes.override_flag -> Migrate_parsetree.Ast_407.Parsetree.open_description
val ppat_any : loc:Location.t -> Migrate_parsetree.Ast_407.Parsetree.pattern
val ppat_var : loc:Location.t -> string Location.loc -> Migrate_parsetree.Ast_407.Parsetree.pattern
val ppat_alias : loc:Location.t -> Migrate_parsetree.Ast_407.Parsetree.pattern -> string Location.loc -> Migrate_parsetree.Ast_407.Parsetree.pattern
val ppat_construct : loc:Location.t -> Ppxlib_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_407.Parsetree.pattern option -> Migrate_parsetree.Ast_407.Parsetree.pattern
val ppat_variant : loc:Location.t -> string -> Migrate_parsetree.Ast_407.Parsetree.pattern option -> Migrate_parsetree.Ast_407.Parsetree.pattern
val ppat_record : loc:Location.t -> (Ppxlib_ast__.Import.Longident.t Location.loc * Migrate_parsetree.Ast_407.Parsetree.pattern) list -> Migrate_parsetree.Ast_407.Asttypes.closed_flag -> Migrate_parsetree.Ast_407.Parsetree.pattern
val ppat_type : loc:Location.t -> Ppxlib_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_407.Parsetree.pattern
val ppat_unpack : loc:Location.t -> string Location.loc -> Migrate_parsetree.Ast_407.Parsetree.pattern
val ppat_extension : loc:Location.t -> (string Location.loc * Migrate_parsetree.Ast_407.Parsetree.payload) -> Migrate_parsetree.Ast_407.Parsetree.pattern
val ppat_open : loc:Location.t -> Ppxlib_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_407.Parsetree.pattern -> Migrate_parsetree.Ast_407.Parsetree.pattern
val position : fname:string -> lnum:int -> bol:int -> cnum:int -> Lexing.position
val psig_attribute : loc:Location.t -> (string Location.loc * Migrate_parsetree.Ast_407.Parsetree.payload) -> Migrate_parsetree.Ast_407.Parsetree.signature_item
val psig_extension : loc:Location.t -> (string Location.loc * Migrate_parsetree.Ast_407.Parsetree.payload) -> (string Location.loc * Migrate_parsetree.Ast_407.Parsetree.payload) list -> Migrate_parsetree.Ast_407.Parsetree.signature_item
val pstr_attribute : loc:Location.t -> (string Location.loc * Migrate_parsetree.Ast_407.Parsetree.payload) -> Migrate_parsetree.Ast_407.Parsetree.structure_item
val pstr_extension : loc:Location.t -> (string Location.loc * Migrate_parsetree.Ast_407.Parsetree.payload) -> (string Location.loc * Migrate_parsetree.Ast_407.Parsetree.payload) list -> Migrate_parsetree.Ast_407.Parsetree.structure_item
val value_description : loc:Location.t -> name:string Location.loc -> type_:Migrate_parsetree.Ast_407.Parsetree.core_type -> prim:string list -> Migrate_parsetree.Ast_407.Parsetree.value_description

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.

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.

OCaml

Innovation. Community. Security.