123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899(* This file is free software, part of Zipperposition. See file "license" for more details. *)(** {1 Unification Substitution} *)(** A tuple containing:
- the substitution itself
- delayed constraints
*)moduleH=HVartypeterm=Subst.termtypevar=Subst.vartypet={subst:Subst.t;cstr_l:Unif_constr.tlist;}letsubstt=t.substletconstr_lt=t.cstr_lletmakesubstcstr_l={subst;cstr_l}letempty:t=makeSubst.empty[]letis_empty(s:t):bool=Subst.is_empty(substs)&&CCList.is_empty(constr_ls)letmap_subst~ft={twithsubst=ft.subst}letof_substs=makes[]lettags(s:t):_list=CCList.flat_mapUnif_constr.tags(constr_ls)letbindtvu={twithsubst=Subst.bindt.substvu}letupdatetvu={twithsubst=Subst.updatet.substvu}letmemtv=Subst.memt.substvletdereftv=Subst.dereft.substvletmerget1t2={subst=Subst.merget1.substt2.subst;cstr_l=t1.cstr_l@t2.cstr_l}letcompose~scopet1t2={subst=Subst.FO.compose~scopet1.substt2.subst;cstr_l=t1.cstr_l@t2.cstr_l}moduleFO=structletbindt(v:Type.tHVar.tScoped.t)u={twithsubst=Subst.FO.bindt.subst(v:>InnerTerm.tHVar.tScoped.t)u}letmemt(v:Type.tHVar.tScoped.t)=Subst.memt.subst(v:>InnerTerm.tHVar.tScoped.t)letderefst=Subst.FO.derefs.substtletsingletonvt=bindemptyvtletrename_to_new_scope~counter(t0,scope0)(t1,scope1)=letapplyst=Subst.FO.applySubst.Renaming.none(substs)tinletapply_tysty=Subst.Ty.applySubst.Renaming.none(substs)tyinletnew_scope=ifscope0<scope1thenscope1+1elsescope0+1inletadd_renamingscopesubstv=ifmemsubst(v,scope)thensubstelseletty=apply_tysubst(HVar.tyv,scope)inletnewvar=Term.var(H.fresh_cnt~counter~ty())inbindsubst(v,scope)(newvar,new_scope)inletsubst=emptyinletsubst=Term.Seq.varst0|>Iter.fold(add_renamingscope0)substinletsubst=Term.Seq.varst1|>Iter.fold(add_renamingscope1)substinlett0',t1'=applysubst(t0,scope0),applysubst(t1,scope1)int0',t1',new_scope,substendlethas_constrt:bool=constr_lt<>[]letadd_constrct={twithcstr_l=c::t.cstr_l}letppoutt:unit=ifhas_constrtthenFormat.fprintfout"(@[%a@ :constr_l (@[<hv>%a@])@])"Subst.pp(substt)(Util.pp_list~sep:""Unif_constr.pp)(constr_lt)elseSubst.ppout(substt)letequalab=Subst.equal(substa)(substb)&&CCList.equalUnif_constr.equal(constr_la)(constr_lb)lethasha=Hash.combine2(Subst.hash@@substa)(Hash.listUnif_constr.hash@@constr_la)letcompareab=letopenCCOrd.InfixinSubst.compare(substa)(substb)<?>(CCList.compareUnif_constr.compare,constr_la,constr_lb)letto_string=CCFormat.to_stringppletconstr_l_substrenaming(s:t):_list=constr_ls|>Unif_constr.apply_subst_lrenaming(substs)