
    UHjB                    h   d Z ddlmZ ddlZddlZddlZddlZddlmZ ddl	m
Z
mZ  ee      j                         j                  d   Zedz  ZdZd	Zg d
Zg dZdddddddddgZd dZd!dZd"dZd#dZd$dZd%dZd&dZ	 	 	 d'	 	 	 	 	 	 	 d(dZd)dZd)dZefd*dZ d+dZ!e"dk(  r e!        yy),zIEnumerate opcode 0x20 active-order space for the current gate-base proof.    )annotationsN)Path)AnyIterable   outmap1_01amap2_02d)zselector-2-0-active-orderzruntime-descriptor-object-statez&direct-route-proof-in-descriptor-orderzstrict-source-hotspot)z;selector 2:0 active order/count or equivalent runtime tracez7runtime descriptor/object state selected by opcode 0x20zFfield-map/frontier/gate direct proof in an enumerated descriptor orderzstrict map1_01a source hotspotz2out/save_selector_opcode20_descriptor_scripts.jsonzDdescriptor script scans used to enumerate direct route proof absence)pathdescriptionz,out/save_selector_opcode20_slot_sources.jsonz=loaded slot capacity and runtime slot descriptor requirementsz4out/save_selector_opcode20_sample_order_effects.jsonzIknown public sample order signatures and current selector sample coveragec                p    | j                         s|S t        j                  | j                  d            S )Nutf-8encoding)existsjsonloads	read_text)r   fallbacks     I/home/exedev/hwanse/tools/summarize_save_selector_opcode20_order_space.py	load_jsonr   -   s*    ;;=::dnngn677    c                    | j                  d      xs g D ci c]'  }t        |j                  d      t              r|d   |) c}S c c}w )NdescriptorRowsindex)get
isinstanceint)descriptor_scriptsrows     r   descriptor_rows_by_indexr!   3   sQ     &))*:;Arcggg&, 	Gc  s   ,Ac                    i }| D ]   }|xs d}|j                  |d      dz   ||<   " t        |j                               D cg c]
  \  }}||d c}}S c c}}w )Nnoner   r   )valuecount)r   sorteditems)valuescountsr$   keyr%   s        r   	histogramr+   ;   sn    F -ovjja(1,s-
 #6<<>2E5 %(  s   Ac              #     K   t        d|dz         D ]B  }|r t        j                  | |      E d {    %t        j                  | |      E d {    D y 7 &7 	w)Nr   )repeat)range	itertoolsproductpermutations)indices	max_slotsrepeat_allowedr%   s       r   iter_ordersr5   F   sV     q)a-( > ((??? --gu===	>?=s!   /AAAAAAc                2    | j                  |      xs ddkD  S )Nr   )r   )r    r*   s     r   row_positiver7   N   s    GGCLA""r   c                   d }d }d}d}d}d}d}| D ]t  }	||	   }
|xs t        |
d      }|xs t        |
d      }|xs t        |
d      }|xs t        |
d      }|
j                  d      }|
j                  d      }|r|}|sq|}d}v t        |       ||||||xs i j                  d	      |xs i j                  d
      |xs i j                  d	      d	S )NFscript4FieldRecordCount$script4CurrentFrontierDirectRefCountscript4GateWriterCountscript4GateReaderCountscript4LastContextA8SetterRow'script4LastNonPointerContextA8SetterRowTbaseExpressionisPointerDword)	orderhasFieldRecordhasCurrentFrontierRefhasGateWriterhasGateReaderhasNonPointerContextA8Setter"finalShapedContextA8BaseExpression"finalShapedContextA8IsPointerDword&finalNonPointerContextA8BaseExpression)r7   r   list)rA   descriptorsfinal_shapedfinal_non_pointerhas_field_recordhas_frontier_refhas_gate_writerhas_gate_readerhas_non_pointer_contextdescriptor_index
descriptorshapednon_pointers                r   summarize_orderrW   R   s!   LOO#! + !12
+b|JHa/b+o|JHn/o)_\*F^-_)_\*F^-_ ?@ nn%NO!L +&*#+ e*!1(((?/;/Ar.F.FGW.X/;/Ar.F.FGW.X3D3J2O2OP`2a
 
