
    xKg                         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 d dlmZmZmZ d dlmZ d dlmZ  G d	 d
e      Z G d de      Zy)    )CompilerDefaultPassBuilder)FunctionPassAnalysisPassregister_pass)InlineInlinables)IRLegalization)jitobjmodenjitcfunc)typespostprocerrors)
FunctionIR)TestCasec                   0     e Zd Z fdZd Zd Zd Z xZS )TestCustomPipelinec                 \    t         t        |            G fddt              | _        y )Nc                   2     e Zd Zg Z fdZ fdZ xZS )0TestCustomPipeline.setUp.<locals>.CustomPipelinec                 X    | j                   j                  |       t        |   |      S N)custom_pipeline_cacheappendsupercompile_extra)selffuncCustomPipeline	__class__s     ]/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/numba/tests/test_pipeline.pyr   z>TestCustomPipeline.setUp.<locals>.CustomPipeline.compile_extra   s)    **11$7^T@FF    c                 `    | j                   j                  |       t        |   |g|i |S r   )r   r   r   
compile_ir)r   func_irargskwargsr    r!   s       r"   r%   z;TestCustomPipeline.setUp.<locals>.CustomPipeline.compile_ir   s>    **11':^T=.".&,. .r#   )__name__
__module____qualname__r   r   r%   __classcell__)r!   r    s   @r"   r    r      s    $&!G
. .r#   r    )r   r   setUpr   pipeline_class)r   r    r!   s    @r"   r-   zTestCustomPipeline.setUp   s'     $-/	.X 	. -r#   c                    | j                  | j                  j                  g        t        | j                        d        }| j	                   |d      d       | j                  | j                  j                  |j
                  g       y )Nr.   c                     | S r    xs    r"   fooz8TestCustomPipeline.test_jit_custom_pipeline.<locals>.foo$       Hr#      )assertListEqualr.   r   r
   assertEqualpy_funcr   r5   s     r"   test_jit_custom_pipelinez+TestCustomPipeline.test_jit_custom_pipeline!   sv    T00FFK	D//	0	 
1	 	Q#T00FF!kk]	,r#   c                 ^   | j                  | j                  j                  g        t        t	        j
                  t        j
                        | j                        d        }| j                   |d      d       | j                  | j                  j                  |j                  g       y )Nr0   c                     | S r   r2   r3   s    r"   r5   z:TestCustomPipeline.test_cfunc_custom_pipeline.<locals>.foo/   r6   r#   r7   )r8   r.   r   r   r   int64r9   __wrapped__r;   s     r"   test_cfunc_custom_pipelinez-TestCustomPipeline.test_cfunc_custom_pipeline,   s    T00FFK	u{{5;;'8K8K	L	 
M	 	Q#T00FF!oo.	0r#   c                    | j                  | j                  j                  g        t        | j                        d        }d}| j	                   ||      |dz          | j	                  t        | j                  j                        d       | j                  j                  d   }| j                  ||j                         | j                  j                  d   }| j                  |t               y )Nr0   c                 f    t        d      5  | t        d      z  } d d d        | S # 1 sw Y   | S xY w)Nintpr3      )r   intr3   s    r"   r5   z<TestCustomPipeline.test_objmode_custom_pipeline.<locals>.foo:   s,    6"SX #H #Hs   &0{   rE      r   )
r8   r.   r   r
   r9   lenassertIsr:   assertIsInstancer   )r   r5   argfirstseconds        r"   test_objmode_custom_pipelinez/TestCustomPipeline.test_objmode_custom_pipeline7   s    T00FFK	D//	0	 
1	
 S37+T00FFGK##99!<eS[[)$$::1=fj1r#   )r)   r*   r+   r-   r<   rA   rO   r,   )r!   s   @r"   r   r      s    -(	,	02r#   r   c                        e Zd ZddZd Zd Zy)TestPassManagerFunctionalityNc                     | j                  du       | j                  du       t        dd       G fdd              G fddt              }|S )z
        Creates a new compiler pipeline with the _InjectDelsPass injected after
        the pass supplied in kwarg 'inject_after'.
        NF)mutates_CFGanalysis_onlyc                   :    e Zd ZdZd eW        z  Z fdZd Zy)LTestPassManagerFunctionality._create_pipeline_w_del.<locals>._InjectDelsPasszD
            This pass injects ir.Del nodes into the IR
            zinject_dels_%sc                 (    j                  |        y r   )__init__)r   bases    r"   rX   zUTestPassManagerFunctionality._create_pipeline_w_del.<locals>._InjectDelsPass.__init__]   s    d#r#   c                 f    t        j                  |j                        }|j                  d       y)NT)	emit_dels)r   PostProcessorr&   run)r   statepps      r"   run_passzUTestPassManagerFunctionality._create_pipeline_w_del.<locals>._InjectDelsPass.run_pass`   s'    ++EMM:&r#   N)r)   r*   r+   __doc__str_namerX   r`   )rY   s   r"   _InjectDelsPassrV   V   s"     %s4y0E$r#   rd   c                       e Zd Z fdZy)ITestPassManagerFunctionality._create_pipeline_w_del.<locals>.TestCompilerc                     t        j                  | j                        }|j                         |j	                          |gS r   )r   define_nopython_pipeliner^   add_pass_afterfinalize)r   pmrd   inject_afters     r"   define_pipelineszZTestPassManagerFunctionality._create_pipeline_w_del.<locals>.TestCompiler.define_pipelinesg   s7    '@@L!!/<@tr#   N)r)   r*   r+   rm   )rd   rl   s   r"   TestCompilerrf   e   s    r#   rn   )
