
    shl_                        S SK JrJr  S SKrS SKrS SKrS SKJrJr  S SK	J
r
JrJr  S SKJr  \S;   a	  S SKJr  SrO\S	;   a  O\" \5      e\" S
S/5      r\" SS5      rSrS rS rS r\" \R4                  5      r\" \R8                  5      r\\-  r\" \" SS/5      5      r\R@                  r \RB                  r! " S S\"5      r#Sr$Sr%Sr&\RN                  RQ                  S5      r)\S;   a  S r*O\S;   a  S r*O\" \5      eS r+ " S S\"5      r, " S S\"5      r-S  r. " S! S"\-5      r/ " S# S$\/5      r0\S%:X  a  \/r1O\S;   a  \0r1O\S%:  a  \-r1O\" \5      e " S& S'\Rd                  5      r3g)(    )
namedtupleOrderedDictN)CodeType
ModuleType)errorsutils	serialize)	PYVERSION)      r      )_inline_cache_entries   r   
   r      opcode_infoargsize_ExceptionTableEntryzstart end target depth lastic                 D    [        U SS5      nU(       a  [        X5      $ U $ )z
Objects that wraps function should provide a "__numba__" magic attribute
that contains a name of an attribute that contains the actual python
function object.
	__numba__Ngetattr)objattrs     g/Users/tiagomarins/Projetos/claudeai/copy_bank/venv/lib/python3.13/site-packages/numba/core/bytecode.pyget_function_objectr!       s%     3T*Ds!!J    c           	      2    [        U S[        U SS5      5      $ )z"Shamelessly borrowed from llpython__code__	func_codeNr   )r   s    r    get_code_objectr&   ,   s    3
GCd$CDDr"   c                     / nU  H8  n[         R                  R                  U5      nUc  M'  UR                  U5        M:     U$ N)disopmapgetappend)seqlstscs       r    _as_opcodesr1   1   s:    
CIIMM!=JJqM  Jr"   RETURN_VALUERAISE_VARARGSc                   ^    \ rS rSrSrSrS r\S 5       r\S 5       r	S r
S r\S	 5       rS
rg)ByteCodeInstB   z
Attributes
----------
- offset:
    byte offset of opcode
- opcode:
    opcode integer value
- arg:
    instruction arg
- lineno:
    -1 means unknown
)offsetnextopcodeopnamearglinenoc                 r    Xl         X@l        X l        [        R                  U   U l        X0l        SU l        g )N)r7   r8   r9   r)   r:   r;   r<   selfr7   r9   r;   
nextoffsets        r    __init__ByteCodeInst.__init__Q   s-    	jj(r"   c                 (    U R                   [        ;   $ r(   )r9   JUMP_OPSr@   s    r    is_jumpByteCodeInst.is_jumpY       {{h&&r"   c                 (    U R                   [        ;   $ r(   )r9   TERM_OPSrF   s    r    is_terminatorByteCodeInst.is_terminator]   rI   r"   c                    U R                   (       d   e[        S;   a4  U R                  S S 5       ;   a  U R                  U R                  S-  -
  $ O[        S;   a7  U R                  S S 5       ;   a  U R
                  U R                  S-
  S-  -
  $ O[[        S	;   a7  U R                  S
 S 5       ;   a  U R
                  U R                  S-
  S-  -
  $ O[        S;   a  O[        [        5      e[        S;   aX  U R                  [        ;   a  U R                  U R                  S-  -   $ U R                  [        ;   d   eU R                  S-  S-
  $ [        [        5      e)Nr   c              3   H   #    U  H  n[         R                  U   v   M     g 7fr(   r)   r*   .0ks     r    	<genexpr>/ByteCodeInst.get_jump_target.<locals>.<genexpr>l   s&      H)G1  #yy|)G    ")JUMP_BACKWARDJUMP_BACKWARD_NO_INTERRUPTr   r   c              3   H   #    U  H  n[         R                  U   v   M     g 7fr(   rQ   rR   s     r    rU   rV   q   s      ;(91  #yy|(9rW   )rX      )r   c              3   H   #    U  H  n[         R                  U   v   M     g 7fr(   rQ   rR   s     r    rU   rV   u   s&      L)K1  #yy|)KrW   )rX   POP_JUMP_BACKWARD_IF_TRUEPOP_JUMP_BACKWARD_IF_FALSEPOP_JUMP_BACKWARD_IF_NONEPOP_JUMP_BACKWARD_IF_NOT_NONEr   )r   r   r   r   )	rG   r
   r9   r8   r;   r7   NotImplementedErrorJREL_OPSJABS_OPSrF   s    r    get_jump_targetByteCodeInst.get_jump_targeta   s[    |||
"{{ H)GH H yyDHHqL11H *${{ ;(9; ;{{dhhla%777; +%{{ L)KL L {{dhhla%777L *$%i00<<{{h&yy488a<//{{h...xx!|a''%i00r"   c                 N    SU R                   U R                  U R                  4-  $ )Nz%s(arg=%s, lineno=%d))r:   r;   r<   rF   s    r    __repr__ByteCodeInst.__repr__   s     &$++txx)MMMr"   c                 h    U R                   R                  S5      (       a  gU R                   S:X  a  gg)zBEffect of the block stack
Returns +1 (push), 0 (none) or -1 (pop)
SETUP_r\   	POP_BLOCKr>   r   )r:   
startswithrF   s    r    block_effectByteCodeInst.block_effect   s.    
 ;;!!(++[[K'r"   )r;   r<   r8   r7   r9   r:   N)__name__
__module____qualname____firstlineno____doc__	__slots__rB   propertyrG   rL   rf   ri   ro   __static_attributes__ r"   r    r5   r5   B   s\     FI ' ' ' ''1RN 	 	r"   r5   r\   NOPrO   c              #     #    / n[         R                  " U 5       H  u  p#pEUR                  X4U45        M     [        U5       H7  u  nu  p4nUS-   [	        U5      :  a  XS-      S   nO[	        U 5      nX4XV4v   M9     g 7fNr\   r   )r)   _unpack_opargsr,   	enumeratelen)codebufistart_offsetopr;   next_offsets          r    r}   r}      s     (+(:(:4(@$ARJJ#./ )A*3C.&A&#1us3x!a%jm!$iS66 +9s   A=A?r   r   r   c              #   4  #    Sn[        U 5      nS=p4XB:  a  X   nU[        -  nU[        :  a  X   U-  n[        [        5       H  nX`XG-      SU-  -  -  nM     U[        -  n[
        S;   a  U[        U   [        -  -  nO[
        S;   a  O[        [
        5      eU[        :X  a  U[        Xd4v   US[        -  -  nUnM  OCSnU[        -  n[
        S;   a  U[        U   [        -  -  nO[
        S;   a  O[        [
        5      eSnX5Xd4v   UnXB:  a  M  gg7f)zX
Returns a 4-int-tuple of
(bytecode offset, opcode, argument, offset of next bytecode).
r      rZ   r   N)r   CODE_LENHAVE_ARGUMENTrangeARG_LENr
   r   	INSTR_LENrc   EXTENDED_ARG
OPCODE_NOP
NO_ARG_LEN)r   extended_argnr7   r   r   r;   js           r    r}   r}      s>    
 IeBMA]"g,wA;1q511C (W
* .r2Y>>A"44-i88% ":s66#&!g+#5LF & Z
* .r2Y>>A"44-i88Ls&&Fa es   DDDc              #      #    S[         S[        4v   U  H.  u  pp4U[        ;   a	  U[        -  nU[        -   X#U[        -   4v   M0     g7f)zhPatch the bytecode stream.

- Adds a NOP bytecode at the start to avoid jump target being at the entry.
r   N)r   _FIXED_OFFSETre   )	bc_streamr7   r9   r;   rA   s        r    _patched_opargsr      sN      j$
..+4'X= C}$f:3MMM	 ,5s   AAc                   6    \ rS rSrS rS rS rS r\rS r	Sr
g)	ByteCodeIter   c                 |    Xl         [        [        [        U R                   R                  5      5      5      U l        g r(   )r   iterr   r}   co_code)r@   r   s     r    rB   ByteCodeIter.__init__   s'    			8I8I)JKL	r"   c                     U $ r(   ry   rF   s    r    __iter__ByteCodeIter.__iter__  s    r"   c                 ,    [        U R                  5      $ r(   )r8   r   rF   s    r    _fetch_opcodeByteCodeIter._fetch_opcode  s    DIIr"   c                 B    U R                  5       u  pp4U[        XUUS94$ )N)r7   r9   r;   rA   )r   r5   r?   s        r    r8   ByteCodeIter.next  s0    *.*<*<*>'|6c/9; ; 	;r"   c                 p    Sn[        U5       H$  n[        U R                  5      u  pEX%SU-  -  -  nM&     U$ )Nr   r   )r   r8   r   )r@   sizer   r   _offsetbytes         r    read_argByteCodeIter.read_arg  s;    tA OMGAE?"C  
r"   )r   r   N)rq   rr   rs   rt   rB   r   r   r8   __next__r   rx   ry   r"   r    r   r      s#    M;
 Hr"   r   c                   `    \ rS rSrSrSrS r\S 5       rS r	S r
S rS	 r\S
 5       rS rSrg)	_ByteCodei  z>
The decoded bytecode of a function, and related information.
)	func_idco_namesco_varnames	co_constsco_cellvarsco_freevarsexception_entriestablelabelsc                    UR                   n[        S [        R                  " UR                  5       5       5      nUR                  S5        [        [        U5      5      nU R                  XB5        Xl	        UR                  U l
        UR                  U l        UR                  U l        UR                  U l        UR                  U l        X@l        [!        U5      U l        g )Nc              3   2   #    U  H  o[         -   v   M     g 7fr(   )r   )rS   xs     r    rU   %_ByteCode.__init__.<locals>.<genexpr>"  s     M0L1&0Ls   r   )r   setr)   
findlabelsr   addr   r   _compute_linenor   r   r   r   r   r   r   sortedr   )r@   r   r   r   r   s        r    rB   _ByteCode.__init__  s    ||Mt||0LMM

1 L./U)++++++
Vnr"   c                    [         R                  " U5       H  u  p4U[        -   nXQ;   d  M  XAU   l        M      UR                  nUR                  5        H4  nUR                  b  UR                  S:  a  UR                  nM.  Xgl        M6     U$ )z9
Compute the line numbers for all bytecode instructions.
r   )r)   findlinestartsr   r<   co_firstlinenovalues)clsr   r   r7   r<   
adj_offsetknowninsts           r    r   _ByteCode._compute_lineno3  s}    
 "006NF-/J"+1j!( 7 ##LLND{{&4;;!+;#	 #
 r"   c                 H    [        U R                  R                  5       5      $ r(   )r   r   r   rF   s    r    r   _ByteCode.__iter__F  s    DJJ%%'((r"   c                      U R                   U   $ r(   r   r@   r7   s     r    __getitem___ByteCode.__getitem__I  s    zz&!!r"   c                     XR                   ;   $ r(   r   r   s     r    __contains___ByteCode.__contains__L  s    ##r"   c                 x   ^ ^ U 4S jmSR                  U4S jT R                  R                  5        5       5      $ )Nc                 B   > U S   R                   TR                  ;   a  gg)Nr\   > )r7   r   )r   r@   s    r    label_marker$_ByteCode.dump.<locals>.label_markerP  s    t{{dkk)r"   
c              3   l   >#    U  H)  nUS    R                   S:w  d  M  ST" U5      4U-   -  v   M+     g7f)r\   CACHEz
%s %10s	%sN)r:   )rS   r   r   s     r    rU   !_ByteCode.dump.<locals>.<genexpr>V  s<      4"4QaDKK72 B<?*<q*@A"4s   44)joinr   items)r@   r   s   `@r    dump_ByteCode.dumpO  s5    	 yy 4"&**"2"2"44 4 	4r"   c           	      B   0 nUR                   nUR                  S[        R                  5      n[	        U[
        5      (       a  UR                  nUR                  5        H=  nUR                  S:X  d  M  U[        UR                  5         n	X;  d  M4   Xi   n
XU	'   M?     U Hd  n[	        U[        5      (       d  M  [        [        U5      5      nUR                  U R!                  XUR"                  UR$                  5      5        Mf     U$ ! [         a    Xy   n
 Nf = f)zI
Compute the globals used by the function with the given
bytecode table.
__builtins__LOAD_GLOBAL)__globals__r+   r   builtins
isinstancer   __dict__r   r:   _fix_LOAD_GLOBAL_argr;   KeyErrorr   r   r   update_compute_used_globalsr   r   )r   funcr   r   r   dglobsr   r   namevaluecosubtables                r    r   _ByteCode._compute_used_globalsZ  s       99^U^^<h
++((HLLND{{m+ 4TXX >?=/ % $dG # B"h''&|B'7822435<<N O 
  $ / (/s   DDDc                     U R                  U R                  R                  U R                  U R                  U R
                  5      $ )z^
Get a {name: value} map of the globals used by this code
object and any nested code objects.
)r   r   r   r   r   r   rF   s    r    get_used_globals_ByteCode.get_used_globalsw  s8    
 ))$,,*;*;TZZ*...$--I 	Ir"   )r   r   r   r   r   r   r   r   N)rq   rr   rs   rt   ru   rv   rB   classmethodr   r   r   r   r   r   r   rx   ry   r"   r    r   r     sU    $I%(  $)"$	4  8Ir"   r   c                 V    [         S;   a  U S-	  $ [         S;   a  U $ [        [         5      e)N)r   r   r   r\   rb   )r
   rc   )r;   s    r    r   r     s,    //ax	j	 
!),,r"   c                   >   ^  \ rS rSrU 4S jr\S 5       rS rSrU =r	$ )ByteCodePy311i  c                    > [         TU ]  U5        [        R                  " UR                  5      R
                  n[        [        U R                  U5      5      U l        g r(   )	superrB   r)   Bytecoder   r   tuplemapfixup_eh)r@   r   entries	__class__s      r    rB   ByteCodePy311.__init__  s@    !,,w||,>>!&s4==''B!Cr"   c                     [         R                  " U R                  [        -   U R                  [        -   U R
                  [        -   U R                  U R                  S9nU$ )N)startendtargetdepthlasti)r)   r   r  r   r	  r
  r  r  )entouts     r    r  ByteCodePy311.fixup_eh  sK     &&))m+=1H::-))399

 
r"   c                     / nU R                    HG  nUR                  Us=::  a  UR                  :  d  M&  O  M*  UR                  UR                  U45        MI     U(       a  [        U5      S   nU$ g)z>
Returns the exception entry for the given instruction offset
r\   N)r   r  r	  r,   r  max)r@   r7   
candidatesr  s       r    find_exception_entry"ByteCodePy311.find_exception_entry  se     
))CyyF,SWW,,!!399c"23 * j/!$CJ r"   )r   )
rq   rr   rs   rt   rB   staticmethodr  r  rx   __classcell__r  s   @r    r   r     s'    D
  
 
r"   r   c                   >   ^  \ rS rSrU 4S jr\S 5       rS rSrU =r	$ )ByteCodePy312i  c                   > [         TU ]  U5        S U l        [        R                  " UR
                  5      R                   Vs/ s H  o R                  U5      PM     nnU R                  U5      nUR                  (       aH  [        U Vs/ s H  o"R                  PM     sn5      nU Vs/ s H  o"R                  U:w  d  M  UPM     nn[        U5      U l        g s  snf s  snf s  snf r(   )r   rB   _ordered_offsetsr)   r   r   r   r  remove_build_list_swap_patternis_generatorr  r
  r  )r@   r   er  max_exception_targetr  s        r    rB   ByteCodePy312.__init__  s    ! !% <<-??? )*==#? 	  55g> #&''B'Q''B#C  #*N'QXX9M-Mq'GN!&w# (C Os   CC +C%C%c                     U R                   (       d!  U R                   Vs/ s H  oPM     snU l         U R                   $ s  snf r(   )r  r   )r@   os     r    ordered_offsetsByteCodePy312.ordered_offsets  s7    $$04

$;
1Q
$;D!$$$ %<s   ?c                    S[         S[        4S jn[        5       nSnU(       Ga  Sn[        5       nUR                  5        GH  nU R                  R                  UR                  5      nU R                  U R                  U      nUR                  S;  a  MW  U R                  U R                  US-         n	U	R                  S:X  d  U	R                  S	:X  a  M  U R                  U R                  US	-         n	U	R                  S
:X  a0  UR                  U	5        U R                  U R                  US-         n	U	R                  S:X  d  GM
  [        S;   a  U R                  R                  UR                  5      nU R                  U R                  US	-
        nUR                  S:X  d  GMk  U R                  U R                  US-
        n	U	R                  S:X  d  GM  U R                  U R                  U      n	U	R                  S:X  d  U	R                  S	:X  a  GM  O[        S;   a  U R                  R                  UR                  5      nU R                  U R                  US-
        nUR                  S:X  d  GM>  U R                  U R                  U      n	U	R                  S:X  d  U	R                  S	:X  a  GM}  O[        [        5      eU" X5      nSnX5-  nGM     U(       a  GM  U HM  n
[        U
R                  [         R"                  S   SU
R$                  5      U R                  U
R                  '   MO     U$ )a{  Find the following bytecode pattern:

BUILD_{LIST, MAP, SET}
SWAP(2)
FOR_ITER
...
END_FOR
SWAP(2)

This pattern indicates that a list/dict/set comprehension has
been inlined. In this case we can skip the exception blocks
entirely along with the dead exceptions that it points to.
A pair of exception that sandwiches these exception will
also be merged into a single exception.

Update for Python 3.13, the ending of the pattern has a extra
POP_TOP:

...
END_FOR
POP_TOP
SWAP(2)

Update for Python 3.13.1, there's now a GET_ITER before FOR_ITER.
This patch the GET_ITER to NOP to minimize changes downstream
(e.g. array-comprehension).
r  entry_to_removec                    U R                  U5      S-
  nU R                  U5      S-   nUS:  a  U[        U 5      :  av  X   nX   nUR                  UR                  :X  aT  [        UR                  UR
                  UR                  UR                  UR                  5      X'   U R                  U5        U R                  U5        U  Vs/ s H!  nUR                  UR                  :X  a  M  UPM#     n nU $ s  snf r|   )	indexr   r
  r   r  r	  r  r  remove)r  r&  lower_entry_idxupper_entry_idxlower_entryupper_entryr  s          r    pop_and_merge_exceptionsNByteCodePy312.remove_build_list_swap_pattern.<locals>.pop_and_merge_exceptions  s    %mmO<q@O%mmO<q@O !##g,(F%6%6%%););;/C#))##**#))#))0+G, NN;/ NN?+") A'Qgg)?)?? 'G ANAs   	C5+C5TF)
BUILD_LIST	BUILD_MAP	BUILD_SETr\   SWAPr   GET_ITERr   FOR_ITERrO   END_FORPOP_TOPr   rz   N)listr   r   copyr#  r(  r  r   r:   r;   r   r
   r	  rc   r5   r7   r)   r*   r8   )r@   r  r.  change_to_nopwork_remainingcurrent_nop_fixesentryr(  	curr_inst	next_instr   s              r    r  ,ByteCodePy312.remove_build_list_swap_pattern  s   8	d 	6J	2  #N #  ,,225;;? !JJt';';E'BC	## ,9 9  !JJt';';EAI'FG	 ''61immq6H JJt';';EAI'FG	
 ##z1%)))4 $

4+?+?	+J KI '':5
* !0066uyyAE $

4+?+?	+J KI$++y8  $

4+?+?	+J KI$++y8  $

4+?+?+F GI$++v5)--1:L "== !0066uyyAE $

4+?+?	+J KI$++y8  $

4+?+?+F GI$++v5)--1:L -i88 37B!% 2K ( nZ "D&24;;3699U3C373799'>DJJt{{# "
 r"   )r  r   )
rq   rr   rs   rt   rB   rw   r#  r  rx   r  r  s   @r    r  r    s(    04 % %I Ir"   r  r   c                   h    \ rS rSrSr\R                  " S5      r\S 5       r	S r
S r\S 5       rSrg	)
FunctionIdentityia  z
A function's identity and metadata.

Note this typically represents a function whose bytecode is
being compiled, not necessarily the top-level user function
(the two might be distinct).
r\   c                 b   [        U5      n[        U5      n[        R                  " U5      nU(       d  [        R
                  " SU-  5      e UR                  nU " 5       nX&l	        XVl
        UR                  S5      S   Ul        X6l        [        R                  " U5      Ul        UR                   c  [        R"                  OUR                   R                  Ul        [        R&                  " U5      Ul        XFl        UR,                  Ul        UR0                  Ul        [5        UR6                  5      Ul        [;        UR6                  5      Ul        [?        U R@                  5      nSRC                  UR                  U5      Ul"        Xvl#        U$ ! [         a    UR                  n GNSf = f)z4
Create the FunctionIdentity of the given function.
z %s does not provide its bytecode.r>   z{}${})$r!   r&   r   pysignaturer   ByteCodeSupportErrorrs   AttributeErrorrq   r   func_qualnamesplit	func_namer   inspect	getmodulemodule_dynamic_modnamemodnameisgeneratorfunctionr  pysigco_filenamefilenamer   firstlinenor   
parameters	arg_countr8  	arg_namesr8   _unique_idsformatunique_name	unique_id)r   pyfuncr   r   rQ  rH  r@   uids           r    from_functionFunctionIdentity.from_functionk  sg   
 #6*t$!!$'--2T9; ;	* --M u	*&,,S1"5	''-;;. ..![[11 	 $77=
((..U--.e../
 3??#">>$*<*<cB5  	* MMM	*s   F F.-F.c                 8    U R                  U R                  5      $ )z:Copy the object and increment the unique counter.
        )r^  r   rF   s    r    deriveFunctionIdentity.derive  s     !!$)),,r"   c                 (    [        U R                  S9$ )$
NOTE: part of ReduceMixin protocol
)r\  )dictr   rF   s    r    _reduce_statesFunctionIdentity._reduce_states  s     499%%r"   c                 $    U R                  U5      $ )rd  )r^  )r   r\  s     r    _rebuildFunctionIdentity._rebuild  s    
   ((r"   )rV  rW  r   rS  rT  r   rJ  rH  r  rO  rM  rQ  r[  rZ  N)rq   rr   rs   rt   ru   	itertoolscountrX  r   r^  ra  rf  ri  rx   ry   r"   r    rB  rB  a  sH     //!$K' 'R-
& ) )r"   rB  )4collectionsr   r   r)   rK  rk  typesr   r   
numba.corer   r   r	   numba.core.utilsr
   r9   r   r   rc   r   r   r   r!   r&   r1   	frozensethasjrelrd   hasjabsre   rE   rK   r   r   objectr5   r   r   r   r:   r(  r   r}   r   r   r   r   r   r  ByteCodeReduceMixinrB  ry   r"   r    <module>rw     s   / 
   & / / & "",I$$
i
(( 4!"8"@B  	E
 S[[!S[[!h[./!BCD!!U6 Up 

ZZe$
 
	7 --8t i
((N6 4fI fIR-I >lM l^ H%%HH
i
((D)y,, D)r"   