U
    iâËdm  ã                   @   s¨   d dl mZmZ d dl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mZmZ d dlmZmZmZ d dlmZ d dlmZ G d	d
„ d
eƒZG dd„ deƒZdS )é    )ÚCompilerÚDefaultPassBuilder)ÚFunctionPassÚAnalysisPassÚregister_pass)ÚInlineInlinables)ÚIRLegalization)ÚjitÚgenerated_jitÚobjmodeÚnjitÚcfunc)ÚtypesÚpostprocÚerrors)Ú
FunctionIR)ÚTestCasec                       s<   e Zd Z‡ fdd„Zdd„ Zdd„ Zdd„ Zd	d
„ Z‡  ZS )ÚTestCustomPipelinec                    s,   t t| ƒ ¡  G ‡ fdd„dtƒ‰ ˆ | _d S )Nc                       s0   e Zd Zg Z‡‡ fdd„Z‡‡ fdd„Z‡  ZS )z0TestCustomPipeline.setUp.<locals>.CustomPipelinec                    s   | j  |¡ tˆ | ƒ |¡S ©N)Úcustom_pipeline_cacheÚappendÚsuperÚcompile_extra)ÚselfÚfunc©ÚCustomPipelineÚ	__class__© úR/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/numba/tests/test_pipeline.pyr      s    z>TestCustomPipeline.setUp.<locals>.CustomPipeline.compile_extrac                    s$   | j  |¡ tˆ | ƒj|f|ž|ŽS r   )r   r   r   Ú
compile_ir)r   Úfunc_irÚargsÚkwargsr   r   r   r       s    
ÿÿÿz;TestCustomPipeline.setUp.<locals>.CustomPipeline.compile_ir)Ú__name__Ú
__module__Ú__qualname__r   r   r    Ú__classcell__r   ©r   ©r   r   r      s   r   )r   r   ÚsetUpr   Úpipeline_class©r   r)   r(   r   r*      s    zTestCustomPipeline.setUpc                 C   sL   |   | jjg ¡ t| jd�dd„ ƒ}|  |dƒd¡ |   | jj|jg¡ d S )N©r+   c                 S   s   | S r   r   ©Úxr   r   r   Úfoo$   s    z8TestCustomPipeline.test_jit_custom_pipeline.<locals>.fooé   )ÚassertListEqualr+   r   r	   ÚassertEqualÚpy_func©r   r0   r   r   r   Útest_jit_custom_pipeline!   s    


ÿz+TestCustomPipeline.test_jit_custom_pipelinec                 C   sV   |   | jjg ¡ tt tj¡| jd�dd„ ƒ}|  |dƒd¡ |   | jj|jg¡ d S )Nr-   c                 S   s   | S r   r   r.   r   r   r   r0   /   s    z:TestCustomPipeline.test_cfunc_custom_pipeline.<locals>.foor1   )r2   r+   r   r   r   Zint64r3   Ú__wrapped__r5   r   r   r   Útest_cfunc_custom_pipeline,   s    

ÿz-TestCustomPipeline.test_cfunc_custom_pipelinec                    sV   |   | jjg ¡ dd„ ‰ t| jd�‡ fdd„ƒ}|  |dƒd¡ |   | jjˆ g¡ d S )Nc                 S   s   | S r   r   r.   r   r   r   Úinner:   s    zDTestCustomPipeline.test_generated_jit_custom_pipeline.<locals>.innerr-   c                    s   t | tjƒrˆ S d S r   )Ú
isinstancer   ÚIntegerr.   ©r9   r   r   r0   =   s    zBTestCustomPipeline.test_generated_jit_custom_pipeline.<locals>.fooé   )r2   r+   r   r
   r3   r5   r   r<   r   Ú"test_generated_jit_custom_pipeline7   s    

ÿz5TestCustomPipeline.test_generated_jit_custom_pipelinec                 C   s†   |   | jjg ¡ t| jd�dd„ ƒ}d}|  ||ƒ|d ¡ |  t| jjƒd¡ | jjd }|  ||j¡ | jjd }|  |t	¡ d S )Nr-   c              	   S   s&   t dd�� | tdƒ7 } W 5 Q R X | S )NZintpr.   é   )r   Úintr.   r   r   r   r0   I   s    z<TestCustomPipeline.test_objmode_custom_pipeline.<locals>.fooé{   r?   é   r   )
r2   r+   r   r	   r3   ÚlenZassertIsr4   ZassertIsInstancer   )r   r0   ÚargÚfirstÚsecondr   r   r   Útest_objmode_custom_pipelineF   s    

