
    sh;                        S SK r S SKrS SKrS SKrS SKJr  S SKrS SKJrJ	r	  S SK
JrJr  S SKJr  S SKJr  S SKJrJr  S SKJrJrJr   " S	 S
\5      r " S S\5      r " S S\5      rS rS rS rS rS r S r! " S S\"5      r#S r$S r%S r&S r'S r(S r) " S S\5      r* " S S \\5      r+\,S!:X  a  \RZ                  " 5         gg)"    N)	takewhile)njitjit)CompilerBaseDefaultPassBuilder)
PreserveIR)IRLegalization)typesir)TestCaseoverride_configSerialMixinc                   &    \ rS rSrS rS rS rSrg)_Dummy   c                 >    Xl         X l        UR                  U 5        g N)recordername
_add_dummy)selfr   r   s      q/Users/tiagomarins/Projetos/claudeai/copy_bank/venv/lib/python3.13/site-packages/numba/tests/test_obj_lifetime.py__init___Dummy.__init__   s     	D!    c                     [        U[        5      (       d   e[        U R                  U R                  < SUR                  < 35      $ )Nz + )
isinstancer   r   r   )r   others     r   __add___Dummy.__add__   s3    %((((dmm$))UZZ%HIIr   c                 H    [        U R                  SU R                  -  5      $ )Nziter(%s))_DummyIteratorr   r   r   s    r   __iter___Dummy.__iter__   s    dmmZ$))-CDDr   )r   r   N)__name__
__module____qualname____firstlineno__r   r   r$   __static_attributes__ r   r   r   r      s    "
JEr   r   c                   "    \ rS rSrSrS r\rSrg)r"      r   c                     U R                   S:  a  [        eU =R                   S-  sl         [        U R                  U R                  < SU R                   < 35      $ )N      #)countStopIterationr   r   r   r#   s    r   __next___DummyIterator.__next__#   s>    ::?

a
dmm		4::%FGGr   r+   N)r&   r'   r(   r)   r2   r4   nextr*   r+   r   r   r"   r"      s    EH Dr   r"   c                   Z    \ rS rSrSrS rS rS r\rS r	S r
\S 5       r\S	 5       rS
rg)RefRecorder,   z
An object which records events when instances created through it
are deleted.  Custom events can also be recorded to aid in
diagnosis.
c                 ^    [         R                  " [        5      U l        / U l        0 U l        g r   )collectionsdefaultdictint_counts_events_wrsr#   s    r   r   RefRecorder.__init__3   s"    "..s3	r   c                     [        X5      $ )z;
Make an object whose deletion will be recorded as *name*.
)r   )r   r   s     r   
make_dummyRefRecorder.make_dummy8   s     d!!r   c                 v    [         R                  " XR                  5      nUR                  U R                  U'   g r   )weakrefref_on_disposalr   r@   )r   dummywrs      r   r   RefRecorder._add_dummy>   s'    [[ 1 12

		"r   c                     U R                   U   S-   nX R                   U'   U R                  R                  UR                  US95        g)zZ
Manually append *event* to the recorded events.
*event* can be formatted using format().
r0   )r2   N)r>   r?   appendformat)r   eventr2   s      r   markRefRecorder.markD   s@    
 U#a'#UELLuL56r   c                 p    U R                   R                  U5      nU R                  R                  U5        g r   )r@   popr?   rM   )r   rJ   r   s      r   rH   RefRecorder._on_disposalM   s&    yy}}R D!r   c                 N    U R                    Vs/ s H	  o" 5       PM     sn$ s  snf )z3
A list of objects which haven't been deleted yet.
)r@   )r   rJ   s     r   aliveRefRecorder.aliveQ   s"    
  $yy)yy)))s   "c                     U R                   $ )z
A list of recorded events.
)r?   r#   s    r   recordedRefRecorder.recordedX   s    
 ||r   )r>   r?   r@   N)r&   r'   r(   r)   __doc__r   rC   r   __call__rP   rH   propertyrV   rY   r*   r+   r   r   r8   r8   ,   sO    
