o
    1&i                     @   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   <C:\wamp64\www\opt\env\Lib\site-packages\numba/core/consts.py__init__   s   
zConstantInference.__init__Nc              
   C   s   || j vr/zd| |f| j |< W n ty. } zd|j|jff| j |< W Y d}~nd}~ww | j | \}}|r:|S |\}}t|trJ||d|i|| )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)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y"   td|f w z| }W |S  tyF   t |tj	r>| 
| Y S | | Y |S w )Nz'infer_constant() called with non-str %rzno single definition for %r)
isinstancestr	TypeErrorr
   Zget_definitionKeyErrorr   r   r   Expr_infer_exprr   )r   r   Z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r*j jj jd}| S  j dkr: fdd jD S  j dkrLt	 fdd	 jD S 
  d S )
Ncallr   getattrZ
build_listc                       g | ]}j |j jd qS r   r   r   r   .0iexprr   r   r   
<listcomp>R       z1ConstantInference._infer_expr.<locals>.<listcomp>Z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,   r1   r3   r   r+   r   r!   I   s   



zConstantInference._infer_exprc                    s    j s jr  |tfv }t|tot|t}|s|r9 fdd jD }|r/|| S |r5||fS J d  d S )Nc                    r%   r&   r'   )r)   ar+   r   r   r-   `   r.   z1ConstantInference._infer_call.<locals>.<listcomp>r   ZUnreachable)	kwsvarargr   slicer   typer   BaseExceptionr   )r   r1   r,   Z_sliceZ_excr   r   r+   r   r2   Y   s   

zConstantInference._infer_callc                 C   s>   t |ttfrzt||jW S  ty   Y nw | | d S r   )r   r   r;   r$   attrAttributeErrorr   )r   r3   r,   r   r   r   r4   o   s   z ConstantInference._infer_getattrr   )__name__
__module____qualname____doc__r   r   r   r   r!   r2   r4   r   r   r   r   r   	   s    
	r   )
typesr   r   Znumba.core.errorsr   r   Z
numba.corer   objectr   r   r   r   r   <module>   s
    