
    "
3ja                        S SK r 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\" \R6                  5      r\" \R:                  5      r\\-  r\" \" SS/5      5      r \RB                  r!\RD                  r" " S S\#5      r$Sr%Sr&Sr'\RP                  RS                  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      r0 " S# S$\05      r1\S%:X  a  \0r2O\S;   a  \1r2O\S%:  a  \.r2O\" \5      e " S& S'\Rf                  5      r4g)(    N)
namedtupleOrderedDict)CodeType
ModuleType)errorsutils	serialize)	PYVERSION)      r      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     M/home/wildlama/miniconda3/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_opcodesr3   2   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)ByteCodeInstC   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)r9   r:   r;   r+   r<   r=   r>   selfr9   r;   r=   
nextoffsets        r"   __init__ByteCodeInst.__init__R   s-    	jj(r$   c                 (    U R                   [        ;   $ r*   )r;   JUMP_OPSrB   s    r"   is_jumpByteCodeInst.is_jumpZ       {{h&&r$   c                 (    U R                   [        ;   $ r*   )r;   TERM_OPSrH   s    r"   is_terminatorByteCodeInst.is_terminator^   rK   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   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>m   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*   rS   rT   s     r"   rW   rX   r   s      ;(91  #yy|(9rY   )rZ      )r   c              3   H   #    U  H  n[         R                  U   v   M     g 7fr*   rS   rT   s     r"   rW   rX   v   s&      L)K1  #yy|)KrY   )rZ   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   r   )	rI   r
   r;   r:   r=   r9   NotImplementedErrorJREL_OPSJABS_OPSrH   s    r"   get_jump_targetByteCodeInst.get_jump_targetb   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EE{{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>   rH   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<   
startswithrH   s    r"   block_effectByteCodeInst.block_effect   s.    
 ;;!!(++[[K'r$   )r=   r>   r:   r9   r;   r<   N)__name__
__module____qualname____firstlineno____doc__	__slots__rD   propertyrI   rN   rh   rk   rq   __static_attributes__ r$   r"   r7   r7   C   s\     FI ' ' ' ''1RN 	 	r$   r7   r^   NOPrQ   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      r\   r   N)r   CODE_LENHAVE_ARGUMENTrangeARG_LENr
   r   	INSTR_LENre   EXTENDED_ARG
OPCODE_NOP
NO_ARG_LEN)r   extended_argnr9   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_OFFSETrg   )	bc_streamr9   r;   r=   rC   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)rB   r   s     r"   rD   ByteCodeIter.__init__   s'    			8I8I)JKL	r$   c                     U $ r*   r{   rH   s    r"   __iter__ByteCodeIter.__iter__  s    r$   c                 ,    [        U R                  5      $ r*   )r:   r   rH   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)r9   r;   r=   rC   )r   r7   rA   s        r"   r:   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   r:   r   )rB   sizer   r   _offsetbytes         r"   read_argByteCodeIter.read_arg  s;    tA OMGAE?"C  
r$   )r   r   N)rs   rt   ru   rv   rD   r   r   r:   __next__r   rz   r{   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   )rU   xs     r"   rW   %_ByteCode.__init__.<locals>.<genexpr>#  s     M0L1&0Ls   r   )r   setr+   
findlabelsr   addr   r   _compute_linenor   r   r   r   r   r   r   sortedr   )rB   r   r   r   r   s        r"   rD   _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   r9   r>   
adj_offsetknowninsts           r"   r   _ByteCode._compute_lineno4  s}    
 "006NF-/J"+1j!( 7 ##LLND{{&4;;!+;#	 #
 r$   c                 H    [        U R                  R                  5       5      $ r*   )r   r   r   rH   s    r"   r   _ByteCode.__iter__G  s    DJJ%%'((r$   c                      U R                   U   $ r*   r   rB   r9   s     r"   __getitem___ByteCode.__getitem__J  s    zz&!!r$   c                     XR                   ;   $ r*   r   r   s     r"   __contains___ByteCode.__contains__M  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^   > )r9   r   )r   rB   s    r"   label_marker$_ByteCode.dump.<locals>.label_markerQ  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<   )rU   r   r   s     r"   rW   !_ByteCode.dump.<locals>.<genexpr>W  s<      4"4QaDKK72 B<?*<q*@A"4s   44)joinr   items)rB   r   s   `@r"   dump_ByteCode.dumpP  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_globals[  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   rH   s    r"   get_used_globals_ByteCode.get_used_globalsx  s8    
 ))$,,*;*;TZZ*...$--I 	Ir$   )r   r   r   r   r   r   r   r   N)rs   rt   ru   rv   rw   rx   rD   classmethodr   r   r   r   r   r   r   rz   r{   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   r^   rd   )r
   re   )r=   s    r"   r   r     s,    88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*   )	superrD   r+   Bytecoder   r   tuplemapfixup_eh)rB   r   entries	__class__s      r"   rD   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)rB   r9   
