
    Jjf                    `   d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	  ee
      j                         j                  d   Zedz  Zdd	d
dddZdg dddg dddg dddg dddg ddgZd"d#dZd$dZd%dZ	 d"	 	 	 	 	 	 	 	 	 	 	 d&dZd'dZd'dZedfd(dZd)d Zed!k(  r e        yy)*z1Consolidate selector-merge runtime proof context.    )annotationsN)Path)Any   outzCsource/predecessor selector-merge execution proof into selector 2:0z=non-diagnostic selected-root runtime execution for 0x00540714zKobserved predecessor fill-state on the route path before the current readerzKroute-pair entry execution that reaches the current reader on a normal pathz:strict map1_01a source coordinate or tile hotspot evidence)selector-merge-execution-proofselected-root-runtime-executionpredecessor-fill-runtime-proofroute-pair-entry-executionstrict-source-hotspotz*out/save_selector_merge_execution_gap.json) selectorMergeExecutionProofFound
proofFound#failedSelectorMergeExecutionGateIdsmissingEvidenceevidenceRefCount)pathfieldsz>out/save_selector_predecessor_fill_site_execution_context.json)fillSiteExecutionContextProvenbranchStatePollSampleCountbranchStatePollFillMatchCountr   failedPredecessorFillGateIdsz2out/save_selector_selected_root_execution_gap.json)selectedRootExecutionRefFoundruntimeProbeGatediagnosticExclusionGater   z5out/save_selector_route_pair_entry_execution_gap.json)routePairEntryExecutionProven)routePairCorrectedTraceReachesReaderCount'sourceOrPredecessorCurrentProducerCountr   z.out/map1_01a_strict_hotspot_review_matrix.json)strictSourceCoordinateFoundtileHotspotConfirmedtransitionReviewRowCounteventTransitionCountcandidateCountc                x    | j                         s|i S |S t        j                  | j                  d            S )Nutf-8encoding)existsjsonloads	read_text)r   fallbacks     J/home/exedev/hwanse/tools/summarize_save_selector_merge_runtime_context.py	load_jsonr-   R   s5    ;;=%r383::dnngn677    c                B    dj                  d | xs g D              xs dS )N,c              3  2   K   | ]  }t        |        y wN)str).0values     r,   	<genexpr>zcsv.<locals>.<genexpr>Y   s     95CJ9s   -)join)valuess    r,   csvr:   X   s     889FLb99@S@r.   c                *    t        t        |             S r2   )r3   bool)r5   s    r,   	bool_textr=   \   s    tE{r.   c                   |xs i }|j                  d      xs i }|j                  d      xs i }| j                  d      du xr= | j                  d      du xr( | j                  d      du xr | j                  d      du}| j                  d      d	k(  xr* | j                  d
      d	k(  xr | j                  d      d	k(  }| j                  d      dk(  xr* | j                  d      dk(  xr | j                  d      d	k(  }	|j                  d      du xr |j                  d      du }
t        |j                  d      xs d	      d	kD  xr |j                  d      d	k(  }|j                  d      du xr |j                  d      du }|j                  d      du xr |j                  d      dk(  }| j                  d      du xr( |j                  d      du xr |j                  d      du }g }| j                  d      dur|j                  d       |j                  d      dus&|j                  d      dus|j                  d      du r|j                  d       |j                  d      dur|j                  d       |j                  d      dur|j                  d        |r|j                  d!       |D cg c]  }t        j                  ||       }}|rd"nd#}d$|rd%nd&d'| j                  d       d(| j                  d       d)t	        | j                  d*      xs g        d+| j                  d       d,d-|rd.nd/d0| j                  d       d1| j                  d
       d2| j                  d       d3| j                  d4       d5| j                  d6       d7| j                  d8       d9t	        | j                  d:             d;t	        | j                  d<             d=| j                  d>       d?| j                  d@       d,dA|	rdBndCdD| j                  d       dE| j                  d       dF| j                  d       d,dG|
rdHndIdJ|j                  d       dK|j                  d       dL|j                  dM       dN|j                  d       dO|j                  dP       
d,dQ|rdRndSdT|j                  dU       dV|j                  dW       dX|j                  d       dY|j                  d       dZ|j                  d       
d,d |rd[nd\d]|j                  d^       d_|j                  d       d`|j                  da       db|j                  d       d,dc|rddnd/de|j                  d       df|j                  d       dg|j                  dh       di|j                  dj       dk|j                  dl       
d,g}dm}i dn| j                  dn      xs dodp| j                  dp      xs dqdr| j                  dr      ds| j                  ds      dt| j                  dt      du| j                  du      d| j                  d      d| j                  d      d*| j                  d*      xs g d| j                  d      dv| j                  dv      d| j                  d      d
| j                  d
      d| j                  d      d4| j                  d4      d6| j                  d6      d8| j                  d8      i d:| j                  d:      xs g dw| j                  dw      d<| j                  d<      xs g dx| j                  dx      d>| j                  d>      d@| j                  d@      d| j                  d      d| j                  d      d| j                  d      dy|dz|d{|	d|j                  d      d|j                  d      d|j                  d      d||j                  d      d}|j                  d      i d~|j                  dW      d|j                  d      d|j                  d      d|j                  d      d|j                  d      d|j                  d      d| j                  d      d|d|d|d|dt
        dt        t
              d| j                  d      du xs | d|d|dg dd|iS c c}w )Nr   r   "currentEqualsPredecessorPlusSourceT#sourcePredecessorUnionCoversCurrentroutePairOnlyCurrentSelectorr   sourceToCurrentBridgeHitCountr   predecessorToCurrentHitCountforwardMergeBridgeHitCountcurrentToPredecessorHitCount3   &currentToPredecessorBeforeFillHitCount$currentToPredecessorFillSiteHitCount-constructedDiagnosticPollReachedRouteSelector&excludedFromSelectedRootExecutionProof(branchStatePollPublicPredecessorHitCountr   r   Fr   r   r      r   r   r   "anyRuntimePollReachedRouteSelectorr	   r
   r   r   zready-for-reviewblockedzmerge-shapez
