
    ܙdm                         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
e          Z G 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                   6     e Zd Z fdZd Zd Zd Zd Z xZS )TestCustomPipelinec                     t          t          |                                             G fddt                    | _        d S )Nc                   2     e Zd Zg Z fdZ fdZ xZS )0TestCustomPipeline.setUp.<locals>.CustomPipelinec                 ~    | j                             |           t          |                               |          S N)custom_pipeline_cacheappendsupercompile_extra)selffuncCustomPipeline	__class__s     9lib/python3.11/site-packages/numba/tests/test_pipeline.pyr   z>TestCustomPipeline.setUp.<locals>.CustomPipeline.compile_extra   s8    *11$777^T22@@FFF    c                 v    | j                             |            t          |           j        |g|R i |S r   )r   r   r   
compile_ir)r   func_irargskwargsr!   r"   s       r#   r&   z;TestCustomPipeline.setUp.<locals>.CustomPipeline.compile_ir   sX    *11':::=u^T22=.". . .&,. . .r$   )__name__
__module____qualname__r   r   r&   __classcell__)r"   r!   s   @r#   r!   r      sh        $&!G G G G G G
. . . . . . . . . .r$   r!   )r   r   setUpr   pipeline_class)r   r!   r"   s    @r#   r.   zTestCustomPipeline.setUp   se     $''--///	. 	. 	. 	. 	. 	. 	.X 	. 	. 	. -r$   c                    |                      | j        j        g            t          | j                  d             }|                      |d          d           |                      | j        j        |j        g           d S )Nr/   c                     | S r    xs    r#   fooz8TestCustomPipeline.test_jit_custom_pipeline.<locals>.foo$       Hr$      )assertListEqualr/   r   r
   assertEqualpy_funcr   r6   s     r#   test_jit_custom_pipelinez+TestCustomPipeline.test_jit_custom_pipeline!   s    T0FKKK	D/	0	0	0	 	 
1	0	 	Q###T0F!k]	, 	, 	, 	, 	,r$   c                 F   |                      | j        j        g            t          t	          j        t          j                  | j                  d             }|                      |d          d           |                      | j        j        |j        g           d S )Nr1   c                     | S r   r3   r4   s    r#   r6   z:TestCustomPipeline.test_cfunc_custom_pipeline.<locals>.foo/   r7   r$   r8   )r9   r/   r   r   r   int64r:   __wrapped__r<   s     r#   test_cfunc_custom_pipelinez-TestCustomPipeline.test_cfunc_custom_pipeline,   s    T0FKKK	u{5;''8K	L	L	L	 	 
M	L	 	Q###T0F!o.	0 	0 	0 	0 	0r$   c                    |                      | j        j        g            d t          | j                  fd            }|                      |d          d           |                      | j        j        g           d S )Nc                     | S r   r3   r4   s    r#   innerzDTestCustomPipeline.test_generated_jit_custom_pipeline.<locals>.inner:   s    Hr$   r1   c                 @    t          | t          j                  rS d S r   )
isinstancer   Integer)r5   rE   s    r#   r6   zBTestCustomPipeline.test_generated_jit_custom_pipeline.<locals>.foo=   s&    !U]++  r$      )r9   r/   r   r   r:   )r   r6   rE   s     @r#   "test_generated_jit_custom_pipelinez5TestCustomPipeline.test_generated_jit_custom_pipeline7   s    T0FKKK	 	 	 
d&9	:	:	:	 	 	 	 
;	:	 	Q###T0F#W	& 	& 	& 	& 	&r$   c                    |                      | j        j        g            t          | j                  d             }d}|                      ||          |dz              |                     t          | j        j                  d           | j        j        d         }|                     ||j                   | j        j        d         }|                     |t                     d S )Nr1   c                 z    t          d          5  | t          d          z  } d d d            n# 1 swxY w Y   | S )Nintpr4      )r   intr4   s    r#   r6   z<TestCustomPipeline.test_objmode_custom_pipeline.<locals>.fooI   s|    6"""  SXX              Hs   044{   rN      r   )
r9   r/   r   r
   r:   lenassertIsr;   assertIsInstancer   )r   r6   argfirstseconds        r#   test_objmode_custom_pipelinez/TestCustomPipeline.test_objmode_custom_pipelineF   s    T0FKKK	D/	0	0	0	 	 