"# H7" * *  r   r8   c                     U " S5      nU " S5      nU " S5      nX#-   nU R                  S5        X-   nU R                  S5        U$ )Nabc--1----2--rP   )recr_   r`   ra   ds        r   simple_usecase1rg   `   sH    CACACA	AHHW	AHHWHr   c                 T    U " S5      nU " S5      nU R                  S5        UnUnS nU$ )Nr_   r`   rb   rd   )re   r_   r`   xys        r   simple_usecase2rk   j   s4    CACAHHW	A	AAHr   c                     U " S5      nU " S5      nU " S5      nUnU H  nXE-   nU R                  S5        M     U R                  S5        XC-   nU$ )Nr_   r`   ra   --loop bottom----loop exit--rd   )re   r_   r`   ra   ri   rj   s         r   looping_usecase1ro   s   sZ    CACACA	AE"#  HH_	AHr   c                    U " S5      nU " S5      nU " S5      nU H  nU R                  S5        X4-   nXD-   nU R                  S5        U H)  nU R                  S5        X6-   nU R                  S5        M+     U R                  S5        U(       a  WU-   nO  O&U R                  S	5        M     U R                  S
5        U R                  S5        U$ )Nr_   r`   cum--outer loop top--z--inner loop entry #{count}--z--inner loop top #{count}--z--inner loop bottom #{count}--z--inner loop exit #{count}--z--outer loop bottom #{count}----outer loop else----outer loop exit--rd   )re   r_   r`   rq   ri   zrj   s          r   looping_usecase2rv      s    CACA
e*C%&gE01AHH23'CHH56  	/0a%C 12 " 	&'HH"#Jr   c              #   <   #    U " S5      nU " S5      nUv   Uv   g 7fNr_   r`   r+   re   r_   r`   s      r   generator_usecase1rz      s!     CACA
G
Gs   c              #   N   #    U " S5      nU " S5      nU H  nUv   M	     Uv   g 7frx   r+   )re   r_   r`   ri   s       r   generator_usecase2r|      s+     CACA 
Gs   #%c                       \ rS rSrSrg)MyError   r+   N)r&   r'   r(   r)   r*   r+   r   r   r~   r~      s    r   r~   c                     [        U 5      er   r~   )ri   s    r   do_raiser      s    
!*r   c                 z    U " S5      nU " S5      nU " S5      nU(       a  [        S5        U " S5      nXA-     WU-     g )Nr_   r`   rf   foora   r   )re   r_   r`   rf   ra   s        r   raising_usecase1r      s<    CACACAH	Er   c                 b    U " S5      nU " S5      nU(       a  U " S5      n[        U5        UW-     g )Nr_   r`   ra   r   )re   r_   r`   ra   s       r   raising_usecase2r      s.    CACAHEr   c                 H    U " S5      nU " S5      nU(       a  [        U5      eg rx   r   ry   s      r   raising_usecase3r      s&    CACAaj 	r   c                 Z   Sn[        U5       H  nU R                  [        U5      5        Sn[        U5       H  n    g   US:  a  M:  US:X  a'  [        U5       H  nUs  s  $    U R                  S5        U R                  S5        U R                  S5        M     U R                  S5        g)zF
This test reveal a bug that there is a del on uninitialized variable
   r      FAILEDOK)rangerP   str)re   nijs       r   del_before_definitionr      s     	
A1XQqA  1uaqAH ""HHX  HHTNr   c              #   |   #     U R                  S5        Sv   U " S5      nU(       a  U R                  S5         M8  7f)zR
test to reveal bug of invalid liveness when infinite loop has multiple
backedge.
yieldNpbrard   )re   r   s     r   inf_loop_multiple_back_edger      s8     
 HHHUO s   :<c                   v    \ rS rSrSrS rSS jrS rS rS r	S	 r
S
 rS rS rS rS rS rS rS rS rSrg)TestObjLifetime   z@
