package ppxlib

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

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

module Located : sig ... end
val attribute : loc:Location.t -> name:string Location.loc -> payload:Migrate_parsetree.Ast_410.Parsetree.payload -> Migrate_parsetree.Ast_410.Parsetree.attribute
val pcl_constr : loc:Location.t -> Ppxlib_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_410.Parsetree.core_type list -> Migrate_parsetree.Ast_410.Parsetree.class_expr
val pcl_extension : loc:Location.t -> (string Location.loc * Migrate_parsetree.Ast_410.Parsetree.payload) -> Migrate_parsetree.Ast_410.Parsetree.class_expr
val pcf_extension : loc:Location.t -> (string Location.loc * Migrate_parsetree.Ast_410.Parsetree.payload) -> Migrate_parsetree.Ast_410.Parsetree.class_field
val pcty_constr : loc:Location.t -> Ppxlib_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_410.Parsetree.core_type list -> Migrate_parsetree.Ast_410.Parsetree.class_type
val pcty_extension : loc:Location.t -> (string Location.loc * Migrate_parsetree.Ast_410.Parsetree.payload) -> Migrate_parsetree.Ast_410.Parsetree.class_type
val pctf_extension : loc:Location.t -> (string Location.loc * Migrate_parsetree.Ast_410.Parsetree.payload) -> Migrate_parsetree.Ast_410.Parsetree.class_type_field
val ptyp_any : loc:Location.t -> Migrate_parsetree.Ast_410.Parsetree.core_type
val ptyp_var : loc:Location.t -> string -> Migrate_parsetree.Ast_410.Parsetree.core_type
val ptyp_constr : loc:Location.t -> Ppxlib_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_410.Parsetree.core_type list -> Migrate_parsetree.Ast_410.Parsetree.core_type
val ptyp_class : loc:Location.t -> Ppxlib_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_410.Parsetree.core_type list -> Migrate_parsetree.Ast_410.Parsetree.core_type
val ptyp_poly : loc:Location.t -> string Location.loc list -> Migrate_parsetree.Ast_410.Parsetree.core_type -> Migrate_parsetree.Ast_410.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_410.Parsetree.core_type) list) -> Migrate_parsetree.Ast_410.Parsetree.core_type
val ptyp_extension : loc:Location.t -> (string Location.loc * Migrate_parsetree.Ast_410.Parsetree.payload) -> Migrate_parsetree.Ast_410.Parsetree.core_type
val pdir_string : loc:Location.t -> string -> Migrate_parsetree.Ast_410.Parsetree.directive_argument
val pdir_int : loc:Location.t -> string -> char option -> Migrate_parsetree.Ast_410.Parsetree.directive_argument
val pdir_ident : loc:Location.t -> Ppxlib_ast__.Import.Longident.t -> Migrate_parsetree.Ast_410.Parsetree.directive_argument
val pdir_bool : loc:Location.t -> bool -> Migrate_parsetree.Ast_410.Parsetree.directive_argument
val pexp_ident : loc:Location.t -> Ppxlib_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_410.Parsetree.expression
val pexp_construct : loc:Location.t -> Ppxlib_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_410.Parsetree.expression option -> Migrate_parsetree.Ast_410.Parsetree.expression
val pexp_record : loc:Location.t -> (Ppxlib_ast__.Import.Longident.t Location.loc * Migrate_parsetree.Ast_410.Parsetree.expression) list -> Migrate_parsetree.Ast_410.Parsetree.expression option -> Migrate_parsetree.Ast_410.Parsetree.expression
val pexp_field : loc:Location.t -> Migrate_parsetree.Ast_410.Parsetree.expression -> Ppxlib_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_410.Parsetree.expression
val pexp_setfield : loc:Location.t -> Migrate_parsetree.Ast_410.Parsetree.expression -> Ppxlib_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_410.Parsetree.expression -> Migrate_parsetree.Ast_410.Parsetree.expression
val pexp_new : loc:Location.t -> Ppxlib_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_410.Parsetree.expression
val pexp_setinstvar : loc:Location.t -> string Location.loc -> Migrate_parsetree.Ast_410.Parsetree.expression -> Migrate_parsetree.Ast_410.Parsetree.expression
val pexp_override : loc:Location.t -> (string Location.loc * Migrate_parsetree.Ast_410.Parsetree.expression) list -> Migrate_parsetree.Ast_410.Parsetree.expression
val pexp_newtype : loc:Location.t -> string Location.loc -> Migrate_parsetree.Ast_410.Parsetree.expression -> Migrate_parsetree.Ast_410.Parsetree.expression
val pexp_extension : loc:Location.t -> (string Location.loc * Migrate_parsetree.Ast_410.Parsetree.payload) -> Migrate_parsetree.Ast_410.Parsetree.expression
val pexp_unreachable : loc:Location.t -> Migrate_parsetree.Ast_410.Parsetree.expression
val extension_constructor : loc:Location.t -> name:string Location.loc -> kind:Migrate_parsetree.Ast_410.Parsetree.extension_constructor_kind -> Migrate_parsetree.Ast_410.Parsetree.extension_constructor
val include_infos : loc:Location.t -> 'a -> 'a Migrate_parsetree.Ast_410.Parsetree.include_infos
val location : start:Lexing.position -> end_:Lexing.position -> ghost:bool -> Location.t
val module_binding : loc:Location.t -> name:string option Location.loc -> expr:Migrate_parsetree.Ast_410.Parsetree.module_expr -> Migrate_parsetree.Ast_410.Parsetree.module_binding
val module_declaration : loc:Location.t -> name:string option Location.loc -> type_:Migrate_parsetree.Ast_410.Parsetree.module_type -> Migrate_parsetree.Ast_410.Parsetree.module_declaration
val pmod_ident : loc:Location.t -> Ppxlib_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_410.Parsetree.module_expr
val pmod_extension : loc:Location.t -> (string Location.loc * Migrate_parsetree.Ast_410.Parsetree.payload) -> Migrate_parsetree.Ast_410.Parsetree.module_expr
val module_substitution : loc:Location.t -> name:string Location.loc -> manifest:Ppxlib_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_410.Parsetree.module_substitution
val pmty_ident : loc:Location.t -> Ppxlib_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_410.Parsetree.module_type
val pmty_extension : loc:Location.t -> (string Location.loc * Migrate_parsetree.Ast_410.Parsetree.payload) -> Migrate_parsetree.Ast_410.Parsetree.module_type
val pmty_alias : loc:Location.t -> Ppxlib_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_410.Parsetree.module_type
val module_type_declaration : loc:Location.t -> name:string Location.loc -> type_:Migrate_parsetree.Ast_410.Parsetree.module_type option -> Migrate_parsetree.Ast_410.Parsetree.module_type_declaration
val ppat_any : loc:Location.t -> Migrate_parsetree.Ast_410.Parsetree.pattern
val ppat_var : loc:Location.t -> string Location.loc -> Migrate_parsetree.Ast_410.Parsetree.pattern
val ppat_alias : loc:Location.t -> Migrate_parsetree.Ast_410.Parsetree.pattern -> string Location.loc -> Migrate_parsetree.Ast_410.Parsetree.pattern
val ppat_construct : loc:Location.t -> Ppxlib_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_410.Parsetree.pattern option -> Migrate_parsetree.Ast_410.Parsetree.pattern
val ppat_variant : loc:Location.t -> string -> Migrate_parsetree.Ast_410.Parsetree.pattern option -> Migrate_parsetree.Ast_410.Parsetree.pattern
val ppat_record : loc:Location.t -> (Ppxlib_ast__.Import.Longident.t Location.loc * Migrate_parsetree.Ast_410.Parsetree.pattern) list -> Migrate_parsetree.Ast_410.Asttypes.closed_flag -> Migrate_parsetree.Ast_410.Parsetree.pattern
val ppat_type : loc:Location.t -> Ppxlib_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_410.Parsetree.pattern
val ppat_unpack : loc:Location.t -> string option Location.loc -> Migrate_parsetree.Ast_410.Parsetree.pattern
val ppat_extension : loc:Location.t -> (string Location.loc * Migrate_parsetree.Ast_410.Parsetree.payload) -> Migrate_parsetree.Ast_410.Parsetree.pattern
val ppat_open : loc:Location.t -> Ppxlib_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_410.Parsetree.pattern -> Migrate_parsetree.Ast_410.Parsetree.pattern
val position : fname:string -> lnum:int -> bol:int -> cnum:int -> Lexing.position
val rtag : loc:Location.t -> string Location.loc -> bool -> Migrate_parsetree.Ast_410.Parsetree.core_type list -> Migrate_parsetree.Ast_410.Parsetree.row_field
val psig_open : loc:Location.t -> Ppxlib_ast__.Import.Longident.t Location.loc Migrate_parsetree.Ast_410.Parsetree.open_infos -> Migrate_parsetree.Ast_410.Parsetree.signature_item
val toplevel_directive : loc:Location.t -> name:string Location.loc -> arg:Migrate_parsetree.Ast_410.Parsetree.directive_argument option -> Migrate_parsetree.Ast_410.Parsetree.toplevel_directive
val value_description : loc:Location.t -> name:string Location.loc -> type_:Migrate_parsetree.Ast_410.Parsetree.core_type -> prim:string list -> Migrate_parsetree.Ast_410.Parsetree.value_description
val enativeint : loc:Location.t -> nativeint -> Migrate_parsetree.Ast_410.Parsetree.expression
val pnativeint : loc:Location.t -> nativeint -> Migrate_parsetree.Ast_410.Parsetree.pattern

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.

val unapplied_type_constr_conv : loc:Location.t -> Longident.t Loc.t -> f:(string -> string) -> Migrate_parsetree.Ast_410.Parsetree.expression

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.