o
    hQ                     @   s  d Z ddlZddlZddlZddlZddlZddlmZ ddl	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 dd	lmZmZ dd
lmZmZ ddlmZ ddlmZmZm Z m!Z!m"Z"m#Z# ddl$m%Z%m&Z& ddl'm(Z( er~ddl)m*Z* ddl+m,Z, dd Z-dd Z.d0ddZ/dd Z0G dd de&Z1G dd de&Z2G dd de1Z3G d d! d!e1Z4G d"d# d#e1Z5G d$d% d%e5Z6G d&d' d'e5Z7G d(d) d)e&Z8G d*d+ d+e8Z9G d,d- d-e8Z:G d.d/ d/e8Z;dS )1a  
Dictionary-related variable tracking classes for PyTorch Dynamo.

This module implements variable tracking for different types of dictionary-like objects:
- Regular Python dictionaries (dict)
- Ordered dictionaries (collections.OrderedDict)
- Default dictionaries (collections.defaultdict)
- Dictionary views (keys and values)
- Sets and frozensets (implemented internally using dictionaries)

These classes are responsible for tracking dictionary operations during graph compilation,
maintaining proper guards for dictionary mutations and key existence checks. They handle
dictionary creation, modification, key/value access, and view operations while ensuring
correct behavior in the compiled code through appropriate guard installation.

The implementation uses a special _HashableTracker wrapper to handle dictionary keys
while preserving proper aliasing semantics. Sets are implemented as dictionaries with
None values for efficiency and code reuse.
    NHashable)OptionalTYPE_CHECKING)is_fake   )graph_break_hints	polyfills	variables)create_call_functioncreate_instruction)raise_observed_exceptionunimplemented_v2)GuardBuilderinstall_guard)is_from_local_source)cmp_name_to_op_mapping
dict_items	dict_keysdict_valuesistypespecialize_symnode   )ValueMutationNewVariableTrackerConstantVariable)	PyCodegenInstructionTranslatorc                 C   s    t t| td| dgd d S )Nzwrong number of arguments for z() callargs)r   	TypeErrorr   )txname r%   c/home/www/facesmatcher.com/frenv_anti/lib/python3.10/site-packages/torch/_dynamo/variables/dicts.pyraise_args_mismatch<   s
   
r'   c                 C   s   t | jddS )N__instancecheck__F)type__dict__get)objr%   r%   r&   was_instancecheck_overrideD   s   r-   c                 C   s>   |d u rddl m} | }tt|tdt|  gd d S )Nr   r   zunhashable type: r    )torch._dynamo.symbolic_convertr   Z
current_txr   r"   r   r)   )argr#   r   r%   r%   r&   raise_unhashableH   s   
r0   c                 C   s   t | tjr|  s|  rdS t | tjr!|  jj	dd uS t | tj
r1tdd | jD S t | tjrRt| jsRt| jdtju rRt | jtrRt | jtS t | tjtjtjtjtjtjtjtjjtjtjtj tj!tj"tj#tj$fS )NTexample_valuec                 s   s    | ]}t |V  qd S N)is_hashable.0er%   r%   r&   	<genexpr>d   s    zis_hashable.<locals>.<genexpr>__hash__)%
isinstancer
   LazyVariableTrackeris_realizedr3   TensorVariableas_proxynodemetar+   TupleVariableallitemsUserDefinedObjectVariabler-   valueinspectgetattr_staticintr8   py_HashableBuiltinVariableZSymNodeVariabler   ZEnumVariableZUserDefinedClassVariableUserFunctionVariableZSkipFunctionVariablemiscZNumpyVariableNNModuleVariableUnspecializedNNModuleVariableZMethodWrapperVariableZTorchInGraphFunctionVariableZTypingVariableZFunctoolsPartialVariableWeakRefVariable)xr%   r%   r&   r3   R   sN   


r3   c                       s2  e Zd ZdhejZG dd dZefdeeef ddf fddZd	d
 Zdd Z	dd Z