shape-onlyznot-merge-shapedz#currentEqualsPredecessorPlusSource=z; unionCoversCurrent=z; extra=sourcePredecessorUnionExtraMapsz; routePairOnlyCurrent=)kindstatusdetailzforward-bridgeabsentpresentzsourceToCurrent=z; predecessorToCurrent=z; forwardMergeBridge=z; encodedRaw=+forwardEncodedAnchorRawScalarCandidateCountz; encodedPromoting=+forwardEncodedAnchorPromotingCandidateCountz; encodedMerge= encodedMergeExecutionBridgeFoundz; aliasPublicForward=+targetAliasPublicCoveredForwardHitSelectorsz; aliasAddressAdjacentForward=-targetAliasAddressAdjacentForwardHitSelectorsz; aliasCoverage=)targetAliasPublicForwardHitCoverageStatusz; aliasExclusion=#targetAliasExecutionExclusionStatuszreverse-reusezbefore-fill-onlyopenzcurrentToPredecessor=z; beforeFill=z; fillSite=zselected-root-runtimezdiagnostic-excludedznot-observedzselectedRootRef=z; anyPollRoute=z; patchedRoute=ApatchedPublicSelector20InputPathCaseAliasPollReachedRouteSelectorz; diagnosticExcluded=z; followup=followupSelectorzpredecessor-fill-runtimez$public-predecessor-fill-not-observedznot-classifiedzbranchPolls=branchStatePollCountz
; samples=r   z; publicHits=z; fillMatches=z; contextProof=zreader-shaped-not-executedexecutedz	entryIdx=routePairEntryIndicesz; correctedReader=z; sourcePredCurrentProducers=r   z; entryExec=zstrict-hotspotmissingzstrictSource=z; tileHotspot=z; routeReviews=r    z; strictEvents=r!   z; candidates=r"   aM  Selector 2:0 remains a merge-shaped runtime gap. It combines the predecessor 1:0 map set with map1_01a and is the only selector carrying the route pair, but no source/predecessor forward bridge, selected-root execution ref, predecessor fill observation, or strict hotspot proves that the merged selector executes on the normal route.sourcemap1_01atargetmap2_02dsourceSelectorpredecessorSelectorcurrentSelectorcurrentRootHexcurrentExactPairUnionCount&targetAliasForwardHitPublicSampleCount)targetAliasForwardHitsAddressAdjacentOnlymergeShapeOnlyforwardBridgeAbsentreverseReuseBeforeFillOnly&constructedDiagnosticExcludedFromProof)predecessorFillSiteExecutionContextProven%predecessorBranchStatePollSampleCount(predecessorBranchStatePollFillMatchCountselectorMergeRuntimeProofFoundr   !failedSelectorMergeRuntimeGateIdsr   evidenceRefsr   selectorMergeGapOpenpromotionStatusevidenceremainingProofs)z;prove a source/predecessor forward bridge into selector 2:0zGcapture selected-root execution for 0x00540714 on a non-diagnostic pathzJobserve predecessor fill-state on the route path before the current readerz?find strict map1_01a source coordinate or tile hotspot evidence
conclusion)getintappend/SELECTOR_MERGE_RUNTIME_MISSING_EVIDENCE_BY_GATEr:   $SELECTOR_MERGE_RUNTIME_EVIDENCE_REFSlen)merge_execution_gap'predecessor_fill_site_execution_contextselected_root_execution_gaproute_pair_entry_execution_gapstrict_hotspot_review_matrixruntime_gatediagnostic_gatemerge_shape_onlyforward_bridge_absentreverse_reuse_before_fill_onlydiagnostic_route_excludedpublic_predecessor_no_fillstrict_hotspot_missingroute_pair_entry_unexecuted"selector_merge_runtime_proof_found&failed_selector_merge_runtime_gate_idsgate_idmissing_evidencepromotion_statusrz   r|   s                        r,   build_summaryr   `   s    $@#E2 .223EFL"L1556OPVTVO DEM 	T##$IJdR	T##$BCtK	T  ##$FGtS	  	 ?@AE 	G##$BCqH	G##$@AQF  	 >?2E 	Q##$LMQSS	Q##$JKqP # 	HITQ 	R HITQ 
 	3778bchghilmm 	^3778WX\]] 
 	%(()FG5P 	N(,,-CDM 
 	'**+JKuT 	a*../Z[_``  
 	 BCtK 	b'++,KLPTT	b3778XY]aa '
 .0*AB$N.556VW#''(GHPTT@AMGHDP.556WX.223ST\``.556VW%))*IJRVV.556RS.556MN > 	8;;GWM  .P)U^ "&6l<N5&**+OPQ R&&9&=&=>c&d%e f0445VW][]^_ `((;(?(?@^(_'`	b	
	
 %"7hY"#6#:#:;Z#["\ ]((;(?(?@^(_'` a&&9&=&=>Z&[%\ ]&**+XYZ [$&**+XYZ [ &**+MNO P&*../\]^_ `/*../^_`a b!&**+VWX Y"&**+PQR!T		
0 $,J(PV'(;(?(?@^(_'` a1556^_` a/334Z[\^		
 ,/H+n"#>#B#BCb#c"d e  , 0 01U VW X  , 0 01t uv w&&5&9&9:b&c%d e+//0BCD	F	
	
 /) =!FJJKabc dBFFGcde fEIIJtuv wFJJKjkl m  G K KLl mn	p	
 16Q2Wa:>>?VWX Y##A#E#EFq#r"s t.1556_`a b;??@_`a	c	
	
 %#9iy < @ @A^ _` a;??@VWX Y  < @ @A[ \] ^  < @ @AW XY Z:>>?OPQ	S	
	
_ZHx	1 j%))(3Azj%))(3Azj 	-112BCj 	2667LM	j
 	.223DEj 	-112BCj 	-.A.E.E0/
j 	./B/F/F10
j 	*+>+B+B-,
 , !j" 	'(;(?(?@^(_#j$ 	%&9&=&=>Z&[%j& 	()<)@)@A`)a'j( 	'(;(?(?@^(_)j* 	%&9&=&=>Z&[+j, 	67J7N7N98
-j2 	67J7N7N98
3j8 	+,?,C,C.-
9j> 	67J7N7N98
 8 EjF 	12E2I2I43
GjL 	89L9P9P;:
 : SjT 	45H5L5L76
UjZ 	45H5L5L76
[j` 	./B/F/F10
ajf 	'(;(?(?@^(_gjh 	12E2I2I43
ijn 	/0C0G0G21
ojt 	*ujv 	4wjx 	%&Dyjz 	()D)H)HIh)i{j| 	-l.>.>?c.d}j~ 	89I9I;:
jD 	1/2E2E43
EjJ 	45\5`5`,6
KjP 	01X1\1\(2
QjV 	34[4_4_+5
Wj\ 	()G)K)K+*
]jb 	45S5W5W76
cjh 	&'C'G'GHe'fijj 	 < @ @AW Xkjl 	+,?,C,C.-
mjr 	)*Lsjt 	8ujv 	,-Swjx 	+yjz 	<{j| 	C DE}j~ 	 3 7 78N OSW W !211AjB 	+CjD 	HEjF 	 
GjR 	jSj jMs   ?c(c           
        g dd| d   dd| d    d| d    dd	| d
    d| d    d| d    dd| d    dd| d    d| d    dt        | j                  d             dd| d    d| d    dt        | j                  d             dt        | j                  d             dd| j                  d        d| j                  d!       dd"| d#    d$| d%    d&| d'    d(| d)    d*| d+    d,| d-    d.| d/    d0| d1    d2| d3    d4t        | j                  d5             dd6t        | j                  d7      xs g        d8| j                  d9       d:| d;    ddd<d| j                  d7      xs g D cg c]  }d=| 	 c}dd>dd?d@}| j                  dA      xs g D ]&  }|j                  dB|dC    dD|dE    dD|dF    dG       ( |j	                  g dH       |j	                  dI | j                  dJ      xs g D               |j                  d       dKj                  |      S c c}w )LNz%# Save Selector Merge Runtime Context r|   z
- route: `rc   z -> re   `z- selectors: source `rg   z`, predecessor `rh   z`, current `ri   z- current root: `rj   z*- current equals predecessor plus source: r?   z+- source+predecessor union covers current: r@   z"- source+predecessor extra maps: `rO   z$- route pair only current selector: rA   z- forward bridge absent: ro   z;- target alias public/address-adjacent forward selectors: `rX   z` / `rY   z+- target alias public coverage/exclusion: `rZ   r[   z"- reverse reuse before fill only: rp   z%- selected-root execution ref found: r   z.- constructed diagnostic excluded from proof: rq   z2- predecessor fill-site execution context proven: rr   z%- route-pair entry execution proven: r   z+- strict source coordinate / tile hotspot: r   z / r   z&- selector merge runtime proof found: ru   z- proof found: r   z(- failed selector-merge runtime gates: `rv   z- missing evidence count: r   z- evidence refs: r   z- promotion status: `ry   z## Missing Evidence- z## Evidencez| kind | status | detail |z| --- | --- | --- |rz   z| rP   z | rQ   rR   z |)r   z## Remaining Proofsr   c              3  &   K   | ]	  }d |   yw)r   N r4   items     r,   r6   zmarkdown.<locals>.<genexpr>  s     N2dVNs   r{   
)r:   r}   r   r   extendr8   )summaryr   linesrows       r,   markdownr   q  s   $/$
$ 	$ 		$
 WX&'tGH,=+>a@$  (8 9::J7ShKiJjjvw~  @Q  xR  wS  ST  	U$ G$456a8$ 5W=a5b4cd$ 6g>c6d5ef$ -S=^1_-`,aabc$ /w7U/V.WX$ $G,A$B#CD$ Fc'++  WD  KE  GF  FG  GL  MP  QX  Q\  Q\  ]L  QM  MN  LO  OP  	Q$ 6gkkBm6n5ootu|  vA  vA  Bg  vh  ui  ij  	k$ -W5Q-R,ST$  08W0X/YZ!$" 9Ai9j8kl#$$ =WEp=q<rs%$& 08W0X/YZ'$( 6g>[6\5]]`ahi  bA  aB  	C)$* 19Y1Z0[\+$, ',/01-$. 33w{{Cf7g3h2iijk/$0 %S5F)G)M2%N$OP1$2 GKK(:;<=3$4  (9 :;1=5$6 	7$8 	9$: 	;$< #*++.?"@"FB	G$Btf+	G=$> 	?$@ 	A$B 	C$D 	%E$F 	G$EJ {{:&," Or#f+c#h-CM?"MNO	LL01	LLN5F)G)M2NN	LL99U 
