
    xKg                     J    d dl mZ d dlZd dlmZmZ d dlmZ  G d de      Z	y)    )
ModuleTypeN)ConstantInferenceError
NumbaError)irc                   <    e Zd ZdZd Zd
dZd Zd Zd Zd Z	d	 Z
y)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                 F    t        j                  |      | _        i | _        y N)weakrefproxy_func_ir_cache)selffunc_irs     U/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/numba/core/consts.py__init__zConstantInference.__init__   s      g.    Nc                 J   || j                   vr!	 d| j                  |      f| j                   |<   | j                   |   \  }}|r|S |\  }}t        |t              r ||d|i || # t        $ r1}d|j                  |j                  ff| j                   |<   Y d}~md}~ww xY w)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   s          r   infer_constantz ConstantInference.infer_constant   s     t{{"G%)4>>$+?$@D!
 {{4(JIC#z*4)S))4j  * G &+S]]CHH,E$FD!Gs    A( (	B"1'BB"c                 "    t        d|d       )Nz%Constant inference not possible for: r   )r   )r   r   s     r   _failzConstantInference._fail/   s     %9<>DJ 	Jr   c                 n   t        |t              st        d|      	 | j                  j	                  |      }	 |j                         }|S # t
        $ r t        d|      w xY w# t        $ rB t        |t        j                        r| j                  |      cY S | j                  |       Y S w xY w)Nz%infer_constant() called with non-str zno single definition for )
isinstancestr	TypeErrorr   get_definitionKeyErrorr   r   r   Expr_infer_exprr!   )r   r   defnconsts       r   r   zConstantInference._do_infer8   s    $$#& ' '	9==//5D	'')E
   	9(1579 9	9
 & 	$(''--JJt		s"   A A) A&)4B4B43B4c                 t    j                   dk(  rC j                  j                  j                  j                        } j                  |      S j                   dk(  rC j                  j                  j                  j                        } j                  |      S j                   dk(  r?j                  D cg c])  } j                  |j                  j                        + c}S j                   dk(  rt         fdj                  D              S  j                         y c c}w )Ncallr    getattr
build_listbuild_tuplec              3   l   K   | ]+  }j                  |j                  j                          - yw)r    N)r   r   r   ).0iexprr   s     r   	<genexpr>z0ConstantInference._infer_expr.<locals>.<genexpr>U   s3      %# HI,,QVV,B#s   14)opr   funcr   r   _infer_callvalue_infer_getattritemstupler!   )r   r4   r7   r9   r3   s   ``   r   r)   zConstantInference._infer_exprI   s   77f&&tyy~~488&DD##D$//WW	!''

TXX'FE&&ud33WW$JJ  CDD''DHH'=   WW% %% % %

4 s   .D5c                    |j                   s|j                  r| j                  |       |t        fv }t	        |t
              xr t        |t              }|s|rR|j                  D cg c])  }| j                  |j                  |j                        + }}|r || S |r||fS J d       | j                  |       y c c}w )Nr    Unreachable)kwsvarargr!   slicer#   typer   BaseExceptionr   r   r   r   )r   r7   r4   _slice_excar   s          r   r8   zConstantInference._infer_callY   s    88t{{JJt%!$%I*T=*ITII CDD''DHH'=  T{"
 Tz!'-'q

4s   '.B=c                     t        |t        t        f      r	 t        ||j                        S | j                  |       y # t
        $ r Y w xY wr
   )r#   r   rB   r.   attrAttributeErrorr!   )r   r9   r4   s      r   r:   z ConstantInference._infer_getattro   sI    ej$/0udii00 	

4 " s   A   	AAr
   )__name__
__module____qualname____doc__r   r   r!   r   r)   r8   r:    r   r   r   r   	   s+    !.J" ,r   r   )
typesr   r   numba.core.errorsr   r   
numba.corer   objectr   rN   r   r   <module>rS      s      @ m mr   