o
    2g!                     @  s  d Z ddlmZ ddlmZmZmZmZmZm	Z	m
Z
mZ ddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ ddlmZ ddl m!Z!m"Z"m#Z# ddl$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8 G dd	 d	Z9d
S )z>Maintain a mapping from mypy concepts to IR/compiled concepts.    )annotations)ARG_STAR	ARG_STAR2GDEFArgKindFuncDefRefExpr
SymbolNodeTypeInfo)AnyTypeCallableTypeInstanceLiteralTypeNoneTyp
OverloadedPartialType	TupleTypeTypeTypedDictTypeTypeTypeTypeVarLikeTypeUnboundTypeUninhabitedType	UnionTypefind_unpack_in_listget_proper_type)ClassIR)FuncDeclFuncSignature
RuntimeArg)	RInstanceRTupleRTypeRUnionbool_rprimitivebytes_rprimitivedict_rprimitivefloat_rprimitiveint16_rprimitiveint32_rprimitiveint64_rprimitiveint_rprimitivelist_rprimitivenone_rprimitiveobject_rprimitiverange_rprimitiveset_rprimitivestr_rprimitivetuple_rprimitiveuint8_rprimitivec                   @  sV   e Zd ZdZd#ddZd$ddZd%ddZd&ddZd'ddZd(ddZ	d(d d!Z
d"S ))Mappera  Keep track of mappings from mypy concepts to IR concepts.

    For example, we keep track of how the mypy TypeInfos of compiled
    classes map to class IR objects.

    This state is shared across all modules being compiled in all
    compilation groups.
    	group_mapdict[str, str | None]returnNonec                 C  s   || _ i | _i | _d S N)r5   
type_to_irfunc_to_decl)selfr5    r=   L/home/garg/my-data/venv/lib/python3.10/site-packages/mypyc/irbuild/mapper.py__init__=   s   
zMapper.__init__typType | Noner"   c                   s|  |d u rt S t|}t|tr|jjdkrtS |jjdkrtS |jjdkr'tS |jjdkr/t	S |jjdkr7t
S |jjdkr?tS tdd |jjD rLtS |jjd	krTtS |jjd
kr\tS |jjdkrdtS |j jv r~t j|j }|jjr|t|t gS |S |jjdkrtS |jjdkrtS |jjdkrtS |jjdkrtS t S t|tr|jjjd
krt|jd u rt fdd|jD S tS t|trt S t|t rt!S t|t"rt# fdd|jD S t|t$rt S t|t%rt S t|t&r '|j(S t|t)r|j*jd us	J  '|j*jS t|t+rt S t|t,r tS t|t-r, '|j.S t|t/t0fr6t S J dt| )Nzbuiltins.intzbuiltins.floatzbuiltins.boolzbuiltins.strzbuiltins.byteszbuiltins.listc                 s  s    | ]}|j d kV  qdS )zbuiltins.dictN)fullname).0clsr=   r=   r>   	<genexpr>W   s    z'Mapper.type_to_rtype.<locals>.<genexpr>zbuiltins.setzbuiltins.tuplezbuiltins.rangezmypy_extensions.i64zmypy_extensions.i32zmypy_extensions.i16zmypy_extensions.u8c                      g | ]}  |qS r=   type_to_rtype)rC   tr<   r=   r>   
<listcomp>y       z(Mapper.type_to_rtype.<locals>.<listcomp>c                   rF   r=   rG   )rC   itemrJ   r=   r>   rK      rL   Fzunexpected type %s)1r.   r   
isinstancer   typerB   r+   r'   r$   r1   r%   r,   anymror&   r0   r2   r/   r:   r    is_protocolr#   r*   r)   r(   r3   r   partial_fallbackr   itemsr!   r   r   r-   r   make_simplified_unionr   r   r   rH   upper_boundr   varr   r   r   fallbackr   r   )r<   r@   instr=   rJ   r>   rH   B   s   







zMapper.type_to_rtyper   kindr   c                 C  s"   |t krtS |tkrtS | |S r9   )r   r2   r   r&   rH   )r<   r@   rZ   r=   r=   r>   get_arg_rtype   s
   
zMapper.get_arg_rtypefdefr   r   c                   s   t |jtr' fddt|jj|jjD }dd |jjD } |jj}n!dd |j	D }dd |j	D }|j
dko@t|j}|rFt}nt}t|drVdd |j	D }nd	d |jD }d
d t||j||D }|j
dv rrt}t||S )Nc                   s   g | ]
\}}  ||qS r=   )r[   )rC   r@   rZ   rJ   r=   r>   rK      s    
z&Mapper.fdef_to_sig.<locals>.<listcomp>c                 S  s   g | ]}|d u qS r9   r=   rC   namer=   r=   r>   rK          c                 S  s   g | ]}t qS r=   )r.   )rC   _r=   r=   r>   rK      s    c                 S  s   g | ]}|j qS r=   )pos_onlyrC   argr=   r=   r>   rK      s    r?   	argumentsc                 S  s   g | ]}|j jqS r=   )variabler^   rb   r=   r=   r>   rK      r_   c                 S  s   g | ]}|pd qS ) r=   r]   r=   r=   r>   rK      r_   c                 S  s"   g | ]\}}}}t ||||qS r=   )r   )rC   arg_namearg_kindarg_typearg_pos_onlyr=   r=   r>   rK      s    
)__eq____ne____lt____gt____le____ge__)rN   rO   r   zip	arg_types	arg_kinds	arg_namesrH   ret_typerd   r^   boolinfor-   r.   hasattrr   )r<   r\   rr   arg_pos_onlysretis_init_methodrt   argsr=   rJ   r>   fdef_to_sig   s.   






zMapper.fdef_to_sigmodulestrrv   c                 C  s
   || j v S )z*Is the given module one compiled by mypyc?)r5   )r<   r~   r=   r=   r>   is_native_module   s   
zMapper.is_native_moduleexprr   c                 C  s6   |j d u rdS d|j jv r| |j jdd S dS )NF.r   T)noderB   r   
rpartitionr<   r   r=   r=   r>   is_native_ref_expr   s
   
zMapper.is_native_ref_exprc                 C  s   |  |o	|jtkS r9   )r   rZ   r   r   r=   r=   r>   is_native_module_ref_expr   s   z Mapper.is_native_module_ref_exprN)r5   r6   r7   r8   )r@   rA   r7   r"   )r@   r   rZ   r   r7   r"   )r\   r   r7   r   )r~   r   r7   rv   )r   r   r7   rv   )__name__
__module____qualname____doc__r?   rH   r[   r}   r   r   r   r=   r=   r=   r>   r4   3   s    
	

Y

.
r4   N):r   
__future__r   
mypy.nodesr   r   r   r   r   r   r	   r
   
mypy.typesr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   mypyc.ir.class_irr   mypyc.ir.func_irr   r   r   mypyc.ir.rtypesr    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r=   r=   r=   r>   <module>   s    (LX