Ë
    pPêjZ  ã                  ó¬   — d Z ddlmZ ddlmZ ddl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 dd	lmZ dd
lmZmZ dd„Zdd„Zdd„Zdd„Zdd„Zy)z=Functions to check that serialization round-tripped properly.é    )Úannotations)ÚIterable)ÚAny)ÚClassIR)ÚFuncDeclÚFuncIRÚFuncSignature)ÚModuleIRÚdeserialize_modules)Ú	DeserMaps)ÚRType)Úis_same_signatureÚis_same_typec                ó²   — t        | d«      r2| j                  D �ci c]  }t        | |«      sŒ|t        | |«      “Œ c}S t        | j                  «      S c c}w )NÚ__mypyc_attrs__)Úhasattrr   ÚgetattrÚdictÚ__dict__)ÚxÚks     úb/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/mypyc/test/test_serialization.pyÚget_dictr      sL   € ÜˆqÐ#Ô$Ø*+×*;Ñ*;ÖM Q¼wÀqÈ!½}�”7˜1˜a“=Ñ ÒMÐMä�A—J‘JÓÐùò Ns
   ›A­Ac                ód   — t        | «      }|j                  dd«       |j                  dd«       |S )zFGet a dict of function attributes safe to compare across serializationÚblocksNÚenv)r   Úpop)r   Úds     r   Úget_function_dictr      s,   € ä�‹€AØ‡E�Eˆ(�DÔØ‡E�Eˆ%�ÔØ€Hó    c                ó   — t        | «      t        |«      u sJ d|› �t        | «      t        |«      f«       ‚t        | t        t        t        f«      r$| j
                  |j
                  k(  s
J d|› �«       ‚yt        | t        «      r•t        | j                  «       «      t        |j                  «       «      k(  s
J d|› �«       ‚t        | j                  «       |j                  «       «      D ],  \  \  }}\  }}t        |||dz   «       t        ||||fz   «       Œ. yt        | t        «      rHt        | t        t        f«      s2t        t        | |«      «      D ]  \  }\  }}t        ||||fz   «       Œ yt        | t         «      rt#        | |«      s
J d|› �«       ‚yt        | t$        «      rt'        | |«      s
J d|› �«       ‚y| |k(  s
J d|› �«       ‚y)	a‰  Compare two blobs of IR as best we can.

    FuncDecls, FuncIRs, and ClassIRs are compared by fullname to avoid
    infinite recursion.
    (More detailed comparisons should be done manually.)

    Types and signatures are compared using mypyc.sametype.

    Containers are compared recursively.

    Anything else is compared with ==.

    The `trail` argument is used in error messages.
    zType mismatch at zName mismatch at zKeys mismatch at )ÚkeyszRType mismatch at zSignature mismatch at zValue mismatch at N)ÚtypeÚ
