
    UHj                        d Z ddlmZ ddlZddlZddlZddlmZ  ee      j                         j                  d   Zedz  ZdZdZdd	Zdd
ZddZddZddZddZddZedk(  r e        yy)zNRank inherited secondaryBranchState producer candidates for the current route.    )annotationsN)Path   outz2:0
0x00540714c                L    | j                  d       d| j                  d       S )Ngroup:slot)get)rows    O/home/exedev/hwanse/tools/summarize_save_selector_inherited_state_candidates.pyselector_keyr      s&    gggq 122    c                8   | D cg c]  }|j                  d      s| }}i }|D ]k  }t        |      }t        |j                  d      xs g       }g }|D ]  }t        |      }||k(  r|j                  d      |j                  d      f|j                  d      |j                  d      fk\  rZt        |j                  d      xs g       }	t        ||	z        }
t        ||	z
        }t        |	|z
        }|
r|s|j	                  ||j                  d      |
||t        |
      dz  t        |      z   t        |      z
  d        |j                  d        ||j                  d      |j                  d      xs g ||r|d	   nd d
||<   n |S c c}w )N	fieldMapsr	   r   selectedPointerHex
   )selectorrootHex
sharedMapsintroducedMapsdroppedMapsscorec                    | d    | d   fS )Nr   r    )items    r   <lambda>z&build_progress_edges.<locals>.<lambda>0   s    gZ8H'I r   )keyr   )r   r   r   previousbestPrevious)r   r   setsortedappendlensort)	selectorsr   
field_rowsedgesr   mapsr    prevprev_key	prev_mapsshared
introduceddroppeds                r   build_progress_edgesr1      s   !*C#cggk.B#CJCE 
3377;'-2. 	D#D)H3!488F#349I377SY?8[[DHH[17R8ID9,-Fy 01JY-.GOO$88$89$",&Vr)C
O;c'lJ 	( 	IJww34-3 +3HQK
c
3
@ LE Ds
   FFc                ^   t        |       }|j                  d      xs g D ci c]  }|j                  d      | }}|j                  t              xs i }g }|j                  d      xs g D ]  }|j                  |j                  d            }|j                  i |t	        |      |xs i j                  dd      |xs i j                  dg       d d ||j                  d      k(  r|rd	n|rd
ndd        d}	t        t
        |j                  d      xs g |r|d   nd ||	dS c c}w )Nrootsr   r    	fillCountr   fills   r!   z$best previous and has secondary fillz)alternate previous and has secondary fillz+progress predecessor without secondary fill)hasSecondaryFillsecondaryFillCount
firstFillscandidateRolea  The selector-progress predecessor for current root 2:0 is 1:0, and that predecessor has opcode-shaped secondaryBranchState fills. This makes 1:0/root 0x00478364 the strongest inherited-state producer candidate for the map1_01a->map2_02d blocker. It still does not promote the transition: the remaining proof is to decode which slot/value 1:0 leaves in secondaryBranchState and to find a strict map1_01a source hotspot.r   )currentSelectorcurrentRootHexcurrentFieldMapsr!   
candidates
conclusion)r1   r   CURRENT_SELECTORr$   boolCURRENT_ROOT)
r'   
fill_rootsr)   r   fill_by_rootcurrentr>   r   fillr?   s
             r   build_summaryrG   ;   sN    +E7A~~g7N7TRTUCGGI&+ULUii()/RGJJ'-2  34 

 $T
#':2"2"2;"B:2**7B7; 7;;~664 7  AB
 	 	l  ,&#KK4:)3
1   1 Vs   D*c                   ddd| d    dd| d    dd| d	    dd
dg}| d   D ]  }dj                  d |j                  d      xs g D              xs d}|j                  d|d    d|d    d|d    ddj                  |j                  d      xs g       xs d ddj                  |j                  d      xs g       xs d d|d    d| d        |j                  d       dj                  |      S )Nz*# Save Selector Inherited State Candidates z- current selector: `r;   `z- current root: `r<   z- conclusion: r?   z]| predecessor | root | secondary fills | shared maps | introduced maps | role | first fills |z,| --- | --- | ---: | --- | --- | --- | --- |r>   , c              3  :   K   | ]  }d |d    d|d    d   yw)rJ   vaHex=valueHexNr   .0r   s     r   	<genexpr>zmarkdown.<locals>.<genexpr>k   s)     jdAd7m_Ad:.>-?qAjs   r9   -z| `r   z` | `r   z` | r8   z | r   r   r:   z |
)joinr   r$   )summarylinesr   r5   s       r   markdownrX   _   sA   4