Hs   Ic                &   dj                  d | j                  d      xs g D              }dj                  d | j                  d      xs g D              }dj                  d | j                  d      xs g D              }dj                  dd	d
dddddddt        j                  | d          ddt        j                  t	        | d                dt        j                  t	        | d                ddt        j                  t	        | d                dt        j                  t	        | d                dt        j                  t	        | d                dt        j                  t	        | d                 d	d!j                  g d"t        | d#          d$t        j                  t        | j                  d%                   d&t        j                  t        | j                  d'                   d(t        j                  t	        | j                  d)                   d&t        j                  t	        | j                  d*                   d+t        j                  t	        | j                  d*                   d,t        | d-          d.t        | d/          d0t        | d1          d2t        | d3   xs | d4          d5t        | d6          d7| d8    d9t        j                  t        | j                  d:                   d;t        | j                  d      xs g        d<| j                  d=       d>t        j                  | d?          d      d@dA| dBdCdD| dEdFdA| dBdGdHd!g      S )INr   c           
   3     K   | ]R  }d t        j                  |d          dt        j                  |d          dt        j                  |d          d T yw)z<tr><td>rP   z	</td><td>rQ   rR   z
</td></tr>Nhtmlescape)r4   r   s     r,   r6   zhtml_page.<locals>.<genexpr>  sg       	{{3v;'( ){{3x=)* +{{3x=)* +	s   AArz   c              3  N   K   | ]  }d t        j                  |       d  ywz<li>z</li>Nr   r   s     r,   r6   zhtml_page.<locals>.<genexpr>  s(      ,0$t{{4 !'   #%r{   c              3  N   K   | ]  }d t        j                  |       d  ywr   r   r   s     r,   r6   zhtml_page.<locals>.<genexpr>  s(      ,0$t{{4 !'r   r   z<!doctype html>z<html lang="en">z<head>z  <meta charset="utf-8">z4  <title>Save Selector Merge Runtime Context</title>a    <style>body{font-family:system-ui,sans-serif;margin:24px;line-height:1.45;max-width:1200px}table{border-collapse:collapse;width:100%;margin:16px 0}td,th{border:1px solid #ddd;padding:6px 8px;text-align:left;vertical-align:top}th{background:#f5f5f5}code{white-space:nowrap}</style>z</head>z<body>z.  <h1>Save Selector Merge Runtime Context</h1>z  <p>r|   z</p>z  <p><b>Route:</b> <code>rc   z</code> -&gt; <code>re   z</code>.</p>z$  <p><b>Selectors:</b> source <code>rg   z</code>; predecessor <code>rh   z</code>; current <code>ri   z</code> root <code>rj   r   z)  <p><b>Proof:</b> forward bridge absent ro   z?; target alias public/address-adjacent forward selectors <code>rX   z</code>/<code>rY   z6</code>; target alias public coverage/exclusion <code>rZ   r[   z</code>; alias exclusion <code>z</code>; selected-root ref r   z; diagnostic excluded rq   z; predecessor fill context rr   z; strict hotspot r   r   z; runtime proof ru   z; proofFound=r   z(; failedSelectorMergeRuntimeGates=<code>rv   z</code>; missingEvidenceCount=z; evidenceRefs=r   z; promotion status <code>ry   z  <h2>Missing Evidence</h2>z  <ul>z</ul>z  <h2>Evidence</h2>zS  <table><thead><tr><th>kind</th><th>status</th><th>detail</th></tr></thead><tbody>z</tbody></table>z  <h2>Remaining Proofs</h2>z</body>z</html>)r8   r}   r   r   r3   r=   r:   r   )r   evidence_rowsproof_itemsmissing_itemss       r,   	html_pager     s   II  ;;z*0b M )) 4;KK@Q4R4XVX K II 4;KK@Q4R4XVX M 99"> 	e8
GL12348[[WX%6!789 :[[WX%6!789G
 KKG4D,E(FGH I!!%S9N1O-P!Q R S![[W5F-G)HIJ K++c'2B*C&DEFl	T\ \ % \%.w7L/M%N$O\P\ [[W[[1^%_!`ab\c\ [[W[[1`%a!bcd	\e<	\
 =AKKGKK  YD  ME  IF  =G  <H\
H\ [[W[[1V%W!XYZ\[%\ &*[[W[[Af5g1h%i$j\k!\ "+73R+S!T U\V#\ $-W5]-^#_"`\a(\ )2':e2f(g'h\i\ (0M(N(qRYZpRqrs\t\ 'w/O'PQR\S\ ",/0\1\ [[W[[1T%U!VWX\Y$\  %(4E(F(L"$M#N!\ O!\" $KK(:;<#\"=&#\$ '+kk':K2L&M%N%\$ O[%\( 	&
u%
]^k]ll|}%
U#
i5 5 5r.   c                   |j                  dd       |dz  }|j                  t        j                  | dd      dz   d	       |9|j                  j                  dd       |j                  t        |       d	       |S )
NT)parentsexist_okz(save_selector_merge_runtime_context.jsonFrL   )ensure_asciiindentr   r$   r%   )mkdir
write_textr(   dumpsparentr   )r   out_dirhtml_outjson_outs       r,   write_outputsr     s    MM$M.CCH

7q9D@   dT:Ig.AOr.   c            
        t        j                  t              } | j                  dt        t
               | j                  dt               | j                         }t        t        |j                  dz        t        |j                  dz        t        |j                  dz        t        |j                  d	z        t        |j                  d
