
    pi                        U d Z ddlmZmZmZmZ ddlmZ ddlm	Z	m
Z
 ddlmZmZ ddlmZmZ 	 ddlZdZed
        Zg Zeg ed   f   ed<   ded   fdZ G d de      Z G d de      Zej4                  d        Zer6 e	d       G d dej8                  j:                               ZdededefdZ yy# e$ r d	ZY w xY w)zw
Implement code coverage support.

Currently contains logic to extend ``coverage`` with lines covered by the
compiler.
    )OptionalSequenceCallableno_type_check)Mapping)	dataclassfield)ABCabstractmethod)irconfigNTFc                  R    d} t         rt        j                  j                         } | S )z>Get active coverage instance or return None if not found.
    N)coverage_availablecoverageCoveragecurrent)covs    ]/opt/services/ai/voice_agent/venv/lib/python3.12/site-packages/numba/misc/coverage_support.pyget_active_coverager      s%     C'')J    NotifyLocBase_the_registryreturnc                  h    t         j                  sg S t        t        d d t        D                    S )zC
    Returns a list of the registered NotifyLocBase instances.
    c                 
    | d uS N )xs    r   <lambda>z+get_registered_loc_notify.<locals>.<lambda>,   s
    $ r   c              3   *   K   | ]  } |         y wr   r   ).0factorys     r   	<genexpr>z,get_registered_loc_notify.<locals>.<genexpr>-   s     ?g	?s   )r   JIT_COVERAGElistfilterr   r   r   r   get_registered_loc_notifyr'   %   s4     	.??A B Br   c                   P    e Zd ZdZedej                  ddfd       Zedd       Zy)r   z<Interface for notifying visiting of a ``numba.core.ir.Loc``.locr   Nc                      y r   r   )selfr)   s     r   notifyzNotifyLocBase.notify3       r   c                      y r   r   r+   s    r   closezNotifyLocBase.close7   r-   r   r   N)	__name__
__module____qualname____doc__r   r   Locr,   r0   r   r   r   r   r   0   s=    F"&& T    r   c                   <    e Zd ZdZd Zdej                  fdZd Zy)NotifyCompilerCoveragez
    Use to notify ``coverage`` about compiled lines.

    The compiled lines are under the "numba_compiled" context in the coverage
    data.
    c                    || _         |j                  j                  j                         }|j	                  t        |j                  |j                  |j                  |j                  |j                  |j                  |j                  |j                  |j                  |j                  j                  
             t!        di || _        |j$                  j'                  | j"                         y )N)
data	lock_dataunlock_data
trace_arcsshould_traceshould_trace_cachewarnshould_start_contextswitch_contextpacked_arcsr   )
_collectorcoretracer_kwargscopyupdatedictr:   r;   r<   branchr>   r?   r@   rA   rB   rC   NumbaTracer_tracertracersappend)r+   	collectorrF   s      r   __init__zNotifyCompilerCoverage.__init__D   s    # "4499;^^#--%11$++&33#,#?#?^^%.%C%C(77%NN66	
 #3]3  .r   r)   c                     | j                   }|j                  j                  d      r4|j                  d       |j	                  |       |j                  d        y y )Nz.pynumba_compiled)rL   filenameendswithrB   trace)r+   r)   tracers      r   r,   zNotifyCompilerCoverage.notifyZ   sK    <<  '!!"23LL!!$' (r   c                      y r   r   r/   s    r   r0   zNotifyCompilerCoverage.closea   s    r   N)	r2   r3   r4   r5   rP   r   r6   r,   r0   r   r   r   r8   r8   <   s!    /,("&& (r   r8   c                  d    t               } | $| j                  }|j                  rt        |      S y y r   )r   rD   rM   r8   )r   cols     r   _register_coverage_notifierrZ   e   s4    

C
nn;;)#..  r   )kw_onlyc                   2   e Zd ZU dZej
                  j                  ed<   eed<   ej
                  j                  ed<   e
eej
                  j                  dz  f   ed<   ej
                  j                  dz  ed<   eedz  gdf   dz  ed<   eg df   ed	<   eg df   ed
<   ej
                  j                  ed<   eed<    ed      Zeed<   dej
                  j$                  dz  fdZddZdefdZddZdeeef   dz  fdZdej6                  ddfdZy)rK   a   
        Not actually a tracer as in the coverage implementation, which will
        setup a Python trace function. This implementation pretends to trace
        but instead receives fake trace events for each line the compiler has
        visited.

        See coverage.PyTracer
        r:   r=   r>   Nr?   rA   rB   r;   r<   r@   rC   F)default	_activityr   c                      y)zPStart this tracer, return a trace function if based on
            sys.settrace.Nr   r/   s    r   startzNumbaTracer.start   s     r   c                      y)zStop this tracer.Nr   r/   s    r   stopzNumbaTracer.stop       r   c                     | j                   S )zHas there been any activity?r^   r/   s    r   activityzNumbaTracer.activity   s    >>!r   c                     d| _         y)zReset the activity() flag.FNre   r/   s    r   reset_activityzNumbaTracer.reset_activity   s	    "DNr   c                      y)z+Return a dictionary of statistics, or None.Nr   r/   s    r   	get_statszNumbaTracer.get_stats   rc   r   r)   c                    | j                   j                  |j                        }|5| j                  |j                  d      }|| j                   |j                  <   |j                  sy|j
                  }| j                          | j                  j                  |t                     }| j                  rd| j                  r0|j                  t        |j                  |j                               nC|j                  |j                  |j                  f       n|j                  |j                         | j                          d| _        y)z8Insert coverage data given source location.
            NT)r?   getrS   r>   rU   source_filenamer;   r:   
setdefaultsetr=   rC   add
_pack_arcsliner<   r^   )r+   r)   disp	tracenamecur_file_datas        r   rU   zNumbaTracer.trace   s     **..s||<D|((t<8<''5::,,INN II00CEBM##!%%j388&DE!%%sxx&:;!!#((+!DNr   r1   )r2   r3   r4   r5   r   types
TTraceData__annotations__boolTShouldTraceFnr   strTFileDispositionTShouldStartContextFnr   TWarnFnr	   r^   TTraceFnr`   rb   rf   rh   rI   intrj   r   r6   rU   r   r   r   rK   rK   q   s)   	 nn'''nn333#00477
 	
 'nnBBTII #*t!34t;;BH%%b$h''nn$$$.	4.	8>>22T9 	
		"d 	"	#	tCH~4 		"RVV 	" 	"r   rK   l1l2c                 T    d}| dk  r|dz  }|  } |dk  r|dz  }| }||dz  | z   z  }|S )zPack arcs into a single integer for compatibility with .packed_arcs
        option.

        See
        https://github.com/nedbat/coveragepy/blob/e7c05fe91ee36c0c94e144bb88d25db4fc3d02fd/coverage/ctracer/tracer.c#L171
        r   l        l           r   )r   r   packeds      r   rq   rq      sP     6gFB6gFB28r/!r   )!r5   typingr   r   r   r   collections.abcr   dataclassesr   r	   abcr
   r   
numba.corer   r   r   r   ImportErrorr   r   rx   r'   r   r8   rN   rZ   rv   TracerrK   r   rq   r   r   r   <module>r      s   ? > # ( # !    :<xH_556 ;B8O#< B	C 	&] &R / / tF"hnn++ F" F"Ps   W {  s   B6 6C ?C 