dd Zdd ZdefddZdd Zdd Zdd Zdd Zd=dd Zd!d"d#efd$d%Zd!d"d#efd&d'Zd#efd(d)Zd#efd*d+Zd,d- Zd.d/ Z	0	1	2	3		4d> fd5d6Zd7d8 Zd9d: Z fd;d<Z  ZS )?ConstDictVariableuser_clsc                   @   sL   e Zd ZdZdddZedd Zdd	 Zed
d Z	dd de
fddZdS )z"ConstDictVariable._HashableTrackeraB  
        Auxiliary opaque internal class that wraps a VariableTracker and makes it hashable
        This should not be seen or touched by anything outside of ConstDictVariable and its children
        Note that it's also fine to put VTs into dictionaries and sets, but doing so does not take into account aliasing
        returnNc                 C   s"   t |}t|st| || _d S r2   )r   r3   r0   vt)selfrS   r%   r%   r&   __init__   s   
z+ConstDictVariable._HashableTracker.__init__c                    s  t | jtjr| j s| j r| j S t | jtjr(| j j	j
d }|S t | jtjrAtj t fdd| jjD }|S t | jtjrL| jjS t | jtjrW| jjS t | jtjrc| j S t | jtjrttj  | jjjS t | jtjr| jjS | j }|S )Nr1   c                 3   s    | ]} |j V  qd S r2   )underlying_valuer4   r   r%   r&   r7          zFConstDictVariable._HashableTracker.underlying_value.<locals>.<genexpr>)r9   rS   r
   r:   r;   r3   original_valuer<   r=   r>   r?   r@   rP   _HashableTrackertuplerB   rL   rD   rM   rJ   Zget_functionrN   Zreferent_vtrV   rC   as_python_constant)rT   rO   r%   r   r&   rV      s6   


z3ConstDictVariable._HashableTracker.underlying_valuec                 C   
   t | jS r2   )hashrV   rT   r%   r%   r&   r8      s   
z+ConstDictVariable._HashableTracker.__hash__c                    sh   t | t |kr
dS t| tr(tj t| t|ko't fddt| |D S t| r0| |u S | |kS )NFc                 3   s     | ]\}}  ||V  qd S r2   )_eq_impl)r5   uvr   r%   r&   r7      s    
z>ConstDictVariable._HashableTracker._eq_impl.<locals>.<genexpr>)	r)   r9   rZ   rP   rY   lenrA   zipr   )abr%   r   r&   r_      s   
z+ConstDictVariable._HashableTracker._eq_implotherc                 C   sN   t j}t||st|sJ t|t||r || j|jS || j|S r2   )rP   rY   r9   r   Z
is_literalr)   r_   rV   )rT   rf   r   r%   r%   r&   __eq__   s   
z)ConstDictVariable._HashableTracker.__eq__rR   N)__name__
__module____qualname____doc__rU   propertyrV   r8   staticmethodr_   boolrg   r%   r%   r%   r&   rY      s    
	

rY   rB   rR   Nc                    s   d|v r	| d d|v r| d t jd	i | tj t fdd| D s-J  fddfdd| D | _t| j | _	|
 | _|| _d S )
Noriginal_itemsshould_reconstruct_allc                 3   s,    | ]\}}t |t fot |tV  qd S r2   )r9   r   r5   rO   ra   r   r%   r&   r7      s    
z-ConstDictVariable.__init__.<locals>.<genexpr>c                    s   t |  r| S  | S r2   )r9   )keyr   r%   r&   make_hashable   s   z1ConstDictVariable.__init__.<locals>.make_hashablec                    s   i | ]	\}} ||qS r%   r%   rr   )rt   r%   r&   
<dictcomp>   s    z.ConstDictVariable.__init__.<locals>.<dictcomp>r%   )popsuperrU   rP   rY   rA   rB   r   sourcerq   copyrp   rQ   )rT   rB   rQ   kwargs	__class__)r   rt   r&   rU      s   