z              }t        ||j                  |j                        }t        d|        y )N)descriptionz	--out-dir)typedefaultz
--html-out)r   z&save_selector_merge_execution_gap.jsonz:save_selector_predecessor_fill_site_execution_context.jsonz.save_selector_selected_root_execution_gap.jsonz1save_selector_route_pair_entry_execution_gap.jsonz*map1_01a_strict_hotspot_review_matrix.jsonz-wrote save selector merge runtime context -> )argparseArgumentParser__doc__add_argumentr   OUT
parse_argsr   r-   r   r   r   print)parserargsr   r   s       r,   mainr     s    $$9F
$<
40D$,,!IIJ$,,!]]^$,,!QQR$,,!TTU$,,!MMNG WdllDMMBH	9(
DEr.   __main__r2   )r   r   r+   z
Any | Nonereturnr   )r9   zlist[Any] | Noner   r3   )r5   r   r   r3   )r   dictr   r   r   r   r   r   r   zdict | Noner   r   )r   r   r   r3   )r   r   r   r   r   zPath | Noner   r   )r   None)r   
__future__r   r   r   r(   pathlibr   typingr   __file__resolver   ROOTr   r   r   r-   r:   r=   r   r   r   r   r   __name__r   r.   r,   <module>r      sK   7 "      H~''*
Ul 	N 	H 	V 	VY3 /" =
	 Q
	 E
 H
 A
	O1( $h8A 15NN-1N "&N %)	N
 #.N 
Nb+\DN 25d 
F  zF r.   