123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766open!Baseopen!PpxlibopenAst_builder.DefaultopenHelpersopenLifted.Monad_infix(* Generates the signature for type conversion to S-expressions *)moduleSig_generate_sexp_of=structlettype_of_sexp_of~loct=letloc={locwithloc_ghost=true}in[%type:[%tt]->Sexplib0.Sexp.t];;letmk_typetd=combinator_type_of_type_declarationtd~f:type_of_sexp_ofletmk_sig~loc:_~path:_(_rf,tds)=List.maptds~f:(funtd->letloc=td.ptype_locinpsig_value~loc(value_description~loc~name:(Located.map((^)"sexp_of_")td.ptype_name)~type_:(mk_typetd)~prim:[]));;letmk_sig_exn~loc:_~path:__te=[]endmoduleStr_generate_sexp_of=structmoduleTypes_being_defined=structtypet=|Nonrec|RecofSet.M(String).tletto_rec_flag=function|Nonrec->Nonrecursive|Rec_->Recursive;;endletsexp_of_type_constr~locidargs=type_constr_conv~locid~f:(funs->"sexp_of_"^s)args;;(* Conversion of types *)letrecsexp_of_type~renamingtyp:Conversion.t=letloc={typ.ptyp_locwithloc_ghost=true}inmatchtypwith|_whenOption.is_some(Attribute.getAttrs.opaquetyp)->Conversion.of_reference_exn[%exprSexplib0.Sexp_conv.sexp_of_opaque]|[%type:_]->Conversion.of_lambda[ppat_any~loc-->[%exprSexplib0.Sexp.Atom"_"]]|[%type:[%t?_]sexp_opaque]->Conversion.of_reference_exn[%exprSexplib0.Sexp_conv.sexp_of_opaque]|{ptyp_desc=Ptyp_tupletp;_}->Conversion.of_lambda[sexp_of_tuple~renaming(loc,tp)]|{ptyp_desc=Ptyp_varparm;_}->(matchRenaming.binding_kindrenamingparm~locwith|Universally_boundfresh->Conversion.of_reference_exn(Fresh_name.expressionfresh)|Existentially_bound->sexp_of_type~renaming[%type:_])|{ptyp_desc=Ptyp_constr(id,args);_}->Conversion.of_reference_exn(sexp_of_type_constr~locid(List.mapargs~f:(funtp->Conversion.to_expression~loc(sexp_of_type~renamingtp))))|{ptyp_desc=Ptyp_arrow(_,_,_);_}->Conversion.of_lambda[ppat_any~loc-->[%exprSexplib0.Sexp_conv.sexp_of_funSexplib0.Sexp_conv.ignore]]|{ptyp_desc=Ptyp_variant(row_fields,Closed,_);_}->sexp_of_variant~renaming(loc,row_fields)|{ptyp_desc=Ptyp_poly(parms,poly_tp);_}->sexp_of_poly~renamingparmspoly_tp|{ptyp_desc=Ptyp_variant(_,Open,_);_}|{ptyp_desc=Ptyp_object(_,_);_}|{ptyp_desc=Ptyp_class(_,_);_}|{ptyp_desc=Ptyp_alias(_,_);_}|{ptyp_desc=Ptyp_package_;_}|{ptyp_desc=Ptyp_extension_;_}->Location.raise_errorf~loc"Type unsupported for ppx [sexp_of] conversion"(* Conversion of tuples *)andsexp_of_tuple~renaming(loc,tps)=letfps=List.map~f:(funtp->sexp_of_type~renamingtp)tpsinlet({bindings;arguments;converted}:Conversion.Apply_all.t)=Conversion.apply_all~locfpsinletin_expr=[%exprSexplib0.Sexp.List[%eelist~locconverted]]inletexpr=pexp_let~locNonrecursivebindingsin_exprinppat_tuple~locarguments-->expr(* Conversion of variant types *)andsexp_of_variant~renaming((loc,row_fields):Location.t*row_fieldlist):Conversion.t=letitemrow=matchrow.prf_descwith|Rtag({txt=cnstr;_},true,[])->ppat_variant~loccnstrNone-->[%exprSexplib0.Sexp.Atom[%eestring~loccnstr]]|Rtag({txt=cnstr;_},_,[tp])whenOption.is_some(Attribute.getAttrs.list_polyrow)->(matchtpwith|[%type:[%t?tp]list]->letcnv_expr=Conversion.to_expression~loc(sexp_of_type~renamingtp)inletname=Fresh_name.create"l"~locinppat_variant~loccnstr(Some(Fresh_name.patternname))-->[%exprSexplib0.Sexp.List(Sexplib0.Sexp.Atom[%eestring~loccnstr]::Sexplib0.Sexp_conv.list_map[%ecnv_expr][%eFresh_name.expressionname])]|_->Attrs.invalid_attribute~locAttrs.list_poly"_ list")|Rtag({txt=cnstr;_},_,[[%type:[%t?tp]sexp_list]])->letcnv_expr=Conversion.to_expression~loc(sexp_of_type~renamingtp)inletname=Fresh_name.create"l"~locinppat_variant~loccnstr(Some(Fresh_name.patternname))-->[%exprSexplib0.Sexp.List(Sexplib0.Sexp.Atom[%eestring~loccnstr]::Sexplib0.Sexp_conv.list_map[%ecnv_expr][%eFresh_name.expressionname])]|Rtag({txt=cnstr;_},false,[tp])->letcnstr_expr=[%exprSexplib0.Sexp.Atom[%eestring~loccnstr]]inletfresh=Fresh_name.create"v"~locinletcnstr_arg=Conversion.apply~loc(sexp_of_type~renamingtp)(Fresh_name.expressionfresh)inletexpr=[%exprSexplib0.Sexp.List[%eelist~loc[cnstr_expr;cnstr_arg]]]inppat_variant~loccnstr(Some(Fresh_name.patternfresh))-->expr|Rinherit{ptyp_desc=Ptyp_constr(id,[]);_}->letname=Fresh_name.create"v"~locinppat_alias~loc(ppat_type~locid)(Fresh_name.to_string_locname)-->sexp_of_type_constr~locid[Fresh_name.expressionname]|Rtag(_,true,[_])|Rtag(_,_,_::_::_)->Location.raise_errorf~loc"unsupported: sexp_of_variant/Rtag/&"|Rinherit({ptyp_desc=Ptyp_constr(id,_::_);_}astyp)->letcall=Conversion.to_expression~loc(sexp_of_type~renamingtyp)inletname=Fresh_name.create"v"~locinppat_alias~loc(ppat_type~locid)(Fresh_name.to_string_locname)-->[%expr[%ecall][%eFresh_name.expressionname]]|Rinherit_->Location.raise_errorf~loc"unsupported: sexp_of_variant/Rinherit/non-id"(* impossible? *)|Rtag(_,false,[])->assertfalseinConversion.of_lambda(List.map~f:itemrow_fields)(* Polymorphic record fields *)andsexp_of_poly~renamingparmstp=letloc=tp.ptyp_locinletrenaming=List.fold_leftparms~init:renaming~f:(Renaming.add_universally_bound~prefix:"_of_")inletbindings=letmk_bindingparm=letname=matchRenaming.binding_kindrenamingparm.txt~loc:parm.locwith|Universally_boundname->name|Existentially_bound->assertfalseinvalue_binding~loc~pat:(Fresh_name.patternname)~expr:[%exprSexplib0.Sexp_conv.sexp_of_opaque]inList.map~f:mk_bindingparmsinConversion.bind(sexp_of_type~renamingtp)bindings;;(* Conversion of record types *)letmk_rec_pattlocpattnamefresh=letp=Loc.make(Longident.Lidentname)~loc,Fresh_name.patternfreshinpatt@[p];;typeis_empty_expr=|Inspect_valueof(location->expression->expression)|Inspect_sexpof(cnv_expr:expression->location->expression->expression)letsexp_of_record_field~renaming~bndspattexprnametp?sexp_ofis_empty_expr=letloc=tp.ptyp_locinletfresh=Fresh_name.createname~locinletpatt=mk_rec_pattlocpattnamefreshinletcnv_expr=Conversion.to_expression~loc(sexp_of_type~renamingtp)inletcnv_expr=matchsexp_ofwith|None->cnv_expr|Somesexp_of->[%expr[%esexp_of][%ecnv_expr]]inletbnd=Fresh_name.create"bnd"~locinletarg=Fresh_name.create"arg"~locinletexpr=[%exprlet[%pFresh_name.patternbnds]=[%ematchis_empty_exprwith|Inspect_valueis_empty_expr->[%exprif[%eis_empty_exprloc(Fresh_name.expressionfresh)]then[%eFresh_name.expressionbnds]else(let[%pFresh_name.patternarg]=[%ecnv_expr][%eFresh_name.expressionfresh]inlet[%pFresh_name.patternbnd]=Sexplib0.Sexp.List[Sexplib0.Sexp.Atom[%eestring~locname];[%eFresh_name.expressionarg]]in[%eFresh_name.expressionbnd]::[%eFresh_name.expressionbnds])]|Inspect_sexpis_empty_expr->[%exprlet[%pFresh_name.patternarg]=[%ecnv_expr][%eFresh_name.expressionfresh]inif[%eis_empty_expr~cnv_exprloc(Fresh_name.expressionarg)]then[%eFresh_name.expressionbnds]else(let[%pFresh_name.patternbnd]=Sexplib0.Sexp.List[Sexplib0.Sexp.Atom[%eestring~locname];[%eFresh_name.expressionarg]]in[%eFresh_name.expressionbnd]::[%eFresh_name.expressionbnds])]]in[%eexpr]]inpatt,expr;;letdisallow_type_variables_and_recursive_occurrences~types_being_defined~loc~attr_nametp=letdisallow_variables=letiter=objectinheritAst_traverse.iterassupermethod!core_type_desc=function|Ptyp_varv->Location.raise_errorf~loc"[@%s] was used, but the type of the field contains a type variable: '%s.\n\
Comparison is not avaiable for type variables.\n\
Consider using [@sexp_drop_if _] or [@sexp_drop_default.sexp] instead."attr_namev|t->super#core_type_desctendiniter#core_typeinletdisallow_recursive_occurrences=match(types_being_defined:Types_being_defined.t)with|Nonrec->fun_->()|Rectypes_being_defined->letiter=objectinheritAst_traverse.iterassupermethod!core_type_desc=function|Ptyp_constr({loc=_;txt=Lidents},_)ast->ifSet.memtypes_being_definedsthenLocation.raise_errorf~loc"[@%s] was used, but the type of the field contains a type defined \
in the current recursive block: %s.\n\
This is not supported.\n\
Consider using [@sexp_drop_if _] or [@sexp_drop_default.sexp] \
instead."attr_names;super#core_type_desct|t->super#core_type_desctendiniter#core_typeindisallow_variablestp;disallow_recursive_occurrencestp;;letsexp_of_default_field~types_being_definedhow~renaming~bndspattexprnametp?sexp_ofdefault=letis_empty=letinspect_valueequality_f=Inspect_value(funlocexpr->[%expr[%eequality_floc][%edefault][%eexpr]])inmatch(how:Record_field_attrs.Sexp_of.Drop.t)with|Sexp->Inspect_sexp(fun~cnv_exprlocsexp_expr->[%exprSexplib0.Sexp_conv.(=)([%ecnv_expr][%edefault])[%esexp_expr]])|>Lifted.return|No_arg->inspect_value(funloc->[%exprSexplib0.Sexp_conv.(=)[@ocaml.ppwarning"[@sexp_drop_default] is deprecated: please use \
one of:\n\
- [@sexp_drop_default f] and give an explicit \
equality function ([f = Poly.(=)] corresponds \
to the old behavior)\n\
- [@sexp_drop_default.compare] if the type \
supports [%compare]\n\
- [@sexp_drop_default.equal] if the type \
supports [%equal]\n\
- [@sexp_drop_default.sexp] if you want to \
compare the sexp representations\n"]])|>Lifted.return|Funclifted->lifted>>|funf->inspect_value(fun_->f)|Compare->inspect_value(funloc->disallow_type_variables_and_recursive_occurrences~types_being_defined~attr_name:"sexp_drop_default.compare"~loctp;[%expr[%compare.equal:[%ttp]]])|>Lifted.return|Equal->inspect_value(funloc->disallow_type_variables_and_recursive_occurrences~types_being_defined~attr_name:"sexp_drop_default.equal"~loctp;[%expr[%equal:[%ttp]]])|>Lifted.returninis_empty>>|sexp_of_record_field~renaming~bndspattexprnametp?sexp_of;;letsexp_of_label_declaration_list~types_being_defined~renaminglocflds~wrap_expr=letbnds=Fresh_name.create"bnds"~locinletlist_empty_expr=Inspect_value(funloclst->[%exprmatch[%elst]with|[]->true|_->false])inletarray_empty_expr=Inspect_value(funlocarr->[%exprmatch[%earr]with|[||]->true|_->false])inletcollliftedld=lifted>>=fun((patt:(Longident.tloc*pattern)list),expr)->letname=ld.pld_name.txtinletloc=ld.pld_name.locinletfresh=Fresh_name.createname~locinmatchRecord_field_attrs.Sexp_of.create~locldwith|Sexp_optiontp->letv=Fresh_name.create"v"~locinletbnd=Fresh_name.create"bnd"~locinletarg=Fresh_name.create"arg"~locinletpatt=mk_rec_pattlocpattnamefreshinletvname=Fresh_name.expressionvinletcnv_expr=Conversion.apply~loc(sexp_of_type~renamingtp)vnameinletexpr=[%exprlet[%pFresh_name.patternbnds]=match[%eFresh_name.expressionfresh]with|Stdlib.Option.None->[%eFresh_name.expressionbnds]|Stdlib.Option.Some[%pFresh_name.patternv]->let[%pFresh_name.patternarg]=[%ecnv_expr]inlet[%pFresh_name.patternbnd]=Sexplib0.Sexp.List[Sexplib0.Sexp.Atom[%eestring~locname];[%eFresh_name.expressionarg]]in[%eFresh_name.expressionbnd]::[%eFresh_name.expressionbnds]in[%eexpr]]inLifted.return(patt,expr)|Sexp_bool->letpatt=mk_rec_pattlocpattnamefreshinletbnd=Fresh_name.create"bnd"~locinletexpr=[%exprlet[%pFresh_name.patternbnds]=if[%eFresh_name.expressionfresh]then(let[%pFresh_name.patternbnd]=Sexplib0.Sexp.List[Sexplib0.Sexp.Atom[%eestring~locname]]in[%eFresh_name.expressionbnd]::[%eFresh_name.expressionbnds])else[%eFresh_name.expressionbnds]in[%eexpr]]inLifted.return(patt,expr)|Sexp_listtp->sexp_of_record_field~renaming~bndspattexprnametp~sexp_of:(* deliberately using whatever [sexp_of_list] is in scope *)[%exprsexp_of_list]list_empty_expr|>Lifted.return|Sexp_arraytp->sexp_of_record_field~renaming~bndspattexprnametp~sexp_of:(* deliberately using whatever [sexp_of_array] is in scope *)[%exprsexp_of_array]array_empty_expr|>Lifted.return|Specific(Drop_defaulthow)->lettp=ld.pld_typein(matchAttribute.getAttrs.defaultldwith|None->Location.raise_errorf~loc"no default to drop"|Some{to_lift=default}->Record_field_attrs.lift_default~loclddefault>>=sexp_of_default_field~types_being_definedhow~renaming~bndspattexprnametp)|Specific(Drop_iftest)->test>>|funtest->lettp=ld.pld_typeinsexp_of_record_field~renaming~bndspattexprnametp(Inspect_value(funlocexpr->[%expr[%etest][%eexpr]]))|Omit_nil->lettp=ld.pld_typeinletpatt=mk_rec_pattlocpattnamefreshinletvname=Fresh_name.expressionfreshinletarg=Fresh_name.create"arg"~locinletcnv_expr=Conversion.apply~loc(sexp_of_type~renamingtp)vnameinletbnds_expr=[%exprmatch[%ecnv_expr]with|Sexplib0.Sexp.List[]->[%eFresh_name.expressionbnds]|[%pFresh_name.patternarg]->Sexplib0.Sexp.List[Sexplib0.Sexp.Atom[%eestring~locname];[%eFresh_name.expressionarg]]::[%eFresh_name.expressionbnds]]in(patt,[%exprlet[%pFresh_name.patternbnds]=[%ebnds_expr]in[%eexpr]])|>Lifted.return|SpecificKeep->lettp=ld.pld_typeinletpatt=mk_rec_pattlocpattnamefreshinletvname=Fresh_name.expressionfreshinletarg=Fresh_name.create"arg"~locinletcnv_expr=Conversion.apply~loc(sexp_of_type~renamingtp)vnameinletbnds_expr=[%exprlet[%pFresh_name.patternarg]=[%ecnv_expr]inSexplib0.Sexp.List[Sexplib0.Sexp.Atom[%eestring~locname];[%eFresh_name.expressionarg]]::[%eFresh_name.expressionbnds]]in(patt,[%exprlet[%pFresh_name.patternbnds]=[%ebnds_expr]in[%eexpr]])|>Lifted.returninletinit_expr=wrap_expr(Fresh_name.expressionbnds)inList.fold_left~f:coll~init:(Lifted.return([],init_expr))flds>>|fun(patt,expr)->(ppat_record~locpattClosed,[%exprlet[%pFresh_name.patternbnds]=[]in[%eexpr]]);;(* Conversion of sum types *)letbranch_sumrowinline_attr~types_being_definedrenaming~locconstr_lidconstr_strargs=matchargswith|Pcstr_recordlds->letcnstr_expr=[%exprSexplib0.Sexp.Atom[%econstr_str]]insexp_of_label_declaration_list~types_being_defined~renamingloclds~wrap_expr:(funexpr->[%exprSexplib0.Sexp.List([%ecnstr_expr]::[%eexpr])])>>|fun(patt,expr)->ppat_construct~locconstr_lid(Somepatt)-->expr|Pcstr_tuplepcd_args->(matchpcd_argswith|[]->ppat_construct~locconstr_lidNone-->[%exprSexplib0.Sexp.Atom[%econstr_str]]|>Lifted.return|args->(matchargswith|[tp]whenOption.is_some(Attribute.getinline_attrrow)->(matchtpwith|[%type:[%t?tp]list]->letcnv_expr=Conversion.to_expression~loc(sexp_of_type~renamingtp)inletname=Fresh_name.create"l"~locinppat_construct~locconstr_lid(Some(Fresh_name.patternname))-->[%exprSexplib0.Sexp.List(Sexplib0.Sexp.Atom[%econstr_str]::Sexplib0.Sexp_conv.list_map[%ecnv_expr][%eFresh_name.expressionname])]|_->Attrs.invalid_attribute~locinline_attr"_ list")|[[%type:[%t?tp]sexp_list]]->letcnv_expr=Conversion.to_expression~loc(sexp_of_type~renamingtp)inletname=Fresh_name.create"l"~locinppat_construct~locconstr_lid(Some(Fresh_name.patternname))-->[%exprSexplib0.Sexp.List(Sexplib0.Sexp.Atom[%econstr_str]::Sexplib0.Sexp_conv.list_map[%ecnv_expr][%eFresh_name.expressionname])]|_->letsexp_of_args=List.map~f:(sexp_of_type~renaming)argsinletcnstr_expr=[%exprSexplib0.Sexp.Atom[%econstr_str]]inlet({bindings;arguments;converted}:Conversion.Apply_all.t)=Conversion.apply_all~locsexp_of_argsinletpatt=matchargumentswith|[arg]->arg|_->ppat_tuple~locargumentsinppat_construct~locconstr_lid(Somepatt)-->pexp_let~locNonrecursivebindings[%exprSexplib0.Sexp.List[%eelist~loc(cnstr_expr::converted)]])|>Lifted.return);;letsexp_of_sum~types_being_defined~renamingtpscds=List.mapcds~f:(funcd->letrenaming=Renaming.with_constructor_declarationrenaming~type_parameters:tpscdinletconstr_lid=Located.maplidentcd.pcd_nameinletconstr_str=estring~loc:cd.pcd_name.loccd.pcd_name.txtinbranch_sumcdAttrs.list_variant~types_being_definedrenaming~loc:cd.pcd_locconstr_lidconstr_strcd.pcd_args)|>Lifted.all>>|Conversion.of_lambda;;(* Empty type *)letsexp_of_nilloc=Conversion.of_lambda[ppat_any~loc-->[%exprassertfalse]](* Generate code from type definitions *)letsexp_of_td~types_being_definedtd=lettd=name_type_params_in_tdtdinlettps=List.maptd.ptype_params~f:get_type_param_nameinlet{ptype_name={txt=type_name;loc=_};ptype_loc=loc;_}=tdinletrenaming=Renaming.of_type_declarationtd~prefix:"_of_"inletbody=letbody=matchtd.ptype_kindwith|Ptype_variantcds->sexp_of_sum~renaming~types_being_defined(List.maptps~f:(funx->x.txt))cds|Ptype_recordlds->sexp_of_label_declaration_list~renamingloclds~types_being_defined~wrap_expr:(funexpr->[%exprSexplib0.Sexp.List[%eexpr]])>>|fun(patt,expr)->Conversion.of_lambda[patt-->expr]|Ptype_open->Location.raise_errorf~loc"ppx_sexp_conv: open types not supported"|Ptype_abstract->(matchtd.ptype_manifestwith|None->sexp_of_nilloc|Somety->sexp_of_type~renamingty)|>Lifted.returninbody>>|funbody->letis_private_alias=matchtd.ptype_kind,td.ptype_manifest,td.ptype_privatewith|Ptype_abstract,Some_,Private->true|_->falseinifis_private_aliasthen((* Replace all type variable by _ to avoid generalization problems *)letty_src=core_type_of_type_declarationtd|>replace_variables_by_underscoresinletmanifest=matchtd.ptype_manifestwith|Somemanifest->manifest|None->Location.raise_errorf~loc"sexp_of_td/no-manifest"inletty_dst=replace_variables_by_underscoresmanifestinletv=Fresh_name.create"v"~locinletcoercion=[%expr([%eFresh_name.expressionv]:[%tty_src]:>[%tty_dst])]in[%exprfun[%pFresh_name.patternv]->[%eConversion.apply~locbodycoercion]])else(* Prevent violation of value restriction, problems with recursive types, and
top-level effects by eta-expanding function definitions *)Conversion.to_value_expression~locbodyinlettyp=Sig_generate_sexp_of.mk_typetdinletfunc_name="sexp_of_"^type_nameinletbody=body>>|funbody->letpatts=List.maptps~f:(funid->matchRenaming.binding_kindrenamingid.txt~loc:id.locwith|Universally_boundname->Fresh_name.patternname|Existentially_bound->assertfalse)inletrec_flag=Types_being_defined.to_rec_flagtypes_being_definedineta_reduce_if_possible_and_nonrec~rec_flag(eabstract~locpattsbody)inletbody=Lifted.let_bind_user_expressions~locbodyin[constrained_function_bindingloctdtyp~tps~func_namebody];;letsexp_of_tds~loc~path:_(rec_flag,tds)=letrec_flag=really_recursive_respecting_opaquerec_flagtdsinlet(types_being_defined:Types_being_defined.t)=matchrec_flagwith|Nonrecursive->Nonrec|Recursive->Rec(Set.of_list(moduleString)(List.maptds~f:(funtd->td.ptype_name.txt)))inletbindings=List.concat_maptds~f:(sexp_of_td~types_being_defined)inpstr_value_list~locrec_flagbindings;;letsexp_of_exn~loc:_~pathec=letrenaming=Renaming.without_type()inletget_full_cnstrstr=path^"."^strinletloc=ec.ptyexn_locinletexpr=matchec.ptyexn_constructorwith|{pext_name=cnstr;pext_kind=Pext_decl(extension_constructor_kind,None);_}->letconstr_lid=Located.maplidentcnstrinbranch_sumecAttrs.list_exception~types_being_defined:Nonrecrenaming~locconstr_lid(estring~loc(get_full_cnstrcnstr.txt))extension_constructor_kind>>|funconverter->letassert_false=ppat_any~loc-->[%exprassertfalse]in[%exprSexplib0.Sexp_conv.Exn_converter.add[%extension_constructor[%epexp_construct~locconstr_lidNone]][%eConversion.to_expression~loc(Conversion.of_lambda[converter;assert_false])]]|{pext_kind=Pext_decl(_,Some_);_}->Location.raise_errorf~loc"sexp_of_exn/:"|{pext_kind=Pext_rebind_;_}->Location.raise_errorf~loc"sexp_of_exn/rebind"inletexpr=Lifted.let_bind_user_expressions~locexprin[pstr_value~locNonrecursive[value_binding~loc~pat:[%pat?()]~expr]];;letsexp_of_core_typecore_type=letloc={core_type.ptyp_locwithloc_ghost=true}insexp_of_type~renaming:(Renaming.without_type())core_type|>Conversion.to_value_expression~loc|>Merlin_helpers.hide_expression;;end