z/TestCustomPipeline.test_objmode_custom_pipeline)	r$   r%   r&   r*   r6   r8   r>   rG   r'   r   r   r)   r   r      s
   r   c                   @   s&   e Zd Zddd„Zdd„ Zdd„ ZdS )	ÚTestPassManagerFunctionalityNc                    sV   |   ˆdk	¡ |   ˆdk	¡ tddd�G ‡fdd„dˆƒƒ‰ G ‡ ‡fdd„dtƒ}|S )zŒ
        Creates a new compiler pipeline with the _InjectDelsPass injected after
        the pass supplied in kwarg 'inject_after'.
        NF)Zmutates_CFGZanalysis_onlyc                       s0   e Zd ZdZde” ƒ Z‡ fdd„Zdd„ ZdS )zLTestPassManagerFunctionality._create_pipeline_w_del.<locals>._InjectDelsPasszD
            This pass injects ir.Del nodes into the IR
            zinject_dels_%sc                    s   ˆ   | ¡ d S r   )Ú__init__r,   ©Úbaser   r   rI   l   s    zUTestPassManagerFunctionality._create_pipeline_w_del.<locals>._InjectDelsPass.__init__c                 S   s   t  |j¡}|jdd� dS )NT)Z	emit_dels)r   ZPostProcessorr!   Úrun)r   ÚstateÚppr   r   r   Úrun_passo   s    zUTestPassManagerFunctionality._create_pipeline_w_del.<locals>._InjectDelsPass.run_passN)r$   r%   r&   Ú__doc__ÚstrÚ_namerI   rO   r   rJ   r   r   Ú_InjectDelsPasse   s   rS   c                       s   e Zd Z‡ ‡fdd„ZdS )zITestPassManagerFunctionality._create_pipeline_w_del.<locals>.TestCompilerc                    s&   t  | j¡}| ˆ ˆ¡ | ¡  |gS r   )r   Zdefine_nopython_pipelinerM   Zadd_pass_afterÚfinalize)r   Úpm©rS   Úinject_afterr   r   Údefine_pipelinesv   s    zZTestPassManagerFunctionality._create_pipeline_w_del.<locals>.TestCompiler.define_pipelinesN)r$   r%   r&   rX   r   rV   r   r   ÚTestCompilert   s   rY   )Ú
assertTruer   r   )r   rK   rW   rY   r   )rS   rK   rW   r   Ú_create_pipeline_w_del]   s    
z3TestPassManagerFunctionality._create_pipeline_w_delc              	   C   sd   |   tt¡}t|d�dd„ ƒ}|  tj¡�}|dƒ W 5 Q R X t|jƒ}|  	d|¡ |  	d|¡ d S )Nr-   c                 S   s   | d S ©Nr?   r   r.   r   r   r   r0   ‚   s    zYTestPassManagerFunctionality.test_compiler_error_on_ir_del_from_functionpass.<locals>.fooé
   zIllegal IR, del found at:zdel x)
r[   r   r   r   ÚassertRaisesr   ZCompilerErrorrQ   Ú	exceptionZassertIn)r   Únew_compilerr0   ZraisesZerrstrr   r   r   Ú/test_compiler_error_on_ir_del_from_functionpass~   s    ÿ

zLTestPassManagerFunctionality.test_compiler_error_on_ir_del_from_functionpassc                 C   s8   |   tt¡}t|d�dd„ ƒ}|  |dƒ| d¡¡ d S )Nr-   c                 S   s   | d S r\   r   r.   r   r   r   r0   š   s    z]TestPassManagerFunctionality.test_no_compiler_error_on_ir_del_after_legalization.<locals>.foor]   )r[   r   r   r   rZ   r4   )r   r`   r0   r   r   r   Ú3test_no_compiler_error_on_ir_del_after_legalizationŽ   s    	ÿ
zPTestPassManagerFunctionality.test_no_compiler_error_on_ir_del_after_legalization)NN)r$   r%   r&   r[   ra   rb   r   r   r   r   rH   [   s   
!rH   N)Znumba.core.compilerr   r   Znumba.core.compiler_machineryr   r   r   Znumba.core.untyped_passesr   Znumba.core.typed_passesr   Znumbar	   r
   r   r   r   Z
numba.corer   r   r   Znumba.core.irr   Znumba.tests.supportr   r   rH   r   r   r   r   Ú<module>   s   O