r   c                   t        | ||      D cg c]  }t        ||       }}|D cg c]  }|d   s|d   s
|d   s|d   r| }}|t        |      t        d |D              t        d |D              t        d |D              t        d |D              t        |      t        d	 |D              t	        d
 |D              t	        d |D              t        d |D              |d d dS c c}w c c}w )NrB   rC   rD   rE   c              3  ,   K   | ]  }|d    s	d  yw)rB   r   N .0r    s     r   	<genexpr>z"summarize_space.<locals>.<genexpr>   s     $P3#>N:OQ$P   
c              3  ,   K   | ]  }|d    s	d  yw)rC   r   NrZ   r[   s     r   r]   z"summarize_space.<locals>.<genexpr>   s     +^#E\A]A+^r^   c              3  ,   K   | ]  }|d    s	d  yw)rD   r   NrZ   r[   s     r   r]   z"summarize_space.<locals>.<genexpr>        #N#_9MA#Nr^   c              3  ,   K   | ]  }|d    s	d  yw)rE   r   NrZ   r[   s     r   r]   z"summarize_space.<locals>.<genexpr>   ra   r^   c              3  ,   K   | ]  }|d    s	d  yw)rF   r   NrZ   r[   s     r   r]   z"summarize_space.<locals>.<genexpr>   s     *dDb@c1*dr^   c              3  &   K   | ]	  }|d      yw)rG   NrZ   r[   s     r   r]   z"summarize_space.<locals>.<genexpr>   s     6qehs;_7`6q   c              3  &   K   | ]	  }|d      yw)rI   NrZ   r[   s     r   r]   z"summarize_space.<locals>.<genexpr>   s     :ymp3?g;h:yre   c              3  0   K   | ]  }|d    du sd  yw)rH   Tr   NrZ   r[   s     r   r]   z"summarize_space.<locals>.<genexpr>   s     +s#EiAjnrArA+ss      )repeatAllowed
orderCountfieldRecordOrderCountcurrentFrontierRefOrderCountgateWriterOrderCountgateReaderOrderCountdirectProofOrderCountnonPointerContextOrderCount!finalShapedContextA8BaseHistogram%finalNonPointerContextA8BaseHistogramfinalShapedPointerDwordCount
sampleRows)r5   rW   lensumr+   )r2   r3   rK   r4   rA   rowsr    direct_proof_rowss           r   summarize_spacery   t   s    !)^D 	{+D 
  &'	 	  ($i!$$P$$P!P(++^+^(^ ##N#N N ##N#N N!$%6!7'**d*d'd-66qlp6q-q1::ytx:y1y(++s+s(s3Bi s
   C,C1c                   | | nt        t        dz  i       } ||nt        t        dz  i       }||nt        t        dz  i       }t        |       }t        |      }t	        |j                  d      xs d      }t        |||d      }t        |||d      }|d	   |d	   z   }d
}	i dt        dt        dt        |      d|d|d|d|d|j                  d      xs g d|j                  d      d|j                  d      d|dk(  dddddddddt        dt        t        t        t              dg d |	d!S )"N.save_selector_opcode20_descriptor_scripts.json(save_selector_opcode20_slot_sources.json0save_selector_opcode20_sample_order_effects.jsonloadedCompleteSlotCapacity   F)r4   Tro   a_  Enumerating every descriptor active-order shape up to the loaded three-slot capacity still finds no static field-map record, current-frontier reference, or 0xe8/0xea gate reader/writer in descriptor+4 scripts. The only non-pointer context+0xa8 base that can be selected by active order alone is the generic runtime object-pointer table path. The 0x0059e310 rows are pointer-dword low-byte collisions in the shaped scan, not reliable script opcodes. Active order alone therefore cannot prove the gate-time base for map1_01a->map2_02d; runtime descriptor/object state or an equivalent trace is still required.sourcetargetdescriptorRowCountdescriptorIndicesslotCapacityuniqueOrderSpacerepeatAllowedOrderSpaceknownSampleSignaturesuniqueSampleSignaturesknownSampleStateCountuniqueSampleStateCountcurrentFrontierSampleCovered'allEnumeratedOrdersLackDirectRouteProofr   activeOrderAlonePromotesRoute$runtimeDescriptorObjectStateRequired
proofFoundopcode20OrderSpaceProofFoundfailedOpcode20OrderSpaceGateIdsmissingEvidenceblocked)zFcapture selector 2:0 active order/count or an equivalent runtime tracezTprove the runtime object pointer selected by descriptor+4 if the 0x42 path is activezJfind a strict map1_01a source hotspot or equivalent non-coordinate trigger)evidenceRefsevidenceRefCountpromotionStatusremainingProofs
conclusion)r   OUTr!   r&   r   r   ry   SOURCETARGETru   $FAILED_OPCODE20_ORDER_SPACE_GATE_IDS%OPCODE20_ORDER_SPACE_MISSING_EVIDENCE"OPCODE20_ORDER_SPACE_EVIDENCE_REFS)
r   slot_sourcessample_order_effectsrK   r2   r3   unique_spacerepeat_spacedirect_proof_countr   s
             r   build_summaryr      s   
 0B/M+S\>>