Test lifetime of Python objects inside jit-compiled functions.
c                 F    [        [        R                  4SSS9" U5      nU$ )NTF)forceobjlooplift)r   r
   pyobject)r   pyfunccfuncs      r   compileTestObjLifetime.compile   s#     U^^%uEfMr   Nc                     [        5       nU R                  U5      nUb$  U R                  U5         U" U5        S S S 5        U$ U" U5        U$ ! , (       d  f       U$ = fr   )r8   r   assertRaises)r   r   raisesre   r   s        r   compile_and_record"TestObjLifetime.compile_and_record   s\    mV$""6*c
 + 
 #J
	 +* 
s   	A
Ac                     / nUR                   n[        U5      nU H,  nXe;   d  M
  UR                  U5        UR                  U5        M.     U R	                  X2SU< 35        g)zS
Check that the *expected* markers occur in that order in *rec*'s
recorded events.
z%the full list of recorded events is: N)rY   listrM   removeassertEqual)r   re   expectedactualrY   	remainingrf   s          r   assertRecordOrder!TestObjLifetime.assertRecordOrder   s_    
 <<N	A~a   #	 
 	FNP	Rr   c                     U R                  [        5      nU R                  UR                  5        U R	                  U/ SQ5        U R	                  U/ SQ5        U R	                  U/ SQ5        g )N)r_   r`   rb   )r_   ra   rb   )rb   zb + crc   )r   rg   assertFalserV   r   r   re   s     r   test_simple1TestObjLifetime.test_simple1  sW    %%o6#s$78s$78s$?@r   c                     U R                  [        5      nU R                  UR                  5        U R	                  U/ SQ5        g )N)r`   rb   r_   )r   rk   r   rV   r   r   s     r   test_simple2TestObjLifetime.test_simple2  s5    %%o6#s$78r   c                     U R                  [        5      nU R                  UR                  5        U R	                  U/ SQ5        U R	                  U/ SQ5        g )N)r_   r`   rn   ra   )	iter(a)#1rm   	iter(a)#2rm   	iter(a)#3rm   iter(a)rn   )r   ro   r   rV   r   r   s     r   test_looping1TestObjLifetime.test_looping1  sK    %%&67#s$DEs %' 	(r   c                 ,   U R                  [        5      nU R                  UR                  5        U R	                  USS/5        U R	                  U/ SQ5        U R	                  U/ SQ5        U R	                  U/ SQ5        U R	                  USS/5        g )Nr_   rr   )r   rs   rt   )iter(b)z--inner loop exit #1--r   z--inner loop exit #2--r   z--inner loop exit #3--)r   z--inner loop entry #1--r   z--inner loop entry #2--r   z--inner loop entry #3--ziter(a)#1 + iter(a)#1z--outer loop bottom #1--)r   rv   r   rV   r   r   s     r   test_looping2TestObjLifetime.test_looping2(  s    %%&67#sS*>$?@s %< 	=s %' 	(
 	s %' 	(
 	s%<%?%' 	(r   c                 <   U R                  U5      n[        5       nU R                  U5         U" U5      n[        U5        U R	                  UR
                  5        [        U5        U R                  UR
                  5        S S S 5        [        5       nU R                  U5         U" U5      nA[        R                  " 5         U R                  UR
                  5        S S S 5        [        5       nU R                  U5         U" U5      n[        U5        U R	                  UR
                  5        A[        R                  " 5         U R                  UR
                  5        S S S 5        g ! , (       d  f       N= f! , (       d  f       N= f! , (       d  f       g = fr   )
r   r8   assertRefCountr6   
assertTruerV   r   r   gccollect)r   genfuncr   re   gens        r   exercise_generator"TestObjLifetime.exercise_generator>  s   W%m  %*CIOOCII&ISYY' & m  %*CJJLSYY'	 & m  %*CIOOCII&JJLSYY' &% &% &% &%s%   AE+%:E<A F+
E9<
F

Fc                 .    U R                  [        5        g r   )r   rz   r#   s    r   test_generator1TestObjLifetime.test_generator1Y       23r   c                 .    U R                  [        5        g r   )r   r|   r#   s    r   test_generator2TestObjLifetime.test_generator2\  r   r   c                 j    U R                  [        5      nU R                  UR                  / SQ5        g )N)012)r   r   r   rY   r   s     r   test_del_before_definition*TestObjLifetime.test_del_before_definition_  s'    %%&;<7r   c                     U R                  [        5         U R                  [        [        S9nU R                  UR                  5        S S S 5        g ! , (       d  f       g = fN)r   )r   r   r   r   r~   r   rV   r   s     r   test_raising1TestObjLifetime.test_raising1c  D      *))*:7)KCSYY' +**   4A
A!c                     U R                  [        5         U R                  [        [        S9nU R                  UR                  5        S S S 5        g ! , (       d  f       g = fr   )r   r   r   r   r~   r   rV   r   s     r   test_raising2TestObjLifetime.test_raising2h  r   r   c                     U R                  [        5         U R                  [        [        S9nU R	                  UR
                  5        S S S 5        g ! , (       d  f       g = fr   )r   r~   r   r   r   rV   r   s     r   test_raising3TestObjLifetime.test_raising3m  sD      )))*:7)KCSYY' *))r   c                    U R                  [        5      n[        5       n[        U" U5      5      n[	        U5        U R                  UR                  / 5        [	        U5        U R                  UR                  / 5        [	        U5        U R                  UR                  / 5        U R                  UR                  / SQ5        g )N)r   r   r   r   r   r   r   )r   r   r8   iterr6   r   rV   rY   )r   r   re   iterators       r    test_inf_loop_multiple_back_edge0TestObjLifetime.test_inf_loop_multiple_back_edger  s    89mc
#XB'XB'XB'L	Nr   r+   r   )r&   r'   r(   r)   r[   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r*   r+   r   r   r   r      sU    R"A9

((,(6448(
(
(
Nr   r   c                        \ rS rSrS rS rSrg)TestExtendingVariableLifetimesi  c                   ^  S nU 4S jnU" S5      n/ [         R                  4S-  Q[         R                  P[         R                  P[         R                  P[         R                  P[         R                  P[         R                  P[         R                  PnU" X45        U" S5      n/ [         R                  4S-  Q[         R                  P[         R                  4S-  Q[         R                  PnU" XT5        g )Nc                      " S S[         5      n[        US9S 5       n[        SU 5         U" 5         UR                  UR                  S      nUR
                  S   nS S S 5        U$ ! , (       d  f       W$ = f)Nc                       \ rS rSrS rSrg)`TestExtendingVariableLifetimes.test_lifetime_basic.<locals>.get_ir.<locals>.IRPreservingCompileri  c                     [         R                  " U R                  5      nUR                  [        [
        5        UR                  5         U/$ r   r   define_nopython_pipelinestateadd_pass_afterr   r	   finalizer   pms     r   define_pipelinesqTestExtendingVariableLifetimes.test_lifetime_basic.<locals>.get_ir.<locals>.IRPreservingCompiler.define_pipelines  6    +DDTZZPB%%j.AKKM4Kr   r+   Nr&   r'   r(   r)   r   r*   r+   r   r   IRPreservingCompilerr          r   r  )pipeline_classc                      Sn SnX-   nX"-  nU$ N
      r+   r_   r`   ra   rf   s       r   r   OTestExtendingVariableLifetimes.test_lifetime_basic.<locals>.get_ir.<locals>.foo      EEr   EXTEND_VARIABLE_LIFETIMESr   preserved_ir)r   r   r   	overloads
signaturesmetadata)extend_lifetimesr  r   cresfunc_irs        r   get_irBTestExtendingVariableLifetimes.test_lifetime_basic.<locals>.get_ir  s~     |   !56 7 !!<>NO}}S^^A%67--7 P
 N PO
 Ns   3A((
A7c                   > TR                  [        U R                  5      S5        [        [	        U R                  R                  5       5      5      n[        XR                  5       H  u  p4TR                  XC5        M     g Nr0   )	r   lenblocksr6   r   valueszipbodyassertIsInstance)r  expectblkexpect_classgot_stmtr   s        r   checkATestExtendingVariableLifetimes.test_lifetime_basic.<locals>.check  s_    S0!4tGNN11345C +.fhh*?&%%h= +@r   Fr/   T   )r   AssignDelReturn)r   r  r!  del_after_use_irr  del_at_block_end_irs   `     r   test_lifetime_basic2TestExtendingVariableLifetimes.test_lifetime_basic  s    	4	> "%=0RYYL1$ 0rvv 0rvv 0ryy 0"&& 0))0VV0%'YY0'$Tl ORYYL1$NryyNRVVIMNBIIN!*r   c                     S nU" SS9nU" SSS9nU" SSS9nS nU R                  U" U5      5        U R                  U" U5      5        U R                  U" U5      5        g )Nc                       " S S[         5      n[        SSU0U D6S 5       nU" 5         UR                  UR                  S      nUR                  S   nU$ )Nc                       \ rS rSrS rSrg)fTestExtendingVariableLifetimes.test_dbg_extend_lifetimes.<locals>.get_ir.<locals>.IRPreservingCompileri  c                     [         R                  " U R                  5      nUR                  [        [
        5        UR                  5         U/$ r   r   r   s     r   r   wTestExtendingVariableLifetimes.test_dbg_extend_lifetimes.<locals>.get_ir.<locals>.IRPreservingCompiler.define_pipelines  r   r   r+   Nr   r+   r   r   r  r.    r  r   r  r  c                      Sn SnX-   nX"-  nU$ r  r+   r  s       r   r   UTestExtendingVariableLifetimes.test_dbg_extend_lifetimes.<locals>.get_ir.<locals>.foo  r
  r   r   r  r+   )r   r   r  r  r  )optionsr  r   r  r  s        r   r  HTestExtendingVariableLifetimes.test_dbg_extend_lifetimes.<locals>.get_ir  sb     |   A!5AA B E==!23DmmN3GNr   T)debug)r5  _dbg_extend_lifetimesFc                    U R                   R                  5       u  nUR                   Vs/ s H  n[        U[        R
                  5      PM     nn[        [        [        R                  U5      5      n[        U5      n[        [        [        R                  X5S  5      5      nU[        U5      -   nU[        U5      S-
  :H  $ s  snf r  )r  r  r  r   r   r%  r   r   operatornot_r  truth)firr  stmtinst_is_delnot_delsbeginall_delsends           r   is_del_grouped_at_the_end[TestExtendingVariableLifetimes.test_dbg_extend_lifetimes.<locals>.is_del_grouped_at_the_end  s    JJ%%'ES@CI:dBFF3KIIhmm[ABHMEIhnnk&6IJKH#h-'C #k*Q... Js   $C)r   r   )r   r  ir_debugir_debug_extir_debug_no_extrB  s         r   test_dbg_extend_lifetimes8TestExtendingVariableLifetimes.test_dbg_extend_lifetimes  sj    	2 %DE t5I	/  	1(;<1,?@2?CDr   r+   N)r&   r'   r(   r)   r)  rG  r*   r+   r   r   r   r     s    
0+d3Er   r   __main__).r;   rF   r   r8  	itertoolsr   unittestnumbar   r   numba.core.compilerr   r   numba.core.untyped_passesr   numba.core.typed_passesr	   
numba.corer
   r   numba.tests.supportr   r   r   objectr   r"   r8   rg   rk   ro   rv   rz   r|   RuntimeErrorr~   r   r   r   r   r   r   r   r   r&   mainr+   r   r   <module>rU     s      	     @ 0 2   F FEV E
V 
1& 1h
2	l 	

.SNh SNljE[( jEZ zMMO r   