+
    &jt                        R t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHtHt ^ RIH	t	H
t
 ^ RIHtHtHt ^ RIt^ RIHt ^RIHtHtHt ^RIHtHtHtHtHtHtHtHtH t H!t!H"t"H#t#H$t$ ^RI%H&t& ^R	I'H(t(H)t)H*t*H+t+ ^R
IH,t,H-t- ^RI.H/t/H0t0 ^RI1H2t2H3t3 ^RI4H5t5 ^RI6H7t7 ^RI8H9t9H:t:H;t;H<t< ^RI=H>t> ]'       d   ^ RI?H@t@ ^RIAHBtB ]P                   ! R R4      4       tD ! R R4      tER# )a  
This module provides utilities for generating Python bytecode in PyTorch's Dynamo system.
It includes functionality for:
- Constructing bytecode sequences for Python operations
- Managing stack operations and variable tracking
- Handling graph outputs and their conversions
- Supporting different Python versions (3.11+, 3.12+, 3.13+)
- Converting high-level operations to low-level bytecode instructions
- Managing constant loading and attribute access
- Supporting function creation and closure handling
N)Counterdeque)CallableIterable)AnyTYPE_CHECKINGUnion)
OrderedSet)configgraph_break_hintsutils)add_push_nulladd_push_null_call_function_excreate_binary_subscrcreate_build_tuplecreate_call_functioncreate_call_function_excreate_call_methodcreate_dup_topcreate_instructioncreate_load_constcreate_load_methodcreate_rot_nInstruction)unimplemented)
AttrSourceChainedSourceDictGetItemSourceSource)is_safe_constantrot_n_helper)ValueMutationExistingVariableTracker)4ContextlibContextManagerLocalGeneratorObjectVariableLocalGeneratorObjectVariable)NNModuleVariable)TorchScriptObjectVariable)NumpyNdarrayVariableSymNodeVariableTensorVariableUnspecializedPythonVariable)TensorWithTFOverrideVariable)GraphArg)InstructionTranslatorBasec                   ,   a  ] tR t^Bt o V 3R ltRtV tR# )GraphOutputEntryc                2   < V ^8  d   Qh/ S[ ;R&   S[;R&   # )   indexvariable)intr"   )format__classdict__s   "m/Users/jameslopez/projects/CWCArchive/cwc-podcast/.venv/lib/python3.14/site-packages/torch/_dynamo/codegen.py__annotate__GraphOutputEntry.__annotate__B   s     J        N)__name__
__module____qualname____firstlineno____annotate_func____static_attributes____classdictcell__r6   s   @r7   r/   r/   B   s      r:   r/   c                     a  ] tR t^Ht o RtRdV 3R lR lltRR/V 3R lR lltV 3R	 lR
 ltV 3R lR ltReV 3R lR llt	RfV 3R lR llt