T $0#;<88
BL 4H3S/Yb@@
Z ++=>K[!GL$$%ABGaHI"7I{SXYL"7I{SWXL%&=>NeAff	h && 	c'l 	W	
 		 	L 	"< 	 !5!9!9:R!S!YWY 	 !5!9!9:R!S 	'(<(@(@A_(` 	23E3J 	( 	/ 	e 	'  	*+O!" 	@#$ ; BC$

 !5 r   c                t   | d   }| d   }ddd| d    d| d    d	d
| d    d| d    d|d    d|d    d|d    d|d    d| d    d| d    d| d    d	d| d    d	d| d    d	d| d   dddg}|j                  d  | d!   D               |j                  g d"       |j                  d# | d$   D               |j                  g d%       |j                  d& | d'   D               |j                  g d(       d)|fd*|ffD ]D  \  }}|j                  d+| d,|d    d,|d-    d,|d.    d,|d/    d,|d0    d,|d1    d,|d2    d3       F |j                  g d4       d)|fd*|ffD ]0  \  }}|d5   D ]#  }|j                  d+| d6|d7    d8|d9    d3       % 2 |j                  g d:       |j                  d; | j                  d<      xs g D               |j                  g d=       |j                  d> | j                  d?      xs g D               |j                  d       d@j                  |      S )ANr   r   z.# Save Selector Opcode 0x20 Active Order Space z
- route: `r   z -> r   `z- descriptor rows: r   z- loaded slot capacity: r   z- unique-index orders: rj   z- repeat-allowed orders: z- unique direct proof orders: ro   z&- repeat-allowed direct proof orders: z#- current selector sample covered: r   z%- active order alone promotes route: r   z- proofFound: `r   z!- opcode20OrderSpaceProofFound: `r   z- promotion status: `r   r   z## Failed Gatesc              3  (   K   | ]
  }d | d  yw- `r   NrZ   r\   items     r   r]   zmarkdown.<locals>.<genexpr>        V43tfAV   r   )r   z## Missing Evidencer   c              3  &   K   | ]	  }d |   ywz- NrZ   r   s     r   r]   zmarkdown.<locals>.<genexpr>   s     D2dVDre   r   )r   z## Evidence Refsr   c              3  8   K   | ]  }d |d    d|d      yw)r   r   z`: r   NrZ   r[   s     r   r]   zmarkdown.<locals>.<genexpr>   s/       c&k]#c-012s   r   )r   z## Order Space Countsr   z| space | orders | field records | frontier refs | gate writers | gate readers | non-pointer context rows | shaped pointer rows |z8| --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: |unique-indexrepeat-allowedz| z | rk   rl   rm   rn   rp   rs   z |)r   z'## Final Non-Pointer Context+0xa8 Basesr   z| space | base | orders |z| --- | --- | ---: |rr   z | `r$   z` | r%   )r   z## Known Sample Signaturesr   c              3  (   K   | ]
  }d | d  ywr   rZ   r   s     r   r]   zmarkdown.<locals>.<genexpr>  r   r   r   )r   z## Remaining Proofsr   c              3  &   K   | ]	  }d |   ywr   rZ   r   s     r   r]   zmarkdown.<locals>.<genexpr>
  s     N2dVNre   r   
)extendappendr   join)summaryuniquer-   lineslabelspacer    s          r   markdownr      s+   '(F./F8

