
    sh8                         S SK r S SKJr  S SKJr  S SKJrJrJrJ	r	J
r
  S SKJr   " S S\ R                  5      r\S:X  a  \ R                   " 5         gg)	    N)contextmanager)ir)typestypingcallconvcpucgutils)
cpu_targetc                   :    \ rS rSrSr\S 5       rS rS rS r	Sr
g)	TestCompileCache
   z
Tests that the caching in BaseContext.compile_internal() works correctly by
checking the state of the cache when it is used by the CPUContext.
c              #     #    [         R                  n[         R                  nUR                  5       R	                  S5      nUR                  U5         [        R                  " S5      n[        R                  " [        R                  [        R                  5      nUR                  R                  UR                  UR                  5      n[         R"                  " XFS5      nUR                  R%                  U5      nUR&                  (       d   eUR)                  S5      n	[        R*                  " U	5      n
X*XX4v   S S S 5        g ! , (       d  f       g = f7f)Ntestingtest_moduletest_fnentry)r
   typing_contexttarget_contextcodegencreate_librarypush_code_libraryr   Moduler   	signaturer   int32	call_convget_function_typereturn_typeargsr	   get_or_insert_functionget_argumentsis_declarationappend_basic_block	IRBuilder)selfr   contextlibmodulesig	llvm_fntyfunctionr   entry_blockbuilders              r/Users/tiagomarins/Projetos/claudeai/copy_bank/venv/lib/python3.13/site-packages/numba/tests/test_compile_cache.py_context_builder_sig_args*TestCompileCache._context_builder_sig_args   s     #22++oo..y9&&s+YY}-F""5;;<C));;COO<?HHFI55f6?AH$$228<D****"55g>Kll;/GC-- ,++s   AEC,E?	E
EEc                 h   S nS nU R                  5        u  p4pV[        UR                  5      nU R                  US-   [        UR                  5      5        UR	                  XAXV5        U R                  US-   [        UR                  5      5        UR	                  XAXV5        U R                  US-   [        UR                  5      5        UR	                  XBXV5        U R                  US-   [        UR                  5      5        [
        R                  " [        R                  [        R                  5      nUR                  R                  UR                  UR                  5      n	[        R                  " UR                  U	S5      n
UR                  R!                  U
5      nU
R"                  (       d   eU
R%                  S5      n[&        R(                  " U5      nUR	                  XX5        U R                  US-   [        UR                  5      5        S S S 5        g ! , (       d  f       g = f)	Nc                     SU -  $ )N    is    r-   times2+TestCompileCache.test_cache.<locals>.times2%       Q3J    c                     U S-  $ )N   r3   r4   s    r-   times3+TestCompileCache.test_cache.<locals>.times3(   r8   r9   r      r2   	test_fn_2r   r;   )r.   lencached_internal_funcassertEqualcompile_internalr   r   r   float64r   r   r   r   r	   r   r'   r    r!   r"   r   r#   )r$   r6   r<   r%   r,   r(   r   initial_cache_sizesig2
llvm_fnty2	function2args2entry_block2builder2s                 r-   
test_cacheTestCompileCache.test_cache$   s   		 ++- 2
c!$W%A%A!B/!3 !=!=>@ $$Wc@/!3 !=!=>@
 $$Wc@/!3 !=!=>@
 $$Wc@/!3 !=!=>@ ##EMM5==AD **<<T=M=M<@IIGJ66w~~7A;PI%%33I>E++++$77@L||L1H $$XtC/!3 !=!=>@M .--s   HH##
H1c                     S nU R                  5        u  p#pEU" SS5      nU" SS5      nU" SS5      n[        UR                  5      n	UR                  X6XE5      n
U R	                  U	S-   [        UR                  5      5        UR                  X7XE5      nU R	                  U	S-   [        UR                  5      5        UR                  X8XE5      nU R	                  U	S-   [        UR                  5      5        SSS5        g! , (       d  f       g= f)z@
Caching must not mix up closures reusing the same code object.
c                    ^ U4S jnU$ )Nc                    > TU -   $ Nr3   )zys    r-   f?TestCompileCache.test_closures.<locals>.make_closure.<locals>.fY   s    1ur9   r3   )xrS   rT   s    ` r-   make_closure4TestCompileCache.test_closures.<locals>.make_closureX   s    Hr9   r>   r2   N)r.   r@   rA   rC   rB   )r$   rW   r%   r,   r(   r   clo11clo12clo22rE   res1res2res3s                r-   test_closuresTestCompileCache.test_closuresT   s	   	
 ++- 2
c !A&E A&E A&E!$W%A%A!B++GCFD/!3 !=!=>@++GCFD/!3 !=!=>@ ++GCFD/!3 !=!=>@! .--s   C"C??
Dc                 2  ^^^ S m[         R                  " [        R                  [        R                  5      mUUU4S jnU R	                  5        u  nmp4[
        R                  " SU5      n[
        R                  " SU5      nUR                  US9nUR                  US9nUR                  US9n	[        UR                  5      n
U R                  U
S-   [        UR                  5      5        U" U5        U R                  U
S-   [        UR                  5      5        U" U5        U R                  U
S-   [        UR                  5      5        U" U	5        U R                  U
S-   [        UR                  5      5        S	S	S	5        g	! , (       d  f       g	= f)
z1
Caching must not mix up different error models.
c                     SU -  $ )Ng      ?r3   )rV   s    r-   inv.TestCompileCache.test_error_model.<locals>.invt   s    7Nr9   c                 *   > U R                  TTT5      $ rQ   )compile_subroutine)r%   r,   rc   inv_sigs    r-   compile_inv6TestCompileCache.test_error_model.<locals>.compile_invy   s    --gsGDDr9   pythonnumpy)error_modelr   r>   r2   N)r   r   r   rD   r.   r   create_error_model	subtargetr@   rA   rB   )r$   rh   r%   r(   r   py_error_modelnp_error_modelpy_context1py_context2
np_contextrE   r,   rc   rg   s              @@@r-   test_error_model!TestCompileCache.test_error_modelp   sp   	 ""5==%--@	E ++- 2
Wc%887KN%88'JN!+++GK!+++GK **~*FJ!$W%A%A!B /!3 !=!=>@ $/!3 !=!=>@$/!3 !=!=>@ 
#/!3 !=!=>@1 .--s   D-F
Fr3   N)__name__
__module____qualname____firstlineno____doc__r   r.   rL   r_   rt   __static_attributes__r3   r9   r-   r   r   
   s.    
 . .&.@`@8%@r9   r   __main__)unittest
contextlibr   llvmliter   
numba.corer   r   r   r   r	   numba.core.registryr
   TestCaser   rv   mainr3   r9   r-   <module>r      sF     %  < < *K@x(( K@\ zMMO r9   