NL iIFUdZddlmZddlZddlZddlmZddlm Z ddl m Z ddl m Z mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%ddl&m'Z'dd l(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.dd l/m0Z0dd l1m2Z2dd l3m4Z4dd l5m6Z6m7Z7m8Z8m9Z9ddl:m;Z;GddZd5<eZ?d4e>d?<d@Z@dAZAGdBdCZB dMdDZC dNdEZDdOdFZEGdGdHe'ZFdPdIZGdQdJZHdRdKZIdSdLZJy)TzGenerate source code formatted as HTML, with bottlenecks annotated and highlighted. Various heuristics are used to detect common issues that cause slower than expected performance. ) annotationsN)escape)Final) BuildResult)AssignmentStmtCallExprClassDef DecoratorDictionaryComprehension ExpressionForStmtFuncDef GeneratorExpr IndexExpr LambdaExpr MemberExprMypyFileNamedTupleExprNameExpr NewTypeExprNodeOpExprRefExpr TupleExpr TypedDictExprTypeInfo TypeVarExprVarWithStmt)TraverserVisitor)AnyTypeInstance ProperTypeType TypeOfAnyget_proper_type)FancyFormatter)FuncIR)ModuleIR)CallC LoadLiteral LoadStaticValue)MapperceZdZdZdddZy) Annotationz(HTML annotation for compiled source codec ||_||_yN)messagepriority)selfr3r4s T/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/mypyc/annotate.py__init__zAnnotation.__init__6s ! N)r3strr4intreturnNone__name__ __module__ __qualname____doc__r7r8r6r0r03s 2!r8r0 PyNumber_AddzGeneric "+" operation.PyNumber_SubtractzGeneric "-" operation.PyNumber_MultiplyzGeneric "*" operation.PyNumber_TrueDividezGeneric "/" operation.PyNumber_FloorDividezGeneric "//" operation.PyNumber_PositivezGeneric unary "+" operation.PyNumber_NegativezGeneric unary "-" operation. PyNumber_AndzGeneric "&" operation. PyNumber_OrzGeneric "|" operation. PyNumber_XorzGeneric "^" operation.PyNumber_LshiftzGeneric "<<" operation.PyNumber_RshiftzGeneric ">>" operation.PyNumber_InvertzGeneric "~" operation. PyObject_CallzGeneric call operation.PyObject_CallObjectPyObject_RichComparezGeneric comparison operation.PyObject_GetItemzGeneric indexing operation.PyObject_SetItemzGeneric indexed assignment.rop_hintsz4"functools.partial" is inefficient in compiled code.r4zQ"itertools.chain" is inefficient in compiled code (hint: replace with for loops).z4"itertools.groupby" is inefficient in compiled code.zb"itertools.islice" is inefficient in compiled code (hint: replace with for loop over index range).zB"copy.deepcopy" tends to be slow. Make a shallow copy if possible.)zfunctools.partialzitertools.chainzitertools.groupbyzitertools.islicez copy.deepcopy stdlib_hintsz.collapsible { cursor: pointer; } .content { display: block; margin-top: 10px; margin-bottom: 10px; } .hint { display: inline; border: 1px solid #ccc; padding: 5px; } abdocument.querySelectorAll('.collapsible').forEach(function(collapsible) { collapsible.addEventListener('click', function() { const content = this.nextElementSibling; if (content.style.display === 'none') { content.style.display = 'block'; } else { content.style.display = 'none'; } }); }); ceZdZdZddZy)AnnotatedSourcez.Annotations for a single compiled source file.c ||_||_yr2)pathr)r5r_rs r6r7zAnnotatedSource.__init__s &r8N)r_r;rdict[int, list[Annotation]]r=r>r?rDr8r6r]r]s 8'r8r]c Lg}|jD]h\}}|j|j}|j|j}|J|jt |xsd|||j |jt|} t|d5} | j| dddttjtjd} | jtjj!|ddd} t#d| dy#1swYtxYw) NzwFnoneT) underlineboldz Wrote z -- open in browser to view )itemsgraphr_treeappendgenerate_annotationstypesgenerate_html_reportopenwriter'sysstdoutstderrstyleosabspathprint) html_fnamresultmodulesmapperrmodmod_irr_rhhtmlf formatter formatteds r6generate_annotated_htmlrsK}} V||C %%||C %%  !3T66< s DD#c:i}|jD]}|jt||t||}|jD]}|j ||j|j |jD] } | |vs|| = t||Sr2) functionsupdatefunction_annotationsASTAnnotateVisitordefsacceptanns ignored_linesr]) r_rhirtype_mapryrfunc_irvisitordefnlines r6rjrjs D<<9 ($789 62G  GKK %% 4<T  4 &&r8ci}|jD]O}|jD]<}t|ts|j}d}|dk(r.t |j d}|dvrd}n|rd|d}nd}n|dk(r/t |j d}|d k(rd}nw|rd |d}nmd }ni|d k(r&t |j d }|rd|d}nBd}n>|tvr t|}n+|dvr&t|j d trt|j dtr|jdk7r|j d } t|j dj}|jj|} | r| jr| j dk(rs| j"dk(rd| jj$t&vrt&| jj$}n*t| jt(r d|ddz}nd|d}|st|tr t+|}|j-|j.gj1|?R|S)z'Generate annotations based on mypyc IR.NCPyObject_GetAttrr:) __prepare__ GeneratorExit StopIterationzGet non-native attribute "".zDynamic attribute lookup.PyObject_SetAttr__mypyc_attrs__zSet non-native attribute "zDynamic attribute set.PyObject_VectorcallMethodrzCall non-native method "z:" (it may be defined in a non-native class, or decorated).zDynamic method call.)CPyDict_GetItemCPyDict_SetItem __top_level__staticglobalszAccess global "z" through namespace z=dictionary (hint: access is faster if you can make it Final).zAccess "z&" through global namespace dictionary.)blocksops isinstancer* function_nameget_str_literalargsrWr,r+namer;valuenamesgetnode namespace identifierfullnamer[rr0 setdefaultrri) rrhrblockoprann attr_name method_nameloadsyms r6rrs=)+D<=)); =B"e$''/3.. / ;I $UU#" :9+RH9// / ;I $55"" :9+RH688"1"''!*"=K" 8 EA4X%"4.CCC"2771:z:&rwwqz;?#LLO;!wwqz"2771:#3#34"jjnnT2 # $( : $9 <"xx00L@&23883D3D&E!+CHHc!:&5dV;O$P&e%f!$ )16\&]!#s+(oOOBGGR077z5ASTAnnotateVisitor.visit_with_stmt..@sK#1g.KFFKFFOO/JJKsAA"z&" uses @contextmanager, which is slow z*in compiled code. Use a native class with z+"__enter__" and "__exit__" methods instead.rXrY) rrrcalleerrr any decoratorsrrrvisit_with_stmt)r5rrrrs r6rz"ASTAnnotateVisitor.visit_with_stmt;sFF D$)jg.N{{''dI."&     {*PQJKKL&' & " "r8c~d}|jdk(r|j}t|jttt fr|jj }|js t|ttttfrd}|r%|jj|jt|A|y)NFrT)rrvaluerrrranalyzed is_alias_defrrrrrrrrvisit_assignment_stmt)r5r special_formrrs r6rz(ASTAnnotateVisitor.visit_assignment_stmtOs ??a *+((H!((Xy&$AB88,,~~; {S" $ ""&&qvv. %a(r8cltj|jx}r|j||yyr2)r[rrr)r5rrs r6visit_name_exprz"ASTAnnotateVisitor.visit_name_expr^s/""1::. .3 . MM!S ! /r8ct||tj|jx}r|j ||yyr2)rvisit_member_exprr[rrr)r5rrrs r6rz$ASTAnnotateVisitor.visit_member_exprbs= !!$""1::. .3 . MM!S ! /r8c2t||t|jtrR|jj dk(r9t |jdk(r!|jd}|j|yt|jtrt|jjtr|jj}|jjj|}|r |jr|@|j jds%|j!|d|j"ddzdy|r2|j$r%|j!|d|j"d d zdyyyt|jtrt|jjt&r^|jj}|jj)|jr"|j!|d |j"d dyyyy) Nzbuiltins.isinstancerZr:z builtins.z*Creating an instance of non-native class "z" zis slow.zClass "z " is only partially native, and z!constructing an instance is slow.zCalling a decorated function ("z'") is inefficient, even if it's native.)rvisit_call_exprrrrrlenrcheck_isinstance_argrrry type_to_irr is_ext_class startswithrr is_augmentedr is_native_ref_expr)r5rarginfoclass_ir decoratorrs r6rz"ASTAnnotateVisitor.visit_call_exprgs " qxx )!!%::AFF q &&)C  % %c * ' *z!((--/R88==D{{--11$7H!6!6 )A)A+)N CDII;bQT^^`ah33 dii[(HI9: 4' *z!((--/S I{{--ahh7 5inn5EEmn80T *r8cDt|tr]t|jtrB|jjr+|j |d|jj dyyyt|tr#|jD]}|j|yy)Nz/Expensive isinstance() check against protocol "r) rrrr is_protocolrrrrfr)r5ritems r6rz'ASTAnnotateVisitor.check_isinstance_args c7 ##((H-#((2F2F J388==/Y[\3G-Y '  0))$/ 0(r8cH|j|dt| |y)NzhA new object is allocated for lambda each time it is evaluated. A module-level function would be faster.)rrvisit_lambda_exprrs r6rz$ASTAnnotateVisitor.visit_lambda_exprs&  9 !!$r8ct|tr t||}|jj |j gj |y)NrY)rr;r0rrrri)r5rrr4s r6rzASTAnnotateVisitor.annotates; c3 S84C QVVR(//4r8c|jj|}|r t|Sttj Sr2)rrr&r!r% unannotated)r5ets r6rzASTAnnotateVisitor.get_types5 MM  a  "1% %y,,--r8)rdict[Expression, Type]ryr.r=r>)rrr=r>)rr r=r>)rr r=r>)rrr=r>)rzlist[Expression]rr;r=r>)rr r=r>)rrr=r>)rrr=r>)rrr=r>)rrr=r>)rrr=r>)rr r=r>)rrr=r>r9)rrrzstr | Annotationr4r<r=r>)rr r=r#)r@rArBrCr7rrrrrrrrrrrrrrr __classcell__)rs@r6rrsW@ "2( 8 #( )"" D0%5 .r8rcpt|tr&t|jtr |jSyr2)rr+rr;)vs r6rrs%![!j#&>ww r8cptd|D}|Dcgc]}|j|k(s|c}Scc}w)Nc34K|]}|jywr2rY)ras r6rzget_max_prio..s,!1::,s)maxr4)rmax_prior s r6 get_max_prior s1,t,,H 6!qzzX5A 66 6s33cg}|jd|jdtd|jd|jd|D] }|jd|jd|jd|j}t |j5}|j }dddt D]~\}}t|}|d z}d |z} ||vrGt||} | D cgc]} | j} } d j| } t| || }n| d z|z}|j||jd |jd|jt|jd|jddj|S#1swYxYwcc} w)Nz zz z z

