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