123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2022 Nomadic Labs <contact@nomadic-labs.com> *)(* Copyright (c) 2022 DaiLambda, Inc. <contact@dailambda,jp> *)(* *)(* 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. *)(* *)(*****************************************************************************)openProtocolopenEnvironmentopenError_monadopenAlpha_contextopenScript_typed_irmoduleStack_utils=structtypekinstr_rewritek={apply:'b'u'r'f.('b,'u)stack_ty->('b,'u,'r,'f)kinstr->('b,'u,'r,'f)kinstr;}[@@ocaml.unboxed](* An existential wrapper around failed [kinstr], whose final stack type
is hidden as it is irrelevant. *)type('a,'s)failed_kinstr_cast={cast:'b'u.('a,'s,'b,'u)kinstr}[@@ocaml.unboxed](* This is a view on a deconstructed [kinstr]. Its type parameters refer to
the type of the viewed [kinstr], while existentials inside describe types of
[kinstr]'s components. The [reconstruct] field in each record stores a
function which reconstructs the original instruction from its components. *)type('a,'s,'r,'f)ex_split_kinstr=|Ex_split_kinstr:{cont_init_stack:('b,'u)stack_ty;continuation:('b,'u,'r,'f)kinstr;reconstruct:('b,'u,'r,'f)kinstr->('a,'s,'r,'f)kinstr;}->('a,'s,'r,'f)ex_split_kinstr|Ex_split_log:{stack:('a,'s)stack_ty;continuation:('a,'s,'r,'f)kinstr;reconstruct:('a,'s,'r,'f)kinstr->('a,'s,'r,'f)kinstr;}->('a,'s,'r,'f)ex_split_kinstr|Ex_split_loop_may_fail:{body_init_stack:('b,'u)stack_ty;body:('b,'u,'r,'f)kinstr;cont_init_stack:('c,'v)stack_ty;continuation:('c,'v,'t,'g)kinstr;reconstruct:('b,'u,'r,'f)kinstr->('c,'v,'t,'g)kinstr->('a,'s,'t,'g)kinstr;}->('a,'s,'t,'g)ex_split_kinstr|Ex_split_loop_may_not_fail:{body_init_stack:('b,'u)stack_ty;body:('b,'u,'r,'f)kinstr;continuation:('c,'v,'t,'g)kinstr;aft_body_stack_transform:('r,'f)stack_ty->('c,'v)stack_tytzresult;reconstruct:('b,'u,'r,'f)kinstr->('c,'v,'t,'g)kinstr->('a,'s,'t,'g)kinstr;}->('a,'s,'t,'g)ex_split_kinstr|Ex_split_if:{left_init_stack:('b,'u)stack_ty;left_branch:('b,'u,'r,'f)kinstr;right_init_stack:('c,'v)stack_ty;right_branch:('c,'v,'r,'f)kinstr;continuation:('r,'f,'t,'g)kinstr;reconstruct:('b,'u,'r,'f)kinstr->('c,'v,'r,'f)kinstr->('r,'f,'t,'g)kinstr->('a,'s,'t,'g)kinstr;}->('a,'s,'t,'g)ex_split_kinstr|Ex_split_halt:Script.location->('a,'s,'a,'s)ex_split_kinstr|Ex_split_failwith:{location:Script.location;arg_ty:('a,_)ty;cast:('a,'s)failed_kinstr_cast;}->('a,'s,'r,'f)ex_split_kinstr(** An existential container for an instruction paired with its
initial stack type. This is used internally to pack together
execution branches with different initial stack types but
the same final stack type (which we want to compute). *)type('r,'f)ex_init_stack_ty=|Ex_init_stack_ty:('a,'s)stack_ty*('a,'s,'r,'f)kinstr->('r,'f)ex_init_stack_tyletrecstack_prefix_preservation_witness_split_input:typeasbtcudv.(b,t,c,u,a,s,d,v)stack_prefix_preservation_witness->(a,s)stack_ty->(b,t)stack_ty=funws->match(w,s)with|KPrefix(_,_,w),Item_t(_,s)->stack_prefix_preservation_witness_split_inputws|KRest,s->sletrecstack_prefix_preservation_witness_split_output:typeasbtcudv.(b,t,c,u,a,s,d,v)stack_prefix_preservation_witness->(c,u)stack_ty->(d,v)stack_ty=funws->match(w,s)with|KPrefix(_,a,w),s->Item_t(a,stack_prefix_preservation_witness_split_outputws)|KRest,s->s(* We apply this function to optional type information which must be present
if functions from this module were called. Use with care. *)letassert_some=functionNone->assertfalse|Somex->xletkinstr_split:typeasrf.(a,s)stack_ty->(a,s,r,f)kinstr->(a,s,r,f)ex_split_kinstrtzresult=letopenResult_syntaxinfunsi->letdummy=Micheline.dummy_locationinmatch(i,s)with|IDrop(loc,k),Item_t(_a,s)->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IDrop(loc,k));}|IDup(loc,k),Item_t(a,s)->lets=Item_t(a,Item_t(a,s))inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IDup(loc,k));}|ISwap(loc,k),Item_t(a,Item_t(b,s))->lets=Item_t(b,Item_t(a,s))inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ISwap(loc,k));}|IPush(loc,a,x,k),s->lets=Item_t(a,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IPush(loc,a,x,k));}|IUnit(loc,k),s->lets=Item_t(unit_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IUnit(loc,k));}|ICons_pair(loc,k),Item_t(a,Item_t(b,s))->let+(Ty_ex_cc)=pair_tdummyabinlets=Item_t(c,s)inEx_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ICons_pair(loc,k));}|ICar(loc,k),Item_t(Pair_t(a,_b,_meta,_),s)->lets=Item_t(a,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ICar(loc,k));}|ICdr(loc,k),Item_t(Pair_t(_a,b,_meta,_),s)->lets=Item_t(b,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ICdr(loc,k));}|IUnpair(loc,k),Item_t(Pair_t(a,b,_meta,_),s)->lets=Item_t(a,Item_t(b,s))inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IUnpair(loc,k));}|ICons_some(loc,k),Item_t(a,s)->let+o=option_tdummyainlets=Item_t(o,s)inEx_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ICons_some(loc,k));}|ICons_none(loc,a,k),s->let+o=option_tdummyainlets=Item_t(o,s)inEx_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ICons_none(loc,a,k));}|(IIf_none{loc;branch_if_none;branch_if_some;k},Item_t(Option_t(a,_meta,_),s))->return@@Ex_split_if{left_init_stack=s;left_branch=branch_if_none;right_init_stack=Item_t(a,s);right_branch=branch_if_some;continuation=k;reconstruct=(funbranch_if_nonebranch_if_somek->IIf_none{loc;branch_if_none;branch_if_some;k});}|IOpt_map{loc;body;k},Item_t(Option_t(a,_meta,_),s)->return@@Ex_split_loop_may_not_fail{body_init_stack=Item_t(a,s);body;continuation=k;aft_body_stack_transform=(function|Item_t(b,s)->let+o=option_tdummybinItem_t(o,s));reconstruct=(funbodyk->IOpt_map{loc;body;k});}|ICons_left(loc,b,k),Item_t(a,s)->let+(Ty_ex_cc)=or_tdummyabinlets=Item_t(c,s)inEx_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ICons_left(loc,b,k));}|ICons_right(loc,a,k),Item_t(b,s)->let+(Ty_ex_cc)=or_tdummyabinlets=Item_t(c,s)inEx_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ICons_right(loc,a,k));}|(IIf_left{loc;branch_if_left;branch_if_right;k},Item_t(Or_t(a,b,_meta,_),s))->return@@Ex_split_if{left_init_stack=Item_t(a,s);left_branch=branch_if_left;right_init_stack=Item_t(b,s);right_branch=branch_if_right;continuation=k;reconstruct=(funbranch_if_leftbranch_if_rightk->IIf_left{loc;branch_if_left;branch_if_right;k});}|ICons_list(loc,k),Item_t(_a,Item_t(l,s))->lets=Item_t(l,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ICons_list(loc,k));}|INil(loc,a,k),s->let+l=list_tdummyainlets=Item_t(l,s)inEx_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->INil(loc,a,k));}|(IIf_cons{loc;branch_if_cons;branch_if_nil;k},Item_t((List_t(a,_meta)asl),s))->return@@Ex_split_if{left_init_stack=Item_t(a,Item_t(l,s));left_branch=branch_if_cons;right_init_stack=s;right_branch=branch_if_nil;continuation=k;reconstruct=(funbranch_if_consbranch_if_nilk->IIf_cons{loc;branch_if_cons;branch_if_nil;k});}|IList_map(loc,body,ty,k),Item_t(List_t(a,_meta),s)->lets=Item_t(a,s)inreturn@@Ex_split_loop_may_not_fail{body_init_stack=s;body;continuation=k;aft_body_stack_transform=(function|Item_t(b,s)->let+l=list_tdummybinItem_t(l,s));reconstruct=(funbodyk->IList_map(loc,body,ty,k));}|IList_iter(loc,ty,body,k),Item_t(List_t(a,_meta),s)->return@@Ex_split_loop_may_fail{body_init_stack=Item_t(a,s);body;cont_init_stack=s;continuation=k;reconstruct=(funbodyk->IList_iter(loc,ty,body,k));}|IList_size(loc,k),Item_t(_l,s)->lets=Item_t(nat_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IList_size(loc,k));}|IEmpty_set(loc,a,k),s->let+b=set_tdummyainlets=Item_t(b,s)inEx_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IEmpty_set(loc,a,k));}|ISet_iter(loc,a,body,k),Item_t(_b,s)->return@@Ex_split_loop_may_fail{body_init_stack=Item_t(assert_somea,s);body;cont_init_stack=s;continuation=k;reconstruct=(funbodyk->ISet_iter(loc,a,body,k));}|ISet_mem(loc,k),Item_t(_,Item_t(_,s))->lets=Item_t(bool_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ISet_mem(loc,k));}|ISet_update(loc,k),Item_t(_,Item_t(_,s))->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ISet_update(loc,k));}|ISet_size(loc,k),Item_t(_,s)->lets=Item_t(nat_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ISet_size(loc,k));}|IEmpty_map(loc,cty,vty,k),s->let+m=map_tdummycty(assert_somevty)inlets=Item_t(m,s)inEx_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IEmpty_map(loc,cty,vty,k));}|IMap_map(loc,ty,body,k),Item_t(Map_t(kty,vty,_meta),s)->let(Map_t(key_ty,_,_))=assert_sometyinlet+(Ty_ex_cp)=pair_tdummykey_tyvtyinEx_split_loop_may_not_fail{body_init_stack=Item_t(p,s);body;continuation=k;aft_body_stack_transform=(fun(Item_t(b,s))->let+m=map_tdummyktybinItem_t(m,s));reconstruct=(funbodyk->IMap_map(loc,ty,body,k));}|IMap_iter(loc,kvty,body,k),Item_t(_,stack)->return@@Ex_split_loop_may_fail{body_init_stack=Item_t(assert_somekvty,stack);body;cont_init_stack=stack;continuation=k;reconstruct=(funbodyk->IMap_iter(loc,kvty,body,k));}|IMap_mem(loc,k),Item_t(_,Item_t(_,s))->lets=Item_t(bool_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IMap_mem(loc,k));}|IMap_get(loc,k),Item_t(_,Item_t(Map_t(_kty,vty,_meta),s))->let+o=option_tdummyvtyinlets=Item_t(o,s)inEx_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IMap_get(loc,k));}|IMap_update(loc,k),Item_t(_,Item_t(_,s))->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IMap_update(loc,k));}|IMap_get_and_update(loc,k),Item_t(_,s)->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IMap_get_and_update(loc,k));}|IMap_size(loc,k),Item_t(_,s)->lets=Item_t(nat_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IMap_size(loc,k));}|IEmpty_big_map(loc,cty,ty,k),s->let+b=big_map_tdummyctytyinlets=Item_t(b,s)inEx_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IEmpty_big_map(loc,cty,ty,k));}|IBig_map_mem(loc,k),Item_t(_,Item_t(_,s))->lets=Item_t(bool_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IBig_map_mem(loc,k));}|(IBig_map_get(loc,k),Item_t(_,Item_t(Big_map_t(_kty,vty,_meta),s)))->let+o=option_tdummyvtyinlets=Item_t(o,s)inEx_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IBig_map_get(loc,k));}|IBig_map_update(loc,k),Item_t(_,Item_t(_,s))->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IBig_map_update(loc,k));}|IBig_map_get_and_update(loc,k),Item_t(_,s)->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IBig_map_get_and_update(loc,k));}|IConcat_string(loc,k),Item_t(_,s)->lets=Item_t(string_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IConcat_string(loc,k));}|IConcat_string_pair(loc,k),Item_t(_,s)->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IConcat_string_pair(loc,k));}|ISlice_string(loc,k),Item_t(_,Item_t(_,Item_t(_,s)))->lets=Item_t(option_string_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ISlice_string(loc,k));}|IString_size(loc,k),Item_t(_,s)->lets=Item_t(nat_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IString_size(loc,k));}|IConcat_bytes(loc,k),Item_t(_,s)->lets=Item_t(bytes_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IConcat_bytes(loc,k));}|IConcat_bytes_pair(loc,k),Item_t(_,s)->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IConcat_bytes_pair(loc,k));}|ISlice_bytes(loc,k),Item_t(_,Item_t(_,Item_t(_,s)))->lets=Item_t(option_bytes_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ISlice_bytes(loc,k));}|IBytes_size(loc,k),Item_t(_,s)->lets=Item_t(nat_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IBytes_size(loc,k));}|ILsl_bytes(loc,k),Item_t(_,Item_t(_,s))->lets=Item_t(bytes_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ILsl_bytes(loc,k));}|ILsr_bytes(loc,k),Item_t(_,Item_t(_,s))->lets=Item_t(bytes_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ILsr_bytes(loc,k));}|IOr_bytes(loc,k),Item_t(_,s)->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IOr_bytes(loc,k));}|IAnd_bytes(loc,k),Item_t(_,s)->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IAnd_bytes(loc,k));}|IXor_bytes(loc,k),Item_t(_,s)->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IXor_bytes(loc,k));}|INot_bytes(loc,k),Item_t(_,s)->lets=Item_t(bytes_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->INot_bytes(loc,k));}|IBytes_nat(loc,k),Item_t(_,s)->lets=Item_t(bytes_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IBytes_nat(loc,k));}|INat_bytes(loc,k),Item_t(_,s)->lets=Item_t(nat_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->INat_bytes(loc,k));}|IBytes_int(loc,k),Item_t(_,s)->lets=Item_t(bytes_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IBytes_int(loc,k));}|IInt_bytes(loc,k),Item_t(_,s)->lets=Item_t(int_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IInt_bytes(loc,k));}|IAdd_seconds_to_timestamp(loc,k),Item_t(_,s)->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IAdd_seconds_to_timestamp(loc,k));}|IAdd_timestamp_to_seconds(loc,k),Item_t(_,Item_t(_,s))->lets=Item_t(timestamp_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IAdd_timestamp_to_seconds(loc,k));}|ISub_timestamp_seconds(loc,k),Item_t(_,Item_t(_,s))->lets=Item_t(timestamp_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ISub_timestamp_seconds(loc,k));}|IDiff_timestamps(loc,k),Item_t(_,Item_t(_,s))->lets=Item_t(int_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IDiff_timestamps(loc,k));}|IAdd_tez(loc,k),Item_t(_,s)->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IAdd_tez(loc,k));}|ISub_tez(loc,k),Item_t(_,Item_t(_,s))->lets=Item_t(option_mutez_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ISub_tez(loc,k));}|ISub_tez_legacy(loc,k),Item_t(_,s)->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ISub_tez_legacy(loc,k));}|IMul_teznat(loc,k),Item_t(_,Item_t(_,s))->lets=Item_t(mutez_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IMul_teznat(loc,k));}|IMul_nattez(loc,k),Item_t(_,s)->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IMul_nattez(loc,k));}|IEdiv_teznat(loc,k),Item_t(_,Item_t(_,s))->lets=Item_t(option_pair_mutez_mutez_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IEdiv_teznat(loc,k));}|IEdiv_tez(loc,k),Item_t(_,Item_t(_,s))->lets=Item_t(option_pair_nat_mutez_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IEdiv_tez(loc,k));}|IOr(loc,k),Item_t(_,s)->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IOr(loc,k));}|IAnd(loc,k),Item_t(_,s)->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IAnd(loc,k));}|IXor(loc,k),Item_t(_,s)->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IXor(loc,k));}|INot(loc,k),s->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->INot(loc,k));}|IIs_nat(loc,k),Item_t(_,s)->lets=Item_t(option_nat_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IIs_nat(loc,k));}|INeg(loc,k),Item_t(_,s)->lets=Item_t(int_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->INeg(loc,k));}|IAbs_int(loc,k),Item_t(_,s)->lets=Item_t(nat_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IAbs_int(loc,k));}|IInt_nat(loc,k),Item_t(_,s)->lets=Item_t(int_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IInt_nat(loc,k));}|IAdd_int(loc,k),Item_t(_,Item_t(_,s))->lets=Item_t(int_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IAdd_int(loc,k));}|IAdd_nat(loc,k),Item_t(_,s)->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IAdd_nat(loc,k));}|ISub_int(loc,k),Item_t(_,Item_t(_,s))->lets=Item_t(int_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ISub_int(loc,k));}|IMul_int(loc,k),Item_t(_,Item_t(_,s))->lets=Item_t(int_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IMul_int(loc,k));}|IMul_nat(loc,k),Item_t(_,s)->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IMul_nat(loc,k));}|IEdiv_int(loc,k),Item_t(_,Item_t(_,s))->lets=Item_t(option_pair_int_nat_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IEdiv_int(loc,k));}|IEdiv_nat(loc,k),Item_t(_,Item_t(a,s))->let*(Ty_ex_cp)=pair_tdummyanat_tinlet+o=option_tdummypinlets=Item_t(o,s)inEx_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IEdiv_nat(loc,k));}|ILsl_nat(loc,k),Item_t(_,s)->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ILsl_nat(loc,k));}|ILsr_nat(loc,k),Item_t(_,s)->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ILsr_nat(loc,k));}|IOr_nat(loc,k),Item_t(_,s)->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IOr_nat(loc,k));}|IAnd_nat(loc,k),Item_t(_,s)->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IAnd_nat(loc,k));}|IAnd_int_nat(loc,k),Item_t(_,s)->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IAnd_int_nat(loc,k));}|IXor_nat(loc,k),Item_t(_,s)->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IXor_nat(loc,k));}|INot_int(loc,k),Item_t(_,s)->lets=Item_t(int_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->INot_int(loc,k));}|IIf{loc;branch_if_true;branch_if_false;k},Item_t(_,s)->return@@Ex_split_if{left_init_stack=s;left_branch=branch_if_true;right_init_stack=s;right_branch=branch_if_false;continuation=k;reconstruct=(funbranch_if_truebranch_if_falsek->IIf{loc;branch_if_true;branch_if_false;k});}|ILoop(loc,body,k),Item_t(_,s)->return@@Ex_split_loop_may_fail{body_init_stack=s;body;cont_init_stack=s;continuation=k;reconstruct=(funbodyk->ILoop(loc,body,k));}|ILoop_left(loc,kl,kr),Item_t(Or_t(a,b,_meta,_),s)->return@@Ex_split_loop_may_fail{body_init_stack=Item_t(a,s);body=kl;cont_init_stack=Item_t(b,s);continuation=kr;reconstruct=(funklkr->ILoop_left(loc,kl,kr));}|IDip(loc,body,ty,k),Item_t(a,s)->return@@Ex_split_loop_may_not_fail{body_init_stack=s;body;continuation=k;aft_body_stack_transform=(funs->return(Item_t(a,s)));reconstruct=(funbodyk->IDip(loc,body,ty,k));}|IExec(loc,sty,k),Item_t(_,Item_t(Lambda_t(_,b,_meta),s))->lets=Item_t(b,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IExec(loc,sty,k));}|(IApply(loc,ty,k),Item_t(_,Item_t(Lambda_t(Pair_t(_,a,_,_),b,_),s)))->let+l=lambda_tdummyabinlets=Item_t(l,s)inEx_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IApply(loc,ty,k));}|ILambda(loc,(Lam(desc,_)asl),k),s->let(Item_t(a,Bot_t))=desc.kbefinlet(Item_t(b,Bot_t))=desc.kaftinlet+lam=lambda_tdummyabinlets=Item_t(lam,s)inEx_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ILambda(loc,l,k));}|ILambda(loc,(LamRec(desc,_)asl),k),s->let(Item_t(a,Item_t(Lambda_t_,Bot_t)))=desc.kbefinlet(Item_t(b,Bot_t))=desc.kaftinlet+lam=lambda_tdummyabinlets=Item_t(lam,s)inEx_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ILambda(loc,l,k));}|IFailwith(location,arg_ty),_->return@@Ex_split_failwith{location;arg_ty;cast={cast=IFailwith(location,arg_ty)}}|ICompare(loc,ty,k),Item_t(_,Item_t(_,s))->lets=Item_t(int_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ICompare(loc,ty,k));}|IEq(loc,k),Item_t(_,s)->lets=Item_t(bool_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IEq(loc,k));}|INeq(loc,k),Item_t(_,s)->lets=Item_t(bool_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->INeq(loc,k));}|ILt(loc,k),Item_t(_,s)->lets=Item_t(bool_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ILt(loc,k));}|IGt(loc,k),Item_t(_,s)->lets=Item_t(bool_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IGt(loc,k));}|ILe(loc,k),Item_t(_,s)->lets=Item_t(bool_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ILe(loc,k));}|IGe(loc,k),Item_t(_,s)->lets=Item_t(bool_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IGe(loc,k));}|IAddress(loc,k),Item_t(_,s)->lets=Item_t(address_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IAddress(loc,k));}|IContract(loc,ty,code,k),Item_t(_,s)->let*c=contract_tdummytyinlet+o=option_tdummycinlets=Item_t(o,s)inEx_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IContract(loc,ty,code,k));}|ITransfer_tokens(loc,k),Item_t(_,Item_t(_,Item_t(_,s)))->lets=Item_t(operation_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ITransfer_tokens(loc,k));}|(IView(loc,(View_signature{output_ty;_}asview_signature),sty,k),Item_t(_,Item_t(_,s)))->let+b=option_tdummyoutput_tyinlets=Item_t(b,s)inEx_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IView(loc,view_signature,sty,k));}|IImplicit_account(loc,k),Item_t(_,s)->lets=Item_t(contract_unit_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IImplicit_account(loc,k));}|(ICreate_contract{loc;storage_type;code;k},Item_t(_,Item_t(_,Item_t(_,s))))->return@@Ex_split_kinstr{cont_init_stack=Item_t(operation_t,Item_t(address_t,s));continuation=k;reconstruct=(funk->ICreate_contract{loc;storage_type;code;k});}|ISet_delegate(loc,k),Item_t(_,s)->lets=Item_t(operation_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ISet_delegate(loc,k));}|INow(loc,k),s->lets=Item_t(timestamp_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->INow(loc,k));}|IBalance(loc,k),s->lets=Item_t(mutez_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IBalance(loc,k));}|ILevel(loc,k),s->lets=Item_t(nat_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ILevel(loc,k));}|ICheck_signature(loc,k),Item_t(_,Item_t(_,Item_t(_,s)))->lets=Item_t(bool_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ICheck_signature(loc,k));}|IHash_key(loc,k),Item_t(_,s)->lets=Item_t(key_hash_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IHash_key(loc,k));}|IPack(loc,ty,k),Item_t(_,s)->lets=Item_t(bytes_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IPack(loc,ty,k));}|IUnpack(loc,ty,k),Item_t(_,s)->let+o=option_tdummytyinlets=Item_t(o,s)inEx_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IUnpack(loc,ty,k));}|IBlake2b(loc,k),s->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IBlake2b(loc,k));}|ISha256(loc,k),s->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ISha256(loc,k));}|ISha512(loc,k),s->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ISha512(loc,k));}|ISource(loc,k),s->lets=Item_t(address_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ISource(loc,k));}|ISender(loc,k),s->lets=Item_t(address_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ISender(loc,k));}|ISelf(loc,ty,ep,k),s->let+c=contract_tdummytyinlets=Item_t(c,s)inEx_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ISelf(loc,ty,ep,k));}|ISelf_address(loc,k),s->lets=Item_t(address_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ISelf_address(loc,k));}|IAmount(loc,k),s->lets=Item_t(mutez_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IAmount(loc,k));}|ISapling_empty_state(loc,memo_size,k),s->return@@Ex_split_kinstr{cont_init_stack=Item_t(sapling_state_t~memo_size,s);continuation=k;reconstruct=(funk->ISapling_empty_state(loc,memo_size,k));}|(ISapling_verify_update_deprecated(loc,k),Item_t(_,Item_t(state_ty,s)))->let*(Ty_ex_cpair_ty)=pair_tdummyint_tstate_tyinlet+ty=option_tdummypair_tyinEx_split_kinstr{cont_init_stack=Item_t(ty,s);continuation=k;reconstruct=(funk->ISapling_verify_update_deprecated(loc,k));}|ISapling_verify_update(loc,k),Item_t(_,Item_t(state_ty,s))->let*(Ty_ex_cint_state_ty)=pair_tdummyint_tstate_tyinlet*(Ty_ex_cpair_ty)=pair_tdummybytes_tint_state_tyinlet+ty=option_tdummypair_tyinlets=Item_t(ty,s)inEx_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ISapling_verify_update(loc,k));}|IDig(loc,n,p,k),s->let(Item_t(b,s))=stack_prefix_preservation_witness_split_inputpsinlets=stack_prefix_preservation_witness_split_outputpsinlets=Item_t(b,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IDig(loc,n,p,k));}|IDug(loc,n,p,k),Item_t(a,s)->lets=stack_prefix_preservation_witness_split_inputpsinlets=Item_t(a,s)inlets=stack_prefix_preservation_witness_split_outputpsinreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IDug(loc,n,p,k));}|IDipn(loc,n,p,k1,k2),s->return@@Ex_split_loop_may_not_fail{body_init_stack=stack_prefix_preservation_witness_split_inputps;body=k1;continuation=k2;aft_body_stack_transform=(funs->return@@stack_prefix_preservation_witness_split_outputps);reconstruct=(funk1k2->IDipn(loc,n,p,k1,k2));}|IDropn(loc,n,p,k),s->lets=stack_prefix_preservation_witness_split_inputpsinreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IDropn(loc,n,p,k));}|IChainId(loc,k),s->lets=Item_t(chain_id_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IChainId(loc,k));}|INeverlocation,Item_t(arg_ty,_)->return@@Ex_split_failwith{location;arg_ty;cast={cast=INeverlocation}}|IVoting_power(loc,k),Item_t(_,s)->lets=Item_t(nat_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IVoting_power(loc,k));}|ITotal_voting_power(loc,k),s->lets=Item_t(nat_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ITotal_voting_power(loc,k));}|IKeccak(loc,k),s->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IKeccak(loc,k));}|ISha3(loc,k),s->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ISha3(loc,k));}|IAdd_bls12_381_g1(loc,k),Item_t(_,s)->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IAdd_bls12_381_g1(loc,k));}|IAdd_bls12_381_g2(loc,k),Item_t(_,s)->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IAdd_bls12_381_g2(loc,k));}|IAdd_bls12_381_fr(loc,k),Item_t(_,s)->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IAdd_bls12_381_fr(loc,k));}|IMul_bls12_381_g1(loc,k),Item_t(g1,Item_t(_,s))->lets=Item_t(g1,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IMul_bls12_381_g1(loc,k));}|IMul_bls12_381_g2(loc,k),Item_t(g2,Item_t(_,s))->lets=Item_t(g2,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IMul_bls12_381_g2(loc,k));}|IMul_bls12_381_fr(loc,k),Item_t(_,s)->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IMul_bls12_381_fr(loc,k));}|IMul_bls12_381_z_fr(loc,k),Item_t(fr,Item_t(_,s))->lets=Item_t(fr,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IMul_bls12_381_z_fr(loc,k));}|IMul_bls12_381_fr_z(loc,k),Item_t(_,s)->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IMul_bls12_381_fr_z(loc,k));}|IInt_bls12_381_fr(loc,k),Item_t(_,s)->lets=Item_t(int_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IInt_bls12_381_fr(loc,k));}|INeg_bls12_381_g1(loc,k),s->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->INeg_bls12_381_g1(loc,k));}|INeg_bls12_381_g2(loc,k),s->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->INeg_bls12_381_g2(loc,k));}|INeg_bls12_381_fr(loc,k),s->return@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->INeg_bls12_381_fr(loc,k));}|IPairing_check_bls12_381(loc,k),Item_t(_,s)->lets=Item_t(bool_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IPairing_check_bls12_381(loc,k));}|IComb(loc,n,p,k),s->letrecaux:typeabscdt.(a,b*s)stack_ty->(a,b,s,c,d,t)comb_gadt_witness->(c,d*t)stack_tytzresult=funsw->match(w,s)with|Comb_one,s->returns|Comb_succw,Item_t(a,s)->let*(Item_t(c,t))=auxswinlet+(Ty_ex_cp)=pair_tdummyacinItem_t(p,t)inlet+s=auxspinEx_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IComb(loc,n,p,k));}|IUncomb(loc,n,p,k),s->letrecaux:typeabscdt.(a,b*s)stack_ty->(a,b,s,c,d,t)uncomb_gadt_witness->(c,d*t)stack_ty=funsw->match(w,s)with|Uncomb_one,s->s|Uncomb_succw,Item_t(Pair_t(a,b,_meta,_),s)->lets=aux(Item_t(b,s))winItem_t(a,s)inlets=auxspinreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IUncomb(loc,n,p,k));}|IComb_get(loc,n,p,k),Item_t(c,s)->letrecaux:typeccca.(c,cc)ty->(c,a)comb_get_gadt_witness->aty_ex_c=funcw->match(w,c)with|Comb_get_zero,c->Ty_ex_cc|Comb_get_one,Pair_t(hd,_tl,_meta,_)->Ty_ex_chd|Comb_get_plus_twow,Pair_t(_hd,tl,_meta,_)->auxtlwinlets=let(Ty_ex_cty)=auxcpinItem_t(ty,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IComb_get(loc,n,p,k));}|IComb_set(loc,n,p,k),Item_t(a,Item_t(b,s))->letrecaux:typeabccacb.(a,ca)ty->(b,cb)ty->(a,b,c)comb_set_gadt_witness->cty_ex_ctzresult=funabw->match(w,b)with|Comb_set_zero,_->return(Ty_ex_ca)|Comb_set_one,Pair_t(_hd,tl,_meta,_)->pair_tdummyatl|Comb_set_plus_twow,Pair_t(hd,tl,_meta,_)->let*(Ty_ex_cc)=auxatlwinpair_tdummyhdcinlet+(Ty_ex_cc)=auxabpinlets=Item_t(c,s)inEx_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IComb_set(loc,n,p,k));}|IDup_n(loc,n,p,k),s->letrecaux:typeabst.(a,b*s)stack_ty->(a,b,s,t)dup_n_gadt_witness->tty_ex_c=funsw->match(w,s)with|Dup_n_succw,Item_t(_,s)->auxsw|Dup_n_zero,Item_t(a,_)->Ty_ex_cainlets=let(Ty_ex_cty)=auxspinItem_t(ty,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IDup_n(loc,n,p,k));}|ITicket(loc,cty,k),Item_t(_,Item_t(_,s))->let*ty=ticket_tdummy(assert_somecty)inlet+t=option_tloctyinlets=Item_t(t,s)inEx_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ITicket(loc,cty,k));}|ITicket_deprecated(loc,cty,k),Item_t(_,Item_t(_,s))->let+t=ticket_tdummy(assert_somecty)inlets=Item_t(t,s)inEx_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ITicket_deprecated(loc,cty,k));}|IRead_ticket(loc,a,k),s->let*(Ty_ex_cp)=pair_tdummy(assert_somea)nat_tinlet+(Ty_ex_ct)=pair_tdummyaddress_tpinlets=Item_t(t,s)inEx_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IRead_ticket(loc,a,k));}|ISplit_ticket(loc,k),Item_t(t,Item_t(_,s))->let*(Ty_ex_cp)=pair_tdummyttinlet+o=option_tdummypinlets=Item_t(o,s)inEx_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->ISplit_ticket(loc,k));}|IJoin_tickets(loc,ty,k),Item_t(Pair_t(t,_t,_meta,_),s)->let+o=option_tdummytinlets=Item_t(o,s)inEx_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IJoin_tickets(loc,ty,k));}|IOpen_chest(loc,k),Item_t(_,Item_t(_,Item_t(_,s)))->lets=Item_t(option_bytes_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IOpen_chest(loc,k));}|IMin_block_time(loc,k),s->lets=Item_t(nat_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IMin_block_time(loc,k));}|IEmit{loc;ty;unparsed_ty;tag;k},Item_t(_,s)->lets=Item_t(operation_t,s)inreturn@@Ex_split_kinstr{cont_init_stack=s;continuation=k;reconstruct=(funk->IEmit{loc;ty;unparsed_ty;tag;k});}|IEmit_,Bot_t->.|IHaltloc,_s->return@@Ex_split_haltloc|ILog(loc,_stack_ty,event,logger,continuation),stack->return@@Ex_split_log{stack;continuation;reconstruct=(funk->ILog(loc,s,event,logger,k));}(* [kinstr_final_stack_type sty instr] computes the stack type after
[instr] has been executed, assuming [sty] is the type of the stack
prior to execution. For the rare instructions which can return stacks
of any type ([FAILWITH] and [NEVER]), this function returns [None]. *)letreckinstr_final_stack_type:typeasrf.(a,s)stack_ty->(a,s,r,f)kinstr->(r,f)stack_tyoptiontzresult=letopenResult_syntaxinfunsi->let*ex_split_kinstr=kinstr_splitsiinmatchex_split_kinstrwith|Ex_split_kinstr{cont_init_stack;continuation;_}->kinstr_final_stack_typecont_init_stackcontinuation|Ex_split_log{stack;continuation;_}->kinstr_final_stack_typestackcontinuation|Ex_split_loop_may_fail{cont_init_stack;continuation;_}->kinstr_final_stack_typecont_init_stackcontinuation|Ex_split_loop_may_not_fail{body_init_stack;body;continuation;aft_body_stack_transform;_}->(let*sty=kinstr_final_stack_typebody_init_stackbodyinmatchstywith|Someafter_body->let*before_k=aft_body_stack_transformafter_bodyinkinstr_final_stack_typebefore_kcontinuation|None->return_none)|Ex_split_if{left_init_stack;left_branch;right_init_stack;right_branch;continuation;_;}->(let*sty=kinstr_final_stack_typeleft_init_stackleft_branchinmatchstywith|Someafter_branch_a->kinstr_final_stack_typeafter_branch_acontinuation|None->(let*sty=kinstr_final_stack_typeright_init_stackright_branchinmatchstywith|Someafter_branch_b->kinstr_final_stack_typeafter_branch_bcontinuation|None->return_none))|Ex_split_halt_->return_somes|Ex_split_failwith{cast={cast=_};_}->return_none(* The same as [kinstr_final_stack_type], but selects from multiple
possible execution branches. If the first instr ends with FAILWITH,
it will try the next and so on. Note that all instructions must
result in the same stack type. *)letrecbranched_final_stack_type:typerf.(r,f)ex_init_stack_tylist->(r,f)stack_tyoptiontzresult=letopenResult_syntaxinfunction|[]->return_none|Ex_init_stack_ty(init_sty,branch)::bs->(let*sty=kinstr_final_stack_typeinit_stybranchinmatchstywith|Some_assty->returnsty|None->branched_final_stack_typebs)letkinstr_rewritek:typeasrf.(a,s)stack_ty->(a,s,r,f)kinstr->kinstr_rewritek->(a,s,r,f)kinstrtzresult=letopenResult_syntaxinfunsif->let*ex_split_kinstr=kinstr_splitsiinmatchex_split_kinstrwith|Ex_split_kinstr{cont_init_stack;continuation;reconstruct}->return@@reconstruct(f.applycont_init_stackcontinuation)|Ex_split_log{continuation;reconstruct;_}->return@@reconstructcontinuation|Ex_split_loop_may_fail{body_init_stack;body;cont_init_stack;continuation;reconstruct}->return@@reconstruct(f.applybody_init_stackbody)(f.applycont_init_stackcontinuation)|Ex_split_loop_may_not_fail{body_init_stack;body;continuation;aft_body_stack_transform;reconstruct;}->let+k=let*sty=kinstr_final_stack_typebody_init_stackbodyinmatchstywith|Someafter_body->let+before_k=aft_body_stack_transformafter_bodyinf.applybefore_kcontinuation|None->returncontinuationinreconstruct(f.applybody_init_stackbody)k|Ex_split_if{left_init_stack;left_branch;right_init_stack;right_branch;continuation;reconstruct;}->let+k=let*sty=kinstr_final_stack_typeleft_init_stackleft_branchinmatchstywith|Someafter_left_branch->return@@f.applyafter_left_branchcontinuation|None->(let*sty=kinstr_final_stack_typeright_init_stackright_branchinmatchstywith|Someafter_right_branch->return@@f.applyafter_right_branchcontinuation|None->returncontinuation)inreconstruct(f.applyleft_init_stackleft_branch)(f.applyright_init_stackright_branch)k|Ex_split_haltloc->return@@IHaltloc|Ex_split_failwith{location;arg_ty;_}->return@@IFailwith(location,arg_ty)(** [dipn_stack_ty witness stack_ty] returns the type of the stack
on which instructions inside dipped block will be operating. *)letrecdipn_stack_ty:typeasezcudw.(a,s,e,z,c,u,d,w)stack_prefix_preservation_witness->(c,u)stack_ty->(a,s)stack_ty=funwitnessstack->match(witness,stack)with|KPrefix(_,_,witness'),Item_t(_,sty)->dipn_stack_tywitness'sty|KRest,sty->sty(** [instrument_cont logger sty] creates a function instrumenting
continuations starting from the stack type described by [sty].
Instrumentation consists in wrapping inner continuations in
[KLog] continuation so that logging continues. *)letinstrument_cont:typeabcd.logger->(a,b)stack_ty->(a,b,c,d)continuation->(a,b,c,d)continuation=funloggersty->functionKLog_ask->k|k->KLog(k,sty,logger)endmoduletypeLogger_base=sigvallog_interp:('a,'s,'b,'f,'c,'u)logging_functionvallog_entry:('a,'s,'b,'f,'a,'s)logging_functionvallog_control:('a,'s,'b,'f)continuation->unitvallog_exit:('a,'s,'b,'f,'c,'u)logging_functionvalget_log:unit->execution_traceoptiontzresultLwt.tendmoduleLogger(Base:Logger_base)=structopenStack_utilsopenLocal_gas_counteropenScript_interpreter_defsopenScript_interpreter.Internals.Raw(** [log_entry ctxt gas instr sty accu stack] simply calls the
[Base.log_entry] function with the appropriate arguments. *)letlog_entryctxtgaskstyaccustack=letctxt=Local_gas_counter.update_contextgasctxtinBase.log_entrykctxt(kinstr_locationk)sty(accu,stack)(** [log_exit ctxt gas loc instr sty accu stack] simply calls the
[Base.log_exit] function with the appropriate arguments. *)letlog_exitctxtgasloc_prevkstyaccustack=letctxt=Local_gas_counter.update_contextgasctxtinBase.log_exitkctxtloc_prevsty(accu,stack)(** [log_control continuation] simply calls the [Base.log_control]
function with the appropriate arguments. *)letlog_controlks=Base.log_controlks(** [log_kinstr logger sty instr] returns [instr] prefixed by an
[ILog] instruction to log the first instruction in [instr]. *)letlog_kinstrloggerstyi=ILog(kinstr_locationi,sty,LogEntry,logger,i)(* [log_next_kinstr logger i] instruments the next instruction of [i]
with [ILog] instructions to make sure it will be logged.
This instrumentation has a performance cost, but importantly, it is
only ever paid when logging is enabled. Otherwise, the possibility
to instrument the script is costless.
Notice that the instrumentation breaks the sharing of continuations
that is normally enforced between branches of conditionals. This
has a performance cost. Anyway, the instrumentation allocates many
new [ILog] instructions and [KLog] continuations which makes
the execution of instrumented code significantly slower than
non-instrumented code. "Zero-cost logging" means that the normal
non-instrumented execution is not impacted by the ability to
instrument it, not that the logging itself has no cost.
*)letlog_next_kinstrloggerstyi=letapplystyk=ILog(kinstr_locationk,sty,LogExit(kinstr_locationi),logger,log_kinstrloggerstyk)inkinstr_rewritekstyi{apply}(** [log_next_continuation logger sty cont] instruments the next
continuation in [cont] with [KLog] continuations to ensure
logging.
This instrumentation has a performance cost, but importantly, it
is only ever paid when logging is enabled. Otherwise, the
possibility to instrument the script is costless. *)letlog_next_continuation:typeabcd.logger->(a,b)stack_ty->(a,b,c,d)continuation->(a,b,c,d)continuationtzresult=letopenResult_syntaxinfunloggerstack_tycont->letenable_logstyki=log_kinstrloggerstykiinmatchcontwith|KCons(ki,k)->(letki'=enable_logstack_tykiinlet+sty=kinstr_final_stack_typestack_tykiinmatchstywith|None->KCons(ki',k)|Somesty->KCons(ki',instrument_contloggerstyk))|KLoop_in(ki,k)->let(Item_t(Bool_t,sty))=stack_tyinreturn@@KLoop_in(enable_logstyki,instrument_contloggerstyk)|KReturn(stack,sty,k)->letk'=instrument_contlogger(assert_somesty)kinreturn@@KReturn(stack,sty,k')|KLoop_in_left(ki,k)->let(Item_t(Or_t(a_ty,b_ty,_,_),rest))=stack_tyinletki'=enable_log(Item_t(a_ty,rest))kiinletk'=instrument_contlogger(Item_t(b_ty,rest))kinreturn@@KLoop_in_left(ki',k')|KUndip(x,ty,k)->letk'=instrument_contlogger(Item_t(assert_somety,stack_ty))kinreturn@@KUndip(x,ty,k')|KIter(body,xty,xs,k)->letbody'=enable_log(Item_t(assert_somexty,stack_ty))bodyinletk'=instrument_contloggerstack_tykinreturn@@KIter(body',xty,xs,k')|KList_enter_body(body,xs,ys,ty,len,k)->letk'=instrument_contlogger(Item_t(assert_somety,stack_ty))kinreturn@@KList_enter_body(body,xs,ys,ty,len,k')|KList_exit_body(body,xs,ys,ty,len,k)->let(Item_t(_,sty))=stack_tyinletk'=instrument_contlogger(Item_t(assert_somety,sty))kinreturn@@KList_exit_body(body,xs,ys,ty,len,k')|KMap_enter_body(body,xs,ys,ty,k)->letk'=instrument_contlogger(Item_t(assert_somety,stack_ty))kinreturn@@KMap_enter_body(body,xs,ys,ty,k')|KMap_exit_body(body,xs,ys,yk,ty,k)->let(Item_t(_,sty))=stack_tyinletk'=instrument_contlogger(Item_t(assert_somety,sty))kinreturn@@KMap_exit_body(body,xs,ys,yk,ty,k')|KMap_head(_,_)|KView_exit(_,_)|KLog_(* This case should never happen. *)|KNil->returncont(*
Zero-cost logging
=================
*)(*
The following functions insert a logging instruction to continue
the logging process in the next execution steps.
There is a special treatment of instructions that generate fresh
continuations: we pass a constructor as argument to their
evaluation rules so that they can instrument these fresh
continuations by themselves. Instructions that create continuations
without calling specialized functions have their branches from [step]
function duplicated and adjusted here.
This on-the-fly instrumentation of the execution allows zero-cost
logging since logging instructions are only introduced if an
initial logging continuation is pushed in the initial continuation
that starts the evaluation.
*)letilog:typeasbtrf.logger->logging_event->(a,s)stack_ty->(a,s,b,t,r,f)step_type=letopenLwt_result_syntaxinfunloggereventsty((ctxt,_)asg)gaskksaccustack->(match(k,event)with|ILog_,LogEntry->()|_,LogEntry->log_entryctxtgaskstyaccustack|_,LogExitprev_loc->log_exitctxtgasprev_lockstyaccustack);let*?k=log_next_kinstrloggerstykin(* We need to match on instructions that create continuations so
that we can instrument those continuations with [KLog] (see
comment above). For functions that don't do this, we simply call
[step], as they don't require any special treatment. *)matchkwith|IIf_none{branch_if_none;branch_if_some;k;_}->(let(Item_t(Option_t(ty,_,_),rest))=styinlet*?sty_opt=branched_final_stack_type[Ex_init_stack_ty(rest,branch_if_none);Ex_init_stack_ty(Item_t(ty,rest),branch_if_some);]inletks'=matchsty_optwith|None->KCons(k,ks)|Somesty'->instrument_contloggersty'@@KCons(k,ks)inmatchaccuwith|None->letaccu,stack=stackin(step[@ocaml.tailcall])ggasbranch_if_noneks'accustack|Somev->(step[@ocaml.tailcall])ggasbranch_if_someks'vstack)|IOpt_map{body;k;loc=_}->(matchaccuwith|None->(step[@ocaml.tailcall])ggaskksNonestack|Somev->let(Item_t(Option_t(ty,_,_),rest))=styinletbsty=Item_t(ty,rest)inletkmap_head=KMap_head(Option.some,KCons(k,ks))inlet*?sty_opt=kinstr_final_stack_typebstybodyinletks'=matchsty_optwith|None->kmap_head|Somesty'->instrument_contloggersty'kmap_headin(step[@ocaml.tailcall])ggasbodyks'vstack)|IIf_left{branch_if_left;branch_if_right;k;_}->(let(Item_t(Or_t(lty,rty,_,_),rest))=styinlet*?sty_opt=branched_final_stack_type[Ex_init_stack_ty(Item_t(lty,rest),branch_if_left);Ex_init_stack_ty(Item_t(rty,rest),branch_if_right);]inletk'=matchsty_optwith|None->KCons(k,ks)|Somesty'->instrument_contloggersty'@@KCons(k,ks)inmatchaccuwith|Lv->(step[@ocaml.tailcall])ggasbranch_if_leftk'vstack|Rv->(step[@ocaml.tailcall])ggasbranch_if_rightk'vstack)|IIf_cons{branch_if_cons;branch_if_nil;k;_}->(let(Item_t((List_t(elty,_)aslty),rest))=styinlet*?sty'=branched_final_stack_type[Ex_init_stack_ty(rest,branch_if_nil);Ex_init_stack_ty(Item_t(elty,Item_t(lty,rest)),branch_if_cons);]inletk'=matchsty'with|None->KCons(k,ks)|Somesty'->instrument_contloggersty'@@KCons(k,ks)inmatchScript_list.unconsaccuwith|None->letaccu,stack=stackin(step[@ocaml.tailcall])ggasbranch_if_nilk'accustack|Some(hd,tl)->(step[@ocaml.tailcall])ggasbranch_if_consk'hd(tl,stack))|IList_map(_,body,ty,k)->let(Item_t(_,sty'))=styinletinstrument=instrument_contloggersty'in(ilist_map[@ocaml.tailcall])instrumentggasbodykkstyaccustack|IList_iter(_,ty,body,k)->let(Item_t(_,sty'))=styinletinstrument=instrument_contloggersty'in(ilist_iter[@ocaml.tailcall])instrumentggasbodytykksaccustack|ISet_iter(_,ty,body,k)->let(Item_t(_,rest))=styinletinstrument=instrument_contloggerrestin(iset_iter[@ocaml.tailcall])instrumentggasbodytykksaccustack|IMap_map(_,ty,body,k)->let(Item_t(_,rest))=styinletinstrument=instrument_contloggerrestin(imap_map[@ocaml.tailcall])instrumentggasbodykkstyaccustack|IMap_iter(_,kvty,body,k)->let(Item_t(_,rest))=styinletinstrument=instrument_contloggerrestin(imap_iter[@ocaml.tailcall])instrumentggasbodykvtykksaccustack|IMul_teznat(loc,k)->(imul_teznat[@ocaml.tailcall])(Somelogger)ggaslockksaccustack|IMul_nattez(loc,k)->(imul_nattez[@ocaml.tailcall])(Somelogger)ggaslockksaccustack|ILsl_nat(loc,k)->(ilsl_nat[@ocaml.tailcall])(Somelogger)ggaslockksaccustack|ILsr_nat(loc,k)->(ilsr_nat[@ocaml.tailcall])(Somelogger)ggaslockksaccustack|IIf{branch_if_true;branch_if_false;k;_}->let(Item_t(Bool_t,rest))=styinlet*?sty'=branched_final_stack_type[Ex_init_stack_ty(rest,branch_if_true);Ex_init_stack_ty(rest,branch_if_false);]inletk'=matchsty'with|None->KCons(k,ks)|Somesty'->instrument_contloggersty'@@KCons(k,ks)inletres,stack=stackinifaccuthen(step[@ocaml.tailcall])ggasbranch_if_truek'resstackelse(step[@ocaml.tailcall])ggasbranch_if_falsek'resstack|ILoop(_,body,k)->letks=instrument_contloggersty@@KLoop_in(body,KCons(k,ks))in(next[@ocaml.tailcall])ggasksaccustack|ILoop_left(_,bl,br)->letks=instrument_contloggersty@@KLoop_in_left(bl,KCons(br,ks))in(next[@ocaml.tailcall])ggasksaccustack|IDip(_,b,ty,k)->let(Item_t(_,rest))=styinlet*?rest'=kinstr_final_stack_typerestbinletign=accuinletks=matchrest'with|None->KUndip(ign,ty,KCons(k,ks))|Somerest'->instrument_contloggerrest'(KUndip(ign,ty,KCons(k,ks)))inletaccu,stack=stackin(step[@ocaml.tailcall])ggasbksaccustack|IExec(_,stack_ty,k)->let(Item_t(_,Item_t(Lambda_t(_,ret,_),_)))=styinletsty'=Item_t(ret,Bot_t)inletinstrument=instrument_contloggersty'iniexecinstrument(Somelogger)ggasstack_tykksaccustack|IFailwith(kloc,tv)->let{ifailwith}=ifailwithin(ifailwith[@ocaml.tailcall])(Somelogger)ggaskloctvaccu|IDipn(_,_n,n',b,k)->letaccu,stack,restore_prefix=kundipn'accustackkinletdipped_sty=dipn_stack_tyn'styinlet*?sty'=kinstr_final_stack_typedipped_stybinletks=matchsty'with|None->KCons(restore_prefix,ks)|Somesty'->instrument_contloggersty'@@KCons(restore_prefix,ks)in(step[@ocaml.tailcall])ggasbksaccustack|IView(_,(View_signature{output_ty;_}asview_signature),stack_ty,k)->letsty'=Item_t(output_ty,Bot_t)inletinstrument=instrument_contloggersty'in(iview[@ocaml.tailcall])instrumentggasview_signaturestack_tykksaccustack|_->(step[@ocaml.tailcall])ggaskksaccustack[@@inline]letklog:typeasrf.logger->outdated_context*step_constants->local_gas_counter->(a,s)stack_ty->(a,s,r,f)continuation->(a,s,r,f)continuation->a->s->(r*f*outdated_context*local_gas_counter)tzresultLwt.t=letopenLwt_result_syntaxinfunloggerggasstack_tyk0ksaccustack->letty_for_logging_unsafe=function(* This function is only called when logging is enabled. If
that's the case, the elaborator must have been called with
[logging_enabled] option, which ensures that this will not be
[None]. Realistically, it can happen that the [logging_enabled]
option was omitted, resulting in a crash here. But this is
acceptable, because logging is never enabled during block
validation, so the layer 1 is safe. *)|None->assertfalse|Somety->tyin(matchkswithKLog_->()|_->log_controlks);let*?continuation=log_next_continuationloggerstack_tyksinmatchcontinuationwith|KCons(ki,k)->(step[@ocaml.tailcall])ggaskikaccustack|KLoop_in(ki,k)->(kloop_in[@ocaml.tailcall])ggask0kikaccustack|KReturn(_,_,_)ask->(next[@ocaml.tailcall])ggaskaccustack|KLoop_in_left(ki,k)->(kloop_in_left[@ocaml.tailcall])ggask0kikaccustack|KUndip(_,_,_)ask->(next[@ocaml.tailcall])ggaskaccustack|KIter(body,xty,xs,k)->letinstrument=instrument_contloggerstack_tyin(kiter[@ocaml.tailcall])instrumentggasbodyxtyxskaccustack|KList_enter_body(body,xs,ys,ty_opt,len,k)->letinstrument=letty=ty_for_logging_unsafety_optinlet(List_t(vty,_))=tyinletsty=Item_t(vty,stack_ty)ininstrument_contloggerstyin(klist_enter[@ocaml.tailcall])instrumentggasbodyxsysty_optlenkaccustack|KList_exit_body(body,xs,ys,ty_opt,len,k)->let(Item_t(_,rest))=stack_tyinletinstrument=instrument_contloggerrestin(klist_exit[@ocaml.tailcall])instrumentggasbodyxsysty_optlenkaccustack|KMap_enter_body(body,xs,ys,ty_opt,k)->letinstrument=letty=ty_for_logging_unsafety_optinlet(Map_t(_,vty,_))=tyinletsty=Item_t(vty,stack_ty)ininstrument_contloggerstyin(kmap_enter[@ocaml.tailcall])instrumentggasbodyxsty_optyskaccustack|KMap_exit_body(body,xs,ys,yk,ty_opt,k)->let(Item_t(_,rest))=stack_tyinletinstrument=instrument_contloggerrestin(kmap_exit[@ocaml.tailcall])instrumentggasbodyxsty_optysykkaccustack|KMap_head(f,k)->(next[@ocaml.tailcall])ggask(faccu)stack|KView_exit(scs,k)->(next[@ocaml.tailcall])(fstg,scs)gaskaccustack|KLog_ask->(* This case should never happen. *)(next[@ocaml.tailcall])ggaskaccustack|KNilask->(next[@ocaml.tailcall])ggaskaccustack[@@inline]endletmake(moduleBase:Logger_base)=letmoduleLogger=Logger(Base)inletopenLoggerinletopenBasein{log_interp;get_log;log_kinstr;klog;ilog}