U
    9%e1                     @   s   d dl mZmZ d dlmZmZmZmZmZm	Z	 d dl
mZ d dlmZ d dlmZmZmZ d dlmZ d dlmZ d dlZd dlZd	d
 Zdd Zdd Zdd Zdd ZG dd dejZe dkre!  dS )    )jitnjit)typestypingirconfigcompilercpu)
cpu_target)type_annotations)copy_propagateapply_copy_propagateget_name_var_table)type_inference_stage)IRPreservingTestPipelineNc                 C   s.   d}|}| dkr|| }nd}d| }|| k S )N   r       )bzwxx1yar   r   ^/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/numba/tests/test_copy_propagate.pytest_will_propagate   s    
r   c                 C   s.   d}| dkr|| }d}nd}d| }|| k S )Nr   r      r   r   )r   r   r   r   r   r   r   r   r   test_wont_propagate   s    r   c                 C   s   d S )Nr   )r   r   cdr   r   r   	null_func(   s    r!   c                 C   s   | D ]}|j |kr dS qdS NTF)name)Zlist_varvarir   r   r   	inListVar,   s    
r&   c                 C   s^   | j  D ]N\}}t|jD ]:\}}t|tjr|jj|kr|	 }t
||r  dS qq
dS r"   )blocksitems	enumeratebody
isinstancer   Assigntargetr#   Z	list_varsr&   )func_irr$   labelblockr%   instZall_varr   r   r   
findAssign3   s    
r2   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestCopyPropagatec                 C   s   t  }t|d}tt}t|| |	  |	  t
jt
jt
jf}t||||d \}}}}tj|||dd ||tjd}	t|j|\}
}t|j|
t|j|| | t|d W 5 Q R X d S )Nr	   r   r.   typemap	calltypesZliftedZlifted_fromargsreturn_typeZhtml_outputr   )r   Contextr	   
CPUContextr   run_frontendr   r
   nested_contextrefreshr   int64r   r   TypeAnnotationr   HTMLr   r'   r   r   ZassertFalser2   selfZ	typingctxZ	targetctxZtest_irr7   r5   r8   r6   _Ztype_annotationZin_cpsZout_cpsr   r   r   test1?   s<    
	 zTestCopyPropagate.test1c                 C   s   t  }t|d}tt}t|| |	  |	  t
jt
jt
jf}t||||d \}}}}tj|||dd ||tjd}	t|j|\}
}t|j|
t|j|| | t|d W 5 Q R X d S )Nr	   r   r4   r   )r   r9   r	   r:   r   r;   r   r
   r<   r=   r   r>   r   r   r?   r   r@   r   r'   r   r   
assertTruer2   rA   r   r   r   test2\   s4    
	zTestCopyPropagate.test2c                 C   s   dd }t td|}| |d|d |j|jd  jd }| t|jdk t	t
|j }d}|jD ]N}t|tjrp|jjd	krpd
}| t|jtjo|jjdko|jjjdk qp| | dS )zmake sure Interpreter._remove_unused_temporaries() has removed extra copies
        in the IR in simple cases so copy propagation is faster
        c                 S   s   | d }|S )Nr   r   )r   r   r   r   r   	test_impl{   s    z?TestCopyPropagate.test_input_ir_extra_copies.<locals>.test_impl)Zpipeline_class   r   Zpreserved_irr   Fr   TZbinopr   N)r   r   assertEqualZ	overloadsZ
signaturesmetadatarE   lenr'   nextitervaluesr*   r+   r   r,   r-   r#   valueExproplhs)rB   rG   Zj_funcZfirr0   Zb_foundstmtr   r   r   test_input_ir_extra_copiesw   s     

z,TestCopyPropagate.test_input_ir_extra_copiesc                 C   s   dd }dd }dd }G dd d}|  |d	t|d	 |  |td
dd	t|td
dd	 |  || d	tdd|| d	 dS )zmake sure Interpreter._remove_unused_temporaries() does not generate
        invalid code for rare chained assignment cases
        c                 S   s   | d  }}||fS )Nr   r   )r   r   r   r   r   r   impl1   s    zDTestCopyPropagate.test_input_ir_copy_remove_transform.<locals>.impl1c                 S   s    |d  }| |< || | d fS Nr   r   r   )Ar%   r   r   r   r   r   impl2   s    zDTestCopyPropagate.test_input_ir_copy_remove_transform.<locals>.impl2c                 S   s   |d  }| _ || j d fS rV   )r   )rW   r   r   r   r   r   impl3   s    zDTestCopyPropagate.test_input_ir_copy_remove_transform.<locals>.impl3c                   @   s   e Zd ZdS )z@TestCopyPropagate.test_input_ir_copy_remove_transform.<locals>.CN)__name__
__module____qualname__r   r   r   r   C   s   r]   rH   r   r   T)ZforceobjN)rI   r   npZonesr   )rB   rU   rX   rY   r]   r   r   r   #test_input_ir_copy_remove_transform   s    ,z5TestCopyPropagate.test_input_ir_copy_remove_transformN)rZ   r[   r\   rD   rF   rT   r_   r   r   r   r   r3   >   s   r3   __main__)"Znumbar   r   Z
numba.corer   r   r   r   r   r	   Znumba.core.registryr
   Znumba.core.annotationsr   Znumba.core.ir_utilsr   r   r   Znumba.core.typed_passesr   Znumba.tests.supportr   numpyr^   Zunittestr   r   r!   r&   r2   ZTestCaser3   rZ   mainr   r   r   r   <module>   s     l