NL idZddlmZddlZddlZddlZddlmZddlm Z m Z ddl m Z m Z mZmZmZmZmZmZddlmZddlmZdd lmZdd lmZdd lmZmZdd lm Z m!Z!dd l"m#Z#ddl$m%Z%m&Z&m'Z'm(Z(ddl)m*Z*m+Z+m,Z,ddl-m.Z.m/Z/m0Z0ddl1m2Z2m3Z3m4Z4m5Z5ddl6m7Z7ddl8m9Z9m:Z:m;Z;mZ>m?Z?m@Z@ddlAmBZBddlCmDZDddlEmFZFmGZGmHZHddlImJZJmKZKddlLmMZMddlNmOZOddlPmQZQddlRmSZSddlTmUZUmVZVddlWmXZXddlYmZZZddl[m\Z\dd l]m^Z^dd!l_m`Z`dd"lambZbdd#lcmdZddd$lemfZfdd%lgmhZheieje e ekfZlejelZmejeiekekfZnGd&d'ZoGd(d)eZp d= d>d*Zq d?d+Zr d@d,Zs dAd-ZtdBd.ZudCd/Zv dDd0Zw dEd1Zx dFd2ZydGd3ZzdHd4Z{dId5Z|Gd6d7Z}e d8Z~dJd9ZdKd:ZdLd;ZdMd<Zy)NzHGenerate C code for a Python C extension module from Python source code.) annotationsN)Iterable)OptionalTypeVar) BuildResult BuildSourceStatebuild compute_hashcreate_metastoreget_cache_namessorted_components) CompileError)FileSystemCache)MypyFile)Options)PluginReportConfigContext) hash_digest json_dumps)c_string_initializer)EmitterEmitterContextHeaderDeclarationc_array_initializer)generate_classgenerate_class_reusegenerate_class_type_decl)generate_native_functionnative_function_doc_initializernative_function_header) generate_legacy_wrapper_functiongenerate_wrapper_functionlegacy_wrapper_function_headerwrapper_function_header)Literals)IS_FREE_THREADED MODULE_PREFIXPREFIXRUNTIME_C_FILESTOP_LEVEL_NAMETYPE_VAR_PREFIXshared_lib_nameshort_id_from_name)Errors)FuncIR)ModuleIR ModuleIRsdeserialize_modules) DeserMaps LoadLiteral)RType)build_ir)Mapper) load_type_map) NameGenerator exported_name)CompilerOptions)do_copy_propagation)insert_exception_handling)do_flag_elimination)insert_event_trace_logging)lower_ir)insert_ref_count_opcodes) insert_spills)insert_uninit_checksceZdZdZddZy)MarkedDeclarationz(Add a mark, useful for topological sort.c ||_d|_y)NF) declarationmark)selfrHrIs ^/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/mypyc/codegen/emitmodule.py__init__zMarkedDeclaration.__init__hs& N)rHrrIboolreturnNone)__name__ __module__ __qualname____doc__rLrMrKrFrFes 2rMrFcDeZdZdZ dfd ZddZddZxZS) MypycPluginaPlugin for making mypyc interoperate properly with mypy incremental mode. Basically the point of this plugin is to force mypy to recheck things based on the demands of mypyc in a couple situations: * Any modules in the same group must be compiled together, so we tell mypy that modules depend on all their groupmates. * If the IR metadata is missing or stale or any of the generated C source files associated missing or stale, then we need to recompile the module so we mark it as stale. ct||i|_|D]/\}}td|D}|D]}||f|j|<1||_t ||_y)Nc34K|]}|jywN)module).0sources rK z'MypycPlugin.__init__..sAvV]]A)superrL group_mapsortedcompiler_optionsr metastore) rJoptionsrcgroupssourcesnamemodulesid __class__s rKrLzMypycPlugin.__init__yss !BD# 5MGTAAAG 5&*G_r" 5 5 !1)'2rMc(|j|j|j}}}||jvry|s|j|St |||j \}}}t |||j } |jj|}|jj|} tj| } t|| dk7ry| djD]o\}} ttjj!|j"j$|d5} | j} dddt }| |k7soy|j|S#t$rYywxYw#1swY;xYw#t$rYywxYw)N meta_hash src_hashesrb)rjpathis_checkrar reget_ir_cache_namerdreadFileNotFoundErrorjsonloadsritemsopenosjoinrc target_dir)rJctxrjrprq meta_path_ir_path meta_jsonir_jsonir_datahashfcontents real_hashs rKreport_config_datazMypycPlugin.report_config_datas !VVSXXs||(D T^^ #>>"% %*"dDLLA 1a#Bdll; ++I6Inn))'2G**W% y !W[%9 9 ",/557 JD$ "'',,t'<'<'G'GNPTU(YZ vvxH($H-Iy  ~~b!!5!   $(($  s<86E)/>F-E8>F) E54E58F =F FFc|jj|jdgfdDcgc]}d|df c}Scc}w)N )ragetfullname)rJfilerjs rKget_additional_depszMypycPlugin.get_additional_depss<'+~~'9'9$--$PR'TUV'WXR XXXs =)rerrcr<rfGroupsrOrP)r|rrOz#tuple[str | None, list[str]] | None)rrrOzlist[tuple[int, str, int]])rQrRrSrTrLrr __classcell__)rks@rKrWrWms9  3 32A 3KQ 3  3/"bYrMrWc |jsJdt||||t|||g}|jrt |j|S)Nz!strict_optional must be turned on)rgre alt_lib_pathfscache extra_plugins)strict_optionalr rWerrorsr)rgrercrfrrresults rKparse_and_typecheckrs\  " "G$GG " !"7,.s-Baff-Br_r)verboseprintformatrzr7graphtypes num_errorsvaluesclassesenv_user_function functionsrDr>rBrC log_tracer@rAr=r?) sccrmapperrcrrienv_user_functionsr[clsfns rKcompile_scc_to_irrsK, n##DII-Bc-B$BCDsFLL&,,@PRXYG 1.."@>> @C$$.!s M2Bfnn>>>Ms"%) r4rrrjratreeallload_scc_from_cacherupdate) rrrcr deser_ctxrirrj scc_statessttreesfreshscc_irs ` rKcompile_modules_to_irr s"b!IG!. #1452fll2&5 5#-WR&:J:J1JrwwWW MMM  vvy A&uff>NPVWF NN6 " # N6WsCC& C3Cc <|Dcic]:\}}|D]0}|j|j|jj2<}}}}t|Dcgc]\}}|Dcgc]}|jc}!c}}}|j} i} |D]o\} } | Dcic]*}|j|vr|j||j,} }| sg| | <Ct | || |j | |}|j| | <q| Scc}}}wcc}wcc}}}wcc}w)zCompile a collection of ModuleIRs to C source text. Returns a dictionary mapping group names to a list of (file name, file text) pairs. )separate)r[rxpathr:rGroupGeneratorragenerate_c_for_modules)rfrirrrcrgr~r] source_pathsnamesctext group_sources group_name group_modules generators rKcompile_ir_to_cr+sJ! GQ   v||FMM2888L AGHH:7Ag .F&-- .H!** E68E%+ ?! z( }}' MM76==1 1   "E*  " <V5E5EuN^ &<<>j ? L9 /H s#?D D !D 4D /D D cHt|||\}}}|jddS)Nz .meta.jsonz.ir.json)r replace)rjrprer}r~s rKrrrrVs)%b$8OIq!   \: 66rMcXt|j|j|jSrZ)rrrjrre)states rKget_state_ir_cache_namer[s UXXu{{EMM BBrMc i}|jD]'\}}|Dcic]\}}|t|c}}||<)|jD]\} } |j| } t| | j|j j \} } } |j jj| }t| }| jt|||| d}|j jj|t||j jjycc}}w#t$rYwxYw)aWrite out the cache information for modules. Each module has the following cache information written (which is in addition to the cache information written by mypy itself): * A serialized version of its mypyc IR, minus the bodies of functions. This allows code that depends on it to use these serialized data structures when compiling against it instead of needing to recompile it. (Compiling against a module requires access to both its mypy and mypyc data structures.) * The hash of the mypy metadata cache file for the module. This is used to ensure that the mypyc cache and the mypy cache are in sync and refer to the same version of the code. This is particularly important if mypyc crashes/errors/is stopped after mypy has written its cache but before mypyc has. * The hashes of all the source file outputs for the group the module is in. This is so that the module will be recompiled if the source outputs are missing. )irrmrnN)rwr rr rrrerdrsOSErrorr serializerwritercommit)rirrarhashesrhfilesrdatarjr[rr}r~ meta_datanewpathrs rK write_cacher_s84F{{}J eCHIZT4l400It JmmoE F \\" )"bhh8N8NO 1a 0055i@I*"-""$$Y/ 2/    &&w 70CD#E& NN##%-J   sD;%E E  E c (|Dcic]h}|jtj|jjj t |j|jdj}}t||}t||||Scc}w)zfLoad IR for an SCC of modules from the cache. Arguments and return are as compile_scc_to_ir. r) rrurvrrdrsrrr3r9)rrrr|k cache_dataris rKrrs   DJJ NN $ $ ) )*A&,,qzzBZ*[ \  J "*c2G&#s# NsA-Bc|Dcic]\}}|D]}|j|}}}}t|}|jjj ddd|jj t ||||} |jdkDrigtifSt|| |||} t| ||| | |D cgc] \} } | |  c} } |fScc}}}wcc} } w)a=Compile Python module(s) to the source of Python C extension modules. This generates the source code for the "shared library" module for each group. The shim modules are generated in mypyc.build. Each shared library module provides, for each module in its group, a PyCapsule containing an initialization function. Additionally, it provides a capsule containing an export table of pointers to all the group's functions and static variables. Arguments: result: The BuildResult from the mypy front-end compiler_options: The compilation options errors: Where to report any errors encountered groups: The groups that we are compiling. See documentation of Groups type above. Returns the IR of the modules and a list containing the generated files for each group. zN)r[scoperer) r[r8rrset_filererrrr) rrcrrfgrouplib_namer]rarrirr~rhs rKcompile_modules_to_crs*AG[[_UHUZ[6([[I[ I F NN""$dFNN4J4J#$FF4DfMG 12vbz!! FGVV=M NEE2 7WQU4[7 ??!\ 8s C?Cctt|j|dd|jj|j |j<|j tk7r|jst||jrZtt||jd|jjt|j|jz<ytt||jd|jjt|j|jz<yyyN;T needs_export)rr!declcontext declarationsnative_function_namerhr+internalis_fastcall_supported capi_versionr%rr)cnamer$)remitters rKgenerate_function_declarationrsJ[ !"''7 3 4A6TKGOO  !=!=bgg!FG ww.  W%9%9 :M^*2w}}=>a@NGOO ( ("((7==2I)I JN_1"gmmDEQGNGOO ( ("((7==2I)I J *5 rMc`d|vr|j|d|dS|j|d|S)zHGiven a C decl and its name, modify it to be a declaration to a pointer.(z(*)*)r)rrhs rK pointerizers= d{||DBtfA,//||DAdV*--rMcdtjj|jdddS)z>Given a group name, return the relative directory path for it..Nr)ryseprzsplit)rs rK group_dirrs' 66;;z'',Sb1 22rMceZdZ ddZeddZeddZddZddZd dZ d!dZ d!dZ d"d Z d#d Z d$d Z d%d Z d$d Z d%dZd&dZd'dZdd d(dZd)dZd*dZd)dZd+dZ d,dZd-dZd.dZd/dZy)0rc||_||_t||||_||_g|_||_|du|_||_|j|_ t|_ y)aGenerator for C source for a compilation group. The code for a compilation group contains an internal and an external .h file, and then one .c if not in multi_file mode or one .c file per module if in multi_file mode. Arguments: modules: (name, ir) pairs for each module in the group source_paths: Map from module names to source file paths group_name: The name of the group (or None if this is single-module compilation) group_map: A map of modules to their group names names: The name generator for the compilation compiler_options: Mypyc specific options, including multi_file mode N) rirrrr simple_initsruse_shared_librc multi_filer'multi_phase_init)rJrirrrarrcs rKrLzGroupGenerator.__init__sg. (%eZC  46$(4 0*55!1rMcN|jrdt|jzSdS)Nr~)rr;rJs rK group_suffixzGroupGenerator.group_suffixs!7;s]4??33NBNrMcr|jr*dt|jjddzSdS)Nr~rrr)rr;rrs rKshort_group_suffixz!GroupGenerator.short_group_suffixs2FJoos]4??#8#8#=b#ABB][]]rMc g}|jxr |j}|jjD]3}|jD]"}t ||j j$5t|j }|jjr tD]}|jd|d|jd|jd|jd|jd|}|j|jjD]\}}|rSt|j }|jd|jd|jd|jd|j!|||j#|||j%|j&||j(D]} | j*st-| |||j/||||jD]}|jt1|||j2|||j4t6k7sB|j8rO|jt;||j<rt?|||j2||tA|||j2|||sdtC|d}|jE|djG|jHft|j } | jd |jJd | jd |jJd | jd | jd |jjLr| jdt|j } | jd|jJd | jd|jJd | jd | jd | jd|jd| j| jd| j|jjD]\}}|jO||jP| |j(D]+} tS| || | | jTstW| || | -|jY||jZ| |jD]}t]|| t_|j j`D]}} tC| } tC| jcdd}| jedjgthjjjGtm| d|dd| d| d|jo}|}|jq||j|D]}|jrr| n| }|jrsp|jdd|jtdg|jtdd|jvr|jd|jvu|jd|jt|jd|jt|jxr9|jjzr|j}| ||j|| jd| jd|jxrtm|jxnd}|thjjjG|d|jddjG|jHfthjjjG|d|jddjG| jHfthjjjG|d|jddjG| jHfgzS)Nz #include ""z#include "__nativez.h"z#include "__native_internal __native_z.crz#ifndef MYPYC_NATIVE_Hz#define MYPYC_NATIVEz#include z#include z#include z#ifndef MYPYC_NATIVE_INTERNALz#define MYPYC_NATIVE_INTERNALzint CPyGlobalsInit(void);rrz #include <{}>z.hzstruct export_table_z exports_rzextern rrz#endif__native__native_internal)@rrrirrcollect_literalsrliteralsrrcinclude_runtime_filesr* emit_linergenerate_literal_tablesrwdeclare_moduledeclare_internal_globalsdeclare_importsimportsr is_ext_classrgenerate_module_defrrrhr+rrrr#r"r;appendrz fragmentsrdepends_on_native_internaldeclare_finals final_namesrreuse_freed_instancerdeclare_type_varstype_var_namesrrb group_depsr emit_linesrryrprtoposort_declarationsgenerate_globals_initis_typerdefnrrgenerate_export_tablegenerate_shared_lib_init)rJ file_contentsrr[r base_emitterrhr module_nameclext_declarationsrlibelib short_lib sorted_declsrHdecls output_dirs rKrz%GroupGenerator.generate_c_for_moduless> ((bA$$dBGGG4E4E,F%GHA IL#4<<0""%9$:K:K9LB#OP""%9$:K:K9LB#OP""#89""#56  ; ;  & &'E Ft||, !>t?P?P>QQSTU!>t?P?P>QQSTU4512!3D4K4K3LCPQ :; #'<<#5#5#7 @ K    V-?-? Nnn V(W6F U**(W6F U V  " ";0E0E| T&& @-b,? @ @$,,112 C %D%ciinR&89I  # #&&rww||IcNiPY{Z\D]'^_&tfIdV1=  113  ""7+' 4K(3(;(;$E&&   7;+;+;A+>*?!@X;CSCSTUTVCWX##&G&& (8(89&G&& (8(89   +"2"23 4 ??$$--**+;WE  ) )' 2""8,x(37??Yt/  Z8D4K4K3LB)OP))*   Z+N[rMc|jj}|jdd|jd|j D]F\}}|j s|j tdj|j|H|j d|jdd|jd|j D]'\}}|j s|j d|d )|j dy ) aGenerate the declaration and definition of the group's export struct. To avoid needing to deal with deeply platform specific issues involving dynamic library linking (and some possibly insurmountable issues involving cyclic dependencies), compiled code accesses functions and data in other compilation groups via an explicit "export struct". Each group declares a struct type that contains a pointer to every function and static variable it exports. It then populates this struct and stores a pointer to it in a capsule stored as an attribute named 'exports' on the group's shared library's python module. On load, a group's init function will import all of its dependencies' exports tables using the capsule mechanism and copy the contents into a local copy of the table (to eliminate the need for a pointer indirection when accessing it). Then, all calls to functions in another group and accesses to statics from another group are done indirectly via the export table. For example, a group containing a module b, where b contains a class B and a function bar, would declare an export table like: struct export_table_b { PyTypeObject **CPyType_B; PyObject *(*CPyDef_B)(CPyTagged cpy_r_x); CPyTagged (*CPyDef_B___foo)(PyObject *cpy_r_self, CPyTagged cpy_r_y); tuple_T2OI (*CPyDef_bar)(PyObject *cpy_r_x); char (*CPyDef___top_level__)(void); }; that would be initialized with: static struct export_table_b exports = { &CPyType_B, &CPyDef_B, &CPyDef_B___foo, &CPyDef_bar, &CPyDef___top_level__, }; To call `b.foo`, then, a function in another group would do `exports_b.CPyDef_bar(...)`. rzstruct export_tablez { };zstatic struct export_tablez exports = {&,N) rrr#rrwrrrrzr)rJ decl_emitter code_emitterr3rhrs rKr(z$GroupGenerator.generate_export_tablesX$$11&9$:K:K9LC$PQ++- OJD$  &&z$))DII2F'MN O t$&@ARAR@SS`$ab++- 4JD$  &&4&{3 4 t$rMc|jJ|jt|jjdd}|j d|ddddd d |j j r<|j d jt|jd d ddddd dd |jD]}t|}|jrd}d}|jd|dnd}d}|jd|d|j dj||t|j||d d dd||dddd dd t|jjD]j}t|}|j djt|dj||t|d|d d dd!j|"d l|j d#d$d%d|jr|j d&|d'd(|d)d*d+d,d-|jrd.nd} |j d/|d0d1d2t|jd3d4d5| d6d7|jr|jd8|d6|jd-|jr|j d9|d:d;|d<dy|j d9|d:d=d>d?d@ddA|d<dBdCddD|dEdFdCdd@dy)GaGenerate the init function for a shared library. A shared library contains all the actual code for a compilation group. The init function is responsible for creating Capsules that wrap pointers to the initialization function of all the real init functions for modules in this shared library as well as the export table containing all the exported functions and values from all the modules. These capsules are stored in attributes of the shared library. Nrrzstatic int exec_(PyObject *module){zint res;zPyObject *capsule;zPyObject *tmp;rz6capsule = PyCapsule_New(&exports, "{}.exports", NULL);zif (!capsule) {z goto fail;}z9res = PyObject_SetAttrString(module, "exports", capsule);zPy_DECREF(capsule);zif (res < 0) {CPyExec_exec_zextern int CPyExec_z (PyObject *);CPyInit_init_zextern PyObject *CPyInit_z(void);z7capsule = PyCapsule_New((void *){}{}, "{}.{}{}", NULL);z&res = PyObject_SetAttrString(module, "z ", capsule);zGtmp = PyImport_ImportModule("{}"); if (!tmp) goto fail; Py_DECREF(tmp);zHstruct export_table_{} *pexports_{} = PyCapsule_Import("{}.exports", 0);zif (!pexports_) {zDmemcpy(&exports_{group}, pexports_{group}, sizeof(exports_{group}));)r return 0;fail: return -1;zstatic PyModuleDef_Slot slots_[] = {z{Py_mod_exec, exec_},K{Py_mod_multiple_interpreters, Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED},"{Py_mod_gil, Py_MOD_GIL_NOT_USED}, {0, NULL},rSrzstatic PyModuleDef module_def_z = {PyModuleDef_HEAD_INIT,z .m_name = "",z.m_doc = NULL,z .m_size = rUz.m_methods = NULL,z.m_slots = slots_PyMODINIT_FUNC PyInit_z(void) {z$return PyModuleDef_Init(&module_def_);zstatic PyObject *module = NULL;z if (module) {zPy_INCREF(module);zreturn module;z%module = PyModule_Create(&module_def_zif (!module) { return NULL;z if (exec_z(module) < 0) {zPy_DECREF(module);)rrr-rr#rcrrrir;rrbrr") rJr short_namemodrhcapsule_func_prefixcapsule_name_prefixregroupsizes rKr)z'GroupGenerator.generate_shared_lib_inits***$T__5;;C@D zl*< =        ) )   HOO#DOO4"K%  << C %D$$&0#&-#!!$7v]"KL&0#&-#!!$=dV7"KL   IPP'#DOO4' "89L8MdVS_`% !  :DLL334 E"5)F   Y``#E*[aaFOE$:!-V]] ^  $ ;sC    0 GD&zl#6]4  ))qr,ZL > $/$//:;2 > a       1*Q? @$    ( I>6zl"E    ( I>1$ 7 |2F J<'78$ ! rMc|jdddddd|jd|jD]\}}|j|d|dd }|jd |d d d |jddd y)Nrzint CPyGlobalsInit(void)rZzstatic int is_initialized = 0;zif (is_initialized) return 0;z CPy_Init(); = rzbCPyLit_Str, CPyLit_Bytes, CPyLit_Int, CPyLit_Float, CPyLit_Complex, CPyLit_Tuple, CPyLit_FrozenSetz&if (CPyStatics_Initialize(CPyStatics, z) < 0) {rcr[zis_initialized = 1;ra)r#rr)rJrsymbolfixuprs rKr%z$GroupGenerator.generate_globals_inits  &  , +    -(!.. 6MFE   E7!4 5 6v4VHI F VY  0+sCrMcF|jj|}|j|||||j|||||jr |j sF|jr|j ||||j||||j|||yy)zFEmit the PyModuleDef struct for a module and the module init function.N) r private_nameemit_module_methodsemit_module_exec_funcrremit_module_def_slotsemit_module_def_structemit_module_init_func)rJrr,r[ module_prefixs rKrz"GroupGenerator.generate_module_defs 22;?    +}fM ""7KO%%$*=*=$$**7M;O  ' 'm L  & &w ] K +>rMcR|d}dt|}|jd|d|jd|dtjdk\r|jdtjd k\r|jd |jd |jd y) N_slotsr\zstatic PyModuleDef_Slot rdz{Py_mod_exec, re) rf)r rgrhrS)r;rsys version_info)rJrrr,rh exec_names rKr|z$GroupGenerator.emit_module_def_slotss '}[9:; 4TF'BCOI;c:;   w &   ]    w &   B C,'$rMc .|jd|d|jD]}|j|jtk(r#t |j|j j|j}t||jrd}nd}t|}|jdj||j|jt|||jd|jd |jy) z3Emit module methods (the static PyMethodDef table).zstatic PyMethodDef zmodule_methods[] = {N METH_FASTCALL METH_VARARGSze{{"{name}", (PyCFunction){prefix}{cname}, {flag} | METH_KEYWORDS, PyDoc_STR({doc}) /* docstring */}},)rhrprefixflagdocz{NULL, NULL, 0, NULL}rS)rr class_namerhr+r.r shortnamelinerrr rrrr)) rJrr,rr[rrhrrs rKrzz"GroupGenerator.emit_module_methodss / >STU"" B}}(BGG~,E%bggrww/@/@"''JD$R)=)=>&%1"5C   :&RXXgmm%R S++ ;ID#!--dK@K  c4 @--c2E    Sq9 :  ; 1A    !B/ 0 1,'#rMc8|jsd|d}ndt|d}|j|d|jr,|d}|j d|d|j dyd t|}|j ||}|jd |d d |dd |dd|j|d|dd|dd|jd |d|dd|j d |d|jdd|jdy)Nrkz(void)zPyObject *CPyInit_rZr[zreturn PyModuleDef_Init(&rlr[r\zif (r`z Py_INCREF(zreturn rz = PyModule_Create(&zmodule);rrrrz) != 0)rbrm)rr;r#rrr)rJrr,rrHdef_name exec_funcrs rKr~z$GroupGenerator.emit_module_init_funcDs_""2;-vFK.}[/I.J&QK;,  '/H    9(2F G   c " }[9:; 88gN =/ &r *m_A &    o1- IM?* 5  T)Am_GDFVWGM?!457N33rMct|jD]G}|jtk(s|j d|j |j dddyy)z8Generate call to function representing module top level.zchar result = z();zif (result == 2)rN)reversedrrhr+r#rr)rJr[rrs rKrz&GroupGenerator.generate_top_level_callms_6++, Bww.(""$W%A%A"''%J$K3O&$  rMcgi|jjjD]\}}t|d|<dfd D] }| S)a~Topologically sort the declaration dict by dependencies. Declarations can require other declarations to come prior in C (such as declaring structs). In order to guarantee that the C output will compile the declarations will thus need to be properly ordered. This simple DFS guarantees that we have a proper ordering. This runs in O(V + E). Fc|}|jry|jjD] }| j|jd|_y)NT)rIrH dependenciesr)rhrchild_toposort_visitmarked_declarationsrs rKrz=GroupGenerator.toposort_declarations.._toposort_visitsU&t,Dyy))66 '& ' MM$** +DIrM)rhstrrOrP)rrrwrF)rJrvrhrrrs @@@rKr$z$GroupGenerator.toposort_declarationsyso<>LL--335 ADAq%6q%%@  " A ( "D D ! " rMNr8cd|vr||}n|jdd\}}||d|}|sd}n |d|dg}||jjvr(t|d||jj|<yy)N[rrur)r')rrrr)rJ type_spacedrhr9baseabr's rKr@zGroupGenerator.declare_globals k !!]4&)D$$S!,DAqSas#DDfC }A./D t||00 0.?4& QU.VDLL % %d + 1rMcL|jd|}|jd|y)Nr PyObject *rr@)rJr,rrs rKrz'GroupGenerator.declare_internal_globalss$)))[A  L+6rMc8|j|dzdtS)N __internalr)rr()rJr,rs rKrz*GroupGenerator.module_internal_static_names"";#=tM"ZZrMc||jvr&|j||}|jd|d|j|dt}|jd||j j |dfy)Nz CPyModule *NULLr8rPy_None)rirr@rr(rr)rJr,rinternal_static_namers rKrzGroupGenerator.declare_modules{ $,, &#'#C#CKQX#Y    /CQW  X))+tM)R  M;7   +y!9:rMc6|D]}|j||yrZ)r)rJimpsrimps rKrzGroupGenerator.declare_importss! .C   W - .rMc |D]c\}}|j||}t|j||d|j||||gd|jj |<eyr)rr ctype_spacedfinal_definitionrr)rJr[rrrhrrs rKrzGroupGenerator.declare_finalssv% ID#!--dF;K8I'',-k]!<&&vtS'BC!9GOO ( ( 5 rMcz|j||}|j|}|j||d|dS)Nrur)rc_initializer_undefined_valuer)rJr[rhrrr undefineds rKrzGroupGenerator.final_definitionsG))$7 99#> &&s+,[MYKqIIrMcL|j|d}|jd|y)Nrr)rJ identifierrrvs rKdeclare_static_pyobjectz&GroupGenerator.declare_static_pyobjects$$$Z6 L&1rMc|D]H}|j||t}td|dd|dgd|jj|<Jy)NrrrrFr)rr,rrr)rJr[r!rrhrs rKr z GroupGenerator.declare_type_varss_" D!--dF?-SK8I[M+k](34"9GOO ( ( 5 rM)rizdict[str, ModuleIR]rzdict[str, str]r str | Noneradict[str, str | None]rr:rcr<rOrP)rOr)rOzlist[tuple[str, str]])rOrP)rVrrWrrOrP)rrrOrP)rrr,rr[r1rOrP)rrrrr,rrOrP) rrr,rrrr[r1rOrP)rrr,rrrrOrP)r[r1rrrOrP)rOzlist[HeaderDeclaration])rrrhrr9rrOrP)r,rrrrOrP)r,rrrrOr)rz Iterable[str]rrrOrP)r[rrzIterable[tuple[str, RType]]rrrOrP) r[rrhrrr6rrrOr)rrrrrOrP)r[rr!z list[str]rrrOrP)rQrRrSrLpropertyrrrrr(r)r%rr|rzr}r{r~rr$r@rrrrrrrr rUrMrKrrs$1$$1%$1 $1 ) $1  $1*$1 $1LOO^^J X\@:%xM^D* L  /2 AD  *-0ADNV 4-0AD (II-0IADINVI IV' ' -0' AD' ' R >IMWW&)W;EW W 7[ ;.  (C NU   J 2rMrTcVgtdfd D] }| S)zUTopologically sort a dict from item to dependencies. This runs in O(V + E). cx|vry|D] }| j|j|yrZ)radd)itemrdepsrvisitvisiteds rKrztoposort..visitsA 7? $Z E %L   d DrM)rrrOrP)set)rrrrrs` @@@rKtoposortrs: FeG d  MrMc||j0|jdk(ry|jdk7xr|jdk7Sy)N__call__TrL__new__)rrh)rrs rKrrs; }} 77j ww*$=I)== rMc|jD]?}|jD].}t|ts|j |j 0Ay)zStore all Python literal object refs in fn. Collecting literals must happen only after we have the final IR. This way we won't include literals that have been optimized away. N)blocksops isinstancer5record_literalvalue)rrblockops rKrrsF 2)) 2B"k*''1 22rMcg}|jd|D]"}|jdt|zdz$|jddj|S)Nz{ z z, r[r)rrrz) componentsrss rKrBrBsZ F MM% @ f3A66>?@ MM# 776?rM)NN)rgzlist[BuildSource]rerrcr<rfrrzFileSystemCache | NonerrrOr) rlist[MypyFile]rrrr8rcr<rr/rOr2) rrrr8rcr<rr/rOr2) rfrrir2rrrr8rcr<rO'dict[str | None, list[tuple[str, str]]])rjrrprrerrOr)rr rOr) rir2rrrarrrrOrP) rrrrrr8r|r4rOr2) rrrcr<rr/rfrrOz,tuple[ModuleIRs, list[FileContents], Mapper])rr0rrrOrP)rrrhrrOr)rrrOr)rzdict[T, set[T]]rOzlist[T])rr0rztuple[int, int]rOrN)rr0rr&rOrP)rz list[bytes]rOr)rT __future__rruryrcollections.abcrtypingrr mypy.buildrrr r r r r r mypy.errorsr mypy.fscacher mypy.nodesr mypy.optionsr mypy.pluginrr mypy.utilrrmypyc.codegen.cstringrmypyc.codegen.emitrrrrmypyc.codegen.emitclassrrrmypyc.codegen.emitfuncrr r!mypyc.codegen.emitwrapperr"r#r$r%mypyc.codegen.literalsr& mypyc.commonr'r(r)r*r+r,r-r. mypyc.errorsr/mypyc.ir.func_irr0mypyc.ir.module_irr1r2r3 mypyc.ir.opsr4r5mypyc.ir.rtypesr6mypyc.irbuild.mainr7mypyc.irbuild.mapperr8mypyc.irbuild.preparer9 mypyc.namegenr:r; mypyc.optionsr< mypyc.transform.copy_propagationr=mypyc.transform.exceptionsr> mypyc.transform.flag_eliminationr?mypyc.transform.log_tracer@mypyc.transform.lowerrAmypyc.transform.refcountrBmypyc.transform.spillrCmypyc.transform.uninitrDtuplelistrGroupr FileContentsrFrWrrrrrrrrrrrrrrrrrrrBrUrMrKrsN # $$   %( 3-6^^bb  ,    #GG/!''/6)@@@@*=/7, d;#./ eE#s(O$ LY&LYh'+#   &   $   *9 9 9 9& 9  9  9x !';JTZ<( ( ( (  ( & ( - (V7 C2& 2& 2&%2& 3 2&  2&j !,6<CL$%@ %@+:%@DJ%@TZ%@1%@P .3 m m ` CL0 2rM