§
    %Vjij  ã                   ót   — d Z ddlZddlZddlmZ ddlmZmZmZ ddl	m
Z
 ddlmZ d	„ Z G d
„ de¦  «        ZdS )aÁ  
This module implements variable tracking for TorchScript objects during Dynamo tracing.

The TorchScriptObjectVariable class provides specialized handling for TorchScript
objects with strong safety guarantees by:
- Enforcing method-call-only access to prevent unsafe attribute manipulation
- Converting graph breaks into hard errors via _raise_hard_error_if_graph_break
- Proper proxy and source tracking for TorchScript method calls
- Integration with higher-order operators for method call handling

Key safety features:
- Strict validation that only method calls are allowed (no direct attribute access)
- Immediate error reporting for potentially unsafe operations
- Proper source tracking for debugging and guard installation
- Safe handling of TorchScript object method calls through torchbind

The module ensures that TorchScript objects are handled safely during tracing
by limiting operations to known-safe patterns and failing fast for unsafe usage.
é    Né   )Úgraph_break_hints)Úunimplemented_v2ÚUnsafeScriptObjectErrorÚUnsupportedé   )ÚVariableTracker)ÚUserDefinedObjectVariablec                 ó   — d„ }|S )Nc                 óF   ‡ — t          j        ‰ ¦  «        ˆ fd„¦   «         }|S )Nc                  ód   •— 	  ‰| i |¤ŽS # t           $ r}t          |j        ¦  «        |‚d }~ww xY w©N)r   r   Úmsg)ÚargsÚkwargsÚeÚfns      €ú_/root/voice-cloning/.venv/lib/python3.11/site-packages/torch/_dynamo/variables/script_object.pyÚgraph_break_as_hard_errorzQ_raise_hard_error_if_graph_break.<locals>.deco.<locals>.graph_break_as_hard_error$   sN   ø€ ð<Ør˜4Ð* 6Ð*Ð*Ð*øÝð <ð <ð <Ý-¨a¬eÑ4Ô4¸!Ð;øøøøð<øøøs   ƒ ‹
/•*ª/)Ú	functoolsÚwraps)r   r   s   ` r   Údecoz._raise_hard_error_if_graph_break.<locals>.deco#   s9   ø€ Ý	Œ˜Ñ	Ô	ð	<ð 	<ð 	<ð 	<ñ 
Ô	ð	<ð )Ð(ó    © )Úreasonr   s     r   Ú _raise_hard_error_if_graph_breakr   "   s   € ð)ð )ð )ð €Kr   c                   óÒ   ‡ — e Zd ZU i Zeed f         ed<   edefd„¦   «         Z	e
d„ ¦   «         Zdˆ fd„Zd„ Z ed	¦  «        d
edefd„¦   «         Z ed	¦  «        d„ ¦   «         Zˆ xZS )ÚTorchScriptObjectVariableÚ_fake_script_object_cacheÚuser_clsc                 ó6   — t          |t          j        ¦  «        S r   )Ú
issubclassÚtorchÚScriptObject)Úclsr    s     r   Úis_matching_clsz)TorchScriptObjectVariable.is_matching_cls3   s   € å˜(¥EÔ$6Ñ7Ô7Ð7r   c                 ó   — t          | |fi |¤ŽS r   )r   )ÚproxyÚvalueÚoptionss      r   Úcreatez TorchScriptObjectVariable.create7   s   € å(¨°ÐAÐA¸ÐAÐAÐAr   ÚreturnNc                 ó€   •—  t          ¦   «         j        |fi |¤Ž || _        || j        j        j        d<   || _        d S )NÚexample_value)ÚsuperÚ__init__r(   ÚnodeÚmetaÚsource)Úselfr(   r)   r3   r   Ú	__class__s        €r   r0   z"TorchScriptObjectVariable.__init__;   sE   ø€ Ø‰ŒÔ˜Ð)Ð) &Ð)Ð)Ð)ØˆŒ
Ø05ˆŒ
ŒÔ˜_Ñ-ØˆŒˆˆr   c                 ó   — | j         S r   )r(   )r4   s    r   Úas_proxyz"TorchScriptObjectVariable.as_proxyA   s
   € ØŒzÐr   z<Dynamo cannot safely trace script object due to graph break.Únamec           
      óˆ  — ddl m} ddlm} ddlm} t          | j        |d ¦  «        }|€Ct          dd| j        › d	|› d
| j        › d|› dd|› d| j        › dgt          j
        ¢¬¦  «         t          |¦  «        st          dd| j        › d	|› ddg¬¦  «         |                     | || j        |¦  «        | |¬¦  «        S )Nr   )Úcall_torchbindr   )Ú
AttrSourcer   )Ú TorchHigherOrderOperatorVariablez.FakeScriptObject missing method implementationúvalue=ú	, method=zTorchScript object z doesn't define the method ú.zEnsure the method z is implemented in ©Úgb_typeÚcontextÚexplanationÚhintsz@Attempted to access non-callable attribute of TorchScript objectzWAttribute accesses of TorchScript objects to non-callable attributes are not supported.z-Use method calls instead of attribute access.)r3   Úscript_obj_varÚmethod_name)Ú!torch._higher_order_ops.torchbindr:   r3   r;   Úhigher_order_opsr<   Úgetattrr)   r   r   Ú
USER_ERRORÚcallableÚmake)r4   Útxr8   r:   r;   r<   Úmethods          r   Úvar_getattrz%TorchScriptObjectVariable.var_getattrD   sH  € ð 	EÐDÐDÐDÐDÐDà'Ð'Ð'Ð'Ð'Ð'ØFÐFÐFÐFÐFÐFå˜œ T¨4Ñ0Ô0ˆØˆ>ÝØHØ< ¤Ð<Ð<°dÐ<Ð<Ø`°$´*Ð`Ð`ÐY]Ð`Ð`Ð`àO¨ÐOÐOÀ$Ä*ÐOÐOÐOðå&Ô1ðð	ñ ô ð õ ˜ÑÔð 	ÝØZØ< ¤Ð<Ð<°dÐ<Ð<ØuàCðð	ñ ô ð ð 0×4Ò4ØØ:˜dœk¨4Ñ0Ô0ØØð	 5ñ 
ô 
ð 	
r   c                 óL   — t          dd| j        › d|› d|› ddg¬¦  «         d S )Nz'Weird method call on TorchScript objectr=   r>   zThis particular method call (zn) is not supported (e.g. calling `__setattr__`). Most method calls to TorchScript objects should be supported.zAvoid calling this method.r@   )r   r)   )r4   rM   r8   r   r   s        r   Úcall_methodz%TorchScriptObjectVariable.call_methodn   sa   € õ 	Ø=Ø8˜TœZÐ8Ð8°$Ð8Ð8ðP°ð Pð Pð Pð -ðð
	
ñ 
	
ô 
	
ð 
	
ð 
	
ð 
	
r   )r,   N)Ú__name__Ú
__module__Ú__qualname__r   ÚdictÚintÚ__annotations__ÚclassmethodÚtyper&   Ústaticmethodr+   r0   r7   r   Ústrr	   rO   rQ   Ú__classcell__)r5   s   @r   r   r   0   s  ø€ € € € € € ØHJÐ˜t CÐ)DÐ$DÔEÐJÐJÑJàð8 tð 8ð 8ð 8ñ „[ð8ð ðBð Bñ „\ðBðð ð ð ð ð ðð ð ð &Ð%ØFñô ð!
 Cð !
¨Oð !
ð !
ð !
ñô ð!
ðN &Ð%ØFñô ð
ð 
ñô ð
ð 
ð 
ð 
ð 
r   r   )Ú__doc__r   r#   Ú r   Úexcr   r   r   Úbaser	   Úuser_definedr
   r   r   r   r   r   ú<module>rb      sÈ   ððð ð( Ð Ð Ð à €€€à  Ð  Ð  Ð  Ð  Ð  Ø HÐ HÐ HÐ HÐ HÐ HÐ HÐ HÐ HÐ HØ !Ð !Ð !Ð !Ð !Ð !Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3ðð ð ðL
ð L
ð L
ð L
ð L
Ð 9ñ L
ô L
ð L
ð L
ð L
r   