
    J/Ph8                         d dl Z d dlmZ d dlmZ d dlmZmZmZm	Z	m
Z
 d dlmZ  G d de j                  Zedk    r e j                     dS dS )	    N)contextmanager)ir)typestypingcallconvcpucgutils)
cpu_targetc                   :    e Zd ZdZed             Zd Zd Zd ZdS )TestCompileCachez
    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              #   |  K   t           j        }t           j        }|                                                    d          }|                    |          5  t          j        d          }t          j	        t          j        t          j                  }|j                            |j        |j                  }t!          j        ||d          }|j                            |          }|j        sJ |                    d          }	t          j        |	          }
||
||fV  d d d            d S # 1 swxY w Y   d S )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              ^/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numba/tests/test_compile_cache.py_context_builder_sig_argsz*TestCompileCache._context_builder_sig_args   sj     #2+oo..y99&&s++ 	. 	.Y}--F"5;<<C);;CO<?HF FI5fi6?A AH$228<<D****"55g>>Kl;//G7C----	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.s   CD11D58D5c                 v   d }d }|                                  5 \  }}}}t          |j                  }|                     |dz   t          |j                             |                    ||||           |                     |dz   t          |j                             |                    ||||           |                     |dz   t          |j                             |                    ||||           |                     |dz   t          |j                             t          j        t          j        t          j                  }|j	        
                    |j        |j                  }	t          j        |j        |	d          }
|j	                            |
          }|
j        sJ |
                    d          }t'          j        |          }|                    ||||           |                     |dz   t          |j                             d d d            d S # 1 swxY w Y   d S )	Nc                     d| z  S )N    is    r,   times2z+TestCompileCache.test_cache.<locals>.times2%       Q3J    c                     | dz  S )N   r1   r2   s    r,   times3z+TestCompileCache.test_cache.<locals>.times3(   r5   r6   r      r0   	test_fn_2r   r8   )r-   lencached_internal_funcassertEqualcompile_internalr   r   r   float64r   r   r   r   r	   r   r&   r   r    r!   r   r"   )r#   r4   r9   r$   r+   r'   r   initial_cache_sizesig2
llvm_fnty2	function2args2entry_block2builder2s                 r,   
test_cachezTestCompileCache.test_cache$   s   	 	 		 	 	 ++-- '	@ 2
Wc4!$W%A!B!B/!3 !=>>@ @ @ $$Wfc4@@@/!3 !=>>@ @ @
 $$Wfc4@@@/!3 !=>>@ @ @
 $$Wfc4@@@/!3 !=>>@ @ @ #EM5=AAD *<<T=M<@IG GJ6w~7A;P PI%33I>>E++++$77@@L|L11H $$XvtUCCC/!3 !=>>@ @ @M'	@ '	@ '	@ '	@ '	@ '	@ '	@ '	@ '	@ '	@ '	@ '	@ '	@ '	@ '	@ '	@ '	@ '	@s   HH..H25H2c                 r   d }|                                  5 \  }}}} |dd          } |dd          } |dd          }t          |j                  }	|                    ||||          }
|                     |	dz   t          |j                             |                    ||||          }|                     |	dz   t          |j                             |                    ||||          }|                     |	dz   t          |j                             ddd           dS # 1 swxY w Y   dS )zP
        Caching must not mix up closures reusing the same code object.
        c                     fd}|S )Nc                     | z   S Nr1   )zys    r,   fz?TestCompileCache.test_closures.<locals>.make_closure.<locals>.fY   s    1ur6   r1   )xrN   rO   s    ` r,   make_closurez4TestCompileCache.test_closures.<locals>.make_closureX   s!        Hr6   r:   r0   N)r-   r<   r=   r?   r>   )r#   rQ   r$   r+   r'   r   clo11clo12clo22rA   res1res2res3s                r,   test_closureszTestCompileCache.test_closuresT   s   	 	 	
 ++-- 	@ 2
Wc4 !LA&&E LA&&E LA&&E!$W%A!B!B++GUCFFD/!3 !=>>@ @ @++GUCFFD/!3 !=>>@ @ @ ++GUCFFD/!3 !=>>@ @ @!	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@s   DD,,D03D0c                 p   d t          j        t          j        t          j                  fd}|                                 5 \  }}}t          j        d|          }t          j        d|          }|                    |          }|                    |          }|                    |          }	t          |j	                  }
| 
                    |
dz   t          |j	                              ||           | 
                    |
dz   t          |j	                              ||           | 
                    |
dz   t          |j	                              ||	           | 
                    |
dz   t          |j	                             d	d	d	           d	S # 1 swxY w Y   d	S )
zA
        Caching must not mix up different error models.
        c                     d| z  S )Ng      ?r1   )rP   s    r,   invz.TestCompileCache.test_error_model.<locals>.invt   s    7Nr6   c                 2    |                                S rL   )compile_subroutine)r$   r+   r[   inv_sigs    r,   compile_invz6TestCompileCache.test_error_model.<locals>.compile_invy   s    --gsGDDDr6   pythonnumpy)error_modelr   r:   r0   N)r   r   r   r@   r-   r   create_error_model	subtargetr<   r=   r>   )r#   r_   r$   r'   r   py_error_modelnp_error_modelpy_context1py_context2
np_contextrA   r+   r[   r^   s              @@@r,   test_error_modelz!TestCompileCache.test_error_modelp   s[   	 	 	 "5=%-@@	E 	E 	E 	E 	E 	E 	E ++-- 	@ 2
Wc4%87KKN%8'JJN!+++GGK!+++GGK **~*FFJ!$W%A!B!B /!3 !=>>@ @ @ K$$$/!3 !=>>@ @ @K$$$/!3 !=>>@ @ @ K
###/!3 !=>>@ @ @1	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@s   EF++F/2F/N)	__name__
__module____qualname____doc__r   r-   rH   rX   rj   r1   r6   r,   r   r   
   sr         
 . . ^.&.@ .@ .@`@ @ @8%@ %@ %@ %@ %@r6   r   __main__)unittest
contextlibr   llvmliter   
numba.corer   r   r   r   r	   numba.core.registryr
   TestCaser   rk   mainr1   r6   r,   <module>rw      s     % % % % % %       < < < < < < < < < < < < < < * * * * * *K@ K@ K@ K@ K@x( K@ K@ K@\ zHMOOOOO r6   