assertTruer   r   )r   rY   rl   rn   rd   s    `` @r"   _create_pipeline_w_delz3TestPassManagerFunctionality._create_pipeline_w_delN   s[    
 	D01D()	5	>	d 	 
?		8 	 r#   c                 F   | j                  t        t              }t        |      d        }| j	                  t
        j                        5 } |d       d d d        t        j                        }| j                  d|       | j                  d|       y # 1 sw Y   CxY w)Nr0   c                     | dz   S NrE   r2   r3   s    r"   r5   zYTestPassManagerFunctionality.test_compiler_error_on_ir_del_from_functionpass.<locals>.foos       q5Lr#   
   zIllegal IR, del found at:zdel x)
rp   r   r   r   assertRaisesr   CompilerErrorrb   	exceptionassertIn)r   new_compilerr5   raiseserrstrs        r"   /test_compiler_error_on_ir_del_from_functionpasszLTestPassManagerFunctionality.test_compiler_error_on_ir_del_from_functionpasso   s    22<3CE 
\	*	 
+	 v334G 5 V%%&16:gv& 54s   	BB c                     | j                  t        t              }t        |      d        }| j	                   |d      |j                  d             y )Nr0   c                     | dz   S rs   r2   r3   s    r"   r5   z]TestPassManagerFunctionality.test_no_compiler_error_on_ir_del_after_legalization.<locals>.foo   rt   r#   ru   )rp   r   r	   r   ro   r:   )r   rz   r5   s      r"   3test_no_compiler_error_on_ir_del_after_legalizationzPTestPassManagerFunctionality.test_no_compiler_error_on_ir_del_after_legalization   sO     22<3AC 
\	*	 
+	 	BR1r#   )NN)r)   r*   r+   rp   r}   r   r2   r#   r"   rQ   rQ   L   s    B' 2r#   rQ   N)numba.core.compilerr   r   numba.core.compiler_machineryr   r   r   numba.core.untyped_passesr   numba.core.typed_passesr	   numbar
   r   r   r   
numba.corer   r   r   numba.core.irr   numba.tests.supportr   r   rQ   r2   r#   r"   <module>r      sE    <: : 6 2 + + . . $ (=2 =2@C28 C2r#   