o
    i-v                     @   s  d Z ddlZddl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 ddlmZmZmZ e																																															ddd	ZG d
d deeZG dd deeZG dd deeZedkre  dS dS )z0
Test bytecode fixes provided in interpreter.py
    N)jitnjitobjmodetypeof	literally)overload)types)UnsupportedError)TestCaseMemoryLeakMixinskip_unless_py10_or_laterc/           /      C   s   | | | | | | | | | |	 |
 | | | | | | | | | | | | | | | | | | | | | |  |! |" |# |$ |% |& |' |( |) |* |+ |, |- |. S N )/arg0arg1arg2arg3arg4arg5arg6arg7arg8arg9arg10arg11arg12arg13arg14arg15Zarg16Zarg17Zarg18Zarg19Zarg20Zarg21Zarg22Zarg23Zarg24Zarg25Zarg26Zarg27Zarg28Zarg29Zarg30Zarg31Zarg32Zarg33Zarg34Zarg35Zarg36Zarg37Zarg38Zarg39Zarg40arg41Zarg42Zarg43Zarg44Zarg45Zarg46r   r   k/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/numba/tests/test_interpreter.pysum_jit_func   s   3	
 !"#$%&'()*+,-.r!   c                   @   s   e Zd ZdZdZdZdd Zedd Zedd	 Z	ed
d Z
edd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zd S )!TestCallFunctionExPeepHolea  
    gh #7812

    Tests that check a peephole optimization for Function calls
    in Python 3.10. The bytecode changes when
    (n_args / 2) + n_kws > 15, which moves the arguments from
    the stack into a tuple and dictionary.

    This peephole optimization updates the IR to use the original format.
    There are different paths when n_args > 30 and n_args <= 30 and when
    n_kws > 15 and n_kws <= 15.
          c           
      C   s   dd t || D }g }t || D ]}|d dkr"d| d}nd| }|| qd|}d	| d
}|d7 }t |D ]}|d||  d7 }q@t ||| D ]}|d||  d||  d7 }qT|d7 }i }	t|dti|	 |	d S )zw
            Generates a function that calls sum_jit_func
            with the desired number of args and kws.
        c                 S   s   g | ]}d | qS )argr   .0ir   r   r    
<listcomp>   s    z7TestCallFunctionExPeepHole.gen_func.<locals>.<listcomp>   r   zpow(argz, 2)r%   z, z	def impl(z):
z    return sum_jit_func(
z        z,
=z    )
r!   impl)rangeappendjoinexecr!   )
selfZn_argsZn_kwsZ
param_listZ	args_listr(   arg_valZtotal_paramsZ	func_text
local_varsr   r   r    gen_func   s$   

 z#TestCallFunctionExPeepHole.gen_funcc                 C   sP   dd t | jD }| | jd}|}t |}|| }|| }| || dS )z
        Tests calling a function when n_args > 30 and
        n_kws = 0. This shouldn't use the peephole, but
        it should still succeed.
        c                 S      g | ]}|qS r   r   r&   r   r   r    r)          z<TestCallFunctionExPeepHole.test_all_args.<locals>.<listcomp>r   N)r-   THRESHOLD_ARGSr4   r   assertEqualr1   
total_argsfpy_funccfuncabr   r   r    test_all_args   s   
z(TestCallFunctionExPeepHole.test_all_argsc                 C   sP   dd t | jD }| d| j}|}t |}|| }|| }| || dS )zR
        Tests calling a function when n_kws > 15 and
        n_args = 0.
        c                 S   r5   r   r   r&   r   r   r    r)      r6   z;TestCallFunctionExPeepHole.test_all_kws.<locals>.<listcomp>r   N)r-   THRESHOLD_KWSr4   r   r8   r9   r   r   r    test_all_kws   s   