V 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR  ltV 3R! lR" ltV 3R# lR$ ltV 3R% lR& ltV 3R' lR( ltV 3R) lR* ltV 3R+ lR, ltV 3R- lR. ltReV 3R/ lR0 lltV 3R1 lR2 ltV 3R3 lR4 ltV 3R5 lR6 ltV 3R7 lR8 ltV 3R9 lR: ltV 3R; lR< lt V 3R= lR> lt!V 3R? lR@ lt"V 3RA lRB lt#RgV 3RC lRD llt$V 3RE lRF lt%V 3RG lRH lt&V 3RI lRJ lt'V 3RK lRL lt(V 3RM lRN lt)V 3RO lRP lt*V 3RQ lRR lt+V 3RS lRT lt,V 3RU lRV lt-V 3RW lRX lt.V 3RY lRZ lt/V 3R[ lR\ lt0V 3R] lR^ lt1V 3R_ lR` lt2V 3Ra lRb lt3Rct4V t5R# )h	PyCodegenz4
Helper class uses for constructing Python bytecode
Nc                   < V ^8  d   QhRRRS[ P                  P                  R,          RS[R,          RS[S[S[,          S[3,          R,          RS[S[S[3,          R,          RR/# )	r1   txr-   rootNgraph_output_vartempvarsoverridden_sourcesreturn)torchnnModulestrdictr"   r   r   )r5   r6   s   "r7   r8   PyCodegen.__annotate__M   s     Q Q'Q hhoo$Q *	Q
 /45<Q !047Q 
Qr:   c                   W n         R V n        \        P                  ! 4       V n        / V n        . V n        T;'       g    / V n        Wn        W0n	        V P                  P                  P                  V n        V P                  P                  V n        V P                  P                  P                  V n        RV n        T;'       g    / V n        R # )NT)rH   top_of_stackcollectionsr   usesgraph_outputs_outputrJ   rG   rI   outputcode_optionscell_and_freevarsnew_varvalue_from_sourcerK   )selfrG   rH   rI   rJ   rK   s   &&&&&&r7   __init__PyCodegen.__init__M   s     	=A7B7J7J7L	:<*,
 >F^^ 0 GGNN77!%!:!:ww~~--'+ 9K8P8Pbr:   r]   Tc                :   < V ^8  d   QhRS[ S[,          RS[RR/# )r1   stack_valuesr]   rL   N)listr   bool)r5   r6   s   "r7   r8   rR   j   s)     * * I*=A*	*r:   c                   V P                   pV ;P                   V,          un          V P                  V4       W0n         R #   Y0n         i ; iN)r]   foreach)r^   rb   r]   prevs   &&$ r7   restore_stackPyCodegen.restore_stackj   s?     %%"33	*LL&%)"T"s   A   Ac                0   < V ^8  d   QhRS[ S[,          /# r1   rL   )rc   r"   )r5   r6   s   "r7   r8   rR   t   s     A A4#8 Ar:   c                r    V P                   P                  4        Uu. uF  qP                  NK  	  up# u upi rf   )rW   valuesr3   )r^   xs   & r7   graph_output_varsPyCodegen.graph_output_varst   s-    $($6$6$=$=$?@$?q

$?@@@s   4c                <   < V ^8  d   QhRS[ S[S[R3,          RR/# )r1   valuer,   rL   N)r   r"   r   )r5   r6   s   "r7   r8   rR   w   s)     9 9?FJ>?9	9r:   c                D    VP                  V 4      pVe   Q RV 24       hR # )Nzreconstruct!=None )reconstruct)r^   rs   ress   && r7   call_reconstructPyCodegen.call_reconstructw   s+     %{8088{r:   c                <   < V ^8  d   QhRS[ . R3,          RS[RR/# )r1   gen_fnNcall_function_exrL   )r   rd   )r5   r6   s   "r7   r8   rR   }   s.      r4x(<@	r:   c                   \        V P                  4      p\        P                  R8  d   V P	                  4        V! 4        V P                  VR pV P                  VR1 V'       d&   V P                  P                  \        V4      4       M$V P                  P                  \        V4      4       \        P                  R8  d   V P	                  4        R# R# )a`  
`gen_fn` generates instructions via PyCodegen methods
that push a single callable to the stack.

`add_push_null` pushes a NULL to the stack before or after the
instructions generated by `gen_fn`, depending on Python version.

Will attempt to use the NULL push bit for instructions
with such bits (LOAD_GLOBAL 3.11+, LOAD_ATTR 3.12+, LOAD_SUPER_ATTR).
N      )lenrX   sysversion_info	clear_tosextendr   r   )r^   rz   r{   old_lenadded_instss   &&&  r7   r   PyCodegen.add_push_null}   s     dll#g% NNll78,LL"LL >{ KLLLk :;w&NN 'r:   c                H   < V ^8  d   QhRS[ S[,          R,          RS[RR/# )r1   rs   Nallow_cacherL   )r"   r   rd   )r5   r6   s   "r7   r8   rR      s4     f" f"$v-4f"CGf"	f"r:   c           
       a aa	a
 Vf   Q h\        V\        4      '       Ed>   S P                  P                  W4      pVRJ g   Q R4       hS P                  VJ d&   S P
                  P                  \        4       4       R# S P                  P                  V4      eE   S P
                  P                  S P                  S P                  V,          4      4       VS n        R# S P                  V;;,          ^,          uu&    S P                  V4       VS P                  9   d5   S P
                  P                  \        4       4       S P%                  V4       VS n        R# \        V\&        4      '       g   Q hS P
                  o
S P(                  oV'       d   S P                  VJ d   S
P                  \        4       4       R# S P                  P                  V4      e;   S
P                  S P                  S P                  V,          4      4       VS n        R# VP+                  4       '       d9   \        V\,        4      '       d#   \        R	R
V 2R. \         P.                  OR7       VP0                  ey   V'       dq   VP+                  4       '       d   \        V\2        4      '       gE   \        VP4                  \6        4      '       g   S P8                  '       d   S ! VP0                  4      # VP;                  4       '       dP   \=        VP?                  4       4      '       d1   S
P                  S PA                  VP?                  4       4      4       EM\        V\B        4      '       d   S PE                  V4      o	S PG                  V 3R l4       S PI                  SS	,          PJ                  4       S
P                  S PM                  VPO                  S PP                  4      RR7      4       S
PS                  \U        ^R4      4       EMM\        V\V        4      '       d   VPY                  4       \Z        J d   S PP                  P\                  '       gt   S PE                  VP_                  S PP                  \`        Pb                  4      4      o	R VV	V
V 3R llpS PG                  V4       S
PS                  \U        ^ R4      4       EM\        V\d        \V        \f        \h        \j        34      '       Ed   S PE                  V4      o	\        V\h        4      '       dU   S PG                  V 3R l4       S PI                  SS	,          PJ                  4       S
PS                  \U        ^R4      4       EM\        V\f        4      '       dM   VPl                  '       d;   R VV	V
V 3R llpS PG                  V4       S
PS                  \U        ^ R4      4       EMS PI                  SS	,          PJ                  4       EMc\        V\n        4      '       d   VPp                  Ps                  R4      pV^ ,          S Pt                  R,          9   d2   S
P                  S P                  V^ ,          4      4       VR,          pM:S Pv                  f   Q hS
P                  S Py                  S Pv                  4      4       V F#  pS
P                  S P{                  V4      4       K%  	  M~S P                  V;;,          ^,          uu&    S P                  V4       V'       dF   VS P                  9   d5   S P
                  P                  \        4       4       S P%                  V4       VS n        R#   \         d=    \        R\        T4      R\        T4       RT R2. \         P"                  OR7        ELi ; i  \         d;   p\        R\        T4      RT R2R.\         P|                  ORNTR7        Rp?LRp?ii ; i)a  
Generate code such that top-of-stack (TOS) is set to value.

`allow_cache` controls the behavior in the following manner. `value` can
either be a VariableTracker or a Source.

If `value` is a `Source`, `allow_cache` must be True (invariant asserted
below). If the source was reconstructed earlier, we will reuse the
generated code by loading from top of stack or tempvars.

If `value` is a `VariableTracker`, we have the following cases:

1) `allow_cache=True`
    a) If the value.source is not None, we will emit the code based on
    `value.source` to handle aliasing.
    b) If value.source is None (example reconstructing a local list
    returned by the compiled function), we will reconstruct the variable
    tracker (w/o any source) to emit bytecode that generates a new
    python object.

    In both cases of value.source being None or not, if the value was
    reconstructed earlier, we will reuse the generated code by loading from
    top of stack or tempvars.

2) `allow_cache=False` - This is a special case (allow_cache defaults to
True).
    a) If the value.source is not None, we reconstruct the variable
    tracker and emit a new python object. You might wonder what about
    aliasing? The place where we use this config also has the followup
    code where the original python object is assigned to this new python
    value to handle aliasing (check side_effects.py and search for
    allow_cache=False).

    b) If value.source is None, this is not allowed

Notable effects:
1. `self.top_of_stack` will be set to `value`, if we don't codegen
   `value` based on source.
2. `self.uses[value]` will increment, unless (a). we codegen via
    `top_of_stack` or cached `tempvars`, or (b). `value` has special VT
    types like `NNModuleVariable`, etc.
NTz#allow_cache must be True for Sourcez:Reconstruction failure: source.reconstruct not implementedz6Dynamo has no bytecode reconstruction implemented for z
 variable .)gb_typecontextexplanationhintsz%reconstructing @contextmanager objectzobject: zMReturning a @contextmanager object from a compiled function is not supported.c                  D   < S P                  \        P                  R 4      # )to_subclassload_import_fromr   r<   r^   s   r7   <lambda>$PyCodegen.__call__.<locals>.<lambda>&  s    --ennmLr:   addFc                    V ^8  d   QhRR/# r1   rL   Nr;   )r5   s   "r7   r8   (PyCodegen.__call__.<locals>.__annotate__@  s     = =D =r:   c                     < SP                  S S,          P                  4       SP                  SP                  R 4      4       R# itemNload_graph_outputr2   appendcreate_load_attrrW   graph_outputs_keyrY   r^   s   r7   rz   "PyCodegen.__call__.<locals>.gen_fn@  s4    &&}5F'G'M'MNd33F;<r:   c                  D   < S P                  \        P                  R 4      # )to_numpy_helperr   r   s   r7   r   r   T  s    D11%..BSTr:   c                    V ^8  d   QhRR/# r   r;   )r5   s   "r7   r8   r   Z  s     A A Ar:   c                     < SP                  S S,          P                  4       SP                  SP                  R 4      4       R# r   r   r   s   r7   rz   r   Z  s4    **=9J+K+Q+QRMM$"7"7"?@r:   co_varnames:   NNzReconstruction failurezJDynamo has no bytecode reconstruction implemented for sourceless variable zIf Dynamo is attempting to trace a return statement and your code is attempting to return a variable that Dynamo cannot reconstruct, then remove it from the return statement.zReport an issue to PyTorch if you need reconstrtuction support. Note that objects that don't have reconstruction rules may be fundamentally unreconstructable.)r   r   r   r   from_exc)?
isinstancer   rK   getrT   rX   r   r   rJ   create_loadrV   rw   NotImplementedErrorr   rP   typer   
DYNAMO_BUG	add_cacher"   rW   is_realizedr#   SUPPORTABLEsourcer$   mutation_typer!   r]   is_python_constantr   as_python_constantr   r+   add_graph_outputr   r   r2   create_load_globalglobal_mangled_class_namerG   r   r   r(   python_typefloatexport	as_tensorrM   float64r)   r*   r'   r&   need_unwrapr%   
module_keysplitrZ   rH   create_load_const_uncheckedr   CAUSED_BY_EARLIER_GRAPH_BREAK)r^   rs   r   r   rz   partsparterW   r   rY   s   f&&     @@@r7   __call__PyCodegen.__call__   sT   Z    eV$$,,00>F$&M(MM&  E)##N$45}}  (4##D$4$4T]]65J$KL$*!IIf"%%f- &##N$45v& &D%1111**  E)n./}}  '3d..t}}U/CDE$)!:G$
 $
 ?"5'*k&22	 LL$!!##
5:V(W(W( 5..0EFF)))ELL))##%%*:5;S;S;U*V*VMM$001I1I1KLM;<< $ 5 5e <L ""=1B#C#I#IJMM''33DGG< (  MM.q%89uo..!!#u,GGNNN !% 5 57!= = v&MM.q%89+$)	
 	
 !% 5 5e <%!566""T &&}5F'G'M'MN21e<=E#>??EDUDUDUA A ""6*21e<=&&}5F'G'M'MN/00$$**3/EQx4,,];;d..uQx89b	yy,,,d>>tyyIJd33D9:  IIe!%%e, u5##N$45u%!Q ' XK"XY]^dYeXffpqwpxxy z9-889	 l ' 4J"lmrlsst ud +HHW	  s+    ] 7^( A^%$^%(_-30_((_-c                &   < V ^8  d   QhRS[ RS[/# r1   rs   rL   )r"   r4   )r5   r6   s   "r7   r8   rR     s     ! !o !# !r:   c                    \        VP                  4       4      pW P                  9  d-   \        \	        V P                  4      V4      V P                  V&   V# rf   )idas_proxyrW   r/   r   )r^   rs   r   s   && r7   r   PyCodegen.add_graph_output  sN    u~~/0$6$664DD&&'5D01 ! r:   c                $   < V ^8  d   QhRS[ RR/# )r1   r2   rL   Nr4   )r5   r6   s   "r7   r8   rR     s     3 3s 3t 3r:   c                   V P                   pV P                  f   Q hVP                  V P                  V P                  4      4       VP                  V P	                  V4      4       VP                  V P                  4       4       R # rf   )rX   rI   r   r   r   r   )r^   r2   rY   s   && r7   r   PyCodegen.load_graph_output  sf    $$000d&&t'<'<=>d,,U34d//12r:   c                4   < V ^8  d   QhRS[ S[,          RR/# )r1   rs   rL   N)r"   r   )r5   r6   s   "r7   r8   rR     s      4 47 4D 4r:   c                    V P                  4       pW P                  V&   V P                  P                  V P	                  V4      4       R # rf   )r\   rJ   rX   r   create_store)r^   rs   vars   && r7   r   PyCodegen.add_cache  s6    lln"eD--c23r:   c                D   < V ^8  d   QhRS[ S[S[,          ,          RR/# )r1   itemsrL   N)r   r"   r   )r5   r6   s   "r7   r8   rR     s%      Xo&>? D r:   c                (    V F  pV ! V4       K  	  R # rf   r;   )r^   r   is   && r7   rg   PyCodegen.foreach  s    AG r:   c                    < V ^8  d   QhRS[ /# rl   r   )r5   r6   s   "r7   r8   rR     s     & &k &r:   c                    \        4       # rf   )r   r   s   &r7   r   PyCodegen.create_binary_subscr  s    #%%r:   c                <   < V ^8  d   QhRS[ RS[RS[S[,          /# )r1   namers   rL   )rP   r   rc   r   )r5   r6   s   "r7   r8   rR     s'     9 9# 9c 9d;>O 9r:   c                    \         P                  ! RRV4      pV P                  P                  pW9   d#   \	        W1,          4      \	        V4      8X  g   Q hMW#V&   V P                  VRR7      .# )zStore value in a new globalz[^a-zA-Z0-9_]+_Tr   )resubrG   	f_globalsr   r   )r^   r   rs   r   s   &&& r7   setup_globally_cachedPyCodegen.setup_globally_cached  sc    vv'd3GG%%	io&"U)333#dO''$'788r:   c                   < V ^8  d   QhRR/# r   r;   )r5   r6   s   "r7   r8   rR     s     ! !4 !r:   c                    R V n         R # rf   )rT   r   s   &r7   r   PyCodegen.clear_tos  s
     r:   c                $   < V ^8  d   QhRS[ RR/# )r1   instrL   Nr   )r5   r6   s   "r7   r8   rR     s      + $ r:   c                    \        V\        4      '       g   Q hV P                  P                  V4       V P	                  4        R # rf   )r   r   rX   r   r   )r^   r   s   &&r7   append_outputPyCodegen.append_output  s1    $,,,,D!r:   c                4   < V ^8  d   QhRS[ S[,          RR/# )r1   instsrL   Nrc   r   )r5   r6   s   "r7   r8   rR     s       4#4  r:   c                    \         ;QJ d    R  V 4       F  '       d   K   RM	  RM! R  V 4       4      '       g   Q hV P                  P                  V4       V P                  4        R# )c              3   B   "   T F  p\        V\        4      x  K  	  R # 5irf   )r   r   ).0ro   s   & r7   	<genexpr>*PyCodegen.extend_output.<locals>.<genexpr>  s     =u!:a--us   FTN)allrX   r   r   )r^   r   s   &&r7   extend_outputPyCodegen.extend_output  sE    s=u=sss=u=====E"r:   c                0   < V ^8  d   QhRS[ S[,          /# rl   r   )r5   r6   s   "r7   r8   rR     s      ${"3 r:   c                    V P                   # rf   )rX   r   s   &r7   get_instructionsPyCodegen.get_instructions  s    ||r:   c                &   < V ^8  d   QhRS[ RS[/# r1   r   rL   rP   r   )r5   r6   s   "r7   r8   rR     s     < < < <r:   c                ^    WP                   R ,          9   g   Q V R24       h\        RVR7      # )r    missing	LOAD_FASTargvalrZ   r   r^   r   s   &&r7   r   PyCodegen.create_load  s2    ((77JD69JJ7!+d;;r:   c                &   < V ^8  d   QhRS[ RS[/# r  r  )r5   r6   s   "r7   r8   rR     s     : : : :r:   c                x    WP                  4       9   g   Q h\        P                  R8  d   RMRp\        W!R7      # )r~   r	  LOAD_CLOSUREr
  r}   )r[   r   r   r   )r^   r   	inst_names   && r7   create_load_closurePyCodegen.create_load_closure  s6    --////#&#3#3w#>KN	!)99r:   c                &   < V ^8  d   QhRS[ RS[/# r  r  )r5   r6   s   "r7   r8   rR     s     = =c =k =r:   c                H    WP                  4       9   g   Q h\        R VR7      # )
LOAD_DEREFr
  r[   r   r  s   &&r7   create_load_derefPyCodegen.create_load_deref  s$    --////!,t<<r:   c                &   < V ^8  d   QhRS[ RS[/# r  r  )r5   r6   s   "r7   r8   rR     s     = = = =r:   c                ^    WP                   R ,          9   g   Q V R24       h\        RVR7      # )r   r  
STORE_FASTr
  r  r  s   &&r7   r   PyCodegen.create_store  s2    ((77JD69JJ7!,t<<r:   c                &   < V ^8  d   QhRS[ RS[/# r  r  )r5   r6   s   "r7   r8   rR     s     > >s >{ >r:   c                H    WP                  4       9   g   Q h\        R VR7      # )STORE_DEREFr
  r  r  s   &&r7   create_store_derefPyCodegen.create_store_deref  s$    --////!-==r:   c                ,   < V ^8  d   QhRS[ RS[RS[/# )r1   r   r   rL   )rP   rd   r   )r5   r6   s   "r7   r8   rR     s"     > >s > >+ >r:   c                    V'       d&   V P                   P                  P                  V4       WP                  R ,          9   g   Q V R24       h\	        RVR7      # )co_namesz not in co_namesLOAD_GLOBALr
  )rG   rY   update_co_namesrZ   r   )r^   r   r   s   &&&r7   r   PyCodegen.create_load_global  sL    GGNN**40((44O>N6OO4!-==r:   c                &   < V ^8  d   QhRS[ RS[/# r   r   r   )r5   r6   s   "r7   r8   rR     s     ( (s ({ (r:   c                    \        V4      # rf   r   r^   rs   s   &&r7   r   PyCodegen.create_load_const  s     ''r:   c                &   < V ^8  d   QhRS[ RS[/# r   r+  )r5   r6   s   "r7   r8   rR     s     7 7 7 7r:   c                    \        VR R7      # )F)checkedr-  r.  s   &&r7   r   %PyCodegen.create_load_const_unchecked  s     66r:   c                $   < V ^8  d   QhRS[ RR/# r1   r   rL   NrP   )r5   r6   s   "r7   r8   rR     s     5 5 5 5r:   c                    V P                   P                  P                  V4       V P                  \	        V4      4       R # rf   )rG   rY   r(  r   r   r  s   &&r7   load_methodPyCodegen.load_method  s,    &&t,-d34r:   c                $   < V ^8  d   QhRS[ RR/# )r1   nargsrL   Nr   )r5   r6   s   "r7   r8   rR     s     6 6 6 6r:   c                :    V P                  \        V4      4       R # rf   )r   r   )r^   r;  s   &&r7   call_methodPyCodegen.call_method  s    -e45r:   c                &   < V ^8  d   QhRS[ RS[/# r  r  )r5   r6   s   "r7   r8   rR     s     < <S <[ <r:   c                    WP                   R ,          9  d!   V P                   R ;;,          V3,          uu&   \        RVR7      # )r&  	LOAD_ATTRr
  r  r  s   &&r7   r   PyCodegen.create_load_attr  s8    ((44j)dW4)!+d;;r:   c                $   < V ^8  d   QhRS[ RR/# r5  r6  )r5   r6   s   "r7   r8   rR     s     8 8c 8d 8r:   c                F    V P                  V P                  V4      4       R # rf   )r   r   r  s   &&r7   	load_attrPyCodegen.load_attr  s    40067r:   c                6   < V ^8  d   QhRS[ RS[S[,          /# )r1   namesrL   )rP   rc   r   )r5   r6   s   "r7   r8   rR     s$     J Js JtK/@ Jr:   c                j    VP                  R 4       Uu. uF  q P                  V4      NK  	  up# u upi )r   )r   r   )r^   rH  r   s   && r7   create_load_attrsPyCodegen.create_load_attrs  s.    8=C8HI8H%%d+8HIIIs   0c                &   < V ^8  d   QhRS[ RS[/# r  r  )r5   r6   s   "r7   r8   rR     s     = =c =k =r:   c                    WP                   R ,          9  d!   V P                   R ;;,          V3,          uu&   \        RVR7      # )r&  
STORE_ATTRr
  r  r  s   &&r7   create_store_attrPyCodegen.create_store_attr  s8    ((44j)dW4)!,t<<r:   c                $   < V ^8  d   QhRS[ RR/# r5  r6  )r5   r6   s   "r7   r8   rR     s     9 9s 9t 9r:   c                F    V P                  V P                  V4      4       R # rf   )r   rO  r  s   &&r7   
store_attrPyCodegen.store_attr  s    411$78r:   c          	      B   < V ^8  d   QhRS[ RS[RS[RS[S[,          /# )r1   fn_name	push_nullnum_on_stackrL   )rP   rd   r4   rc   r   )r5   r6   s   "r7   r8   rR     s2      '+;>	k	r:   c           	        . pV'       d   \         P                  R8  dv   VP                  \        V P	                  VRR7      4      4       V^ 8  dB   VP                  . V P                  V^,           4      OV P                  V^,           4      O4       V# VP                  V P	                  VRR7      .V P                  V^,           4      O4       V# )z6Load the global fn_name on the stack num_on_stack downTr   r~      )r   r   r   r   r   rot_n)r^   rV  rW  rX  rY   s   &&&& r7   load_function_namePyCodegen.load_function_name  s     ))W4MM-(?(?T(?(RSTaL1$45L1$45  MM++G+>ZZq 01 r:   c                6   < V ^8  d   QhRS[ RS[S[,          /# )r1   nrL   )r4   rc   r   )r5   r6   s   "r7   r8   rR     s       s tK0 r:   c                     \        V4      #   \         dM    \        T4      T P                  \	        T4      4      .\        ^4      O\        RR4      O\        RTR7      Nu # i ; i)r1   FUNPACK_SEQUENCEarg)r   AttributeErrorr   r   r    r   r   )r^   r`  s   &&r7   r\  PyCodegen.rot_n  sw    
	?" 	 #1%00aA a )6	
 ##4!< 	s   
 AA$#A$c                0   < V ^8  d   QhRS[ S[,          /# rl   r   )r5   r6   s   "r7   r8   rR     s     
 
${+ 
r:   c                    \         P                  R8  g   Q hV P                  R 4      .\         P                  R8  d   \        R^R7      3MRO\	        ^ R4      O\        R4      N# )	r~   c                      R # rf   r;   r;   r:   r7   r   $PyCodegen.pop_null.<locals>.<lambda>  s    Tr:   SWAPrc  FPOP_TOPrZ  r}   r;   )r   r   r   r   r   r   s   &r7   pop_nullPyCodegen.pop_null  sw     7***,,\:


 ##w. $F24

 "!U+

 y)

 
	
r:   c                   < V ^8  d   QhRR/# r   r;   )r5   r6   s   "r7   r8   rR   (  s     : : :r:   c                :    V P                  \        R 4      4       R# )rl  N)r   r   r   s   &r7   pop_topPyCodegen.pop_top(  s    -i89r:   c                *   < V ^8  d   QhRS[ RS[RR/# )r1   r;  rW  rL   N)r4   rd   )r5   r6   s   "r7   r8   rR   +  s'     M M3 M4 MD Mr:   c                <    V P                  \        WR 7      4       R# ))rW  N)r   r   )r^   r;  rW  s   &&&r7   call_functionPyCodegen.call_function+  s    /KLr:   c                   < V ^8  d   QhRR/# r   r;   )r5   r6   s   "r7   r8   rR   .  s     - - -r:   c                8    V P                  \        4       4       R # rf   )r   r   r   s   &r7   dup_topPyCodegen.dup_top.  s    >+,r:   c                $   < V ^8  d   QhRS[ RR/# r1   varnamerL   Nr6  )r5   r6   s   "r7   r8   rR   1  s     7 7S 7T 7r:   c                F    V P                  V P                  V4      4       R # rf   )r   r   r^   r}  s   &&r7   storePyCodegen.store1  s    4,,W56r:   c                $   < V ^8  d   QhRS[ RR/# r|  r6  )r5   r6   s   "r7   r8   rR   4  s     < <# <$ <r:   c                F    V P                  V P                  V4      4       R # rf   )r   r  r  s   &&r7   
load_derefPyCodegen.load_deref4  s    411':;r:   c                >   < V ^8  d   QhRS[ RS[P                  RR/# )r1   rV  coderL   N)rP   typesCodeType)r5   r6   s   "r7   r8   rR   7  s-       nn 
	r:   c                   V P                   pVP                  V P                  V4      4       \        P                  R8  d!   VP                  V P                  V4      4       \        P                  R8  d)   VP                  \        R4      \        R^R7      .4       MVP                  \        R^R7      4       V P                  4        R# )a#  Creates a closure with code object `code`.

Expects the TOS to be the tuple of cells to use for this closure.
TOS will be popped to create the closure.
Args:
    - fn_name: name of the function
    - code: code object of the function
        (does not include the tuple of cells on the TOS)
MAKE_FUNCTIONSET_FUNCTION_ATTRIBUTErc  NrZ  r}   )rX   r   r   r   r   r   r   r   )r^   rV  r  rY   s   &&& r7   make_function_with_closure$PyCodegen.make_function_with_closure7  s     d,,T23g%MM$009:w&MM&7&'?TJ MM,_$GHr:   c                :   < V ^8  d   QhRS[ P                  RS[/# )r1   modrL   )r  
ModuleTyper   )r5   r6   s   "r7   r8   rR   V  s!     > >U-=-= >+ >r:   c                V   V P                   P                  pVP                  p\        P                  ! RRVP
                  4      pVP                  VR4      VJ d   V P                  VRR7      # RV 2pV P                   P                  P                  WQ4      pV P                  VRR7      # )zD
Generate a LOAD_GLOBAL instruction to fetch a given python module.
z^.*[.] NTr   
___module_)	rG   rY   global_scoper   r   r<   r   r   install_global_by_id)r^   r  rY   r  r   prefixglobal_names   &&     r7   create_load_python_module#PyCodegen.create_load_python_moduleV  s     **vviS\\2D$'3.**4T*::dV$ggnn99&F&&{&==r:   c                $   < V ^8  d   QhRS[ RR/# )r1   r   rL   N)r   )r5   r6   s   "r7   r8   rR   c  s     ) )v )$ )r:   c                H    WP                   9  d   RV P                   V&   R# R# )z=
Mark a source as a temp variable, so that it can be reused.
N)rJ   )r^   r   s   &&r7   mark_source_tempPyCodegen.mark_source_tempc  s!     &$(DMM&! 'r:   c                $   < V ^8  d   QhRS[ RR/# )r1   rV  rL   Nr6  )r5   r6   s   "r7   r8   rR   j  s#     KH KH KH KHr:   c                  a a S P                  S P                  VR4      4       S P                  P                  P                  pR R loR V3R llpT! \        V Uu. uF  qDP                  f   K  VP                  NK   	  up4      S 4       Rp\        P                  '       dR   S P                  V 3R l4       S P                  \        ^ R4      4       S P                  4       pS P                  V4       V Fi  pVP                  '       dD   S P                  V 3R	 l4       S P                  V4       S P                  \        ^R4      4       KX  S P                  V4       Kk  	  \        P                  '       dh   S P                  V 3R
 l4       Vf   Q hS P                  S P                  V4      .4       S P                  \        ^R4      4       S P!                  4        S P                  \        \#        V4      R4      4       R# u upi )z2Call the generated code function stored in fn_nameTc                F    V ^8  d   QhR\         R\        \         ,          /# )r1   r   rL   )r   rc   )r5   s   "r7   r8   8PyCodegen.make_call_generated_code.<locals>.__annotate__p  s     	" 	"6 	"d6l 	"r:   c                    . p\        V \        4      '       d   VP                  V P                  4       \        V \        4      '       d<   \        V P
                  \        4      '       d   VP                  V P
                  4       V# rf   )r   r   r   baser   r2   r   )r   nested_sourcess   & r7   extract_nested_sourcesBPyCodegen.make_call_generated_code.<locals>.extract_nested_sourcesp  sc    +-N&-00%%fkk2&"344f: : %%fll3!!r:   c                J    V ^8  d   QhR\         \        ,          R\        RR/# )r1   sourcescodegenrL   N)r   r   rE   )r5   s   "r7   r8   r  z  s+     	G 	G%- 	G) 	GPT 	Gr:   c                    < \        4       pV '       dT   V P                  4       pW29   d   VP                  V4       K1  VP                  V4       V P	                  S! V4      4       K[  R # rf   )r	   popleftr  r   r   )r  r  seen_sourcescurrent_sourcer  s   &&  r7   collect_temp_sources@PyCodegen.make_call_generated_code.<locals>.collect_temp_sourcesz  sW    /9|L!(!2!1,,^<   05nEF r:   Nc                  D   < S P                  \        P                  R 4      # )record_pregraph_bytecode_enterr   r   s   r7   r   4PyCodegen.make_call_generated_code.<locals>.<lambda>  s    --NN$Dr:   Fc                  n   < S P                  S P                  \        4      S P                  R 4      .4      # )_as_tensor_fullprec)r   r  rM   r   r   s   r7   r   r    s2    D.. ::5A 112GHr:   c                  D   < S P                  \        P                  R 4      # )record_pregraph_bytecode_exitr   r   s   r7   r   r    s    --NN$Cr:   )r   r]  rG   rY   	graphargsr   r   r
   record_runtime_overheadr   r   r\   r  pass_arg_as_tensorrw   r   rq  r   )r^   rV  r  r  rd  cm_varr  s   f&    @r7   make_call_generated_code"PyCodegen.make_call_generated_codej  s   4227DABGGNN,,		"	G 	G  	M#jj:3::MNPT	
 )))
 3Au=>\\^FJJvC%%%"" %%c*""#75#AB%%c*  )))
 %%% 0 0 89:3Au=>LLN/IFGU Ns   H	2H	c                &   < V ^8  d   QhRS[ RS[/# )r1   module_namerL   r  )r5   r6   s   "r7   r8   rR     s     E Ec Ek Er:   c                    \        R VR7      # )IMPORT_NAMEr
  r   )r^   r  s   &&r7   create_import_namePyCodegen.create_import_name  s    !-DDr:   c                *   < V ^8  d   QhRS[ RS[ RR/# )r1   r  object_namerL   Nr6  )r5   r6   s   "r7   r8   rR     s"      C c d r:   c                    \        V P                  P                  V4      V4      pV P                  V4       V ! V4       R # rf   )r   rG   import_sourcer  )r^   r  r  r   s   &&& r7   r   PyCodegen.load_import_from  s4    DGG11+>L
 	f%Vr:   c          	      R   < V ^8  d   QhRS[ RS[S[,          RS[RS[S[,          /# )r1   r;  kw_namesrW  rL   )r4   r   rP   rd   rc   r   )r5   r6   s   "r7   r8   rR     s6     
 

$,SM
>B
	k	
r:   c                   \         P                  R8  dY   \        W4      pVR	,          P                  R8X  g   Q hVP	                  R	V P                  V4      4       \        RVR7      VR	&   V# \         P                  R
8  dc   \        W4      p\         P                  R8  d   R	pRpMRpRpWE,          P                  V8X  g   Q h\        RVR7      pVP	                  WW4       V# V P                  V4      \        RVR7      .# )r~   CALLCALL_KWrc  PRECALLKW_NAMESr
  CALL_FUNCTION_KWr}   rZ  )r~      )r   r   r   opnameinsertr   r   )r^   r;  r  rW  rY   idxexpected_instkw_names_insts   &&&&    r7   create_call_function_kw!PyCodegen.create_call_function_kw  s     w&)%;F":$$...MM"d44X>?+I5AF2JM()%;F7* & );%%666.z(KMMM#-M""8,1u=
 	
r:   c                &   < V ^8  d   QhRS[ RS[/# r   )objectr   )r5   r6   s   "r7   r8   rR     s     ? ?6 ?k ?r:   c                    \        R VR7      # )DELETE_FASTr
  r  r.  s   &&r7   create_deletePyCodegen.create_delete  s    !->>r:   )rX   r[   rZ   rI   rW   r\   rK   rH   rJ   rT   rG   rV   r]   )NNNN)F)T)    )6r<   r=   r>   r?   __doc__r_   ri   rp   rw   r   r   r   r   r   rg   r   r   r   r   r   r  r   r  r  r   r"  r   r   r   r8  r=  r   rE  rJ  rO  rS  r]  r\  rm  rq  ru  ry  r  r  r  r  r  r  r  r   r  r  rA   rB   rC   s   @r7   rE   rE   H   s    Q Q:*DH* *A A9 9 >f" f"P! !3 34 4
 & &9 9! ! 
 
 < <: :
= == => >> >( (7 75 56 6< <
8 8J J= =
9 9 . 
 
 : :M M- -7 7< < >> >) )KH KHZE E 
 
4? ?r:   rE   )Fr  rU   dataclassesr   r   r  r   r   collections.abcr   r   typingr   r   r   torch.nnrM   torch.utils._ordered_setr	   r  r
   r   r   bytecode_transformationr   r   r   r   r   r   r   r   r   r   r   r   r   excr   r   r   r   r   r   r   r    variables.baser!   r"   variables.functionsr#   r$   variables.nn_moduler%   variables.script_objectr&   variables.tensorr'   r(   r)   r*   variables.torch_functionr+   torch._dynamo.variables.builderr,   symbolic_convertr-   	dataclassr/   rE   r;   r:   r7   <module>r     s   
   	 
  & . , ,  / . .     H H 1 B 2 >  C 8;   
V
? V
?r:   