zConstDictVariable.__init__c                 C      dd | j   D S )Nc                 S       i | ]\}}|j  | qS r%   rS   r=   r5   kra   r%   r%   r&   ru           z.ConstDictVariable.as_proxy.<locals>.<dictcomp>rB   r^   r%   r%   r&   r=      s   zConstDictVariable.as_proxyc                 C   s"   dd dd | j D  d S )N{, c                 s   s,    | ]\}}|j   d |  V  qdS )z: NrS   
debug_reprr   r%   r%   r&   r7      s    
z/ConstDictVariable.debug_repr.<locals>.<genexpr>})joinrB   r^   r%   r%   r&   r      s   
zConstDictVariable.debug_reprc                 C   r}   )Nc                 S   r~   r%   rS   r[   r   r%   r%   r&   ru         z8ConstDictVariable.as_python_constant.<locals>.<dictcomp>r   r^   r%   r%   r&   r[     s   z$ConstDictVariable.as_python_constantc                 C   s   |    dd | j D S )Nc                 S   s   i | ]
\}}|j  |qS r%   r   r   r%   r%   r&   ru     s    z=ConstDictVariable.keys_as_python_constant.<locals>.<dictcomp>)install_dict_keys_match_guardrB   r^   r%   r%   r&   keys_as_python_constant
     z)ConstDictVariable.keys_as_python_constantc                 C      | j S r2   )rQ   r^   r%   r%   r&   python_type     zConstDictVariable.python_typec                 C   sB   t |tsJ tj}t|o ||| jv o t | j|| tj S r2   )r9   r   rP   rY   r3   rB   r
   DeletedVariable)rT   rS   r   r%   r%   r&   __contains__  s   zConstDictVariable.__contains__c                 C   s   t dd | j D S )Nc                 S   s   g | ]
}t |tjs|qS r%   )r9   r
   r   r5   rO   r%   r%   r&   
<listcomp>  s    
z)ConstDictVariable.len.<locals>.<listcomp>)rb   rB   valuesr^   r%   r%   r&   rb     s
   zConstDictVariable.lenc                    s&    j rdS t fdd j D S )NTc                 3   s*    | ]\}}   j|j|V  qd S r2   )is_new_itemrp   r+   rS   )r5   rs   rD   r^   r%   r&   r7   &  s
    
z2ConstDictVariable.has_new_items.<locals>.<genexpr>)rq   anyrB   r^   r%   r^   r&   has_new_items#  s
   zConstDictVariable.has_new_itemsc                 C   s<   |r|  r|  rt| t| kS t|t|kS r2   )r;   idrealize)rT   rD   rf   r%   r%   r&   r   +  s   zConstDictVariable.is_new_itemc                 C   sh   d}| j   D ]!\}}| j|j}| ||s| jr(||j || |d7 }q|td|d d S )Nr   r   	BUILD_MAPr/   )rB   rp   r+   rS   r   rq   append_outputr   )rT   codegennum_argsrs   rD   itemr%   r%   r&   reconstruct_kvs_into_new_dict1  s   
z/ConstDictVariable.reconstruct_kvs_into_new_dictr   r   c                    sJ   | j tju r  fdd |    tdd d S |   d S )Nc                            t dgS )NOrderedDictextend_outputcreate_load_python_modulecollectionscreate_load_attrr%   r   r%   r&   <lambda>A  
    z/ConstDictVariable.reconstruct.<locals>.<lambda>r   F)rQ   r   r   add_push_nullr   r   r   rT   r   r%   r   r&   reconstruct=  s   

zConstDictVariable.reconstructr#   r   r/   c                 C   s(   t |}|| jvrtt| | j| S r2   )rP   rY   rB   r   KeyError)rT   r#   r/   rs   r%   r%   r&   'getitem_const_raise_exception_if_absentM  s   



z9ConstDictVariable.getitem_const_raise_exception_if_absentc                 C   sL   t |}|| jvr!d|j d}tdd|j |dgtjd | j| S )NzDictionary key z not found during tracingzkey not found in dictzKey z>Check if the key exists in the dictionary before accessing it.Zgb_typecontextZexplanationhints)rP   rY   rB   rD   r   r   Z
USER_ERROR)rT   r#   r/   rs   msgr%   r%   r&   getitem_constU  s   



	zConstDictVariable.getitem_constc                 C   s"   t |}|| jvrd S | j| S r2   )rP   rY   rB   )rT   r/   rs   r%   r%   r&   maybe_getitem_constd  s   


z%ConstDictVariable.maybe_getitem_constc                 C   sX   || v sJ t |}t| j |}t| j | }t|tj	r*|
  d S d S r2   )rP   rY   rZ   rB   keysindexrp   r9   r
   r:   r   )rT   r/   rs   r   Zoriginal_key_vtr%   r%   r&   realize_key_vtj  s   