1	0	
 S37+++T0FGGKKK#9!<eS[)))$:1=fj11111r$   )	r*   r+   r,   r.   r=   rB   rJ   rX   r-   )r"   s   @r#   r   r      st        - - - - -(	, 	, 	,	0 	0 	0& & &2 2 2 2 2 2 2r$   r   c                   "    e Zd ZddZd Zd ZdS )TestPassManagerFunctionalityNc                     |                      du           |                      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           z  Z fdZd ZdS )LTestPassManagerFunctionality._create_pipeline_w_del.<locals>._InjectDelsPasszD
            This pass injects ir.Del nodes into the IR
            zinject_dels_%sc                 2                         |            d S r   )__init__)r   bases    r#   ra   zUTestPassManagerFunctionality._create_pipeline_w_del.<locals>._InjectDelsPass.__init__l   s    d#####r$   c                 d    t          j        |j                  }|                    d           dS )NT)	emit_dels)r   PostProcessorr'   run)r   statepps      r#   run_passzUTestPassManagerFunctionality._create_pipeline_w_del.<locals>._InjectDelsPass.run_passo   s-    +EM::&&&tr$   N)r*   r+   r,   __doc__str_namera   ri   )rb   s   r#   _InjectDelsPassr_   e   s[          %ss4yy0E$ $ $ $ $    r$   rm   c                       e Zd Z fdZdS )ITestPassManagerFunctionality._create_pipeline_w_del.<locals>.TestCompilerc                     t          j        | j                  }|                               |                                 |gS r   )r   define_nopython_pipelinerg   add_pass_afterfinalize)r   pmrm   inject_afters     r#   define_pipelineszZTestPassManagerFunctionality._create_pipeline_w_del.<locals>.TestCompiler.define_pipelinesv   s?    '@LL!!/<@@@tr$   N)r*   r+   r,   rv   )rm   ru   s   r#   TestCompilerro   t   s3               r$   rw   )
assertTruer   r   )r   rb   ru   rw   rm   s    `` @r#   _create_pipeline_w_delz3TestPassManagerFunctionality._create_pipeline_w_del]   s    
 	D0111D()))	5	>	>	>	 	 	 	 	 	 	d 	 	 
?	>		 	 	 	 	 	 	 	8 	 	 	 r$   c                 |   |                      t          t                    }t          |          d             }|                     t
          j                  5 } |d           d d d            n# 1 swxY w Y   t          |j                  }| 	                    d|           | 	                    d|           d S )Nr1   c                     | dz   S NrN   r3   r4   s    r#   r6   zYTestPassManagerFunctionality.test_compiler_error_on_ir_del_from_functionpass.<locals>.foo       q5Lr$   
   zIllegal IR, del found at:zdel x)
ry   r   r   r   assertRaisesr   CompilerErrorrk   	exceptionassertIn)r   new_compilerr6   raiseserrstrs        r#   /test_compiler_error_on_ir_del_from_functionpasszLTestPassManagerFunctionality.test_compiler_error_on_ir_del_from_functionpass~   s    22<3CE E 
\	*	*	*	 	 
+	*	 v344 	CGGG	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 V%&&16:::gv&&&&&s   A11A58A5c                     |                      t          t                    }t          |          d             }|                      |d          |                    d                     d S )Nr1   c                     | dz   S r|   r3   r4   s    r#   r6   z]TestPassManagerFunctionality.test_no_compiler_error_on_ir_del_after_legalization.<locals>.foo   r}   r$   r~   )ry   r   r	   r   rx   r;   )r   r   r6   s      r#   3test_no_compiler_error_on_ir_del_after_legalizationzPTestPassManagerFunctionality.test_no_compiler_error_on_ir_del_after_legalization   su     22<3AC C 
\	*	*	*	 	 
+	*	 	BR11111r$   )NN)r*   r+   r,   ry   r   r   r3   r$   r#   rZ   rZ   [   sG           B' ' ' 2 2 2 2 2r$   rZ   N)numba.core.compilerr   r   numba.core.compiler_machineryr   r   r   numba.core.untyped_passesr   numba.core.typed_passesr	   numbar
   r   r   r   r   
numba.corer   r   r   numba.core.irr   numba.tests.supportr   r   rZ   r3   r$   r#   <module>r      sP   < < < < < < < <: : : : : : : : : : 6 6 6 6 6 6 2 2 2 2 2 2 : : : : : : : : : : : : : : . . . . . . . . . . $ $ $ $ $ $ ( ( ( ( ( (L2 L2 L2 L2 L2 L2 L2 L2^C2 C2 C2 C2 C28 C2 C2 C2 C2 C2r$   