z'TestCallFunctionExPeepHole.test_all_kwsc           	      C   sd   | j d }| jd }dd t|| D }| ||}|}t |}|| }|| }| || dS )zs
        Tests calling a function when (n_args / 2) + n_kws > 15,
        but n_args <= 30 and n_kws <= 15
           c                 S   r5   r   r   r&   r   r   r    r)      r6   zHTestCallFunctionExPeepHole.test_small_args_small_kws.<locals>.<listcomp>Nr7   rA   r-   r4   r   r8   	r1   	used_argsZused_kwsr:   r;   r<   r=   r>   r?   r   r   r    test_small_args_small_kws   s   


z4TestCallFunctionExPeepHole.test_small_args_small_kwsc           	      C   s`   | j d }| j}dd t|| D }| ||}|}t |}|| }|| }| || dS )zr
        Tests calling a function when (n_args / 2) + n_kws > 15,
        but n_args <= 30 and n_kws > 15
        rC   c                 S   r5   r   r   r&   r   r   r    r)      r6   zHTestCallFunctionExPeepHole.test_small_args_large_kws.<locals>.<listcomp>NrD   rE   r   r   r    test_small_args_large_kws   s   

z4TestCallFunctionExPeepHole.test_small_args_large_kwsc           	      C   s`   | j }| jd }dd t|| D }| ||}|}t |}|| }|| }| || dS )zr
        Tests calling a function when (n_args / 2) + n_kws > 15,
        but n_args > 30 and n_kws <= 15
        rC   c                 S   r5   r   r   r&   r   r   r    r)      r6   zHTestCallFunctionExPeepHole.test_large_args_small_kws.<locals>.<listcomp>NrD   rE   r   r   r    test_large_args_small_kws   s   

z4TestCallFunctionExPeepHole.test_large_args_small_kwsc           	      C   s\   | j }| j}dd t|| D }| ||}|}t |}|| }|| }| || dS )zq
        Tests calling a function when (n_args / 2) + n_kws > 15,
        but n_args > 30 and n_kws > 15
        c                 S   r5   r   r   r&   r   r   r    r)      r6   zHTestCallFunctionExPeepHole.test_large_args_large_kws.<locals>.<listcomp>NrD   rE   r   r   r    test_large_args_large_kws   s   
z4TestCallFunctionExPeepHole.test_large_args_large_kwsc                    s<   dd  t  fdd}tt  }| }| || dS )zO
        Tests calling an objectmode function with > 15 return values.
        c                   S   s   dS )N)r   rC            r*            	   
                  r   r   r   r   r    r<        zBTestCallFunctionExPeepHole.test_large_kws_objmode.<locals>.py_funcc                     s   t di ddddddddddddddd	dd