z ConstDictVariable.realize_key_vtc                 C   s   | j rt| tj d S d S r2   )rx   r   
make_guardr   ZDICT_KEYS_MATCHr^   r%   r%   r&   r   s  s   z/ConstDictVariable.install_dict_keys_match_guardc                 C   s   ddl m} | jsd S |jj| rd S |d | v }|d jd u r<t|d |r<t| t	j
tj|d j| d d S |d jrR|rL| |d  d S |   d S d S )Nr   r   r   )rs   invert) r   rx   outputside_effectsZis_modifiedr9   r   r   	functoolspartialr   ZDICT_CONTAINSrD   r   r   )rT   r#   r!   r   containsr%   r%   r&   install_dict_contains_guardw  s*   
	z-ConstDictVariable.install_dict_contains_guardr!   list[VariableTracker]rz   dict[str, VariableTracker]r   c                    s>  ddl m}m  tj|ot|d }|dkr9ttj|g|R i |}|j	j
|  | j|j  d S |dkrMt|dksEJ | ||d S |dkrj|sU|rWJ |   | jrf|j	j| j t| S |dkr|   | jr}|j	j| j |s|rJ t| S |dkr|   | jr|j	j| j |s|rJ t| S |d	kr|   |s|rJ | j| j t d d
S |dkr|s|rJ |    t| jS |dkr|  r|st|d  |   |st|dksJ |j	j
|  |d | j|d <  d S |dkr5|r5|  r5|   d| _|j	j
|  | j|d   d S |dv rgt|dv rg|d | vrg| || t|dkrc|dkr_t t!|  d S |d S |dkr|r|  rd| _|j	j
|  | j"|d S |dkrd| _|j	j
|  | j#   d S |dkr|  r|   t|dk}t|dk}	|s|	r|j	j
|  |rt$|d tr|d   |d }
n	|%|t|d }
| j|
j |	r fdd| D }| j|  d S t& '||||S |dv r%|d | v r%| (||d S |dkrKt|dkrK|s:t|d  | || |d | v } |S |dkr|r|  r|   |raJ t|dksjJ | )|d }|d urx|S t|dkr d }n|d }|j	j
|  || j|d < |S |dkr|   |st|dksJ |j	j
|  |d }| j| }| j"| || j|<  d S |dkrt|dksJ t$|d tst*d|d + j, d|   | j| j t d d
}|d   |j|d j |S t& '||||S )Nr   )rI   r   r   rU   __getitem__rB   r   r   ry   )rB   Zmutation_typerx   __len____setitem__r   __delitem__T)rv   r+   )r   r   rv   clearupdatec                    s    i | ]\}}  ||qS r%   )creater   r   r   r%   r&   ru     r   z1ConstDictVariable.call_method.<locals>.<dictcomp>)r+   __getattr__r   
setdefaultmove_to_end__or__z/unsupported operand type(s) for |: 'dict' and '')-r   rI   r   rP   rY   r3   r
   dictZ	call_dictr   r   mutationrB   r   r   rb   r   r   rx   Zguard_on_key_orderaddDictItemsVariableDictKeysVariableDictValuesVariableclonery   r   
is_mutabler0   rq   r   r   r   r   rv   r   r9   Zcall_custom_dictrw   call_methodr   r   r"   r   ri   )rT   r#   r$   r!   rz   rI   Zarg_hashableZtemp_dict_vtZhas_argZ
has_kwargsZdict_vtr   rD   rO   rs   valZnew_dict_vtr{   r   r&   r     s  



&














zConstDictVariable.call_methodc                 C   s   |    dd | j D S )Nc                 S      g | ]}|j qS r%   rS   r   r%   r%   r&   r   M      z9ConstDictVariable.unpack_var_sequence.<locals>.<listcomp>)r   rB   r   rT   r#   r%   r%   r&   unpack_var_sequenceK  r   z%ConstDictVariable.unpack_var_sequencec                 C   s\   | j tu r|| j jv rtdS tdS d| j  d}tdd| j  |dgtjd d S )	NTFzhasattr on z is not supportedzunsupported hasattr operationzClass z+Consider using a regular dictionary insteadr   )rQ   r   r*   r   r   r   r   SUPPORTABLE)rT   r#   r$   r   r%   r%   r&   call_obj_hasattrO  s   




