Module Ast_builder.Default

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

module Located : sig ... end
val pdir_int : loc:Warnings.loc -> string -> char option -> Migrate_parsetree.Ast_408.Parsetree.directive_argument
val location : start:Stdlib.Lexing.position -> end_:Stdlib.Lexing.position -> ghost:bool -> Warnings.loc
val position : fname:string -> lnum:int -> bol:int -> cnum:int -> Stdlib.Lexing.position
val eint : loc:Location.t -> 'a
val echar : loc:Location.t -> 'a
val estring : loc:Location.t -> 'a
val efloat : loc:Location.t -> 'a
val eint32 : loc:Location.t -> 'a
val eint64 : loc:Location.t -> 'a
val enativeint : loc:Location.t -> 'a
val ebool : loc:Location.t -> 'a
val pint : loc:Location.t -> 'a
val pchar : loc:Location.t -> 'a
val pstring : loc:Location.t -> 'a
val pfloat : loc:Location.t -> 'a
val pint32 : loc:Location.t -> 'a
val pint64 : loc:Location.t -> 'a
val pnativeint : loc:Location.t -> 'a
val pbool : loc:Location.t -> 'a
val eunit : loc:Location.t -> 'a
val punit : loc:Location.t -> 'a
val evar : loc:Location.t -> 'a

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".

val pvar : loc:Location.t -> 'a
val eapply : loc:Location.t -> 'a

Same as pexp_apply but without labels

val eabstract : loc:Location.t -> 'a
val esequence : loc:Location.t -> 'a
val ppat_tuple_opt : loc:Location.t -> 'a
val pexp_tuple_opt : loc:Location.t -> 'a
val elist : loc:Location.t -> 'a
val plist : loc:Location.t -> 'a

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

val nonrec_type_declaration : loc:Location.t -> 'a
val unapplied_type_constr_conv : loc:Location.t -> 'a

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.
val type_constr_conv : loc:Location.t -> 'a

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.