a
    du)                     @   sX  d dl Z d dlZd dlZd dlmZmZmZ d dlmZm	Z	 ddl
mZ ddlmZ ddlmZmZ ejejejejejejejejiZejejejejejejejejiZdd	 Zd
d ZejG dd de	ZejG dd deZejG dd de	ZejG dd de	ZejG dd de	ZejG dd de	ZG dd dejZ ejG dd de	Z!ejG dd de	Z"ejG dd de	Z#ejG d d! d!e	Z$ejG d"d# d#e$Z%ejG d$d% d%e	Z&ejG d&d' d'e	Z'ejG d(d) d)e	Z(ejG d*d+ d+e	Z)G d,d- d-e)Z*ejG d.d/ d/e	Z+ejG d0d1 d1e	Z,dS )2    N)AnyOptionalUnion)GuardSourceSource   )utils)create_instruction)	enum_reprrename_implicitc                 C   s>   t | trdS z|  tjkr$W dS W n ty8   Y n0 dS )NTF)
isinstanceConstantSourceguard_sourcer   CONSTANTNotImplementedErrorsource r   ]/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/torch/_dynamo/source.pyis_constant_source   s    

r   c                 C   s   |   tjtjtjtjfv S N)r   r   LOCALGLOBALLOCAL_NN_MODULEGLOBAL_NN_MODULEr   r   r   r   is_input_source'   s    r   c                   @   s.   e Zd ZU eed< dd Zdd Zdd ZdS )	LocalSource
local_namec                 C   s   | | jgS r   )create_loadr   selfcodegenr   r   r   reconstruct4   s    zLocalSource.reconstructc                 C   s   t jS r   )r   r   r    r   r   r   r   7   s    zLocalSource.guard_sourcec                 C   s
   t | jS r   )r   r   r#   r   r   r   name:   s    zLocalSource.nameN__name__
__module____qualname__str__annotations__r"   r   r$   r   r   r   r   r   0   s   
r   c                   @   s   e Zd ZU eed< dS )LocalInputSourceposN)r&   r'   r(   intr*   r   r   r   r   r+   >   s   
r+   c                   @   s.   e Zd ZU eed< dd Zdd Zdd ZdS )	RandomValueSourcerandom_call_indexc                 C   s   t jS r   )r   ZRANDOM_VALUEr#   r   r   r   r   G   s    zRandomValueSource.guard_sourcec                 C   s"   | |jjj|| jtdgS NBINARY_SUBSCR)r   ZtxoutputZrandom_values_varcreate_load_constr/   r	   r   r   r   r   r"   J   s    
zRandomValueSource.reconstructc                 C   s   t d| j S )NZrandom_value_)r   r/   r#   r   r   r   r$   Q   s    zRandomValueSource.nameN)r&   r'   r(   r-   r*   r   r"   r$   r   r   r   r   r.   C   s   
r.   c                   @   s.   e Zd ZU eed< dd Zdd Zdd ZdS )	GlobalSourceglobal_namec                 C   s   |j | jddgS )NTadd)create_load_globalr5   r   r   r   r   r"   Y   s    zGlobalSource.reconstructc                 C   s   t jS r   r   r   r#   r   r   r   r   \   s    zGlobalSource.guard_sourcec                 C   s   | j S r   r5   r#   r   r   r   r$   _   s    zGlobalSource.nameNr%   r   r   r   r   r4   U   s   
r4   c                   @   s.   e Zd ZU eed< dd Zdd Zdd ZdS )	GlobalWeakRefSourcer5   c                 C   s   |j | jddtddgS )NTr6   CALL_FUNCTIONr   )r8   r5   r	   r   r   r   r   r"   g   s    zGlobalWeakRefSource.reconstructc                 C   s   t jS r   r9   r#   r   r   r   r   m   s    z GlobalWeakRefSource.guard_sourcec                 C   s   | j  dS )Nz()r:   r#   r   r   r   r$   p   s    zGlobalWeakRefSource.nameNr%   r   r   r   r   r;   c   s   
r;   c                       sF   e Zd ZU eed< eed<  fddZdd Zdd Zd	d
 Z	  Z
S )
AttrSourcebasememberc                    sl   t    |sJ dd|v rN|d}t|d|d d | _|d | _n|| _|| _| jd ushJ d S )Nz9Can't construct an AttrSource without a valid base source.)super__init__splitr=   joinr>   r?   )r    r>   r?   Zmember_parts	__class__r   r   rC   y   s    

zAttrSource.__init__c                 C   s   | j ||| j S r   )r>   r"   create_load_attrsr?   r   r   r   r   r"      s    zAttrSource.reconstructc                 C   s
   | j  S r   r>   r   r#   r   r   r   r      s    zAttrSource.guard_sourcec                 C   s:   | j  r$d| j  d| j dS | j  d| j  S )Nzgetattr(, )r@   )r?   	isnumericr>   r$   r#   r   r   r   r$      s    
