1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283openPpxliblet(>>)fgx=g(fx)let(>|=)xf=List.mapfxmoduleOption=structincludeOptionletto_bool:unitoption->bool=functionSome()->true|None->falseendmoduleList=structincludeList(* TODO(4.10): remove *)letconcat_map=letrecauxfacc=function|[]->revacc|x::l->letxs=fxinauxf(List.rev_appendxsacc)linfun~fl->auxf[]lletreduce~f=function|[]->None|[x]->Somex|_::_::_asl->letrecaux=function|[]->assertfalse|[a;b]->fab|x::xs->fx(auxxs)inSome(auxl)letreduce_exn~fl=matchreduce~flwith|Somex->x|None->failwith"Cannot reduce empty list"endmoduleMake(A:Ast_builder.S):sigvalcompose_all:('a->'a)list->'a->'a(** Left-to-right composition of a list of functions. *)vallambda:stringlist->expression->expression(** [lambda \[ "x_1"; ...; "x_n" \] e] is [fun x1 ... x_n -> e] *)valarrow:core_typelist->core_type->core_type(** [arrow \[ "t_1"; ...; "t_n" \] u] is [t_1 -> ... -> t_n -> u] *)end=structopenAletcompose_alllx=List.fold_left(|>)x(List.revl)letlambda=List.map(pvar>>pexp_funNolabelNone)>>compose_allletarrow=List.map(ptyp_arrowNolabel)>>compose_allend(* Extracted from [Ppxlib.0.24.0] to avoid depending on the particular naming
scheme used (which is exposed in our snapshot tests). This scheme was
changed in https://github.com/ocaml-ppx/ppxlib/pull/285. *)letname_type_params_in_td=letgen_symbol=letcnt=ref0infun~prefix()->cnt:=!cnt+1;Printf.sprintf"%s__%03i_"prefix!cntinfun(td:type_declaration):type_declaration->letprefix_stringi=(* a, b, ..., y, z, aa, bb, ... *)String.make((i/26)+1)(Char.chr(Char.code'a'+(imod26)))inletname_parami(tp,variance)=letptyp_desc=matchtp.ptyp_descwith|Ptyp_any->Ptyp_var(gen_symbol~prefix:(prefix_stringi)())|Ptyp_var_asv->v|_->Location.raise_errorf~loc:tp.ptyp_loc"not a type parameter"in({tpwithptyp_desc},variance)in{tdwithptype_params=List.mapiname_paramtd.ptype_params}