z"ConstDictVariable.call_obj_hasattrc                    s   |    t jdi |S Nr%   )r   rw   r   )rT   rz   r{   r%   r&   r   b  s   zConstDictVariable.cloner   r   r!   r   rz   r   rR   r   )ri   rj   rk   r   Z_nonvar_fieldsrY   r   rU   r=   r   r[   r   r   ro   r   rb   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__r%   r%   r{   r&   rP      sX    P
"			

	' .rP   c                       sb   e Zd Zdeddf fddZdd Zdd	 ZdddZded de	e
df ddfddZ  ZS )MappingProxyVariabledv_dictrR   Nc                    s*   t  jdi | t|tsJ || _d S r   )rw   rU   r9   rP   r   rT   r   rz   r{   r%   r&   rU   i  s   
zMappingProxyVariable.__init__c                 C   s   t jS r2   )typesMappingProxyTyper^   r%   r%   r&   r   n  r   z MappingProxyVariable.python_typec                 C   s   | j |S r2   )r   r   r   r%   r%   r&   r   q  s   z(MappingProxyVariable.unpack_var_sequencer   r   c                    sd   | j rd| j  d}tdd| j  |dgtjd   fdd  | j  td	d
 d S )Nz*Preexisting MappingProxyVariable (source: zS) cannot be reconstructed because the connection to the original dict will be lost.z%mapping proxy cannot be reconstructedSource: zCUse a mapping proxy constructed in the same `torch.compile` region.r   c                      r   )Nr   )r   r   r   r   r%   r   r%   r&   r     r   z2MappingProxyVariable.reconstruct.<locals>.<lambda>r   F)rx   r   r   r   r   r   r   r   )rT   r   r   r%   r   r&   r   t  s"   
	

z MappingProxyVariable.reconstructr!   r   rz   c                 C   sF   | j r|jj rd}tdd| j  d|ddgd | j||||S )Na  A dict has been modified while we have an existing mappingproxy object. A mapping proxy object, as the name suggest, proxies a mapping object (usually a dict). If the original dict object mutates, it is reflected in the proxy object as well. For an existing proxy object, we do not know the original dict it points to. Therefore, for correctness we graph break when there is dict mutation and we are trying to access a proxy object.z-mapping proxy affected by dictionary mutationr   z, Dict mutation detectedzNAvoid modifying dictionaries that might be referenced by mapping proxy objectszROr avoid using the mapping proxy objects after modifying its underlying dictionaryr   )rx   r   r   Zhas_existing_dict_mutationr   r   r   )rT   r#   r$   r!   rz   r   r%   r%   r&   r     s   
	z MappingProxyVariable.call_methodr   )ri   rj   rk   rP   rU   r   r   r   listr   strr   r   r%   r%   r{   r&   r   g  s    

r   c                   @   s   e Zd Zdd Zdd ZdS )NNModuleHooksDictVariablec                 C      d S r2   r%   r^   r%   r%   r&   r        z7NNModuleHooksDictVariable.install_dict_keys_match_guardc                 C   r   r2   r%   rT   r#   r!   r%   r%   r&   r     r   z5NNModuleHooksDictVariable.install_dict_contains_guardN)ri   rj   rk   r   r   r%   r%   r%   r&   r     s    r   c                       sf   e Zd Zdd fddZ fddZ fddZed	d
 Z						d fddZdd Z	  Z
S )DefaultDictVariableNrR   c                    s.   t  j||fi | |tju sJ || _d S r2   )rw   rU   r   defaultdictdefault_factory)rT   rB   rQ   r   rz   r{   r%   r&   rU     s   
zDefaultDictVariable.__init__c                    s$   | j tttfvr| jsdS t  S )NF)r   r   rZ   r   rB   rw   is_python_constantr^   r{   r%   r&   r     s   
z&DefaultDictVariable.is_python_constantc                    s   d| j   dt   dS )Nzdefaultdict(r   ))r   r   rw   r^   r{   r%   r&   r     s   zDefaultDictVariable.debug_reprc                 C   s,   t | tjr| jttttfv S t | tjj	S r2   )
r9   r
   rI   fnr   rZ   r   setZ	functionsZBaseUserFunctionVariabler   r%   r%   r&   is_supported_arg  s   z$DefaultDictVariable.is_supported_argr!   r   rz   r   r   c                    s   |dkr=t |dksJ |d | v r| ||d S | jd u r&t|d  | j|g i }t |d|d |f| |S t ||||S )Nr   r   r   r   )rb   r   r   r   call_functionrw   r   )rT   r#   r$   r!   rz   Zdefault_varr{   r%   r&   r     s   