(9 :;1=
G$456a8
./0
g6	E |$ 
		jcggVbNcNigijjqnq#j/"%I'7tC@T<U;VVYyy.4"5<=S377ScKdKjhjAkAror@ssv?#$Cwb2	

 
LL99Ur   c                    dj                  d | d   D              }dj                  dddd| d    d	| d
    ddt        j                  | d          dd|dg      S )NrT   c              3  *  K   | ]
  }d t        j                  |d          dt        j                  t        |d                d|d    dt        j                  dj                  |j	                  d      xs g       xs d	       dt        j                  dj                  |j	                  d
      xs g       xs d	       dt        j                  |d          ddj                  d |j	                  d      xs g D              xs d	 d  yw)z<tr><td><code>r   z</code></td><td><code>r   z</code></td><td>r8   z	</td><td>rK   r   rS   r   r:   c              3     K   | ]>  }d t        j                  |d         z   dz   t        j                  |d         z   dz    @ yw)z<code>rM   rN   rO   z</code>N)htmlescaperP   s     r   rR   z&html_page.<locals>.<genexpr>.<genexpr>~   sI       ZuyDKKW$>>Dt{{SWXbScGddgpp  Zs   AAr9   z
</td></tr>N)r\   r]   strrU   r   )rQ   r   s     r   rR   zhtml_page.<locals>.<genexpr>v   sD      	[[Z12 3[[S^!456 7'() *{{499SWW\%:%@bAHSIJ K{{499SWW-=%>%D"ELMN O{{3/01 2yy  Z  ~A  ~E  ~E  FR  ~S  ~Y  WY  Z  Z  a  ^a  b b	s   DDr>   z\<!doctype html><meta charset="utf-8"><title>Save Selector Inherited State Candidates</title>z<style>body{font-family:system-ui,sans-serif;background:#111;color:#eee}table{border-collapse:collapse}td,th{border:1px solid #444;padding:6px 8px;vertical-align:top}code{color:#9bd4ff}</style>z1<h1>Save Selector Inherited State Candidates</h1>z<p>Current selector: <code>r;   z</code>; current root: <code>r<   z</code></p>z<p>r?   z</p>z<table><thead><tr><th>predecessor</th><th>root</th><th>secondary fills</th><th>shared maps</th><th>introduced maps</th><th>role</th><th>first fills</th></tr></thead><tbody>z</tbody></table>)rU   r\   r]   )rV   rowss     r   	html_pager`   u   s    99  <( D 99h 	L;
%g.?&@%AA^_fgw_x^y  zE  	F
dkk',/016 	w	 	 	r   c                    |j                  dd       |dz  j                  t        j                  | dd      dz   d	       y )
NT)parentsexist_ok-save_selector_inherited_state_candidates.jsonF   )ensure_asciiindentrT   utf-8encoding)mkdir
write_textjsondumps)rV   out_dirs     r   write_outputsrp      sD    MM$M.>>JJ

7q9D@ K r   c                 .   t        j                         } | j                  dt        t        dz         | j                  dt        t        dz         | j                  dt        t               | j                         }t        t        j                  |j                  j                  d            t        j                  |j                  j                  d                  }t        ||j                         t        d	|j                  d
z          y )Nz--selectorszsave_scene_selectors.json)typedefaultz--fill-rootsz'save_selector_secondary_fill_roots.jsonz	--out-dirrh   ri   z$wrote inherited state candidates -> rd   )argparseArgumentParseradd_argumentr   OUT
parse_argsrG   rm   loadsr'   	read_textrC   rp   ro   print)parserargsrV   s      r   mainr~      s    $$&F
D#@[:[\
T3Aj;jk
$<D

4>>++W+=>

4??,,g,>?G '4<<(	0@o1o0p
qrr   __main__)r   dictreturnr^   )r'   
list[dict]r   zdict[str, dict])r'   r   rC   r   r   r   )rV   r   r   r^   )rV   r   ro   r   r   None)r   r   )__doc__
__future__r   rt   r\   rm   pathlibr   __file__resolverb   ROOTrw   r@   rB   r   r1   rG   rX   r`   rp   r~   __name__r   r   r   <module>r      s    T "     H~''*
Ul 3#L!H,2s zF r   