123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117(* Every kind of candidate behind {!Candidate_kind.S}, asked in one order: the
order offers are made in breaks ties between equal savings. *)openStylesheetopenStdlibtypeoffer=Candidate_kind.offerletkey=Candidate_kind.keyletcandidate=Candidate_kind.candidatetypet={core:Candidate_kind.core;bodies:Candidate_groups.t;selectors:Candidate_groups.t;inlining:Candidate_inlining.t;exact:Candidate_factoring.t;default:Candidate_factoring.t;}letremove_nodetid=Candidate_groups.removet.coret.bodiesid;Candidate_groups.removet.coret.selectorsid;Candidate_inlining.removet.coret.inliningid;Candidate_factoring.removet.coret.exactid;Candidate_factoring.removet.coret.defaultidletadd_nodetid=Candidate_groups.addt.coret.bodiesid;Candidate_groups.addt.coret.selectorsid;Candidate_inlining.addt.coret.inliningid;Candidate_factoring.addt.coret.exactid;Candidate_factoring.addt.coret.defaultidletreorder_movedtmoved=Candidate_groups.reordert.coret.bodiesmoved;Candidate_groups.reordert.coret.selectorsmoved;Candidate_inlining.reordert.coret.inliningmoved;Candidate_factoring.reordert.coret.exactmoved;Candidate_factoring.reordert.coret.defaultmovedletsettletchanges=Candidate_groups.settlet.coret.bodieschanges;Candidate_groups.settlet.coret.selectorschanges;Candidate_inlining.settlet.coret.inliningchanges;Candidate_factoring.settlet.coret.exactchanges;Candidate_factoring.settlet.coret.defaultchangesmoduleRule_table=Hashtbl.Make(structtypet=ruleletequalab=Stylesheet.equal_statement(Rulea)(Ruleb)lethash=Stylesheet.rule_hashend)(* [finalize] is a pure normalisation, and the candidates of one run hand it the
same leftover rules over and over: every subset that factors the same
declarations out of a member leaves it the same rule. *)letrememberedsizefinalize=letknown=Rule_table.createsizeinfunrule->matchRule_table.find_optknownrulewith|Somefinalized->finalized|None->letfinalized=finalizeruleinRule_table.replaceknownrulefinalized;finalizedletv~ctx~finalizeg=(* Tables start at the run's size: most runs hold a handful of rules. *)letsize=Rule_graph.node_countginletfinalize=rememberedsizefinalizeinletbudget=Subsets.v~aggressive:(Ctx.aggressivectx)inlett={core=Candidate_kind.v~ctx~finalizeg;bodies=Candidate_groups.vsizeBodies;selectors=Candidate_groups.vsizeSelectors;inlining=Candidate_inlining.vsize;exact=Candidate_factoring.vsizeExactbudget;default=Candidate_factoring.vsizeDefaultbudget;}inList.iter(add_nodet)(Rule_graph.live_nodesg);tletrefresht=matchCandidate_kind.pendingt.corewith|None->[]|Somechanges->settletchanges;Candidate_kind.closet.coreletstart~ctx~finalizeg=v~ctx~finalizegletrewritetgraph~consume=letchanges=Candidate_kind.rewritet.coregraph~consumeinList.iter(remove_nodet)changes.consumed;List.iter(add_nodet)changes.produced;ifchanges.moved<>[]thenreorder_movedtchanges.movedletofferst=[]|>Candidate_groups.offerst.bodies|>Candidate_groups.offerst.selectors|>Candidate_inlining.offerst.inlining|>Candidate_factoring.offerst.exact|>Candidate_factoring.offerst.default|>List.sort(funab->Int.compare(keya)(keyb))letis_livetid=Candidate_kind.is_live(Candidate_kind.viewt.core)idletcandidatest=List.mapcandidate(offerst)letenumerate~ctx~finalizeg=lett=v~ctx~finalizeginignore(refresht);candidatest