zDefaultDictVariable.call_methodc                    s:      fdd  | j |    tdd d S )Nc                      r   )Nr   r   r%   r   r%   r&   r     r   z1DefaultDictVariable.reconstruct.<locals>.<lambda>r   F)r   r   r   r   r   r   r%   r   r&   r     s   


zDefaultDictVariable.reconstructr2   rh   r   )ri   rj   rk   rU   r   r   rn   r   r   r   r   r%   r%   r{   r&   r     s    
r   c                       s   e Zd ZdZdee ddf fddZdd Zed	d
 Z	e
dd Zdd Zdd Zdd Zd%ddZdee deeef ddf fddZdddefdd Zd!d" Zd#d$ Z  ZS )&SetVariablez.We model a sets as dictionary with None valuesrB   rR   Nc                    s(   t |t }t j|fi | d S r2   )r   fromkeysr   _default_valuerw   rU   rT   rB   rz   r{   r%   r&   rU     s   zSetVariable.__init__c                 C   ,   | j sdS dddd | j  D  d S )Nzset()r   ,c                 s       | ]}|j  V  qd S r2   r   r5   r   r%   r%   r&   r7     rW   z)SetVariable.debug_repr.<locals>.<genexpr>r   rB   r   r   r^   r%   r%   r&   r        "zSetVariable.debug_reprc                 C   s   t | j S r2   )r   rB   r   r^   r%   r%   r&   	set_items
  s   zSetVariable.set_itemsc                   C   s
   t d S r2   )r   r   r%   r%   r%   r&   r     s   
zSetVariable._default_valuec                 C      dd | j D S )Nc                 S      h | ]}|j  qS r%   r   r  r%   r%   r&   	<setcomp>      z'SetVariable.as_proxy.<locals>.<setcomp>r  r^   r%   r%   r&   r=        zSetVariable.as_proxyc                 C      t S r2   )r   r^   r%   r%   r&   r     r   zSetVariable.python_typec                 C   r  )Nc                 S   r	  r%   r   r  r%   r%   r&   r
    r  z1SetVariable.as_python_constant.<locals>.<setcomp>r  r^   r%   r%   r&   r[     r  zSetVariable.as_python_constantr   r   c                 C   s2   | dd | jD  |tdt| jd d S )Nc                 S   r   r%   r   r   r%   r%   r&   r     r   z+SetVariable.reconstruct.<locals>.<listcomp>	BUILD_SETr   )foreachr  r   r   rb   r   r%   r%   r&   r     s   zSetVariable.reconstructr!   rz   r   c           
   
      s  |dkr*t tj|g||R  }|jj|  | j  | j	|j t
d S |dkrI|r2J t|dkr=t|| d}|d t f}n|dkr|rQJ |rUJ z| j j}W n  ty} } ztt|ttt
j|jd W Y d }~nd }~ww t |||f| |S |dkr|rJ t|dksJ t tj|| |d gi S |d	kr|rJ t tj|| g|i S |d
kr|rJ t tj|| g|i S |dkr|rJ t tj || g|i S |dkr|rJ t tj!|| g|i S |dkr|rJ t tj"|| g|i S |dkr>t|dkr+t|| |r0J t tj#|| g|i S |dkrbt|dkrOt|| |rTJ t tj$|| g|i S |dkr| % r|rqJ t tj&|| g|i S |dkr|rJ t|dksJ |d | vrtt||d t |d||S |dkr|rJ t|dksJ |d | v rt |d||S t
jd dS |dv rt'j(t'j)d}|d * }	t+|	tst t||	gi }	t |,||| |	gi S t ||||S )NrU   r   r   r   r   rv   r    
isdisjointintersectionintersection_updateunion
differencedifference_updatesymmetric_differencesymmetric_difference_updater   removediscard)rD   )issubset
issuperset)-r
   rI   r   Zcall_setr   r   r   rB   r   r   r   r   rb   r'   r   r   r  rv   rS   r   r   r   mapr!   rw   r   rJ   r	   Zset_isdisjointr   Zset_intersectionZset_intersection_updateZ	set_unionZset_differenceZset_difference_updateZset_symmetric_differenceZset_symmetric_difference_updater   Z
