o
    i8                     @   sr   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 de jZedkr7e   dS dS )	    N)contextmanager)ir)typestypingcallconvcpucgutils)
cpu_targetc                   @   s4   e Zd ZdZedd Zdd Zdd Zd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                 c   s    t j}t j}| d}||B td}t	t
jt
j}|j|j|j}t||d}|j|}|js<J |d}	t|	}
||
||fV  W d    d S 1 sXw   Y  d S )NtestingZtest_moduleZtest_fnentry)r	   typing_contextZtarget_contextZcodegenZcreate_libraryZpush_code_libraryr   Moduler   	signaturer   Z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sigZ	llvm_fntyfunctionr   Zentry_blockbuilder r    m/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/numba/tests/test_compile_cache.py_context_builder_sig_args   s&   




"z*TestCompileCache._context_builder_sig_argsc                 C   sZ  dd }dd }|   \}}}}t|j}| |d t|j ||||| | |d t|j ||||| | |d t|j ||||| | |d t|j ttjtj}|j	
|j|j}	t|j|	d}
|j	|
}|
js~J |
d	}t|}||||| | |d
 t|j W d    d S 1 sw   Y  d S )Nc                 S   s   d|  S )N   r    ir    r    r!   times2%      z+TestCompileCache.test_cache.<locals>.times2c                 S   s   | d S )N   r    r$   r    r    r!   times3(   r'   z+TestCompileCache.test_cache.<locals>.times3r      r#   Z	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   r&   r)   r   r   r   r   initial_cache_sizeZsig2Z
llvm_fnty2Z	function2Zargs2Zentry_block2Zbuilder2r    r    r!   
test_cache$   sH   










"zTestCompileCache.test_cachec                 C   s   dd }|   Z\}}}}|dd}|dd}|dd}t|j}	|||||}
| |	d t|j |||||}| |	d t|j |||||}| |	d t|j W d   dS 1 sew   Y  dS )zP
        Caching must not mix up closures reusing the same code object.
        c                    s    fdd}|S )Nc                    s    |  S Nr    )zyr    r!   fY   r'   z?TestCompileCache.test_closures.<locals>.make_closure.<locals>.fr    )xr5   r6   r    r4   r!   make_closureX   s   z4TestCompileCache.test_closures.<locals>.make_closurer*   r#   N)r"   r+   r,   r.   r-   )r   r8   r   r   r   r   Zclo11Zclo12Zclo22r0   Zres1Zres2Zres3r    r    r!   test_closuresT   s(   







"zTestCompileCache.test_closuresc                    s  dd t tjtj fdd}|  h\} }}td|}td|}|j|d}|j|d}|j|d}	t|j	}
| 
|
d t|j	 || | 
|
d	 t|j	 || | 
|
d	 t|j	 ||	 | 
|
d
 t|j	 W d   dS 1 sw   Y  dS )zA
        Caching must not mix up different error models.
        c                 S   s   d|  S )Ng      ?r    )r7   r    r    r!   invt   r'   z.TestCompileCache.test_error_model.<locals>.invc                    s   |   S r2   )Zcompile_subroutine)r   r   r:   Zinv_sigr    r!   compile_invy   s   z6TestCompileCache.test_error_model.<locals>.compile_invpythonnumpy)Zerror_modelr   r*   r#   N)r   r   r   r/   r"   r   Zcreate_error_modelZ	subtargetr+   r,   r-   )r   r<   r   r   r   Zpy_error_modelZnp_error_modelZpy_context1Zpy_context2Z
np_contextr0   r    r;   r!   test_error_modelp   s6   





"z!TestCompileCache.test_error_modelN)	__name__
__module____qualname____doc__r   r"   r1   r9   r?   r    r    r    r!   r
   
   s    
0r
   __main__)Zunittest
contextlibr   Zllvmliter   Z
numba.corer   r   r   r   r   Znumba.core.registryr	   ZTestCaser
   r@   mainr    r    r    r!   <module>   s     