isinstancer   r   r   Úfullnamer   Úlenr"   ÚzipÚitemsÚassert_blobs_samer   ÚstrÚsetÚ	enumerater   r   r	   r   )r   ÚyÚtrailÚxkÚxvÚykÚyvÚis           r   r)   r)   "   s«  € ô  �‹7”d˜1“gÑÐNÐ"3°E°7Ð ;¼TÀ!»WÄdÈ1ÃgÐNÓNÐÜ�!”h¤¬Ð0Ô1Ø�z‰z˜QŸZ™ZÒ'ÐDÐ+<¸U¸GÐ)DÓDÑ'Ü	�A”tÔ	Ü�1—6‘6“8‹}¤ A§F¡F£H£Ò-ÐJÐ1BÀ5À'Ð/JÓJÐ-Ü"% a§g¡g£i°·±³Ó";ò 	5Ñ‰HˆR�‘h�r˜2Ü˜b " e¨iÑ&7Ô8Ü˜b " e¨r¨e¡mÕ4ñ	5ô 
�A”xÔ	 ¬°A¼¼S°zÔ)Bô %¤S¨¨A£YÓ/ò 	4‰KˆA‰x��BÜ˜b " e¨q¨d¡lÕ3ñ	4ä	�A”uÔ	Ü˜A˜qÔ!Ð?Ð%7¸°wÐ#?Ó?Ñ!Ü	�A”}Ô	%Ü   AÔ&ÐHÐ*@ÀÀÐ(HÓHÑ&à�AŠvÐ3Ð+¨E¨7Ð3Ó3‰vr    c                ó  — | j                   |j                   k(  sJ ‚| j                  |j                  k(  sJ ‚t        | j                  |j                  «      D ]:  \  }}t	        t        |«      t        |«      | j                   |j                   f«       Œ< t        | j                  |j                  «      D ]ƒ  \  }}t	        t        |«      t        |«      | j                   |j                   f«       t	        t        |j                  «      t        |j                  «      | j                   |j                   f«       Œ… t	        | j                  |j                  | j                   df«       | j                  |j                  k(  sJ ‚y)zÕAssert that two module IRs are the same (*).

    * Or rather, as much as we care about preserving across
    serialization.  We drop the actual IR bodies of functions but try
    to preserve everything else.
    Úfinal_namesN)r%   Úimportsr'   Úclassesr)   r   Ú	functionsr   Údeclr5   Údependencies)Úir1Úir2Úcls1Úcls2Úfn1Úfn2s         r   Úassert_modules_samerA   H   s+  € ð �<‰<˜3Ÿ<™<Ò'Ð'Ð'à�;‰;˜#Ÿ+™+Ò%Ð%Ð%ä˜#Ÿ+™+ s§{¡{Ó3ò Y‰
ˆˆdÜœ( 4›.¬(°4«.¸3¿<¹<ÈÏÉÐ:WÕXðYô ˜Ÿ™ s§}¡}Ó5ò `‰ˆˆSÜÜ˜cÓ"Ô$5°cÓ$:¸S¿\¹\È3Ï<É<Ð<Xô	
ô 	œ( 3§8¡8Ó,¬h°s·x±xÓ.@À3Ç<Á<ÐQT×Q]ÑQ]ÐB^Õ_ð	`ô �c—o‘o s§¡¸¿¹À}Ð8UÔVà×Ñ˜s×/Ñ/Ò/Ð/Ñ/r    c                ó  — | j                  «       D ��ci c]  \  }}||j                  «       “Œ }}}t        i i «      }t        ||«      }| j	                  «       |j	                  «       k(  sJ ‚| D ]  }t        | |   ||   «       Œ yc c}}w )zOCheck that we can serialize modules out and deserialize them to the same thing.N)r(   Ú	serializer   r   r"   rA   )Úirsr   ÚirÚ
serializedÚctxÚirs2s         r   Úcheck_serialization_roundtriprI   a   s‚   € à14·±³×=©¨¨2�!�R—\‘\“^Ñ#Ð=€JÑ=ä
�B˜Ó
€CÜ˜z¨3Ó/€DØ�8‰8‹:˜Ÿ™›Ò$Ð$Ð$àò -ˆÜ˜C ™F D¨¡GÕ,ñ-ùó >s   ”BN)r   r   Úreturnúdict[str, Any])r   r   rJ   rK   )r   r   r-   r   r.   ztuple[Any, ...]rJ   ÚNone)r;   r
   r<   r
   rJ   rL   )rD   zdict[str, ModuleIR]rJ   rL   )Ú__doc__Ú
__future__r   Úcollections.abcr   Útypingr   Úmypyc.ir.class_irr   Úmypyc.ir.func_irr   r   r	   Úmypyc.ir.module_irr
   r   Úmypyc.ir.opsr   Úmypyc.ir.rtypesr   Úmypyc.sametyper   r   r   r   r)   rA   rI   © r    r   ú<module>rX      sB   ðÙ Cõ
 #å $Ý å %ß <Ñ <ß <Ý "Ý !ß :ó óó#4óL0ô2	-r    