set_updateoperatorleger   r   r+   )
rT   r#   r$   r!   rz   Ztemp_set_vtresultr6   oprf   r{   r%   r&   r      s   


















zSetVariable.call_methodr#   r   r/   c                 C   s   t d)NzIllegal to getitem on a set)RuntimeError)rT   r#   r/   r%   r%   r&   r     s   zSetVariable.getitem_constc                 C   r   r2   r%   r^   r%   r%   r&   r        z)SetVariable.install_dict_keys_match_guardc                 C   r   r2   r%   r   r%   r%   r&   r     r$  z'SetVariable.install_dict_contains_guardr   )ri   rj   rk   rl   r   r   rU   r   rm   r  rn   r   r=   r   r[   r   r   r   r   r   r   r   r   r%   r%   r{   r&   r     s4    



lr   c                       s~   e Zd Zdee ddf fddZdd Zedd	 Zd
d Z	dd Z
dddZdee deeef ddf fddZ  ZS )FrozensetVariablerB   rR   Nc                       t  j|fi | d S r2   rw   rU   r   r{   r%   r&   rU        zFrozensetVariable.__init__c                 C   r  )Nzfrozenset()r   r  c                 s   r  r2   r   r  r%   r%   r&   r7     rW   z/FrozensetVariable.debug_repr.<locals>.<genexpr>r   r  r^   r%   r%   r&   r     r  zFrozensetVariable.debug_reprc                 C   s
   | j  S r2   )rB   r   r^   r%   r%   r&   r       
zFrozensetVariable.set_itemsc                 C   r  r2   )	frozensetr^   r%   r%   r&   r     r   zFrozensetVariable.python_typec                 C   r  )Nc                 S   r	  r%   r   r  r%   r%   r&   r
    r  z7FrozensetVariable.as_python_constant.<locals>.<setcomp>r  r^   r%   r%   r&   r[     r  z$FrozensetVariable.as_python_constantr   r   c                    s<     dd | jD    fdd  tdd d S )Nc                 S   r   r%   r   r   r%   r%   r&   r     r   z1FrozensetVariable.reconstruct.<locals>.<listcomp>c                      s      dgS )Nr*  )r   Zcreate_load_globalr%   r   r%   r&   r     s    z/FrozensetVariable.reconstruct.<locals>.<lambda>r   F)r  r  r   r   r   r   r%   r   r&   r     s
   
zFrozensetVariable.reconstructr!   rz   r   c                    s<   |dv rt d| d|dkrtd S t ||||S )Nr   rv   r   r  r  r   Illegal call_method z on a frozensetrU   )r#  r   r   rw   r   rT   r#   r$   r!   rz   r{   r%   r&   r     s
   
zFrozensetVariable.call_methodr   )ri   rj   rk   r   r   rU   r   rm   r  r   r[   r   r   r   r   r   r%   r%   r{   r&   r%    s&    


r%  c                       st   e Zd Zdee ddf fddZdd Zedd	 Zd
d Z	dd Z
dee deeef ddf fddZ  ZS )DictKeySetVariablerB   rR   Nc                    r&  r2   r'  r   r{   r%   r&   rU     r(  zDictKeySetVariable.__init__c                 C   r  )Nzdict_keys([])zdict_keys([r  c                 s   r  r2   r   r  r%   r%   r&   r7     rW   z0DictKeySetVariable.debug_repr.<locals>.<genexpr>z])r  r^   r%   r%   r&   r     s   zDictKeySetVariable.debug_reprc                 C   r   r2   r   r^   r%   r%   r&   r    s   zDictKeySetVariable.set_itemsc                 C   r  r2   r   r^   r%   r%   r&   r     r   zDictKeySetVariable.python_typec                 C   s   t dd | jD d  S )Nc                 S   r	  r%   r   r  r%   r%   r&   r
    r  z8DictKeySetVariable.as_python_constant.<locals>.<setcomp>)r   r   r  r   r^   r%   r%   r&   r[     s
   z%DictKeySetVariable.as_python_constantr!   rz   r   c                    s*   |dv rt d| dt ||||S )Nr+  r,  z on a dict_keys)r#  rw   r   r-  r{   r%   r&   r     s   zDictKeySetVariable.call_method)ri   rj   rk   r   r   rU   r   rm   r  r   r[   r   r   r   r   r%   r%   r{   r&   r.    s$    