zAttrSource.name)r&   r'   r(   r   r*   r)   rC   r"   r   r$   __classcell__r   r   rF   r   r=   t   s   
r=   c                   @   s   e Zd ZdZdZdZdS )TensorPropertyr   r      N)r&   r'   r(   SIZESTRIDESTORAGE_OFFSETr   r   r   r   rN      s   rN   c                   @   sN   e Zd ZU eed< eed< dZee ed< dd Z	dd Z
d	d
 Zdd ZdS )TensorPropertySourcer>   propNidxc                 C   s<   | j d usJ | jtju r*| jd u s8J n| jd us8J d S r   )r>   rT   rN   rR   rU   r#   r   r   r   __post_init__   s    z"TensorPropertySource.__post_init__c                 C   s
   t  d S r   r   r   r   r   r   r"      s    z TensorPropertySource.reconstructc                 C   s
   | j  S r   rI   r#   r   r   r   r      s    z!TensorPropertySource.guard_sourcec                 C   s   | j tju r$| j  d| j dS | j tju rH| j  d| j dS | j tju rr| jd u sbJ | j  dS td| j  d S )Nz.size()[]z
.stride()[z.storage_offset()z
unhandled )	rT   rN   rP   r>   r$   rU   rQ   rR   AssertionErrorr#   r   r   r   r$      s    zTensorPropertySource.name)r&   r'   r(   r   r*   rN   rU   r   r-   rV   r"   r   r$   r   r   r   r   rS      s   
rS   c                   @   s6   e Zd ZU eed< dd Zdd Zdd Zdd	 Zd
S )NegateSourcer>   c                 C   s   | j d usJ d S r   r>   r#   r   r   r   rV      s    zNegateSource.__post_init__c                 C   s
   t  d S r   rW   r   r   r   r   r"      s    zNegateSource.reconstructc                 C   s
   | j  S r   rI   r#   r   r   r   r      s    zNegateSource.guard_sourcec                 C   s   | j   dS )Nz
.__neg__()r>   r$   r#   r   r   r   r$      s    zNegateSource.nameN	r&   r'   r(   r   r*   rV   r"   r   r$   r   r   r   r   rZ      s
   
