123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805(******************************************************************************
* OxCaml *
* Andrej Ivaskovic, Jane Street *
* -------------------------------------------------------------------------- *
* MIT License *
* *
* Copyright (c) 2025 Jane Street Group LLC *
* opensource-contacts@janestreet.com *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included *
* in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
* DEALINGS IN THE SOFTWARE. *
******************************************************************************)(* CR metaprogramming aivaskovic: This file has not been code reviewed *)type'alam='amoduleStamp:sig(** [t] is the type of stamps. Stamps have no structure, only a notion
of identity. *)typet(** [fresh ()] creates a fresh stamp, unequal to any other. *)valfresh:unit->t(** [compare] is a total ordering on stamps. *)valcompare:t->t->intend=structtypet=intexternalfresh:unit->int="caml_fresh_oo_id"[@@noalloc]letcompare=Int.compareendmoduleLoc=structtypet=|Unknown|Knownof{file:string;start_line:int;start_col:int;end_line:int;end_col:int}letunknown=Unknownletknown~file~start_line~start_col~end_line~end_col=Known{file;start_line;start_col;end_line;end_col}letprintfmt=function|Unknown->Format.fprintffmt"<unknown>"|Known{file;start_line;start_col;end_line;end_col}->ifstart_line=end_linethenFormat.fprintffmt"File %s, line %d, characters %d-%d"filestart_linestart_colend_colelseFormat.fprintffmt"File %s, lines %d-%d, characters %d-%d"filestart_lineend_linestart_colend_colendmoduleLevel:sig(** [t] is the type of binding levels. All variable bindings have an
associated level and all bindings of the same level have the same
scope. Each level is associated with a point on the call
stack. Each level has a location attached for error messages. *)typet(** [with_fresh loc f] creates a fresh level not equal to any others,
associated with the current point in the call stack, with [loc] as
the attached location. *)valwith_fresh:Loc.t->(t->'a)->'a(** [compare] is a total order on levels. *)valcompare:t->t->int(** [loc t] is the location attached to [t]. *)valloc:t->Loc.tend=structtypet={stamp:Stamp.t;mutable_valid:bool;loc:Loc.t}letfreshloc=letstamp=Stamp.fresh()inlet_valid=truein{stamp;_valid;loc}letwith_freshlocf=letlevel=freshlocintryletr=flevelinlevel._valid<-false;rwithe->level._valid<-false;raiseeletcomparet1t2=Stamp.comparet1.stampt2.stampletloct=t.locendletlet_prefixes=["let";"and"]moduleName=structtypet=stringletmkt=tletbase_names=letwhole_possibly_parenss=ifList.for_all(funp->not(String.starts_with~prefix:ps))let_prefixesthenselse"("^s^")"inmatchString.rindex_opts'_'with|None->whole_possibly_parenss|Somei->beginifi=0thenwhole_possibly_parensselseifs.[i-1]='_'thenletn=String.lengthsinmatchInt32.of_string_opt(String.subs(i+1)(n-i-1))with|None->s|Some_->String.subs0(i-1)elsesendletprintfmts=Format.fprintffmt"%s"sendtypestamp_num=(Stamp.t,int)Hashtbl.ttypename_counter=(string,int)Hashtbl.ttypeenv_rec={value:name_counter;type_var:name_counter;type_constr:name_counter;module_:name_counter}typeenv={stamps:stamp_num;env:env_rec}letnew_env()={stamps=Hashtbl.create32;env={value=Hashtbl.create32;type_var=Hashtbl.create32;type_constr=Hashtbl.create32;module_=Hashtbl.create32}}letprint_name_and_countfmt(name,count)=ifcount>0thenFormat.fprintffmt"%s__%d"namecountelseFormat.fprintffmt"%s"namemoduleVar:sig(** [t] is the type of variables of any sort *)typettypevar:=tmoduleModule:sig(** [t] is the type of module variables *)typet(** [generate lv n] creates a fresh module variable bound at [lv]
whose name is [n]. *)valgenerate:Level.t->Name.t->t(** [generic t] is [t] as a generic variable *)valgeneric:t->var(** [generic t] is [t] as a list of generic variables *)valgeneric_list:tlist->varlist(** [name t] is the name of [t]. *)valname:t->Name.t(** [print env formatter t] prints [t] using [formatter], with [env] as the
naming environment. *)valprint:env->Format.formatter->t->unitendmoduleValue:sig(** [t] is the type of ordinary variables *)typet(** [generate lv n] creates a fresh variable bound at [lv] whose
name is [n]. *)valgenerate:Level.t->Name.t->t(** [generic t] is [t] as a generic variable *)valgeneric:t->var(** [generic t] is [t] as a list of generic variables *)valgeneric_list:tlist->varlist(** [name t] is the name of [t]. *)valname:t->Name.t(** [print env formatter t] prints [t] using [formatter], with [env] as the
naming environment. *)valprint:env->Format.formatter->t->unitendmoduleType_var:sig(** [t] is the type of type variables *)typet(** [generate lv n] creates a fresh type constructor variable
bound at [lv] whose name is [n]. *)valgenerate:Level.t->Name.t->t(** [name t] is the name of [t]. *)valname:t->Name.t(** [print env formatter t] prints [t] using [formatter], with [env] as the
naming environment. *)valprint:env->Format.formatter->t->unitendmoduleType_constr:sig(** [t] is the type of type constructor variables *)typet(** [generate lv n] creates a fresh type constructor variable
bound at [lv] whose name is [n]. *)valgenerate:Level.t->Name.t->t(** [generic t] is [t] as a generic variable *)valgeneric:t->var(** [name t] is the name of [t]. *)valname:t->Name.t(** [print env formatter t] prints [t] using [formatter], with [env] as the
naming environment. *)valprint:env->Format.formatter->t->unitend(** [name t] is the name of [t]. *)valname:t->Name.t(** [loc t] is [Level.loc (level t)]. *)valloc:t->Loc.tmoduleSet:sig(** [t] is the type of sets of variables. *)typet(** [empty] is the empty set. *)valempty:t(** [singleton v] is the set containing just [v]. *)valsingleton:var->t(** [add v t] is the set containing [v] and the elements of [t]. *)valadd:var->t->t(** [union ~shared t1 t2] is the union of [t1] and [t2]. [shared] is run on
all the variables that are in both [t1] and [t2]. *)valunion:shared:(var->unit)->t->t->t(** [inter ~left_only ~right_only t1 t2] is the intersection of [t1]
and [t2]. [left_only] is run on all the variables that are in
[t1] and not in [t2]. [right_only] is run on all the variables
that are in [t2] and not in [t1]. *)valinter:left_only:(var->unit)->right_only:(var->unit)->t->t->t(** [iter f t] runs [f] on every variable in [t]. *)valiter:(var->unit)->t->unit(** [differences ~left_only ~right_only t1 t2] runs [left_only] on every
element of [t1] that is not an element of [t2] and [right_only] on every
element of [t2] that is not an element of [t1]. *)valdifferences:left_only:(var->unit)->right_only:(var->unit)->t->t->unitendmoduleMap:sig(** ['a t] is the type of maps from variables to ['a] values. *)type'at(** [empty] is the empty set. *)valempty:'at(** [singleton v data] is the map containing just a binding of [v] to
[data]. *)valsingleton:var->'a->'at(** [union ~join t1 t2] is the union of [t1] and [t2]. [join] is run on all
the variables that are in both [t1] and [t2]. *)valunion:(var->'a->'a->'a)->'at->'at->'at(** [remove_level l t] is the map containing the bindings of [t] whose
variables's level is not [l]. *)valremove_level:Level.t->'at->'at(** [iter f t] runs [f] on every variable in [t]. *)valiter:(var->'a->unit)->'at->unitendend=structtypet={name:string;stamp:Stamp.t;level:Level.t}moduleSet=structtypevar=tmoduleStamp_map=Map.Make(Stamp)typet=varStamp_map.tletempty=Stamp_map.emptyletsingletonv=Stamp_map.singletonv.stampvletaddvt=Stamp_map.addv.stampvtletunion~sharedt1t2=Stamp_map.union(fun_v1v2->sharedv2;Somev1)t1t2letinter~left_only~right_onlyt1t2=Stamp_map.merge(fun_v1v2->matchv1,v2with|None,None->None|Somev1,None->left_onlyv1;None|None,Somev2->right_onlyv2;None|Somev1,Some_->Somev1)t1t2letiterft=Stamp_map.iter(fun_v->fv)tletdifferences~left_only~right_onlyt1t2=ignore(Stamp_map.merge(fun_v1v2->matchv1,v2with|None,None->None|Somev,None->left_onlyv;None|None,Somev->right_onlyv;None|_->None)t1t2)endmoduleMap=structtypevar=tmoduleVar_map=Map.Make(structtypet=varletcomparet1t2=Stamp.comparet1.stampt2.stampend)moduleLevel_map=Map.Make(Level)type'at='aVar_map.tLevel_map.tletempty=Level_map.emptyletsingletonvdata=Level_map.singletonv.level(Var_map.singletonvdata)letremove_level=Level_map.removeletunioncombinet1t2=Level_map.union(fun_m1m2->letm=Var_map.union(funvdata1data2->letdata=combinevdata1data2inSomedata)m1m2inSomem)t1t2letiterft=Level_map.iter(fun_m->Var_map.iter(funvdata->fvdata)m)tendletgeneratelevelname=letstamp=Stamp.fresh()in{name;stamp;level}letnamet=t.nameletloct=Level.loct.levelletprint_var_envstamp_envname_envfmtvar=matchHashtbl.find_optstamp_envvar.stampwith|Somecount->print_name_and_countfmt(Name.base_namevar.name,count)|None->(letdict_update_and_printnew_val=Hashtbl.addstamp_envvar.stampnew_val;Hashtbl.addname_env(Name.base_namevar.name)new_val;print_name_and_countfmt(Name.base_namevar.name,new_val)inmatchHashtbl.find_optname_env(Name.base_namevar.name)with|Somev->dict_update_and_print(v+1)|None->dict_update_and_print0)moduleModule=structtypevar=ttypet=varletgenerate=generateletgenerict=tletgeneric_list=List.mapgenericletname=nameletprintenvfmtt=Format.fprintffmt"%a"(print_var_envenv.stampsenv.env.module_)tendmoduleValue=structtypevar=ttypet=varletgenerate=generateletgenerict=tletgeneric_list=List.mapgenericletname=nameletprintenvfmtt=Format.fprintffmt"%a"(print_var_envenv.stampsenv.env.value)tendmoduleType_var=structtypevar=ttypet=varletgenerate=generateletname=nameletprintenvfmtt=Format.fprintffmt"'%a"(print_var_envenv.stampsenv.env.type_var)tendmoduleType_constr=structtypevar=ttypet=varletgenerate=generateletgenerict=tletname=nameletprintenvfmtt=Format.fprintffmt"%a"(print_var_envenv.stampsenv.env.type_constr)tendendmoduleWith_bound_vars:sig(** ['a t] is the type of ['a]s paired with a set of variables that
are bound by the ['a]. *)type'at(** [return x] is [mk Var.Set.empty x]. *)valreturn:'a->'at(** [value_var v] is [mk (Var.Set.singleton (Var.Value.generic v)) v]. *)valvalue_var:Var.Value.t->Var.Value.tt(** [module_var v] is [mk (Var.Set.singleton (Var.Module.generic v)) v]. *)valmodule_var:Var.Module.t->Var.Module.tt(** [map f t] is [f v], where [v] is the value of [t], paired with the
same variables as [t]. *)valmap:('a->'b)->'at->'bt(** [meet t1 t2] is [(v1, v2)], where [v1] and [v2] are the values of
[t1] and [t2] respectively, paired with the union of the variables
from [t1] and [t2] which are expected to be disjoint. If [t1] and
[t2] share any variables then [duplicated] will be run on the
shared variables.*)valmeet:duplicated:(Var.t->unit)->'at->'bt->('a*'b)t(** [join ~left_only ~right_only t1 t2] is [(v1, v2)], where [v1] and
[v2] are the values of [t1] and [t2] respectively, paired with the
intersection of the variables from [t1] and [t2] which are
expected to be equal. If any variables in [t1] are missing from
[t2] then [left_only] with be run on them. If any variables in
[t2] are missing from [t1] then [right_only] will be run on
them. *)valjoin:left_only:(Var.t->unit)->right_only:(Var.t->unit)->'at->'bt->('a*'b)t(** [meet_all ~duplicated [t1; t2; ...]] is [[v1; v2; ...]], where
each [vn] is the value of [tn], paired with the union of the
variables from all the [ts] which are expected to be disjoint. If
the [ts] share any variables then [duplicated] will be run on the
shared variables. *)valmeet_all:duplicated:(Var.t->unit)->'atlist->'alistt(** [optional tm] is [Some v], where [v] is the value of [t], paired
with the variables from [t] if [tm] is [Some t]. It is [return
None] if [tm] is [None]. *)valoptional:'atoption->'aoptiont(** [value ~extra ~missing t vs] is [t]'s value. [t] is expected to
bind exactly the variables [vs]. [extra] is run on any additional
variables that are bound. [missing] is run on any variables that
are missing. *)valvalue:extra:(Var.t->unit)->missing:(Var.t->unit)->'at->Var.tlist->'a(** [value_nonbinding ~extra t] is [t]'s value. [t] is expected to
bind no variables. [extra] is run on any additional variables that
are bound. *)valvalue_nonbinding:extra:(Var.t->unit)->'at->'aend=structtype'at={vars:Var.Set.t;v:'a}letmkvarsv={vars;v}letreturnv=mkVar.Set.emptyvletvalue_varv=mk(Var.Set.singleton(Var.Value.genericv))vletmodule_varv=mk(Var.Set.singleton(Var.Module.genericv))vletmapf{vars;v}=letv=fvin{vars;v}letmeet~duplicated{vars=vars1;v=v1}{vars=vars2;v=v2}=letvars=Var.Set.union~shared:duplicatedvars1vars2inletv=v1,v2in{vars;v}letjoin~left_only~right_only{vars=vars1;v=v1}{vars=vars2;v=v2}=letvars=Var.Set.inter~left_only~right_onlyvars1vars2inletv=v1,v2in{vars;v}letmeet_all~duplicatedl=letvars,v=List.fold_left_map(funacc{vars;v}->letacc=Var.Set.union~shared:duplicatedaccvarsinacc,v)Var.Set.emptylin{vars;v}letoptional=functionNone->returnNone|Somet->mapOption.sometletvalue~extra~missingtvs=letexpected=List.fold_left(funaccv->Var.Set.addvacc)Var.Set.emptyvsinVar.Set.differences~left_only:extra~right_only:missingt.varsexpected;t.vletvalue_nonbinding~extrat=Var.Set.iterextrat.vars;t.vendmoduleWith_free_vars:sig(** ['a t] is the type of ['a]s paired with a set of variables that
are free in the ['a] along with their associated locations. *)type'at(** [mk vars x] is [x] paired with [vars]. *)valmk:Loc.tVar.Map.t->'a->'at(** [return x] is [mk Var.Map.empty x]. *)valreturn:'a->'at(** [map f t] is [f v], where [v] is the value of [t], paired with the
same variables as [t]. *)valmap:('a->'b)->'at->'bt(** [both t1 t2] is [(v1, v2)], where [v1] and [v2] are the values of
[t1] and [t2] respectively, paired with the union of the variables
from [t1] and [t2]. *)valboth:'at->'bt->('a*'b)t(** [all [t1; t2; ...]] is [[v1; v2; ...]], where each [vn] is the
value of [tn], paired with the union of the variables from all the
[ts]. *)valall:'atlist->'alistt(** [optional tm] is [Some t], where [v] is the value of [t], paired
with the variables from [t] if [tm] is [Some t]. It is [return
None] if [tm] is [None]. *)valoptional:'atoption->'aoptiont(** [value ~free t] is the value of [t]. [t] is expected to have no
free variables. [free] is run on any variables paired with [t]. *)valvalue:free:(Var.t->Loc.t->unit)->'at->'a(** [value_binding loc name t] is the value of [t]. [t] is expected to have
a single free variable named [name]. [t] is represented as a function
from this variable to the term itself. *)valvalue_binding:Loc.t->Name.t->(Var.Value.t->'at)->'at(** [value_bindings loc names t] is the value of [t]. [t] is expected to have
free variables whose names are given by [names]. [t] is represented as a
function from these variables to the term itself. *)valvalue_bindings:Loc.t->Name.tlist->(Var.Value.tlist->'at)->'at(** [type_var_bindings loc names t] is the value of [t]. [t] is expected to
have a list of free type variables names are [names]. [t] is represented
as a function from this type variable to the term itself. *)valtype_var_bindings:Loc.t->Name.tlist->(Var.Type_var.tlist->'at)->'at(** [type_bindings loc name t] is the value of [t]. [t] is expected to have
a single free type constructor variable named [name]. [t] is represented
as a function from these type constructor variables to the term itself. *)valtype_binding:Loc.t->Name.t->(Var.Type_constr.t->'at)->'at(** [module_binding loc name t] is the value of [t]. [t] is expected to have
a single free module variable named [name]. [t] is represented as a
function from this module variable to the term itself. *)valmodule_binding:Loc.t->Name.t->(Var.Module.t->'at)->'at(** [complex_bindings ~extra ~missing ~bound_values ~bound_modules t] is the
value of [t]. [t] is expected to have free value-kinded variables (named
[bound_values]) and free module variables (named [bound_modules]).
[t] is expected to bind exactly these variables. [extra] is run on any
additional variables that are bound. [missing] is run on any variables
that are missing. *)valcomplex_bindings:Loc.t->extra:(Var.t->unit)->missing:(Var.t->unit)->bound_values:Name.tlist->bound_modules:Name.tlist->(Var.Value.tlist->Var.Module.tlist->'aWith_bound_vars.tt*'bt)->('a*'b)tend=structtype'at={vars:Loc.tVar.Map.t;v:'a}letmkvarsv={vars;v}letreturnv=mkVar.Map.emptyvletmapf{vars;v}=letv=fvin{vars;v}letboth{vars=vars1;v=v1}{vars=vars2;v=v2}=letvars=Var.Map.union(fun_loc1_->loc1)vars1vars2inletv=v1,v2in{vars;v}letallts=letvars,v=List.fold_left_map(funacc{vars;v}->letacc=Var.Map.union(fun_loc1_->loc1)accvarsinacc,v)Var.Map.emptytsin{vars;v}letoptional=functionNone->returnNone|Somet->mapOption.sometletvalue~freet=Var.Map.iterfreet.vars;t.vletvalue_bindinglocnamef=Level.with_freshloc(funlevel->letfresh_var=Var.Value.generatelevelnameinlet{vars;v}=ffresh_varinletvars=Var.Map.remove_levellevelvarsin{vars;v})lettype_var_bindingslocnamesf=Level.with_freshloc(funlevel->letfresh_vars=List.map(funname->Var.Type_var.generatelevelname)namesinlet{vars;v}=ffresh_varsinletvars=Var.Map.remove_levellevelvarsin{vars;v})lettype_bindinglocnamef=Level.with_freshloc(funlevel->letfresh_var=Var.Type_constr.generatelevelnameinlet{vars;v}=ffresh_varinletvars=Var.Map.remove_levellevelvarsin{vars;v})letmodule_bindinglocnamef=Level.with_freshloc(funlevel->letfresh_var=Var.Module.generatelevelnameinlet{vars;v}=ffresh_varinletvars=Var.Map.remove_levellevelvarsin{vars;v})letvalue_bindingslocnamesf=Level.with_freshloc(funlevel->letfresh_vars=List.map(funname->Var.Value.generatelevelname)namesinlet{vars;v}=ffresh_varsinletvars=Var.Map.remove_levellevelvarsin{vars;v})letcomplex_bindingsloc~extra~missing~bound_values~bound_modulesf=Level.with_freshloc(funlevel->letfresh_value_vars=List.map(Var.Value.generatelevel)bound_valuesinletfresh_module_vars=List.map(Var.Module.generatelevel)bound_modulesinlet{vars=bindings_vars;v=bindings},{vars;v}=ffresh_value_varsfresh_module_varsinletfresh_vars=Var.Module.generic_listfresh_module_vars@Var.Value.generic_listfresh_value_varsinletbindings=With_bound_vars.value~extra~missingbindingsfresh_varsinletvars=Var.Map.remove_levellevelvarsinletvars=Var.Map.union(fun_loc1_->loc1)bindings_varsvarsinletv=bindings,vin{vars;v})endmoduleWith_free_and_bound_vars=structtype'at='aWith_bound_vars.tWith_free_vars.tletreturnp=With_free_vars.return(With_bound_vars.returnp)letwith_no_free_varsv=With_free_vars.returnvletwith_no_bound_varsv=With_free_vars.mapWith_bound_vars.returnvletbound_value_varv=with_no_free_vars(With_bound_vars.value_varv)letbound_module_varv=with_no_free_vars(With_bound_vars.module_varv)letmapft=With_free_vars.map(With_bound_vars.mapf)tletmeet~duplicatedt1t2=With_free_vars.map(fun(t1,t2)->With_bound_vars.meet~duplicatedt1t2)(With_free_vars.botht1t2)letjoin~left_only~right_onlyt1t2=With_free_vars.map(fun(t1,t2)->With_bound_vars.join~left_only~right_onlyt1t2)(With_free_vars.botht1t2)letmeet_all~duplicatedts=With_free_vars.map(With_bound_vars.meet_all~duplicated)(With_free_vars.allts)letoptionalts=With_free_vars.mapWith_bound_vars.optional(With_free_vars.optionalts)endtyperaw_ident_module_t=|Compilation_unitofstring|MDotofraw_ident_module_t*string|MVarofVar.Module.t*Loc.ttyperaw_ident_value_t=|VDotofraw_ident_module_t*string|VVarofVar.Value.t*Loc.ttyperaw_ident_type_t=|TDotofraw_ident_module_t*string|TVarofVar.Type_constr.t*Loc.t|TBuiltinofstringtyperaw_ident_constructor_t=|CDotofraw_ident_module_t*string|CBuiltinofstringtyperaw_ident_module_type_t=MtDotofraw_ident_module_t*stringtyperaw_ident_field_t=FDotofraw_ident_module_t*stringletsuffix_string_of_ident_value=function|VDot(_,s)->s|VVar(v,_)->Var.Value.namevletspecial_symbols=['!';'?';'~';'=';'<';'>';'@';'^';'|';'&';'+';'-';'*';'/';'$';'%';'#']letspecial_infix_strings=["asr";"land";"lor";"lsl";"lsr";"lxor";"mod";"or";":=";"!=";"::"]letprint_opfmts=ifList.memsspecial_infix_strings||List.mems.[0]special_symbolsthenFormat.fprintffmt"( %s )"selseFormat.fprintffmt"%s"sletrecprint_raw_ident_moduleenvfmt=function|Compilation_units->Format.fprintffmt"%s"s|MDot(m,s)->Format.fprintffmt"%a.%s"(print_raw_ident_moduleenv)ms|MVar(vm,_)->Format.fprintffmt"%a"(Var.Module.printenv)vmletprint_raw_ident_valueenvfmt=function|VDot(m,s)->Format.fprintffmt"%a.%a"(print_raw_ident_moduleenv)mprint_ops|VVar(v,_)->Var.Value.printenvfmtvletprint_raw_ident_typeenvfmt=function|TDot(m,s)->Format.fprintffmt"%a.%s"(print_raw_ident_moduleenv)ms|TVar(v,_)->Var.Type_constr.printenvfmtv|TBuiltins->Format.fprintffmt"%s"sletprint_raw_ident_constructorenvfmt=function|CDot(m,s)->Format.fprintffmt"%a.%s"(print_raw_ident_moduleenv)ms|CBuiltins->Format.fprintffmt"%s"sletprint_raw_ident_module_typeenvfmt=function|MtDot(m,s)->Format.fprintffmt"%a.%s"(print_raw_ident_moduleenv)msletprint_raw_ident_fieldenvfmt=function|FDot(m,s)->Format.fprintffmt"%a.%s"(print_raw_ident_moduleenv)msletrecfree_vars_module=function|Compilation_unit_->Var.Map.empty|MDot(t,_)->free_vars_modulet|MVar(v,loc)->Var.Map.singleton(Var.Module.genericv)locletfree_vars_value=function|VDot(d,_)->free_vars_moduled|VVar(v,loc)->Var.Map.singleton(Var.Value.genericv)locletfree_vars_type=function|TDot(t,_)->free_vars_modulet|TVar(v,loc)->Var.Map.singleton(Var.Type_constr.genericv)loc|TBuiltin_->Var.Map.emptylet_free_vars_module_type=functionMtDot(t,_)->free_vars_moduletletfree_vars_constructor=function|CDot(t,_)->free_vars_modulet|CBuiltin_->Var.Map.emptylet_free_vars_field=functionFDot(t,_)->free_vars_moduletmoduleIdentifier=structmoduleModule=structtypet=raw_ident_module_tWith_free_vars.tlet(let+)mf=With_free_vars.mapfmletmkt=With_free_vars.mk(free_vars_modulet)tletcompilation_units=mk(Compilation_units)letdotts=let+t=tinMDot(t,s)letvarvloc=mk(MVar(v,loc))endmoduleValue=structtypet=raw_ident_value_tWith_free_vars.tlet(let+)mf=With_free_vars.mapfmletmkt=With_free_vars.mk(free_vars_valuet)tletdotts=let+t=tinVDot(t,s)letvarvl=mk(VVar(v,l))endmoduleType=structtypet=raw_ident_type_tWith_free_vars.tlet(let+)mf=With_free_vars.mapfmletmkt=With_free_vars.mk(free_vars_typet)tletdotts=let+t=tinTDot(t,s)letvarvl=mk(TVar(v,l))letint=TBuiltin"int"|>mkletchar=TBuiltin"char"|>mkletstring=TBuiltin"string"|>mkletbytes=TBuiltin"bytes"|>mkletfloat=TBuiltin"float"|>mkletfloat32=TBuiltin"float32"|>mkletbool=TBuiltin"bool"|>mkletunit=TBuiltin"unit"|>mkletexn=TBuiltin"exn"|>mkletarray=TBuiltin"array"|>mkletiarray=TBuiltin"iarray"|>mkletlist=TBuiltin"list"|>mkletoption=TBuiltin"option"|>mkletnativeint=TBuiltin"nativeint"|>mkletint32=TBuiltin"int32"|>mkletint64=TBuiltin"int64"|>mkletlazy_t=TBuiltin"lazy_t"|>mkletextension_constructor=TBuiltin"extension_constructor"|>mkletfloatarray=TBuiltin"floatarray"|>mkletlexing_position=TBuiltin"lexing_position"|>mkletcode=TBuiltin"code"|>mkletunboxed_float=TBuiltin"float#"|>mkletunboxed_nativeint=TBuiltin"nativeint#"|>mkletunboxed_int32=TBuiltin"int32#"|>mkletunboxed_int64=TBuiltin"int64#"|>mkletint8x16=TBuiltin"int8x16"|>mkletint16x8=TBuiltin"int16x8"|>mkletint32x4=TBuiltin"int32x4"|>mkletint64x2=TBuiltin"int64x2"|>mkletfloat32x4=TBuiltin"float32x4"|>mkletfloat64x2=TBuiltin"float64x2"|>mkendmoduleModule_type=structtypet=raw_ident_module_type_tWith_free_vars.tlet(let+)mf=With_free_vars.mapfmletdotts=let+t=tinMtDot(t,s)endmoduleConstructor=structtypet=raw_ident_constructor_tWith_free_vars.tlet(let+)mf=With_free_vars.mapfmletmkt=With_free_vars.mk(free_vars_constructort)tletdotts=let+t=tinCDot(t,s)letfalse_=CBuiltin"false"|>mklettrue_=CBuiltin"true"|>mkletvoid=CBuiltin"()"|>mkletnil=CBuiltin"[]"|>mkletcons=CBuiltin"::"|>mkletnone=CBuiltin"None"|>mkletsome=CBuiltin"Some"|>mkletmatch_failure=CBuiltin"Match_failure"|>mkletout_of_memory=CBuiltin"Out_of_memory"|>mkletinvalid_argument=CBuiltin"Invalid_argument"|>mkletfailure=CBuiltin"Failure"|>mkletnot_found=CBuiltin"Not_found"|>mkletsys_error=CBuiltin"Sys_error"|>mkletend_of_file=CBuiltin"End_of_file"|>mkletdivision_by_zero=CBuiltin"Division_by_zero"|>mkletstack_overflow=CBuiltin"Stack_overflow"|>mkletsys_blocked_io=CBuiltin"Sys_blocked_io"|>mkletassert_failure=CBuiltin"Assert_failure"|>mkletundefined_recursive_module=CBuiltin"Undefined_recursive_module"|>mkendmoduleField=structtypet=raw_ident_field_tWith_free_vars.tlet(let+)mf=With_free_vars.mapfmletdotts=let+t=tinFDot(t,s)endendmoduleVariant=structtypet=stringletof_strings=sletprintfmts=Format.fprintffmt"`%s"sendmoduleMethod=structtypet=stringletof_strings=sletprintfmts=Format.fprintffmt"%s"sendmoduleAst=structtypeconstant=|Intofint|Int32ofint32|Int64ofint64|Nativeintofnativeint|Charofchar|Stringofstring*stringoption|Floatofstring|Float32ofstring|UnboxedFloatofstring|UnboxedFloat32ofstring|UnboxedInt32ofint32|UnboxedInt64ofint64|UnboxedNativeintofnativeinttyperec_flag=|Nonrecursive|Recursivetypedirection_flag=|Upto|Downtotyperecord_flag=|OpenRec|ClosedRectypevariant_form=|VFixed|VOpen|VClosedofstringlisttypeobject_closed_flag=|OClosed|OOpentypearg_label=|Nolabel|Labelledofstring|Optionalofstringtypetuple_label=|NolabelTup|LabelledTupofstringtypemodule_type=|MTIdentofraw_ident_module_type_t|MTBasicofstringtypeconstr=|CIdentofraw_ident_constructor_t|CBasicofstringtyperecord_field=|FIdentofraw_ident_field_t|FBasicofstringtypecore_type=|TypeAny|TypeVarofVar.Type_var.t|TypeArrowofarg_label*core_type*core_type|TypeTupleof(tuple_label*core_type)list|TypeUnboxedTupleof(tuple_label*core_type)list|TypeConstrofraw_ident_type_t*core_typelist|TypeObjectofobject_fieldlist*object_closed_flag|TypeClassofName.t*core_typelist|TypeAliasofcore_type*Name.t|TypeVariantofrow_fieldlist*variant_form|TypePolyofVar.Type_var.tlist*core_type|TypePackageofpackage_type|TypeQuoteofcore_type|TypeCallPosandobject_field=|OtagofName.t*core_type|Oinheritofcore_typeandrow_field=|VtagofVariant.t*bool*core_typelist|Vinheritofcore_typeandpackage_type=module_type*(fragment*core_type)listandfragment=|NameofName.t|Dotoffragment*Name.ttypetype_constraint=|Constraintofcore_type|Coerceofcore_typeoption*core_typetypepattern=|PatAny|PatVarofVar.Value.t|PatAliasofpattern*Var.Value.t|PatConstantofconstant|PatTupleof(tuple_label*pattern)list|PatUnboxedTupleof(tuple_label*pattern)list|PatConstructofconstr*patternoption|PatVariantofVariant.t*patternoption|PatRecordof(record_field*pattern)list*record_flag|PatUnboxedRecordof(record_field*pattern)list*record_flag|PatArrayofpatternlist|PatOrofpattern*pattern|PatConstraintofpattern*core_type|PatLazyofpattern|PatAnyModule|PatUnpackofVar.Module.t|PatExceptionofpatterntypeexpression_attribute=|Inline|Inlined|Specialise|Specialised|Unrolled|Nontail|Tail|Poll|Loop|Tail_mod_cons|Quotationletattribute_as_string=function|Inline->"inline"|Inlined->"inlined"|Specialise->"specialise"|Specialised->"specialised"|Unrolled->"unrolled"|Nontail->"nontail"|Tail->"tail"|Poll->"poll"|Loop->"loop"|Tail_mod_cons->"tail_mod_cons"|Quotation->"quotation"typeexpression={desc:expression_desc;attributes:expression_attributelist}andexpression_desc=|Identofraw_ident_value_t|Constantofconstant|Letofrec_flag*value_bindinglist*expression|Funoffunction_|Applyofexpression*(arg_label*expression)list|Matchofexpression*caselist|Tryofexpression*caselist|Tupleof(tuple_label*expression)list|Constructofconstr*expressionoption|Variantofstring*expressionoption|Recordof(record_field*expression)list*expressionoption|Fieldofexpression*record_field|Setfieldofexpression*record_field*expression|Arrayofexpressionlist|Ifthenelseofexpression*expression*expressionoption|Sequenceofexpression*expression|Whileofexpression*expression|Forofpattern*expression*expression*direction_flag*expression|Sendofexpression*Method.t|ConstraintExpofexpression*core_type|CoerceExpofexpression*core_typeoption*core_type|LetmoduleofVar.Module.toption*module_expr*expression|Assertofexpression|Lazyofexpression|Packofmodule_expr|Newofraw_ident_value_t|Unreachable|Src_pos|Stackofexpression|Exclaveofexpression|Unboxed_tupleof(tuple_label*expression)list|Unboxed_record_productof(record_field*expression)list*expressionoption|Unboxed_fieldofexpression*record_field|Let_opofraw_ident_value_tlist*expressionlist*case|Let_exceptionofName.t*expression|Extension_constructorofName.t|List_comprehensionofcomprehension|Array_comprehensionofcomprehension|Quoteofexpression|Antiquoteofexpression|Evalofcore_typeandcase={lhs:pattern;guard:expressionoption;rhs:expressionoption}andvalue_binding={pat:pattern;expr:expression}andfunction_body=|Pfunction_bodyofexpression|Pfunction_casesofcaselistandfunction_param=|Pparam_valofarg_label*expressionoption*pattern|Pparam_newtypeofVar.Type_constr.tandfunction_={params:function_paramlist;constraint_:type_constraintoption;body:function_body}andmodule_expr=|ModuleIdentofraw_ident_module_t|ModuleApplyofmodule_expr*module_expr|ModuleApply_unitofmodule_exprandcomprehension_clause=|RangeofVar.Value.t*expression*expression*direction_flag|Inofpattern*expressionandcomprehension=|Bodyofexpression|Whenofcomprehension*expression|ForCompofcomprehension*comprehension_clause(* quotation printing logic *)letpp=Format.fprintfletprefix_symbols=['!';'?';'~']letinfix_symbols=['=';'<';'>';'@';'^';'|';'&';'+';'-';'*';'/';'$';'%';'#']letspecial_infix_strings=["asr";"land";"lor";"lsl";"lsr";"lxor";"mod";"or";":=";"!=";"::"]letwithout_parens=function|swhen(s.[0],s.[String.lengths-1])=('(',')')->String.subs1(String.lengths-2)|s->sletfixity_of_string=function|""->`Normal|swhenList.memsspecial_infix_strings->`Infixs|swhenList.mems.[0]infix_symbols->`Infixs|swhenList.mems.[0]prefix_symbols->`Prefixs|swhens.[0]='.'->`Mixfixs|_->`Normalletview_fixity_of_exp=function(* FIXME: properly check that it is safe to treat the operator as infix
within the quotation context *)|{desc=Identl;attributes=[]}->fixity_of_string(suffix_string_of_ident_valuel)|_->`Normalletprint_tuple_like?(with_space=true)delimopen_symclose_symprinterfmtentries=ppfmt"%s@["open_sym;(matchentrieswith|[]->()|e::es->printerfmte;List.iter(fune->ifwith_spacethenppfmt"%s@ %a"delimprintereelseppfmt"%s@,%a"delimprintere)es);ppfmt"@]%s"close_symletprint_label_tupprinterfmt(lab,entry)=matchlabwith|LabelledTups->ppfmt"~%s:%a"sprinterentry|NolabelTup->printerfmtentryletprint_arrayprinterfmtentries=print_tuple_like";""[|""|]"printerfmtentriesletprint_tupleprinterfmtentries=print_tuple_like",""("")"(print_label_tupprinter)fmtentriesletprint_obj_closedfmtclosed_flag=ppfmt"%s"(matchclosed_flagwithOOpen->".."|OClosed->"")letprint_prefixfmtrec_flag=matchrec_flagwith|Nonrecursive->ppfmt"let"|Recursive->ppfmt"let@ rec"letrecprint_vbenvfmt({pat;expr}:value_binding)=ppfmt"%a@ =@ @[<2>%a@]"(print_patenv)pat(print_exp_with_parensenv)exprandprint_constfmt=function|Intn->ppfmt"%d"n|Charc->ppfmt"\'%c\'"c|String(s,id_opt)->(matchid_optwith|None->ppfmt"\"%s\""s|Someid->ppfmt"{%s|@[%s@]|%s}"idsid)|Floats->ppfmt"%s"s|Float32s->ppfmt"%ss"s|Int32n->ppfmt"%ld"n|Int64n->ppfmt"%Ld"n|Nativeintn->ppfmt"%nd"n|UnboxedFloats->ppfmt"#%s"s|UnboxedFloat32s->ppfmt"#%ss"s|UnboxedInt32n->ppfmt"#%ldl"n|UnboxedInt64n->ppfmt"#%LdL"n|UnboxedNativeintn->ppfmt"#%ndn"nandprint_constrenvfmt=function|CBasics->ppfmt"%s"s|CIdentid->print_raw_ident_constructorenvfmtidandprint_module_typeenvfmt=function|MTBasics->ppfmt"%s"s|MTIdentid->print_raw_ident_module_typeenvfmtidandprint_fieldenvfmt=function|FBasics->ppfmt"%s"s|FIdentid->print_raw_ident_fieldenvfmtidandprint_pat_with_parensenvfmtpat=matchpatwith|PatAny|PatVar_|PatConstant_|PatTuple_|PatUnboxedTuple_|PatVariant(_,Some_)|PatRecord_|PatUnboxedRecord_|PatArray_->print_patenvfmtpat|_->ppfmt"(@[%a@])"(print_patenv)patandprint_patenvfmtpat=matchpatwith|PatAny->ppfmt"_"|PatVarv->Var.Value.printenvfmtv|PatAlias(pat,v)->ppfmt"%a@ as@ %a"(print_patenv)pat(Var.Value.printenv)v|PatConstantc->print_constfmtc|PatTuplets->print_tuple(print_patenv)fmtts|PatUnboxedTuplets->ppfmt"#%a"(print_tuple(print_patenv))ts|PatConstruct(ident,pat_opt)->(matchpat_optwith|None->print_constrenvfmtident|Somep->matchidentwith|CIdent(CBuiltin"::")->print_list_patenvfmtpat|_->ppfmt"%a@ %a"(print_constrenv)ident(print_pat_with_parensenv)p)|PatVariant(variant,pat_opt)->(matchpat_optwith|None->Variant.printfmtvariant|Somepat->ppfmt"%a@ %a"Variant.printvariant(print_patenv)pat)|PatRecord(entries,rec_flag)->ppfmt"{@[";List.iter(fun(field,pat)->ppfmt"%a=%a;@ "(print_fieldenv)field(print_patenv)pat)entries;ifrec_flag=OpenRecthenppfmt"_";ppfmt"@]}"|PatUnboxedRecord(entries,rec_flag)->ppfmt"#{@[";List.iter(fun(field,pat)->ppfmt"@[%a@ =@ %a;@]@ "(print_fieldenv)field(print_patenv)pat)entries;ifrec_flag=OpenRecthenppfmt"_";ppfmt"@]}"|PatArraypats->print_array(print_patenv)fmtpats|PatOr(pat1,pat2)->ppfmt"%a@ |@ %a"(print_patenv)pat1(print_patenv)pat2|PatConstraint(pat,ty)->ppfmt"(%a@ :@ %a)"(print_patenv)pat(print_core_typeenv)ty|PatLazypat->ppfmt"lazy@ (%a)"(print_patenv)pat|PatAnyModule->ppfmt"module _"|PatUnpackv->ppfmt"module@ %a"(Var.Module.printenv)v|PatExceptionpat->ppfmt"(exception@ %a)"(print_patenv)patandprint_type_constraintenvfmt=function|Constraintty->ppfmt"%@ :@ @[%a@]"(print_core_typeenv)ty|Coerce(None,ty)->ppfmt"%@ :>@ @[%a@]"(print_core_typeenv)ty|Coerce(Somety_constr,ty)->ppfmt"%@ :@ @[%a@]@ :>@ @[%a@]"(print_core_typeenv)ty_constr(print_core_typeenv)tyandprint_exp_with_parensenvfmtexp=matchexp.descwith|Ident_|Constant_|Tuple_|Construct(_,None)|Variant(_,None)|Record(_,None)|Field_|Array_|Send_|Unreachable|Src_pos|Unboxed_tuple_|Unboxed_record_product(_,None)|List_comprehension_|Array_comprehension_|Quote_->(print_expenv)fmtexp|_->ppfmt"(@[%a@])"(print_expenv)expandprint_caseenvfmt{lhs;guard;rhs}=ppfmt"@ |@ %a"(print_patenv)lhs;(matchguardwith|None->()|Someguard->ppfmt"@ with@ %a"(print_exp_with_parensenv)guard);ppfmt"@ ->@ ";matchrhswithNone->ppfmt"."|Somerhs->print_expenvfmtrhsandprint_row_fieldenvwith_orfmtrf=ifwith_orthenppfmt"@ |@ ";matchrfwith|Vinheritty->print_core_typeenvfmtty|Vtag(_,false,[])->()(* fatal_error "Invalid polymorphic variant type" *)|Vtag(variant,true,[])->ppfmt"%a"Variant.printvariant|Vtag(variant,true,tys)->ppfmt"%a@ of"Variant.printvariant;List.iter(funty->ppfmt"@ &@ %a"(print_core_type_with_arrowenv)ty)tys|Vtag(variant,false,ty::tys)->ppfmt"%a@ of@ %a"Variant.printvariant(print_core_type_with_arrowenv)ty;List.iter(funty->ppfmt"@ &@ %a"(print_core_type_with_arrowenv)ty)tysandprint_fragmentfmt=function|Names->Name.printfmts|Dot(frag,s)->ppfmt"%a.%a"print_fragmentfragName.printsandprint_core_type_with_arrowenvfmtty=matchtywith|TypeArrow_->ppfmt"(@[%a@])"(print_core_typeenv)ty|_->print_core_typeenvfmttyandprint_core_type_with_parensenvfmtty=matchtywith|TypeArrow_|TypeTuple_|TypeConstr_|TypeAlias_|TypePoly_->ppfmt"(@[%a@])"(print_core_typeenv)ty|_->print_core_typeenvfmttyandprint_object_fieldenvfmt=function|Oinheritty->ppfmt"<inherit %a TODO>"(print_core_typeenv)ty|Otag(name,ty)->ppfmt"%a@ :@ %a"Name.printname(print_core_typeenv)tyandprint_module_expenvfmt=function|ModuleIdentident->print_raw_ident_moduleenvfmtident|ModuleApply(module_1,module_2)->ppfmt"%a(@[%a@])"(print_module_expenv)module_1(print_module_expenv)module_2|ModuleApply_unitmodule_->ppfmt"%a()"(print_module_expenv)module_andprint_core_typeenvfmt=function|TypeAny->ppfmt"_"|TypeVarv->Var.Type_var.printenvfmtv|TypeArrow(arg_label,ty1,ty2)->ppfmt"%a%a@ ->@ %a"print_arg_labarg_label(print_core_type_with_arrowenv)ty1(print_core_typeenv)ty2|TypeTuple((tl,ty)::ts)->(matchtlwith|LabelledTupl->ppfmt"%s:%a"l(print_core_type_with_parensenv)ty|NolabelTup->print_core_type_with_parensenvfmtty);List.iter(fun(tl,ty)->ppfmt" * ";matchtlwith|LabelledTupl->ppfmt"%s:%a"l(print_core_type_with_parensenv)ty|NolabelTup->print_core_type_with_parensenvfmtty)ts|TypeTuple[]->()(* fatal_error "Invalid tuple type" *)|TypeUnboxedTuple((tl,ty)::ts)->(matchtlwith|LabelledTupl->ppfmt"%s:%a"l(print_core_type_with_parensenv)ty|NolabelTup->print_core_type_with_parensenvfmtty);List.iter(fun(tl,ty)->ppfmt" * ";matchtlwith|LabelledTupl->ppfmt"%s:%a"l(print_core_type_with_parensenv)ty|NolabelTup->print_core_type_with_parensenvfmtty)ts(* possibly incorrect way of displaying unboxed tuples *)|TypeUnboxedTuple[]->()(* fatal_error "Invalid unboxed tuple type" *)|TypeConstr(ident,[])->print_raw_ident_typeenvfmtident|TypeConstr(ident,[ty])->ppfmt"%a@ %a"(print_core_type_with_parensenv)ty(print_raw_ident_typeenv)ident|TypeConstr(ident,ty::tys)->print_tuple_like",""("")"(print_core_typeenv)fmt(ty::tys);ppfmt"@ %a"(print_raw_ident_typeenv)ident|TypeObject([],closed_flag)->ppfmt"< %a >"print_obj_closedclosed_flag|TypeObject(f::fs,closed_flag)->ppfmt"<@ @[";print_tuple_like","""""(print_object_fieldenv)fmt(f::fs);print_obj_closedfmtclosed_flag;ppfmt"@]@ >"|TypeClass(name,[])->Name.printfmtname|TypeClass(name,[ty])->ppfmt"[%a]@ %a"(print_core_typeenv)tyName.printname|TypeClass(name,ty::tys)->print_tuple_like",""[""]"(print_core_typeenv)fmt(ty::tys);ppfmt"@ %a"Name.printname|TypeAlias(ty,tv)->ppfmt"%a@ as@ %a"(print_core_typeenv)tyName.printtv|TypeVariant([],_)->()(* fatal_error "Invalid variant type" *)|TypeVariant(rf::row_fields,variant_form)->(matchvariant_formwith|VFixed->ppfmt"[ "|VOpen->ppfmt"[> "|VClosed_->ppfmt"[< ");print_row_fieldenvfalsefmtrf;List.iter(print_row_fieldenvtruefmt)row_fields;ppfmt" ]"|TypePoly([],_)->()(* fatal_error "Invalid poly-type" *)|TypePoly(tv::tvs,ty)->print_tuple_like"""""."(Var.Type_var.printenv)fmt(tv::tvs);ppfmt"@ %a"(print_core_typeenv)ty|TypePackage(ident,[])->print_module_typeenvfmtident|TypePackage(ident,(fragment,core_type)::wcs)->ppfmt"@[%a@ with@ type@ %a@ =@ %a"(print_module_typeenv)identprint_fragmentfragment(print_core_typeenv)core_type;List.iter(fun(fragment,core_type)->ppfmt"@ and@ type@ %a@ =@ %a"print_fragmentfragment(print_core_typeenv)core_type)wcs;ppfmt"@]"|TypeQuotecore_type->ppfmt"@[<2><[@,%a@,]>@]"(print_core_typeenv)core_type|TypeCallPos->ppfmt"call_pos"andprint_arg_labfmt=function|Nolabel->ppfmt""|Labelleds->ppfmt"~%s:"s|Optionals->ppfmt"?%s:"sandprint_paramenvfmt=function|Pparam_val(arg_lab,None,pat)->ppfmt"@ %a%a"print_arg_labarg_lab(print_patenv)pat|Pparam_val(arg_lab,Someexp,pat)->ppfmt"@ %a%a=(@[%a@])"print_arg_labarg_lab(print_patenv)pat(print_expenv)exp|Pparam_newtypety->ppfmt"@ (type@ %a)"(Var.Type_constr.printenv)tyandprint_recordenvfmt(fields,exp_opt)=ppfmt"@[<2>{@ ";(matchexp_optwith|None->()|Someexp->ppfmt"%a@ with@ "(print_expenv)exp);List.iter(fun(field,exp)->ppfmt"%a@ =@ %a;@ "(print_fieldenv)field(print_expenv)exp)fields;ppfmt"@]}"andprint_attributefmtattr=ppfmt"@ [%@%s]"(attribute_as_stringattr)andprint_applyenvfmtexpargs=ppfmt"@[<2>%a"(print_exp_with_parensenv)exp;List.iter(fun(arg_lab,exp)->ppfmt"@ %a@[%a@]"print_arg_labarg_lab(print_exp_with_parensenv)exp)args;ppfmt"@]"andprint_list_patenvfmtpat=letreclist_items_and_conspat=matchpatwith|PatConstruct(CIdent(CBuiltin"::"),Somep)->(matchpwith|PatTuple[(NolabelTup,p);(NolabelTup,tl)]->letremainder,has_cons=list_items_and_constlinp::remainder,has_cons|_->failwith"Unexpected list contents encountered.")|PatConstruct(CIdent(CBuiltin"[]"),None)->[],false|_->[pat],trueinletitems,has_cons=list_items_and_conspatinifhas_consthenprint_tuple_like~with_space:false"::"""""(print_pat_with_parensenv)fmtitemselseprint_tuple_like";""[""]"(print_patenv)fmtitemsandprint_list_expenvfmtexp=letreclist_items_and_consexp=matchexp.descwith|Construct(CIdent(CBuiltin"::"),Somee)->(matche.descwith|Tuple[(NolabelTup,e);(NolabelTup,tl)]->letremainder,has_cons=list_items_and_constline::remainder,has_cons|_->failwith"Unexpected list contents encountered.")|Construct(CIdent(CBuiltin"[]"),None)->[],false|_->[exp],trueinletitems,has_cons=list_items_and_consexpinifhas_consthenprint_tuple_like~with_space:false"::"""""(print_exp_with_parensenv)fmtitemselseprint_tuple_like";""[""]"(print_expenv)fmtitemsandprint_exp_descenvfmtexp=matchexp.descwith|Identid->print_raw_ident_valueenvfmtid|Constantc->print_constfmtc|Apply(exp,args)->(matchview_fixity_of_expexpwith|`Infixs->(matchargswith|[(Nolabel,arg1);(Nolabel,arg2)]->ppfmt"@[<2>%a@;%s@;%a@]"(print_exp_with_parensenv)arg1s(print_exp_with_parensenv)arg2|_->print_applyenvfmtexpargs)|`Prefixs->(matchargswith|[(Nolabel,arg)]->ppfmt"@[<2>%s@;%a@]"s(print_exp_with_parensenv)arg|_->print_applyenvfmtexpargs)|_->print_applyenvfmtexpargs)|Fun{params;constraint_;body}->(matchbodywith|Pfunction_bodyexp->ppfmt"@[<2>fun";List.iter(print_paramenvfmt)params;Option.iter(print_type_constraintenvfmt)constraint_;ppfmt"@ ->@ %a@]"(print_expenv)exp|Pfunction_casescases->ppfmt"function@[";List.iter(print_caseenvfmt)cases;Option.iter(print_type_constraintenvfmt)constraint_;ppfmt"@]")|Let(_,[],_)->failwith"Cannot create empty let-expressions. This should not happen."|Let(rec_flag,vb::vbs,body)->ppfmt"@[@[%a@ %a@]@ "print_prefixrec_flag(print_vbenv)vb;List.iter(funvb->ppfmt"@[and@ %a@]@ "(print_vbenv)vb)vbs;ppfmt"in@;@[<2>%a@]@]"(print_expenv)body|Let_op([],_,_)->failwith"Cannot create empty let-expressions. This should not happen."|Let_op(binders,defs,case)->(letbind_lefts=matchcase.lhswithPatTuplel->l|pat->[NolabelTup,pat]inletreciter3fxsyszs=matchxs,ys,zswith|[],[],[]->()|x::xs,y::ys,z::zs->fxyz;iter3fxsyszs|_->failwith"Lists should have equal length."inppfmt"@[";iter3(funbinder(_,pat_bind)def->ppfmt"@[%s@ %a@ =@ @[<2>%a@]@]@ "(without_parens(suffix_string_of_ident_valuebinder))(print_patenv)pat_bind(print_expenv)def)bindersbind_leftsdefs;matchcase.rhswith|Someexp->ppfmt"in@;@[<2>%a@]@]"(print_expenv)exp|None->ppfmt".@]")|Exclaveexp->ppfmt"exclave_@ %a"(print_expenv)exp|Construct(ident,exp_opt)->(matchexp_optwith|None->print_constrenvfmtident|Somee->matchidentwith|CIdent(CBuiltin"::")->print_list_expenvfmtexp|_->ppfmt"%a@ %a"(print_constrenv)ident(print_exp_with_parensenv)e)|Variant(s,exp_opt)->(matchexp_optwith|None->ppfmt"`%s"s|Someexp->ppfmt"`%s@ %a"s(print_exp_with_parensenv)exp)|Record(fields,exp_opt)->print_recordenvfmt(fields,exp_opt)|Field(exp,field)->ppfmt"%a.%a"(print_exp_with_parensenv)exp(print_fieldenv)field|Arrayentries->print_array(print_exp_with_parensenv)fmtentries|Tupleentries->print_tuple(print_exp_with_parensenv)fmtentries|Ifthenelse(cond,then_,else_)->(ppfmt"@[if@ %a@ @[<2>then@ %a@]"(print_exp_with_parensenv)cond(print_exp_with_parensenv)then_;matchelse_with|Someelse_->ppfmt"@ @[<2>else@ %a@]@]"(print_expenv)else_|None->ppfmt"@]")|Sequence(exp1,exp2)->ppfmt"%a;@ @,%a"(print_expenv)exp1(print_expenv)exp2|While(cond,body)->ppfmt"@[<2>while@ %a@ do@; @[%a@]@]@;done"(print_expenv)cond(print_exp_with_parensenv)body|For(it,start,stop,dir,body)->letdir=matchdirwithUpto->"to"|Downto->"downto"inppfmt"for@ %a@ =@ %a@ %s@ %a@ do@ @,@[<2>%a@]@ @,done"(print_patenv)it(print_expenv)startdir(print_expenv)stop(print_exp_with_parensenv)body|Send(exp,meth)->ppfmt"%a#@[%a@]"(print_exp_with_parensenv)expMethod.printmeth|ConstraintExp(exp,ty)->ppfmt"%a@ :@ %a"(print_expenv)exp(print_core_typeenv)ty|CoerceExp(exp,opt_ty,ty)->(matchopt_tywith|None->ppfmt"%a@ :>@ %a"(print_expenv)exp(print_core_typeenv)ty|Somety_constr->ppfmt"%a@ :@ %a@ :>@ %a"(print_expenv)exp(print_core_typeenv)ty_constr(print_core_typeenv)ty)|Match(exp,cases)->ppfmt"@[<2>match@ @[%a@]@ with"(print_expenv)exp;List.iter(print_caseenvfmt)cases;ppfmt"@]"|Try(try_,with_)->(ppfmt"@[<2>try@ %a"(print_expenv)try_;matchwith_with|[]->()|with_->ppfmt"@ @[<2>with@ ";List.iter(funcase->ppfmt"%a"(print_caseenv)case)with_;ppfmt"@]");ppfmt"@]"|Setfield(obj,field,exp)->ppfmt"%a#%a <- %a"(print_exp_with_parensenv)obj(print_fieldenv)field(print_expenv)exp|Letmodule(None,module_exp,exp)->ppfmt"@[<2>let@ module@ _@ =@ @[%a@]@ in@ %a@]"(print_module_expenv)module_exp(print_expenv)exp|Letmodule(Somemodvar,module_exp,exp)->ppfmt"@[<2>let@ module@ %a@ =@ @[%a@]@ in@ %a@]"(Var.Module.printenv)modvar(print_module_expenv)module_exp(print_expenv)exp|Assertexp->ppfmt"@[<2>assert@ %a@]"(print_expenv)exp|Lazyexp->ppfmt"@[<2>lazy@ %a@]"(print_expenv)exp|Packmodule_exp->ppfmt"(@[<2>module@ %a@])"(print_module_expenv)module_exp|Newident->ppfmt"@[<2>new@ %a@]"(print_raw_ident_valueenv)ident|Stackexp->ppfmt"@[<2>stack_@ %a@]"(print_exp_with_parensenv)exp|Let_exception(name,exp)->ppfmt"@[<2>let@ exception@ %s@ in@ %a@]"name(print_expenv)exp|Extension_constructorname->ppfmt"@[[%%extension_constructor@ %a]@]"Name.printname|Unboxed_tuplets->ppfmt"#";print_tuple(print_expenv)fmtts|Unboxed_record_product(ts,exp_opt)->print_recordenvfmt(ts,exp_opt)|Unboxed_field(exp,rec_field)->ppfmt"#%a.%a"(print_expenv)exp(print_fieldenv)rec_field|Quoteexp->ppfmt"@[<2><[@,%a@,@]]>"(print_expenv)exp|Antiquoteexp->ppfmt"@[<2>$@,%a@]"(print_exp_with_parensenv)exp|List_comprehension_|Array_comprehension_->ppfmt"(* comprehension *)"|Evaltyp->ppfmt"@[<2>[%%eval:@ %a]@]"(print_core_typeenv)typ|Unreachable|Src_pos->ppfmt"."andprint_expenvfmtexp=print_exp_descenvfmtexp;List.iter(print_attributefmt)exp.attributesendmoduleLabel=structtypet=Ast.arg_labelmoduleNonoptional=structtypet=Ast.tuple_labelletno_label=Ast.NolabelTupletlabelleds=Ast.LabelledTupsendletno_label=Ast.Nolabelletlabelleds=Ast.Labelledsletoptionals=Ast.OptionalsendmoduleFragment=structtypet=Ast.fragmentletnames=Ast.Namesletdotfs=Ast.Dot(f,s)endmoduleConstant=structtypet=Ast.constantletinti=Ast.Intiletcharc=Ast.Charcletstringsid=Ast.String(s,id)letfloatf=Ast.Floatfletfloat32f=Ast.Float32fletint32i=Ast.Int32iletint64i=Ast.Int64iletnativeinti=Ast.Nativeintiletunboxed_int32i=Ast.UnboxedInt32iletunboxed_int64i=Ast.UnboxedInt64iletunboxed_nativeinti=Ast.UnboxedNativeintiletunboxed_floatf=Ast.UnboxedFloatfletunboxed_float32f=Ast.UnboxedFloat32fendmoduleBinding_error=structletunexpectedvarloc:unit=letmsg=Format.asprintf"Unexpected binding detected for the identifier %s from %a at %a"(Var.namevar)Loc.print(Var.locvar)Loc.printlocinfailwithmsgletunexpected_at_loclocvar:unit=unexpectedvarlocletmissingvar:unit=letmsg=Format.asprintf"Missing binding for the identifier %s at %a"(Var.namevar)Loc.print(Var.locvar)infailwithmsgletduplicatevar=letmsg=Format.asprintf"Duplicate bindings detected for the identifier %s at %a"(Var.namevar)Loc.print(Var.locvar)infailwithmsgletmismatchvar=letmsg=Format.asprintf"Mismatched bindings detected for the identifier %s at %a"(Var.namevar)Loc.print(Var.locvar)infailwithmsgletcode_not_closedvarloc=letmsg=Format.asprintf"The code built at %a is not closed: identifier %s bound at %a is free"Loc.printloc(Var.namevar)Loc.print(Var.locvar)infailwithmsgendmoduleModule_type=structtypet=Ast.module_typeWith_free_vars.tlet(let+)xf=With_free_vars.mapfxletreturn=With_free_vars.returnletidentid=let+id=idinAst.MTIdentidletof_strings=return(Ast.MTBasics)endmoduleConstructor=structtypet=Ast.constrWith_free_vars.tlet(let+)mf=With_free_vars.mapfmletreturn=With_free_vars.returnletidentid=let+id=idinAst.CIdentidletof_strings=return(Ast.CBasics)endmoduleField=structtypet=Ast.record_fieldWith_free_vars.tlet(let+)mf=With_free_vars.mapfmletreturn=With_free_vars.returnletidentid=let+id=idinAst.FIdentidletof_strings=return(Ast.FBasics)endmoduleObject_field=structtypet=Ast.object_fieldWith_free_vars.tlet(let+)mf=With_free_vars.mapfmletinherit_ty=let+ty=tyinAst.Oinherittylettagnamety=let+ty=tyinAst.Otag(name,ty)endmodulePat=structopenWith_free_and_bound_varstypet=Ast.patternWith_free_and_bound_vars.tlet(let+)xf=mapfxlet(and+)t1t2=meet~duplicated:Binding_error.duplicatet1t2letallts=meet_all~duplicated:Binding_error.duplicatetsletjoint1t2=join~left_only:Binding_error.mismatch~right_only:Binding_error.mismatcht1t2letany=returnAst.PatAnyletvarv=let+var=bound_value_varvinAst.PatVarvarletaliastv=let+p=tand+v=bound_value_varvinAst.PatAlias(p,v)letconstantconst=return(Ast.PatConstantconst)lettuplets=letps=List.map(fun(lab,e)->let+v=einlab,v)tsinlet+ps=allpsinAst.PatTuplepsletunboxed_tuplets=letps=List.map(fun(lab,e)->let+v=einlab,v)tsinlet+ps=allpsinAst.PatUnboxedTuplepsletconstructlidtm=let+pm=optionaltmand+id=with_no_bound_varslidinAst.PatConstruct(id,pm)letvariantlabeltm=let+pm=optionaltminAst.PatVariant(Variant.of_stringlabel,pm)letrecordfieldsclosed=letclosed_ast=ifclosedthenAst.ClosedRecelseAst.OpenRecinletts=List.map(fun(lid,t)->let+lbl=with_no_bound_varslidand+p=tinlbl,p)fieldsinlet+ps=alltsinAst.PatRecord(ps,closed_ast)letunboxed_recordfieldsclosed=letclosed_ast=ifclosedthenAst.ClosedRecelseAst.OpenRecinletts=List.map(fun(lid,t)->let+lbl=with_no_bound_varslidand+p=tinlbl,p)fieldsinlet+ps=alltsinAst.PatUnboxedRecord(ps,closed_ast)letarrayts=let+ps=alltsinAst.PatArraypsletor_t1t2=let+p1,p2=joint1t2inAst.PatOr(p1,p2)letlazy_t=let+p=tinAst.PatLazypletany_module=returnAst.PatAnyModuleletunpackv=let+v=bound_module_varvinAst.PatUnpackvletexception_t=let+p=tinAst.PatExceptionpletconstraint_patty=let+pat=patand+ty=with_no_bound_varstyinAst.PatConstraint(pat,ty)endmoduleExp_attribute=structtypet=Ast.expression_attributeletinline=Ast.Inlineletinlined=Ast.Inlinedletspecialise=Ast.Specialiseletspecialised=Ast.Specialisedletunrolled=Ast.Unrolledletnontail=Ast.Nontaillettail=Ast.Tailletpoll=Ast.Pollletloop=Ast.Looplettail_mod_cons=Ast.Tail_mod_consletquotation=Ast.QuotationendmoduleVariant_type=structmoduleVariant_form=structtypet=|Fixed|Open|Closedofstringlistletfixed=Fixedletopen_=Openletcloseds=Closedsletto_ast_variant_form=function|Fixed->Ast.VFixed|Open->Ast.VOpen|Closedl->Ast.VClosedlendmoduleRow_field=structtypet=Ast.row_fieldWith_free_vars.tlet(let+)mf=With_free_vars.mapfmletinherit_ty=let+ty=tyinAst.Vinherittylettagvarianthas_emptytypes=let+types=With_free_vars.alltypesinAst.Vtag(variant,has_empty,types)endtypet=Ast.row_fieldlistWith_free_vars.t*Ast.variant_formletof_row_fields_listrow_fieldsvariant_form=With_free_vars.allrow_fields,Variant_form.to_ast_variant_formvariant_formendmoduleType=structtypet=Ast.core_typeWith_free_vars.tlet(let+)mf=With_free_vars.mapfmlet(and+)=With_free_vars.bothletall=With_free_vars.allletvar=function|None->With_free_vars.returnAst.TypeAny|Sometv->With_free_vars.return(Ast.TypeVartv)letarrowlablhsrhs=let+l=lhsand+r=rhsinAst.TypeArrow(lab,l,r)lettuplets=letw=List.map(fun(lab,t)->let+t=tinlab,t)tsinlet+e=allwinAst.TypeTupleeletunboxed_tuplets=letw=List.map(fun(lab,t)->let+t=tinlab,t)tsinlet+e=allwinAst.TypeUnboxedTupleeletconstrconstyps=let+ts=alltypsand+cons=consinAst.TypeConstr(cons,ts)letobject_object_fieldsis_closed=letclosed_flag=ifis_closedthenAst.OClosedelseAst.OOpeninlet+object_fields=allobject_fieldsinAst.TypeObject(object_fields,closed_flag)letclass_nametys=let+tys=alltysinAst.TypeClass(name,tys)letaliastyptv=let+t=typinAst.TypeAlias(t,Var.Type_var.nametv)letvariantvty=letrfs,form=vtyinlet+rfs=rfsinAst.TypeVariant(rfs,form)letpolylocnamesf=With_free_vars.type_var_bindingslocnames(funtvs->let+t=ftvsinAst.TypePoly(tvs,t))letpackagemspec=lets=List.map(fun(frag,typ)->let+t=typinfrag,t)specinlet+specs=allsand+m=minAst.TypePackage(m,specs)letquotet=let+t=tinAst.TypeQuotetletcall_pos=With_free_vars.returnAst.TypeCallPosendmoduleModule=structtypet=Ast.module_exprWith_free_vars.tlet(let+)mf=With_free_vars.mapfmlet(and+)=With_free_vars.bothletidentid=let+id=idinAst.ModuleIdentidletapplyfuncarg=let+func=funcand+arg=arginAst.ModuleApply(func,arg)letapply_unitfunc=let+func=funcinAst.ModuleApply_unitfuncendmoduleCase=structtypet=Ast.caseWith_free_vars.tletmklhsguardrhs:Ast.case={lhs;guard;rhs}let(let+)mf=With_free_vars.mapfmlet(and+)=With_free_vars.bothletnonbindingloc(pat:Pat.t)exp=let+pat=patand+rhs=expinletlhs=With_bound_vars.value_nonbinding~extra:(Binding_error.unexpected_at_locloc)patinmklhsNone(Somerhs)letsimplelocnamef=With_free_vars.value_bindinglocname(funvar->let+rhs=fvarinmk(Ast.PatVarvar)None(Somerhs))letpatternloc~bound_values~bound_modulesf=let+lhs,rhs=With_free_vars.complex_bindingsloc~extra:(Binding_error.unexpected_at_locloc)~missing:Binding_error.missing~bound_values~bound_modulesfinmklhsNone(Somerhs)letguardedloc~bound_values~bound_modulesf=let+lhs,(guard,rhs)=With_free_vars.complex_bindingsloc~extra:(Binding_error.unexpected_at_locloc)~missing:Binding_error.missing~bound_values~bound_modules(funvalue_varsmodule_vars->letlhs,guard,rhs=fvalue_varsmodule_varsinlhs,With_free_vars.bothguardrhs)inmklhs(Someguard)(Somerhs)letrefutationloc~bound_values~bound_modulesf=let+lhs,_=With_free_vars.complex_bindingsloc~extra:(Binding_error.unexpected_at_locloc)~missing:Binding_error.missing~bound_values~bound_modules(funvm->fvm,With_free_vars.return())inmklhsNoneNoneendmoduleType_constraint=structtypet=Ast.type_constraintWith_free_vars.tlet(let+)mf=With_free_vars.mapfmlet(and+)=With_free_vars.bothletconstraint_typ=let+typ=typinAst.Constrainttypletcoerciontyp1typ2=let+typ1=With_free_vars.optionaltyp1and+typ2=typ2inAst.Coerce(typ1,typ2)endmoduleFunction=structtypet=Ast.function_With_free_vars.tlet(let+)mf=With_free_vars.mapfmlet(and+)=With_free_vars.bothletmkparamsconstraint_body:Ast.function_={params;constraint_;body}letbodyeconstraint_=let+b=eand+constraint_=With_free_vars.optionalconstraint_inmk[]constraint_(Ast.Pfunction_bodyb)letcasesclconstraint_=let+c=With_free_vars.allcland+constraint_=With_free_vars.optionalconstraint_inmk[]constraint_(Ast.Pfunction_casesc)letparamlabexplocnamesrest=With_free_vars.value_bindingslocnames(funvars->letpat,fn=restvarsinlet+pat=patand+({params;constraint_;body}:Ast.function_)=fnand+e=With_free_vars.optionalexpinletpat=With_bound_vars.value~extra:(Binding_error.unexpected_at_locloc)~missing:Binding_error.missingpat(Var.Value.generic_listvars)inmk(Ast.Pparam_val(lab,e,pat)::params)constraint_body)letparam_module_nonbindinglablocpatfn=let+pat=patand+({params;constraint_;body}:Ast.function_)=fninletpat=With_bound_vars.value_nonbinding~extra:(Binding_error.unexpected_at_locloc)patinmk(Ast.Pparam_val(lab,None,pat)::params)constraint_bodyletparam_modulelablocnamerest=With_free_vars.module_bindinglocname(funvar->letpat,fn=restvarinlet+({params;constraint_;body}:Ast.function_)=fnand+pat=patinletpat=With_bound_vars.value~extra:(Binding_error.unexpected_at_locloc)~missing:Binding_error.missingpat[Var.Module.genericvar]inmk(Ast.Pparam_val(lab,None,pat)::params)constraint_body)letnewtypelocnamef=With_free_vars.type_bindinglocname(funtyp->let+({params;constraint_;body}:Ast.function_)=ftypinmk(Ast.Pparam_newtypetyp::params)constraint_body)endmoduleComprehension=structtypet=Ast.comprehensionWith_free_vars.tlet(let+)mf=With_free_vars.mapfmlet(and+)=With_free_vars.bothletbodyexp=let+exp=expinAst.Bodyexpletwhen_clauseexpcompr=let+exp=expand+compr=comprinAst.When(compr,exp)letfor_rangelocnamestartstopdirectioncompr=With_free_vars.value_bindinglocname(funvar->let+start=startand+stop=stopand+compr=comprvarinletdir=ifdirectionthenAst.UptoelseAst.DowntoinAst.ForComp(compr,Ast.Range(var,start,stop,dir)))letfor_inlocexpnamescompr=With_free_vars.value_bindingslocnames(funvars->letpat,compr=comprvarsinlet+pat=patand+compr=comprand+exp=expinletp=With_bound_vars.value~extra:(Binding_error.unexpected_at_locloc)~missing:Binding_error.missingpat(Var.Value.generic_listvars)inAst.ForComp(compr,Ast.In(p,exp)))endmoduleCode=structtypecode_rep={exp:Ast.expression;_loc:Loc.t}typet=code_repWith_free_vars.tlet(let+)mf=With_free_vars.mapfmletto_expcode=let+{exp;_}=codeinexpletof_exp_locexp=let+exp=expin{exp;_loc}letof_exp_with_type_vars_locnamesbody=let+exp=With_free_vars.type_var_bindings_locnamesbodyin{exp;_loc}moduleClosed=structtypeexp=ttypet=code_repletclosecode=With_free_vars.value~free:Binding_error.code_not_closedcodeletopen_=With_free_vars.returnendletprintfmtc=letast_exp=With_free_vars.value~free:(fun__->())cinFormat.fprintffmt"@[<2><[@,%a@]@,]>"(Ast.print_exp(new_env()))ast_exp.expendmoduleExp_desc=structtypet=Ast.expression_descWith_free_vars.tlet(let+)mf=With_free_vars.mapfmlet(and+)=With_free_vars.bothletall=With_free_vars.allletoptional=With_free_vars.optionalletreturn=With_free_vars.returnletmk_vbpatexpr:Ast.value_binding={pat;expr}letidentid=let+id=idinAst.Identidletconstant(const:Constant.t)=return(Ast.Constantconst)letlet_rec_simplelocnamesf=With_free_vars.value_bindingslocnames(funvars->letdefs,body=fvarsinlet+defs=alldefsand+body=bodyinletvbs_rev=List.rev_map2(funvardef->letpat=Ast.PatVarvarinmk_vbpatdef)varsdefsinletvbs=List.revvbs_revinAst.Let(Recursive,vbs,body))letlet_locnames_valuesnames_modulesdefsf=let+defs=alldefsand+pats,body=With_free_vars.complex_bindingsloc~extra:Binding_error.duplicate~missing:Binding_error.missing~bound_values:names_values~bound_modules:names_modulesfinmatchpatswith|Ast.PatTuplepats->letvbs=List.map2(fun(_,pat)def->mk_vbpatdef)patsdefsinAst.Let(Nonrecursive,vbs,body)|_->failwith"Cannot use non-tuple patterns in building let-expressions."letfunction_fn=let+fn=fninAst.Funfnletapplyfnargs=letargs=List.map(fun(lab,arg)->let+exp=arginlab,exp)argsinlet+args=allargsand+fn=fninAst.Apply(fn,args)letmatch_expcases=let+cases=allcasesand+exp=expinAst.Match(exp,cases)lettry_expcases=let+cases=allcasesand+exp=expinAst.Try(exp,cases)lettuplefs=letentries=List.map(fun(lab,exp)->let+exp=expinlab,exp)fsinlet+entries=allentriesinAst.Tupleentriesletconstructconsexp=let+exp=optionalexpand+cons=consinAst.Construct(cons,exp)letvariantvexp=let+exp=optionalexpinAst.Variant(v,exp)letrecordentriesexp=letentries=List.map(fun(field,e)->let+e=eand+field=fieldinfield,e)entriesinlet+entries=allentriesand+exp=optionalexpinAst.Record(entries,exp)letfieldexpfield=let+exp=expand+field=fieldinAst.Field(exp,field)letsetfieldexpfieldvalue=let+exp=expand+field=fieldand+value=valueinAst.Setfield(exp,field,value)letarrayelements=let+elements=allelementsinAst.Arrayelementsletifthenelsecondthen_else_=let+cond=condand+then_=then_and+else_=optionalelse_inAst.Ifthenelse(cond,then_,else_)letsequencelhsrhs=let+lhs=lhsand+rhs=rhsinAst.Sequence(lhs,rhs)letwhile_condbody=let+cond=condand+body=bodyinAst.While(cond,body)letfor_nonbindinglocpatbegin_end_dirbody=letdir=ifdirthenAst.UptoelseAst.Downtoinlet+body=bodyand+pat=patand+begin_=begin_and+end_=end_inletpat=With_bound_vars.value_nonbinding~extra:(Binding_error.unexpected_at_locloc)patinAst.For(pat,begin_,end_,dir,body)letfor_simplelocnamebegin_end_dirbody=letdir=ifdirthenAst.UptoelseAst.Downtoinlet+var,body=With_free_vars.value_bindinglocname(funvar->let+body=bodyvarinvar,body)and+begin_=begin_and+end_=end_inAst.For(Ast.PatVarvar,begin_,end_,dir,body)letsendexpmeth=let+exp=expinAst.Send(exp,meth)letassert_exp=let+exp=expinAst.Assertexpletlazy_exp=let+exp=expinAst.Lazyexpletletmodule_nonbindingmod_expbody=let+mod_exp=mod_expand+body=bodyinAst.Letmodule(None,mod_exp,body)letletmodulelocnamemod_expbody=let+mod_exp=mod_expand+var,body=With_free_vars.module_bindinglocname(funm->let+body=bodyminm,body)inAst.Letmodule(Somevar,mod_exp,body)letconstraint_expconstr=let+exp=expand+constr=constrinmatchconstrwith|Ast.Coerce(ty_opt,ty_to)->Ast.CoerceExp(exp,ty_opt,ty_to)|Ast.Constraintty->Ast.ConstraintExp(exp,ty)letnew_class_id=let+class_id=class_idinAst.Newclass_idletpackm=let+m=minAst.Packmletunreachable=returnAst.Unreachableletsrc_pos=returnAst.Src_posletexclaveexp=let+exp=expinAst.Exclaveexpletlist_comprehensioncompr=let+compr=comprinAst.List_comprehensioncomprletarray_comprehensioncompr=let+compr=comprinAst.Array_comprehensioncomprletunboxed_tuplefs=letentries=List.map(fun(lab,exp)->let+exp=expinlab,exp)fsinlet+entries=allentriesinAst.Unboxed_tupleentriesletunboxed_record_productentriesexp=letentries=List.map(fun(field,e)->let+e=eand+field=fieldinfield,e)entriesinlet+entries=allentriesand+exp=optionalexpinAst.Unboxed_record_product(entries,exp)letunboxed_fieldexpfield=let+exp=expand+field=fieldinAst.Unboxed_field(exp,field)letextension_constructorname=return(Ast.Extension_constructorname)letlet_exceptionnameexp=let+exp=expinAst.Let_exception(name,exp)letlet_opidentsdefscase=let+idents=allidentsand+defs=alldefsand+case=caseinAst.Let_op(idents,defs,case)letstackexp=let+exp=expinAst.Stackexpletquoteexp=let+exp=expinAst.Quoteexpletantiquoteexp=let+exp=expinAst.Antiquoteexpletsplicecode=let+exp=Code.to_expcodeinAst.(exp.desc)letevaltyp=let+typ=typinAst.EvaltypendmoduleExp=structtypet=Ast.expressionWith_free_vars.tlet(let+)xf=With_free_vars.mapfxletmkexp_descattributes=let+desc=exp_descin({desc;attributes}:Ast.expression)letprintfmtexp=letast=With_free_vars.value~free:(fun__->())expinAst.print_exp(new_env())fmtastend