candidatesr  s       r"   find_exception_entry"ByteCodePy311.find_exception_entry  se     
))CyyF,SWW,,!!399c"23 * j/!$CJ r$   )r   )
rs   rt   ru   rv   rD   staticmethodr  r  rz   __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  rD   _ordered_offsetsr+   r  r   r   r  remove_build_list_swap_patternis_generatorr  r  r  )rB   r   er  max_exception_targetr  s        r"   rD   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   )rB   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  aG  [        R                  SS S:w  a  UR                  U	5        U R                  U R                  US-         n	U	R                  S:X  d  GM!  [        S;   G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S-
        n	[        S;   a  U	R                  S:X  d  GM  O-[        S;   a  U	R                  S:X  d  GM  O[        [        5      e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_ITERNr   )r   r      FOR_ITERrQ   END_FOR)r   POP_TOP)r   POP_ITERr   r|   )listr   r   copyr%  r*  r
  r   r<   r=   sysversion_infor   r
   r  re   r7   r9   r+   r,   r:   )rB   r  r0  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 ''+z9)--i8 $

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

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

4+?+?	+J KI K/(//9<$  ="k1(//:=$  > 2)<< $

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_ ( nn "D&24;;3699U3C373799'>DJJt{{# "
 r$   )r  r   )
rs   rt   ru   rv   rD   ry   r%  r  rz   r  r  s   @r"   r  r    s(    04 % %S S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	)
FunctionIdentityil  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   ByteCodeSupportErrorru   AttributeErrorrs   r   func_qualnamesplit	func_namer   inspect	getmodulemodule_dynamic_modnamemodnameisgeneratorfunctionr  pysigco_filenamefilenamer   firstlinenor   
parameters	arg_countr<  	arg_namesr:   _unique_idsformatunique_name	unique_id)r   pyfuncr   r   rW  rN  rB   uids           r"   from_functionFunctionIdentity.from_functionv  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.
        )rd  r   rH   s    r"   deriveFunctionIdentity.derive  s     !!$)),,r$   c                 (    [        U R                  S9$ )$
NOTE: part of ReduceMixin protocol
)rb  )dictr   rH   s    r"   _reduce_statesFunctionIdentity._reduce_states  s     499%%r$   c                 $    U R                  U5      $ )rj  )rd  )r   rb  s     r"   _rebuildFunctionIdentity._rebuild  s    
   ((r$   )r\  r]  r   rY  rZ  r   rP  rN  r  rU  rS  rW  ra  r`  N)rs   rt   ru   rv   rw   	itertoolscountr^  r   rd  rg  rl  ro  rz   r{   r$   r"   rH  rH  l  sH     //!$K' 'R-
& ) )r$   rH  )5r>  collectionsr   r   r+   rQ  rq  typesr   r   
numba.corer   r   r	   numba.core.utilsr
   r;   r   r   re   r   r   r   r#   r(   r3   	frozensethasjrelrf   hasjabsrg   rG   rM   r   r   objectr7   r   r   r   r<   r*  r   r   r   r   r   r   r   r  ByteCodeReduceMixinrH  r{   r$   r"   <module>r}     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 >vM vr H--HH
i
((D)y,, D)r$   