U
    ð¾|e•  ã                   @   sD   d dl mZ d dlZd dlmZmZ d dlmZ G dd„ deƒZ	dS )é    )Ú
ModuleTypeN)ÚConstantInferenceErrorÚ
NumbaError)Úirc                   @   sJ   e Zd ZdZdd„ Zddd„Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dS )ÚConstantInferencezì
    A constant inference engine for a given interpreter.
    Inference inspects the IR to try and compute a compile-time constant for
    a variable.

    This shouldn't be used directly, instead call Interpreter.infer_constant().
    c                 C   s   t  |¡| _i | _d S ©N)ÚweakrefÚproxyÚ_func_irÚ_cache)ÚselfZfunc_ir© r   úN/var/www/website-v5/atlas_env/lib/python3.8/site-packages/numba/core/consts.pyÚ__init__   s    zConstantInference.__init__Nc              
   C   s    || j kr\zd|  |¡f| j |< W n8 tk
rZ } zd|j|jff| j |< W 5 d}~X Y nX | j | \}}|rr|S |\}}t|tƒr”||d|iŽ‚n||Ž ‚dS )z£
        Infer a constant value for the given variable *name*.
        If no value can be inferred, numba.errors.ConstantInferenceError
        is raised.
        TFNÚloc)r   Ú	_do_inferr   Ú	__class__ÚargsÚ
issubclassr   )r   Únamer   ÚexcÚsuccessÚvalr   r   r   r   Úinfer_constant   s    
(
z ConstantInference.infer_constantc                 C   s   t d|f d d�‚d S )Nz'Constant inference not possible for: %s©r   )r   )r   r   r   r   r   Ú_fail/   s     ÿzConstantInference._failc                 C   s–   t |tƒstd|f ƒ‚z| j |¡}W n" tk
rJ   td|f ƒ‚Y nX z| ¡ }W n8 tk
r�   t |tj	ƒr‚|  
|¡ Y S |  |¡ Y nX |S )Nz'infer_constant() called with non-str %rzno single definition for %r)Ú
isinstanceÚstrÚ	TypeErrorr
   Úget_definitionÚKeyErrorr   r   r   ÚExprÚ_infer_exprr   )r   r   ÚdefnÚconstr   r   r   r   8   s"    
ÿÿ
zConstantInference._do_inferc                    s¦   ˆ j dkr*ˆjˆ jjˆ jd�}ˆ |ˆ ¡S ˆ j dkrTˆjˆ jjˆ jd�}ˆ |ˆ ¡S ˆ j dkrt‡ ‡fdd„ˆ jD ƒS ˆ j dkr˜t	‡ ‡fdd	„ˆ jD ƒƒS ˆ 
ˆ ¡ d S )
NÚcallr   ÚgetattrÚ
build_listc                    s   g | ]}ˆj |jˆ jd �‘qS ©r   ©r   r   r   ©Ú.0Úi©Úexprr   r   r   Ú
<listcomp>R   s     z1ConstantInference._infer_expr.<locals>.<listcomp>Úbuild_tuplec                 3   s    | ]}ˆj |jˆ jd �V  qdS )r   Nr)   r*   r-   r   r   Ú	<genexpr>U   s     z0ConstantInference._infer_expr.<locals>.<genexpr>)Úopr   Úfuncr   r   Ú_infer_callÚvalueÚ_infer_getattrÚitemsÚtupler   )r   r.   r3   r5   r   r-   r   r"   I   s    


ÿ
ÿzConstantInference._infer_exprc                    s„   ˆ j sˆ jrˆ ˆ ¡ |tfk}t|tƒo2t|tƒ}|s<|rv‡ ‡fdd„ˆ jD ƒ}|r^||Ž S |rj||fS dsvt	dƒ‚ˆ ˆ ¡ d S )Nc                    s   g | ]}ˆj |jˆ jd �‘qS r(   r)   )r+   Úar-   r   r   r/   `   s     z1ConstantInference._infer_call.<locals>.<listcomp>r   ZUnreachable)
ÚkwsÚvarargr   Úslicer   Útyper   ÚBaseExceptionr   ÚAssertionError)r   r3   r.   Z_sliceZ_excr   r   r-   r   r4   Y   s    

ÿzConstantInference._infer_callc                 C   s@   t |ttfƒr2zt||jƒW S  tk
r0   Y nX |  |¡ d S r   )r   r   r=   r&   ÚattrÚAttributeErrorr   )r   r5   r.   r   r   r   r6   o   s    z ConstantInference._infer_getattr)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r"   r4   r6   r   r   r   r   r   	   s   
	r   )
Útypesr   r   Únumba.core.errorsr   r   Ú
numba.corer   Úobjectr   r   r   r   r   Ú<module>   s   