z

z
r:z%5d )	hint_html  z
zz ) riCSSr_rrm readlines enumeraterr r3join colorize_lineJS)sourcesr|srcsrc_annsr}linesirrlinenumrr ann_strshints r6rlrls DKK"#KK)C5 +,KK KK  hsxxj 56 G?? #((^ "qKKME "e$ DAqq Aq5DdlGx#HTN3/34!AII44xx)!'1=dNQ& KKN  H%( KK KKOKK KK"# 774=+ " "5s&F8;G8G cXdt|zdz}d|d|d}d|d|d}d||d S) Nrrz8
z
z
z
z
zz)r)rrr hint_prefix line_spanhint_divs r6rrsVG $t+KJ7)SUVWUXX^_I&{m3Ei[P\]H I;xj 00r8) rvr;rwrrxzdict[str, ModuleIR]ryr.r=r>) r_r;rhrrr)rrryr.r=r])rr(rhrr=r`)rr-r=z str | None)rlist[Annotation]r=r$)rzlist[AnnotatedSource]r=r;)rr;rr;rr;r=r;)KrC __future__ros.pathrsror|rtypingr mypy.buildr mypy.nodesrrr r r r r rrrrrrrrrrrrrrrrrrmypy.traverserr mypy.typesr!r"r#r$r%r& mypy.utilr'mypyc.ir.func_irr(mypyc.ir.module_irr) mypyc.ir.opsr*r+r,r-mypyc.irbuild.mapperr.r0rW__annotations__r[rrr]rrjrrrr rlrrDr8r6r2s # "6,VV$#'>>' ! !J78$<=$<=:&>?  J'@A  $BC $BCJ78:67J78z";<z";<z":;Z 9::&?@ J'FG!" #@A#$ #@A%%,$>"[$>#l LWX e($ ''??'?2E?OU? ?( '  ' '#+ '7M 'W] ' ' AHj.)j.Z 7 D1r8