o
    i                     @   s&  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 zddlZW n ey>   dZY nw d	Zed
d Zg Zeg ed f ed< ded fddZG dd deZG dd deZejdd Zere	d	dG dd dejjZdededefddZ dS dS )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configNFTc                  C   s   d} t r	tj } | S )z>Get active coverage instance or return None if not found.
    N)coverage_availablecoverageCoveragecurrent)cov r   Y/home/ubuntu/transcripts/venv/lib/python3.10/site-packages/numba/misc/coverage_support.pyget_active_coverage   s   
r   NotifyLocBase_the_registryreturnc                   C   s&   t jsg S ttdd dd tD S )zC
    Returns a list of the registered NotifyLocBase instances.
    c                 S   s   | d uS Nr   )xr   r   r   <lambda>,   s    z+get_registered_loc_notify.<locals>.<lambda>c                 s   s    | ]}| V  qd S r   r   ).0factoryr   r   r   	<genexpr>-   s    z,get_registered_loc_notify.<locals>.<genexpr>)r   JIT_COVERAGElistfilterr   r   r   r   r   get_registered_loc_notify%   s
   
r!   c                   @   s6   e Zd ZdZedejddfddZed	ddZdS )
r   z<Interface for notifying visiting of a ``numba.core.ir.Loc``.locr   Nc                 C      d S r   r   )selfr"   r   r   r   notify3      zNotifyLocBase.notifyc                 C   r#   r   r   r$   r   r   r   close7   r&   zNotifyLocBase.closer   N)	__name__
__module____qualname____doc__r
   r   Locr%   r(   r   r   r   r   r   0   s    c                   @   s0   e Zd ZdZdd ZdejfddZdd Zd	S )
NotifyCompilerCoveragez
    Use to notify ``coverage`` about compiled lines.

    The compiled lines are under the "numba_compiled" context in the coverage
    data.
    c                 C   sl   || _ |jj }|t|j|j|j|j	|j
|j|j|j|j|jjd
 tdi || _|j| j d S )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dictr0   r1   r2   branchr4   r5   r6   r7   r8   r9   NumbaTracer_tracertracersappend)r$   	collectorr<   r   r   r   __init__D   s$   zNotifyCompilerCoverage.__init__r"   c                 C   s8   | j }|jdr|d || |d  d S d S )Nz.pynumba_compiled)rB   filenameendswithr8   trace)r$   r"   tracerr   r   r   r%   Z   s   

zNotifyCompilerCoverage.notifyc                 C   r#   r   r   r'   r   r   r   r(   a   s   zNotifyCompilerCoverage.closeN)	r*   r+   r,   r-   rF   r   r.   r%   r(   r   r   r   r   r/   <   s
    r/   c                  C   s*   t  } | d ur| j}|jrt|S d S d S r   )r   r:   rC   r/   )r   colr   r   r   _register_coverage_notifiere   s   rM   )kw_onlyc                   @   s   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B f ed< ejjdB ed< eedB gdf dB ed< eg df ed	< eg df ed
< ejjed< eed< eddZeed< dejjdB fddZdddZdefddZdddZdeeef dB fddZdejddfddZdS )rA   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
        r0   r3   r4   Nr5   r7   r8   r1   r2   r6   r9   F)default	_activityr   c                 C      dS )zPStart this tracer, return a trace function if based on
            sys.settrace.Nr   r'   r   r   r   start   s   zNumbaTracer.startc                 C   rQ   )zStop this tracer.Nr   r'   r   r   r   stop   r&   zNumbaTracer.stopc                 C   s   | j S )zHas there been any activity?rP   r'   r   r   r   activity   s   zNumbaTracer.activityc                 C   s
   d| _ dS )zReset the activity() flag.FNrT   r'   r   r   r   reset_activity   s   
zNumbaTracer.reset_activityc                 C   rQ   )z+Return a dictionary of statistics, or None.Nr   r'   r   r   r   	get_stats   r&   zNumbaTracer.get_statsr"   c                 C   s   | j |j}|du r| |jd}|| j |j< |jsdS |j}|   | j|t	 }| j
rG| jr=|t|j|j n||j|jf n||j |   d| _dS )z8Insert coverage data given source location.
            NT)r5   getrH   r4   rJ   source_filenamer1   r0   
setdefaultsetr3   r9   add
_pack_arcsliner2   rP   )r$   r"   disp	tracenamecur_file_datar   r   r   rJ      s    
zNumbaTracer.tracer)   )r*   r+   r,   r-   r   types
TTraceData__annotations__boolTShouldTraceFnr   strTFileDispositionTShouldStartContextFnr   TWarnFnr   rP   TTraceFnrR   rS   rU   rV   r?   intrW   r   r.   rJ   r   r   r   r   rA   q   s*   
 	

rA   l1l2c                 C   sD   d}| dk r|dO }|  } |dk r|dO }| }||d> |  O }|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   )rm   rn   packedr   r   r   r]      s   r]   )!r-   typingr   r   r   r   collections.abcr   dataclassesr   r   abcr	   r
   
numba.corer   r   r   ImportErrorr   r   r   rd   r!   r   r/   rD   rM   rb   TracerrA   rl   r]   r   r   r   r   <module>   s2    
	)
	H