WX&'tGH,=+>a@
g&:;<=
"7>#:";<
!&"6!78
#F<$8#9:
(0G)H(IJ
08O1P0QR
-g6T.U-VW
/8W0X/YZ
',/02
+G4R,S+TTUV
(9 :;1=


'E* 
LLV73T+UVV	LL  
 
LLD1B)CDD	LL  
 
LL >*  
LL   )&14Df3MN 
us5./s59P3Q2RRU345S?U9V8WWZ+,-S7T1U0VVY345R9	

 
LLyz(&14Df3MN Mu@A 	MCLL2eWDWd3w<.KL	MM 
LL78	LLV7;;7N+O+USUVV	LL01	LLN5F)G)M2NN	LL99Ur   c                   | d   }| d   }dj                  d | d   D              }dj                  d | d   D              }dj                  d | d	   D              }g }d
|fd|ffD ]D  \  }}|j                  d| d|d    d|d    d|d    d|d    d|d    d|d    d|d    d       F g }	d
|fd|ffD ]C  \  }}|d   D ]6  }
|	j                  d| dt        j                  |
d          d|
d    d       8 E dj                  d | j	                  d      xs g D              }dj                  d | j	                  d      xs g D              }dj                  g dd d!d"d#t        j                  | d$          d%t        j                  | d&          d'd(| d)    d*d+| d,    d*d-|d    d*d.|d    d*d/|d0    d*d1|d0    d*d2| d3    d*d4| d5    d*d6| d7    d'd8t        j                  | d9          d'd:d;t        j                  | d<          d=d>|d?|d@|d:dAdBdCj                  |      dDdEdFdCj                  |	      dDdG|dH|d:      S )INr   r   r   c              3  N   K   | ]  }d t        j                  |       d  yw
<li><code></code></li>Nhtmlescaper   s     r   r]   zhtml_page.<locals>.<genexpr>  s+       T[[&'|4   #%r   c              3  N   K   | ]  }d t        j                  |       d  ywz<li></li>Nr   r   s     r   r]   zhtml_page.<locals>.<genexpr>  s+      ! t{{4 !'!r   r   c              3     K   | ]9  }d t        j                  |d          dt        j                  |d          d ; yw)r   r   z	</code>: r   r   Nr   r[   s     r   r]   zhtml_page.<locals>.<genexpr>  sE       T[[V-.iCDV8W7XX]^s   ?Ar   r   r   z<tr><td>z	</td><td>rj   rk   rl   rm   rn   rp   rs   z
</td></tr>rr   z</td><td><code>r$   z</code></td><td>r%   c              3  `   K   | ]&  }d t        j                  t        |             d ( ywr   )r   r   strr   s     r   r]   zhtml_page.<locals>.<genexpr>6  s/       T[[T+,L9s   ,.r   c              3  N   K   | ]  }d t        j                  |       d  ywr   r   r   s     r   r]   zhtml_page.<locals>.<genexpr>:  s#     h4dkk$/06hr   r   z`<!doctype html><meta charset="utf-8"><title>Save Selector Opcode 0x20 Active Order Space</title>z<style>body{font-family:system-ui,sans-serif;background:#111;color:#eee}table{border-collapse:collapse;max-width:1400px}td,th{border:1px solid #444;padding:6px 8px;vertical-align:top}code{color:#9bd4ff}</style>z5<h1>Save Selector Opcode 0x20 Active Order Space</h1>z<ul>z<li>route: <code>r   z -&gt; r   r   z<li>descriptor rows: r   r   z<li>loaded slot capacity: r   z<li>unique-index orders: z<li>repeat-allowed orders: z <li>unique direct proof orders: ro   z(<li>repeat-allowed direct proof orders: z%<li>current selector sample covered: r   z'<li>active order alone promotes route: r   z<li>proofFound: <code>r   z<li>promotion status: <code>r   z</ul>z<p>r   z</p>z<h2>Failed Gates</h2><ul>z"</ul><h2>Missing Evidence</h2><ul>z</ul><h2>Evidence Refs</h2><ul>z<h2>Order Space Counts</h2>z<table><thead><tr><th>space</th><th>orders</th><th>field records</th><th>frontier refs</th><th>gate writers</th><th>gate readers</th><th>non-pointer context rows</th><th>shaped pointer rows</th></tr></thead><tbody>r   z</tbody></table>z-<h2>Final Non-Pointer Context+0xa8 Bases</h2>zP<table><thead><tr><th>space</th><th>base</th><th>orders</th></tr></thead><tbody>z$<h2>Known Sample Signatures</h2><ul>z"</ul><h2>Remaining Proofs</h2><ul>)r   r   r   r   r   )r   r   r-   failed_gatesmissing_evidenceevidence_refs
count_rowsr   r   	base_rowsr    samplesproofss                r   	html_pager     s   '(F./F99 => L yy !-.!  II >* M J(&14Df3MN 
u' &' (012 3789 :/01 2/01 2678 9789 :		

 I(&14Df3MN u@A 	Cg ![[W67 87|n %	 ii KK 78>B G YYh7;;O`CaCgeghhF99 &l& 	]& 	@& 		&
 DKK(9:;74;;wW_O`CaBbbno&  (< =>eD& %W^%<$=UC& $F<$8#9?& &f\&:%;5A& +62I+J*K5Q& 36:Q3R2SSXY& 08V0W/XX]^& 2':Y2Z1[[`a& !!6 7|D& 't{{7;L3M'N&O|\&  	!&" dkk',/016#&$ 	$%&& 	'&( 	-)&* 	+&, 	*-&. 	/&0 	1&2 	&3&4 	a5&6 	
7&8 	9&: 	8;&< 	[=&> 		?&@ 	A&B 	/C&D 	E&F 	-G&H 	I&J 	K& & &r   c                    |j                  dd       |dz  j                  t        j                  | dd      dz   d	       |d
z  j                  t	        |       d	       y )NT)parentsexist_okz'save_selector_opcode20_order_space.jsonF   )ensure_asciiindentr   r   r   'save_selector_opcode20_order_space.html)mkdir
write_textr   dumpsr   )r   out_dirs     r   write_outputsr   d  se    MM$M.88DD

7q9D@ E  88DDYwEWbiDjr   c                    t        j                  t              } | j                  dt        t
               | j                         }t        t        |j                  dz  i       t        |j                  dz  i       t        |j                  dz  i             }t        ||j                         t        d|j                  dz          y )	N)r   z	--out-dir)typedefaultr{   r|   r}   z%wrote opcode20 active order space -> r   )argparseArgumentParser__doc__add_argumentr   r   
parse_argsr   r   r   r   print)parserargsr   s      r   mainr   m  s    $$9F
$<D$,,!QQSUV$,,!KKRP$,,!SSUWXG
 '4<<(	1$,,Aj2j1k
lmr   __main__)r   r   r   r   returnr   )r   dictr   dict[int, dict])r(   zIterable[str | None]r   z
list[dict])r2   	list[int]r3   r   r4   boolr   zIterable[tuple[int, ...]])r    r   r*   r   r   r   )rA   ztuple[int, ...]rK   r   r   r   )
r2   r   r3   r   rK   r   r4   r   r   r   )NNN)r   dict | Noner   r   r   r   r   r   )r   r   r   r   )r   r   r   r   r   None)r   r   )#r   
__future__r   r   r   r/   r   pathlibr   typingr   r   __file__resolver   ROOTr   r   r   r   r   r   r   r!   r+   r5   r7   rW   ry   r   r   r   r   r   __name__rZ   r   r   <module>r      s   O "        H~''*
Ul		( $) % E]
 ?V
 Gb& " 8>#D: '+ $(,:#:: &: 
	:z?DRj 25 k
n zF r   