r.  c                       s   e Zd ZU dZdZee ed< deddf fddZ	e
dd	 Ze
d
d Zdd ZdddZded deedf ddf fddZ  ZS )DictViewVariablezu
    Models _PyDictViewObject

    This is an "abstract" class. Subclasses will override kv and the items method
    Nkvr   rR   c                    s8   t  jdi | | jdv sJ t|tsJ || _d S )N)r   r   rB   r%   )rw   rU   r1  r9   rP   r   r   r{   r%   r&   rU     s   
zDictViewVariable.__init__c                 C   s   t | jj| j S r2   )getattrr   rB   r1  r^   r%   r%   r&   
view_items	  s   zDictViewVariable.view_itemsc                 C   s   t r2   )NotImplementedErrorr^   r%   r%   r&   view_items_vt  s   zDictViewVariable.view_items_vtc                 C   r   r2   )r5  r   r%   r%   r&   r     r   z$DictViewVariable.unpack_var_sequencer   r   c                 C   s$   || j  || j |d d S )Nr   )r   Zload_methodr1  r   r   r%   r%   r&   r     s   
zDictViewVariable.reconstructr!   r   rz   c                    s,   |dkr| j ||||S t ||||S )Nr   )r   r   rw   r-  r{   r%   r&   r     s   zDictViewVariable.call_methodr   )ri   rj   rk   rl   r1  r   r   __annotations__rP   rU   rm   r3  r5  r   r   r   r   r   r   r%   r%   r{   r&   r0    s"   
 



r0  c                       sZ   e Zd ZdZedd Zedd Zdd Zded	 d
e	e
d	f dd	f fddZ  ZS )r   r   c                 C   r\   r2   )r   r3  r^   r%   r%   r&   r  *  r)  zDictKeysVariable.set_itemsc                 C   r  )Nc                 S   r   r%   r   r   r%   r%   r&   r   1  r   z2DictKeysVariable.view_items_vt.<locals>.<listcomp>r3  r^   r%   r%   r&   r5  .     zDictKeysVariable.view_items_vtc                 C   r  r2   r/  r^   r%   r%   r&   r   3  r   zDictKeysVariable.python_typer!   r   rz   rR   c                    sl   |dkr| j ||||S |tv r-t|d ttfsttS tt| | j	|d j	S t
 ||||S )Nr   r   )r   r   r   r9   r   r   r   r   NotImplementedr  rw   r-  r{   r%   r&   r   6  s   
zDictKeysVariable.call_method)ri   rj   rk   r1  rm   r  r5  r   r   r   r   r   r   r%   r%   r{   r&   r   '  s    


r   c                   @   $   e Zd ZdZedd Zdd ZdS )r   r   c                 C   r\   r2   )r   r3  r^   r%   r%   r&   r5  L  r)  z DictValuesVariable.view_items_vtc                 C   r  r2   )r   r^   r%   r%   r&   r   P  r   zDictValuesVariable.python_typeNri   rj   rk   r1  rm   r5  r   r%   r%   r%   r&   r   H  s
    
r   c                   @   r:  )r   rB   c                 C   r  )Nc                 S   s    g | ]\}}t |j|gqS r%   )r
   r@   rS   r   r%   r%   r&   r   Z  r   z3DictItemsVariable.view_items_vt.<locals>.<listcomp>r7  r^   r%   r%   r&   r5  W  r8  zDictItemsVariable.view_items_vtc                 C   r  r2   )r   r^   r%   r%   r&   r   \  r   zDictItemsVariable.python_typeNr;  r%   r%   r%   r&   r   T  s
    
r   r2   )<rl   r   r   rE   r  r   collections.abcr   rH   typingr   r   Ztorch._subclasses.fake_tensorr   r   r   r	   r
   Zbytecode_transformationr   r   excr   r   Zguardsr   r   rx   r   utilsr   r   r   r   r   r   baser   r   Zconstantr   Ztorch._dynamo.codegenr   r.   r   r'   r-   r0   r3   rP   r   r   r   r   r%  r.  r0  r   r   r   r%   r%   r%   r&   <module>   sN    

1   gF	C  8*-!