123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112open!BaseopenPpxlibopenAst_builder.DefaultmodulePervasive=struct(* this list comes from lib/typerep_lib/lib/type_generic.mli *)typet=|Array|Lazy|List|Option|Refletof_string=function|"array"->SomeArray|"lazy_t"->SomeLazy|"list"->SomeList|"option"->SomeOption|"ref"->SomeRef|_->None;;end(* The specification for which values need to be replaced *)typet=|None|Replaceofstring|Tupleoftlist|Constr_pervasiveofPervasive.t*t|Constr_toflongident*tlistletrecneeds_mapping=function|None->false|Replace_->true|Constr_pervasive(_,t)->needs_mappingt|Constr_t(_,ts)|Tuplets->List.existsts~f:needs_mapping;;letrecapply~loc~maptexpr=matchtwith|None->expr|Constr_pervasive(pervasive,t)->(matchpervasivewith|Option->[%exprStdlib.Option.map[%eapply_fn~loc~mapt][%eexpr]]|List->[%exprStdlib.List.map[%eapply_fn~loc~mapt][%eexpr]]|Ref->[%exprref[%eapply~loc~mapt[%expr![%eexpr]]]]|Array->[%exprStdlib.Array.map[%eapply_fn~loc~mapt][%eexpr]]|Lazy->[%exprlazy[%eapply~loc~mapt[%exprStdlib.Lazy.force[%eexpr]]]])|Constr_t(longident,ts)->letmap_fn=pexp_ident~loc(Located.mk~loc(Ldot(longident,"map")))in(matchtswith|[]->expr|[t]->[%expr[%emap_fn][%eexpr]~f:[%eapply_fn~loc~mapt]]|ts->letexprs=(Nolabel,expr)::List.mapits~f:(funit->Labelled("f"^Int.to_string(i+1)),apply_fn~loc~mapt)inpexp_apply~locmap_fnexprs)|Replacetext->[%expr[%eMap.find_exnmaptext][%eexpr]]|Tuplets->letnames=List.mapits~f:(funi_->"v"^Int.to_stringi)inpexp_let~locNonrecursive[value_binding~loc~pat:(ppat_tuple~loc(List.mapnames~f:(pvar~loc)))~expr](pexp_tuple~loc(List.map2_exntsnames~f:(funtname->apply~loc~mapt(evar~locname))))andapply_fn~loc~mapt=pexp_fun~locNolabelNone(pvar~loc"x")(apply~loc~mapt(evar~loc"x"));;letrecfind_targets~target~loccore_type=letlisttys~f=letrecs=List.maptys~f:(find_targets~target~loc)inifList.existsrecs~f:needs_mappingthenfrecselseNoneinmatchcore_type.ptyp_descwith|Ptyp_constr(lid_loc,args)->(matchlid_loc.txtwith|Lapply_->Location.raise_errorf~loc"Unexpected Lapply"|LidenttextwhenSet.memtargettext->Replacetext|Lidenttext->(matchPervasive.of_stringtextwith|None->None|Somekind->(matchargswith|[]|_::_::_->(* Pervasive type with unexpected arity, so it's not a pervasive *)None|[arg]->lett=find_targets~target~locargin(matchneeds_mappingtwith|false->None|true->Constr_pervasive(kind,t))))|Ldot(l,"t")->listargs~f:(funrecs->Constr_t(l,recs))|Ldot_->None)|Ptyp_tupleargs->listargs~f:(funx->Tuplex)|_->None;;typereplace_result=|Unchanged|Replacedletbuild~loc~maptyexpr=lett=find_targets~target:(Set.of_list(moduleString)(Map.keysmap))~loctyinifneeds_mappingtthenReplaced,apply~loc~maptexprelseUnchanged,expr;;