ddddddddddddddd   \} }}}}}}}}}	}
}}}}}W d   n1 sSw   Y  | | | | | | | | | |	 |
 | | | | | S )z
            Wrapper to call py_func from objmode. This tests
            large kws with objmode. If the definition for the
            call is not properly updated this test will fail.
            r>   Zint64r?   cder;   ghr(   jklmnopNr   )r   )r>   r?   rY   rZ   r[   r;   r\   r]   r(   r^   r_   r`   ra   rb   rc   rd   r<   r   r    objmode_func  s   	
#%	
zGTestCallFunctionExPeepHole.test_large_kws_objmode.<locals>.objmode_funcN)r   sumlistr8   )r1   rf   r>   r?   r   re   r    test_large_kws_objmode   s   =z1TestCallFunctionExPeepHole.test_large_kws_objmodec                 C   V   dd }|  t}t |d W d   n1 sw   Y  | dt|j dS )ze
        Tests generating large args when one of the inputs
        has inlined controlflow.
        c                 S   s   t g ddddddddddddddddddddd| r0dndddddddddddddddR ddiS NrC   rK   r   r!   flagr   r   r    inline_func^  s   	

 !"#$%zRTestCallFunctionExPeepHole.test_large_args_inline_controlflow.<locals>.inline_funcFN9You can resolve this issue by moving the control flow outassertRaisesr	   r   ZassertInstr	exceptionr1   ro   Zraisesr   r   r    "test_large_args_inline_controlflowX  s   )z=TestCallFunctionExPeepHole.test_large_args_inline_controlflowc                 C   6   dd }|}t  |}|d}|d}| || dS )
        Tests generating large args when one of the inputs
        has the change suggested in the error message
        for inlined control flow.
        c                 S   s   | rdnd}t g ddddddddddddddddddddd|ddddddddddddddR ddiS rk   rl   rn   Za_valr   r   r    ro     s   	
 !"#$%zVTestCallFunctionExPeepHole.test_large_args_noninlined_controlflow.<locals>.inline_funcFNr   r8   r1   ro   r<   r=   r>   r?   r   r   r    &test_large_args_noninlined_controlflow  s   *
zATestCallFunctionExPeepHole.test_large_args_noninlined_controlflowc                 C   rj   )z
        Tests generating only large args when one of the inputs
        has inlined controlflow. This requires a special check
        inside peep_hole_call_function_ex_to_call_function_kw
        because it usually only handles varkwargs.
        c                 S   s   t g ddddddddddddddddddddd| r0dndddddddddddddddR  S NrC   rK   rl   rm   r   r   r    ro     s   	

 !"#$zPTestCallFunctionExPeepHole.test_all_args_inline_controlflow.<locals>.inline_funcFNrp   rq   ru   r   r   r     test_all_args_inline_controlflow  s   (z;TestCallFunctionExPeepHole.test_all_args_inline_controlflowc                 C   rw   )rx   c                 S   s   | rdnd}t g ddddddddddddddddddddd|ddddddddddddddR  S r}   rl   ry   r   r   r    ro     s   	
 !"#$zTTestCallFunctionExPeepHole.test_all_args_noninlined_controlflow.<locals>.inline_funcFNrz   r{   r   r   r    $test_all_args_noninlined_controlflow  s   )
z?TestCallFunctionExPeepHole.test_all_args_noninlined_controlflowc                 C   rj   )zd
        Tests generating large kws when one of the inputs
        has inlined controlflow.
        c                 S   sv   t di ddddddddddddddd	dd
dddddddddddddd| r7dS dS )Nr   rC   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rK   r   rl   rm   r   r   r    ro   8  sF   	
zQTestCallFunctionExPeepHole.test_large_kws_inline_controlflow.<locals>.inline_funcFNrp   rq   ru   r   r   r    !test_large_kws_inline_controlflow2  s   z<TestCallFunctionExPeepHole.test_large_kws_inline_controlflowc                 C   rw   )z
        Tests generating large kws when one of the inputs
        has the change suggested in the error message
        for inlined control flow.
        c                 S   sv   | rdnd}t di ddddddddddddd	dd
dddddddddddddddd|S )NrC   rK   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rl   ry   r   r   r    ro   Z  sD   	
zUTestCallFunctionExPeepHole.test_large_kws_noninlined_controlflow.<locals>.inline_funcFNrz   r{   r   r   r    %test_large_kws_noninlined_controlflowS  s   
z@TestCallFunctionExPeepHole.test_large_kws_noninlined_controlflowN)__name__
__module____qualname____doc__r7   rA   r4   r   r@   rB   rG   rH   rI   rJ   ri   rv   r|   r~   r   r   r   r   r   r   r    r"   u   s>    






Z
5
6
6
5
 r"   c                   @   sp   e Zd ZdZedd Zedd Zedd Zedd	 Zed
d Z	edd Z
edd Zedd ZdS )TestLargeConstDicta  
    gh #7894

    Tests that check a peephole optimization for constant
    dictionaries in Python 3.10. The bytecode changes when
    number of elements > 15, which splits the constant dictionary
    into multiple dictionaries that are joined by a DICT_UPDATE
    bytecode instruction.

    This optimization modifies the IR to rejoin dictionaries
    and remove the DICT_UPDATE generated code. This then allows
    code that depends on literal dictionaries or literal keys
    to succeed.
    c                 C   s2   dd }|}t  |}| }| }| || dS )r
        Tests that a function with a large heterogeneous constant
        dictionary remains a constant.
        c                  S   s|   i ddddddddddddddd	dd
dddddddddddddddddddd} | d S )NArC   BCDEFGHIJKLMNOPQr>   RSr   r   rZ   r   r   r    
const_func  N   	
zJTestLargeConstDict.test_large_heterogeneous_const_dict.<locals>.const_funcNrz   )r1   r   r<   r=   r>   r?   r   r   r    #test_large_heterogeneous_const_dict  s   
z6TestLargeConstDict.test_large_heterogeneous_const_dictc                    6   dd  t  fdd}t fdd}|  dS )zvCheck the literal values for a LiteralStrKeyDict requiring
        optimizations because it is heterogeneous.
        c                 S      d S r   r   r   r   r   r    bar  rX   zYTestLargeConstDict.test_large_heterogeneous_LiteralStrKeyDict_literal_values.<locals>.barc                    s   i ddddddddddddddd	dd
dddddddddddddddddddd}dd   fdd|  D }t| tj | j| t| dd dd S )Nr   rC   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r>   r   c                 S   s   t | r
t | S t| S r   )r   Zmaybe_literalliteralr   )zr   r   r    specific_ty  s   zqTestLargeConstDict.test_large_heterogeneous_LiteralStrKeyDict_literal_values.<locals>.ol_bar.<locals>.specific_tyc                    s    i | ]\}}t | |qS r   )r   r   )r'   xyr   r   r    
<dictcomp>  s     zpTestLargeConstDict.test_large_heterogeneous_LiteralStrKeyDict_literal_values.<locals>.ol_bar.<locals>.<dictcomp>initial_valueFc                 S      | S r   r   r   r   r   r    <lambda>      znTestLargeConstDict.test_large_heterogeneous_LiteralStrKeyDict_literal_values.<locals>.ol_bar.<locals>.<lambda>)items
assertTrue
isinstancer   ZLiteralStrKeyDictr8   Zliteral_valuehasattr)rZ   r>   expectedr1   r   r    ol_bar  sX   	
z\TestLargeConstDict.test_large_heterogeneous_LiteralStrKeyDict_literal_values.<locals>.ol_barc                     s   i ddddddddddddddd	dd
dddddddddddddddddddd}  |  d S )Nr   rC   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r>   r   r   r   r   r   r    foo  sN   	
zYTestLargeConstDict.test_large_heterogeneous_LiteralStrKeyDict_literal_values.<locals>.fooNr   r   r1   r   r   r   r   r1   r    9test_large_heterogeneous_LiteralStrKeyDict_literal_values  s   
zLTestLargeConstDict.test_large_heterogeneous_LiteralStrKeyDict_literal_valuesc                 C   s:   dd }|}t  |}d}||}||}| || dS )r   c                 S   s|   i ddddddddddddddd	dd
dddddddddddddddddd| d}|d S )Nr   rC   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r>   rZ   r   r   r    const_keys_func  r   zTTestLargeConstDict.test_large_heterogeneous_const_keys_dict.<locals>.const_keys_funca_stringNrz   )r1   r   r<   r=   valuer>   r?   r   r   r    (test_large_heterogeneous_const_keys_dict  s   
z;TestLargeConstDict.test_large_heterogeneous_const_keys_dictc                    r   )zChecks that the optimization for large dictionaries
        do not incorrectly update initial values due to other
        mutations.
        c                 S   r   r   r   r   r   r   r    r   #  rX   zDTestLargeConstDict.test_large_dict_mutation_not_carried.<locals>.barc                    s   i ddddddddddddddd	dd
dddddddddddddddddddd}| j d u rCdd S  t| tj  | j | dd S )Nr   rC   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rO   r   c                 S      t | S r   r   r   r   r   r    r   >      zYTestLargeConstDict.test_large_dict_mutation_not_carried.<locals>.ol_bar.<locals>.<lambda>c                 S   r   r   r   r   r   r   r    r   A  r   r   r   r   r   DictTyper8   rZ   r>   r   r   r    r   &  sV   	

zGTestLargeConstDict.test_large_dict_mutation_not_carried.<locals>.ol_barc                     s   i ddddddddddddddd	dd
dddddddddddddddddddd} d| d<  |  d S )Nr   rC   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rO   r   rM   Xr   r   r   r   r    r   C  sP   	
zDTestLargeConstDict.test_large_dict_mutation_not_carried.<locals>.fooNr   r   r   r   r    $test_large_dict_mutation_not_carried  s   
z7TestLargeConstDict.test_large_dict_mutation_not_carriedc                    s   dd dd  ddt ddfdd	}t  ddfd
d} fdd}|}t |}| }| }|| dS )zf
        Tests an example using a regular update is
        not modified by the optimization.
        c                 S   r   r   r   r   r   r   r    check_beforeh  rX   zDTestLargeConstDict.test_usercode_update_use_d2.<locals>.check_beforec                 S   r   r   r   r   r   r   r    check_afterk  rX   zCTestLargeConstDict.test_usercode_update_use_d2.<locals>.check_afterFT)Zprefer_literalc                    s<    sd dddd} t| tj | j| dd S )NTrC   rK   rL   r>   r?   rY   c                 S   r   r   r   r   r   r   r    r     r   zYTestLargeConstDict.test_usercode_update_use_d2.<locals>.ol_check_before.<locals>.<lambda>)r   r   r   r   r8   r   r   )checked_beforer1   r   r    ol_check_beforeq  s   zGTestLargeConstDict.test_usercode_update_use_d2.<locals>.ol_check_beforec                    s2    sd  t| tj  | jd u  dd S )NTc                 S   r   r   r   r   r   r   r    r     r   zXTestLargeConstDict.test_usercode_update_use_d2.<locals>.ol_check_after.<locals>.<lambda>)r   r   r   r   r   r   )checked_afterr1   r   r    ol_check_after  s
   zFTestLargeConstDict.test_usercode_update_use_d2.<locals>.ol_check_afterc                     sD   dddd} ddd}|  |  |  |  t| dkr |S | S )z
            Dictionary update between two constant
            dictionaries. This verifies d2 doesn't
            get incorrectly removed.
            rC   rK   rL   r   rM   )rZ   r[   )updatelen)Zd1Zd2)r   r   r   r    const_dict_func  s   
zGTestLargeConstDict.test_usercode_update_use_d2.<locals>.const_dict_funcN)r   r   r8   )r1   r   r   r   r<   r=   r>   r?   r   )r   r   r   r   r1   r    test_usercode_update_use_d2a  s   


z.TestLargeConstDict.test_usercode_update_use_d2c                 C   sX   dd }|  t}t |dd W d   n1 sw   Y  | dt|j dS )z
        Tests generating a large dictionary when one of
        the inputs requires inline control flow
        has the change suggested in the error message
        for inlined control flow.
        c                 S   s   i ddddddddddddddd	|rdnd
ddddddddddddddddddd| d}|d S )Nr   rC   r   r   r   r   r   r   r   rK   r   r   r   r   r   r   r   r   r   r   r   r   )r>   rn   rZ   r   r   r    ro     sN   	
zPTestLargeConstDict.test_large_const_dict_inline_controlflow.<locals>.inline_funcr   FNrp   rq   ru   r   r   r    (test_large_const_dict_inline_controlflow  s   z;TestLargeConstDict.test_large_const_dict_inline_controlflowc                 C   s>   dd }|}t  |}d}||d}||d}| || dS )z
        Tests generating large constant dict when one of the
        inputs has the change suggested in the error message
        for inlined control flow.
        c                 S   s   |rdnd}i ddddddddddddd	dd
|ddddddddddddddddddd| d}|d S )NrC   rK   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r>   rn   valrZ   r   r   r    non_inline_func  sP   	
zWTestLargeConstDict.test_large_const_dict_noninline_controlflow.<locals>.non_inline_funcr   FNrz   )r1   r   r<   r=   r   r>   r?   r   r   r    +test_large_const_dict_noninline_controlflow  s   


z>TestLargeConstDict.test_large_const_dict_noninline_controlflowc                    r   )z
        Tests that the correct literal values are generated
        for a dictionary that produces two DICT_UPDATE
        bytecode entries for the same dictionary.
        c                 S   r   r   r   r   r   r   r    r     rX   z>TestLargeConstDict.test_fuse_twice_literal_values.<locals>.barc                    s  i ddddddddd	d
dddddddddddddddddddddd d!d"i d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFi}| j d u rwdGdH S  t| tj  | j | dIdH S )JNa1rC   a2rK   a3rL   a4rM   a5r*   a6rN   a7rO   a8rP   a9rQ   a10rR   a11rS   a12rT   a13rU   a14rV   a15rW   a16r$   a17   a18   a19   a20   a21   a22   a23   a24   a25   a26   a27   a28   a29   a30   a31r#   a32    a33!   a34"   a35#   c                 S   r   r   r   r   r   r   r    r   4  r   zSTestLargeConstDict.test_fuse_twice_literal_values.<locals>.ol_bar.<locals>.<lambda>c                 S   r   r   r   r   r   r   r    r   7  r   r   r   r   r   r    r     s   	
 !"$
&zATestLargeConstDict.test_fuse_twice_literal_values.<locals>.ol_barc                     s   i ddddddddd	d
dddddddddddddddddddddd d!d"i d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFi}  |  d S )GNr   rC   r   rK   r   rL   r   rM   r   r*   r   rN   r   rO   r   rP   r   rQ   r   rR   r   rS   r   rT   r   rU   r   rV   r   rW   r   r$   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r#   r  r  r  r  r  r	  r
  r  r   r   r   r   r    r   9  s   	
 !"$&z>TestLargeConstDict.test_fuse_twice_literal_values.<locals>.fooNr   r   r   r   r    test_fuse_twice_literal_values  s   -
+z1TestLargeConstDict.test_fuse_twice_literal_valuesN)r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r   r    r   v  s$    
&
F
(
C
K
)
)r   c                   @   s   e Zd ZdZdd ZdS )'TestListExtendInStarArgNonTupleIterablea^  Test `fn(pos_arg0, pos_arg1, *args)` where args is a non-tuple iterable.

    Python 3.9+ will generate LIST_EXTEND bytecode to combine the positional
    arguments with the `*args`.

    See #8059

    NOTE: At the moment, there are no meaningful tests for NoPython because the
    lack of support for `tuple(iterable)` for most iterable types.
    c                    sL   dd  t dd fdd}|d}|d}| |d | || d S )	Nc                  W   r   r   r   r   r   r   r    consumert  rX   zSTestListExtendInStarArgNonTupleIterable.test_list_extend_forceobj.<locals>.consumerT)Zforceobjc                    s    ddg| R  S r}   r   r   r  r   r    r   w  s   zNTestListExtendInStarArgNonTupleIterable.test_list_extend_forceobj.<locals>.fooZijo)rC   rK   r(   r^   rc   )r   r<   r8   )r1   r   gotexpectr   r  r    test_list_extend_forceobjs  s   
zATestListExtendInStarArgNonTupleIterable.test_list_extend_forceobjN)r   r   r   r   r  r   r   r   r    r  h  s    
r  __main__)/r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   ZunittestZnumbar   r   r   r   r   Znumba.extendingr   Z
numba.corer   Znumba.core.errorsr	   Znumba.tests.supportr
   r   r   r!   r"   r   r  r   mainr   r   r   r    <module>   s    d       u