rZ   c                       s`   e Zd ZU eed< eeef ed< eed< eed< d fdd	Z	dd	 Z
d
d Zdd Z  ZS )DefaultsSourcer>   idx_keyis_kwfieldFc                    s   t    |sJ d|| _|| _|| _| jrft|ts<J d| _| j  d| j d| j d| _	n6t|t
stJ d| _| j  d| j d| j d| _	d S )	Nz]Base must be a valid source in order to properly track and guard this Defaults to its origin.__kwdefaults__r@   z['z']__defaults__[rX   )rB   rC   r>   r_   r`   r   r)   ra   r$   _namer-   )r    r>   r_   r`   rF   r   r   rC      s    
$zDefaultsSource.__init__c                 C   s<   | j |}||| j ||| jtdg |S r0   )r>   r"   extendrH   ra   r3   r_   r	   r    r!   Zinstrsr   r   r   r"      s    
zDefaultsSource.reconstructc                 C   s
   | j  S r   rI   r#   r   r   r   r      s    zDefaultsSource.guard_sourcec                 C   s   | j S r   )re   r#   r   r   r   r$      s    zDefaultsSource.name)F)r&   r'   r(   r   r*   r   r-   r)   boolrC   r"   r   r$   rM   r   r   rF   r   r^      s   
r^   c                   @   s>   e Zd ZU eed< eed< dd Zdd Zdd Zd	d
 Z	dS )GetItemSourcer>   indexc                 C   s   | j d usJ d S r   r[   r#   r   r   r   rV      s    zGetItemSource.__post_init__c                 C   sP   | j |}t| jtr,|| j| n||| j |td |S r0   )	r>   r"   r   rj   r   rf   appendr3   r	   rg   r   r   r   r"      s    zGetItemSource.reconstructc                 C   s
   | j  S r   rI   r#   r   r   r   r     s    zGetItemSource.guard_sourcec                 C   sn   t | jtr(| j  d| j  dS t | jtjrR| j  dt| j dS | j  d| jdS d S )Nrd   rX   )r   rj   r   r>   r$   enumEnumr
   r#   r   r   r   r$     s
    zGetItemSource.nameN
r&   r'   r(   r   r*   r   rV   r"   r   r$   r   r   r   r   ri      s   
ri   c                   @   s   e Zd Zdd Zdd ZdS )TupleIteratorGetItemSourcec                 C   s0   | tjd | j||| jtddg S )NZtuple_iterator_getitemr<   rO   )load_import_fromr   r&   r>   r"   r3   rj   r	   r   r   r   r   r"     s
    

z&TupleIteratorGetItemSource.reconstructc                 C   s   d| j   d| jdS )Nz___tuple_iterator_getitem(rJ   rK   r>   r$   rj   r#   r   r   r   r$     s    zTupleIteratorGetItemSource.nameN)r&   r'   r(   r"   r$   r   r   r   r   ro     s   ro   c                   @   s6   e Zd ZU eed< dd Zdd Zdd Zdd	 Zd
S )
TypeSourcer>   c                 C   s   | j d usJ d S r   r[   r#   r   r   r   rV   #  s    zTypeSource.__post_init__c                 C   s$   | dd | j|tddg S )Nbuiltinstyper<   r   )rp   r>   r"   r	   r   r   r   r   r"   &  s    zTypeSource.reconstructc                 C   s
   | j  S r   rI   r#   r   r   r   r   *  s    zTypeSource.guard_sourcec                 C   s   d| j   dS )Nztype(rK   r\   r#   r   r   r   r$   -  s    zTypeSource.nameNr]   r   r   r   r   rr     s
   
rr   c                   @   s>   e Zd ZU eed< eed< dd Zdd Zdd Zd	d
 ZdS )SuperSourcert   objc                 C   s    | j d usJ | jd usJ d S r   )rt   rv   r#   r   r   r   rV   6  s    zSuperSource.__post_init__c                 C   s0   | dd | j|| j| tddg S )Nrs   rB   r<   rO   )rp   rt   r"   rv   r	   r   r   r   r   r"   :  s    


zSuperSource.reconstructc                 C   s
   | j  S r   )rv   r   r#   r   r   r   r   B  s    zSuperSource.guard_sourcec                 C   s   d| j   d| j  dS )Nzsuper(rJ   rK   )rt   r$   rv   r#   r   r   r   r$   E  s    zSuperSource.nameNr]   r   r   r   r   ru   1  s   
ru   c                   @   s>   e Zd ZU eed< eed< dd Zdd Zdd Zd	d
 Z	dS )ODictGetItemSourcer>   rj   c                 C   s   | j d usJ d S r   r[   r#   r   r   r   rV   N  s    z ODictGetItemSource.__post_init__c                 C   s2   | tjjg| j| || jtddg S )Nr<   rO   )	Z_create_load_constcollectionsOrderedDict__getitem__r>   r"   r3   rj   r	   r   r   r   r   r"   Q  s    

zODictGetItemSource.reconstructc                 C   s
   | j  S r   rI   r#   r   r   r   r   [  s    zODictGetItemSource.guard_sourcec                 C   s   d| j   d| jdS )Nz___odict_getitem(rJ   rK   rq   r#   r   r   r   r$   ^  s    zODictGetItemSource.nameNrn   r   r   r   r   rw   I  s   

rw   c                   @   s.   e Zd ZU eed< dd Zdd Zdd ZdS )	NNModuleSourceinnerc                 C   s   | j |S r   )r|   r"   r   r   r   r   r"   f  s    zNNModuleSource.reconstructc                 C   s   t | j  S r   )_GUARD_SOURCE_NN_MODULEr|   r   r#   r   r   r   r   i  s    zNNModuleSource.guard_sourcec                 C   s
   | j  S r   )r|   r$   r#   r   r   r   r$   l  s    zNNModuleSource.nameN)r&   r'   r(   r   r*   r"   r   r$   r   r   r   r   r{   b  s   
r{   c                   @   s   e Zd Zdd ZdS )NotNNModuleSourcec                 C   s   t | j  S r   )_GUARD_SOURCE_NOT_NN_MODULEr|   r   r#   r   r   r   r   q  s    zNotNNModuleSource.guard_sourceN)r&   r'   r(   r   r   r   r   r   r~   p  s   r~   c                   @   s8   e Zd ZU eed< dd Zdd Zdd Zdd	d
ZdS )r   source_namec                 C   s   |j | jddgS )NFr6   )r8   r   r   r   r   r   r"   y  s    zConstantSource.reconstructc                 C   s   t jS r   )r   r   r#   r   r   r   r   |  s    zConstantSource.guard_sourcec                 C   s   | j S r   )r   r#   r   r   r   r$     s    zConstantSource.nameFc                 C   s
   t  d S r   rW   )r    fnZis_volatiler   r   r   
make_guard  s    zConstantSource.make_guardN)F)	r&   r'   r(   r)   r*   r"   r   r$   r   r   r   r   r   r   u  s
   
r   c                   @   s   e Zd Zdd Zdd ZdS )ShapeEnvSourcec                 C   s   dS )N r   r#   r   r   r   r$     s    zShapeEnvSource.namec                 C   s   t jS r   )r   Z	SHAPE_ENVr#   r   r   r   r     s    zShapeEnvSource.guard_sourceN)r&   r'   r(   r$   r   r   r   r   r   r     s   r   )-rx   Zdataclassesrl   typingr   r   r   Ztorch._guardsr   r   r   r   Zbytecode_transformationr	   r
   r   r   r   r   r   r}   r   r   r   Z	dataclassr   r+   r.   r4   r;   r=   rm   rN   rS   rZ   r^   ri   ro   rr   ru   rw   r{   r~   r   r   r   r   r   r   <module>   sn   	)