U
    hâËdæ[  ã                   @   sÚ  d Z ddlmZmZmZ ddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlZddlZddlZddlmZ ddl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 dd
lmZ dd„ Z G dd„ ded�Z!G dd„ de!ƒZ"G dd„ ded�Z#G dd„ de$ƒZ%G dd„ de%e#ƒZ&G dd„ de%e#ƒZ'G dd„ de%e#ƒZ(G dd„ de#ƒZ)G dd„ ded�Z*G d d!„ d!e*ƒZ+G d"d#„ d#e*ƒZ,G d$d%„ d%e$ƒZ-G d&d'„ d'e!ƒZ.G d(d)„ d)e.ƒZ/e0d*gƒZ1d+d,„ Z2dS )-z+
Caching mechanism for compiled functions.
é    )ÚABCMetaÚabstractmethodÚabstractpropertyN)ÚAppDirs)ÚNumbaWarning)ÚBaseContext)ÚCodeLibrary)ÚCompileResult)ÚconfigÚcompiler©Údumpsc                 G   s   t jr| | } t| ƒ d S ©N)r
   ZDEBUG_CACHEÚprint)ÚmsgÚargs© r   úK/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/numba/core/caching.pyÚ
_cache_log   s    r   c                   @   sT   e Zd Zedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZed	d
„ ƒZ	edd„ ƒZ
dS )Ú_Cachec                 C   s   dS )zW
        The base filesystem path of this cache (for example its root folder).
        Nr   ©Úselfr   r   r   Ú
cache_path&   s    z_Cache.cache_pathc                 C   s   dS )zµ
        Load an overload for the given signature using the target context.
        The saved object must be returned if successful, None if not found
        in the cache.
        Nr   ©r   ÚsigÚtarget_contextr   r   r   Úload_overload,   s    z_Cache.load_overloadc                 C   s   dS )z<
        Save the overload for the given signature.
        Nr   ©r   r   Údatar   r   r   Úsave_overload4   s    z_Cache.save_overloadc                 C   s   dS )z#
        Enable the cache.
        Nr   r   r   r   r   Úenable:   s    z_Cache.enablec                 C   s   dS )z$
        Disable the cache.
        Nr   r   r   r   r   Údisable@   s    z_Cache.disablec                 C   s   dS )z"
        Flush the cache.
        Nr   r   r   r   r   ÚflushF   s    z_Cache.flushN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r    r!   r"   r   r   r   r   r   $   s   




r   )Ú	metaclassc                   @   s@   e Zd Zedd„ ƒZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dS )Ú	NullCachec                 C   s   d S r   r   r   r   r   r   r   N   s    zNullCache.cache_pathc                 C   s   d S r   r   r   r   r   r   r   R   s    zNullCache.load_overloadc                 C   s   d S r   r   )r   r   Úcresr   r   r   r   U   s    zNullCache.save_overloadc                 C   s   d S r   r   r   r   r   r   r    X   s    zNullCache.enablec                 C   s   d S r   r   r   r   r   r   r!   [   s    zNullCache.disablec                 C   s   d S r   r   r   r   r   r   r"   ^   s    zNullCache.flushN)
r#   r$   r%   Úpropertyr   r   r   r    r!   r"   r   r   r   r   r'   M   s   
r'   c                   @   sT   e Zd ZdZdd„ Zedd„ ƒZedd„ ƒZedd	„ ƒZe	d
d„ ƒZ
e	dd„ ƒZdS )Ú_CacheLocatorz<
    A filesystem locator for caching a given function.
    c                 C   s*   |   ¡ }tj|dd� tj|d� ¡  d S )NT)Úexist_ok)Údir)Úget_cache_pathÚosÚmakedirsÚtempfileÚTemporaryFileÚclose)r   Úpathr   r   r   Úensure_cache_pathg   s    z_CacheLocator.ensure_cache_pathc                 C   s   dS )zA
        Return the directory the function is cached in.
        Nr   r   r   r   r   r-   m   s    z_CacheLocator.get_cache_pathc                 C   s   dS )z{
        Get a timestamp representing the source code's freshness.
        Can return any picklable Python object.
        Nr   r   r   r   r   Úget_source_stamps   s    z_CacheLocator.get_source_stampc                 C   s   dS )z™
        Get a string disambiguator for this locator's function.
        It should allow disambiguating different but similarly-named functions.
        Nr   r   r   r   r   Úget_disambiguatorz   s    z_CacheLocator.get_disambiguatorc                 C   s   t ‚dS )ze
        Create a locator instance for the given function located in the
        given file.
        N)ÚNotImplementedError)ÚclsÚpy_funcÚpy_filer   r   r   Úfrom_function�   s    z_CacheLocator.from_functionc                 C   sH   t j |¡}t j |¡}t j |¡d }t | ¡ ¡ ¡ }d 	||g¡S )zâGiven the Python file path, compute a suitable path inside the
        cache directory.

        This will reduce a file path that is too long, which can be a problem
        on some operating system (i.e. Windows 7).
        éÿÿÿÿÚ_)
r.   r3   ÚabspathÚdirnameÚsplitÚhashlibÚsha1ÚencodeÚ	hexdigestÚjoin)r8   r:   r3   ÚsubpathÚ	parentdirÚhashedr   r   r   Úget_suitable_cache_subpath‰   s
    z(_CacheLocator.get_suitable_cache_subpathN)r#   r$   r%   Ú__doc__r4   r   r-   r5   r6   Úclassmethodr;   rI   r   r   r   r   r*   b   s   



r*   c                   @   s,   e Zd ZdZdd„ Zdd„ Zedd„ ƒZdS )	Ú_SourceFileBackedLocatorMixinzf
    A cache locator mixin for functions which are backed by a well-known
    Python source file.
    c                 C   s2   t tddƒrt tj¡}nt | j¡}|j|jfS ©NÚfrozenF)ÚgetattrÚsysr.   ÚstatÚ
executableÚ_py_fileÚst_mtimeÚst_size)r   Ústr   r   r   r5   ¡   s    z._SourceFileBackedLocatorMixin.get_source_stampc                 C   s
   t | jƒS r   )ÚstrÚ_linenor   r   r   r   r6   ª   s    z/_SourceFileBackedLocatorMixin.get_disambiguatorc                 C   sB   t j |¡sd S | ||ƒ}z| ¡  W n tk
r<   Y d S X |S r   )r.   r3   Úexistsr4   ÚOSError©r8   r9   r:   r   r   r   r   r;   ­   s    
z+_SourceFileBackedLocatorMixin.from_functionN)r#   r$   r%   rJ   r5   r6   rK   r;   r   r   r   r   rL   ›   s
   	rL   c                       s4   e Zd ZdZdd„ Zdd„ Ze‡ fdd„ƒZ‡  ZS )Ú_UserProvidedCacheLocatorzd
    A locator that always point to the user provided directory in
    `numba.config.CACHE_DIR`
    c                 C   s0   || _ |jj| _|  |¡}tj tj	|¡| _
d S r   )rS   Ú__code__Úco_firstlinenorX   rI   r.   r3   rE   r
   Ú	CACHE_DIRÚ_cache_path)r   r9   r:   Úcache_subpathr   r   r   Ú__init__À   s    

z"_UserProvidedCacheLocator.__init__c                 C   s   | j S r   ©r`   r   r   r   r   r-   Æ   s    z(_UserProvidedCacheLocator.get_cache_pathc                    s    t js
d S tt| ƒ}| ||¡S r   )r
   r_   Úsuperr\   r;   )r8   r9   r:   Úparent©Ú	__class__r   r   r;   É   s    
z'_UserProvidedCacheLocator.from_function)	r#   r$   r%   rJ   rb   r-   rK   r;   Ú__classcell__r   r   rf   r   r\   »   s
   r\   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )Ú_InTreeCacheLocatorzn
    A locator for functions backed by a regular Python module with a
    writable __pycache__ directory.
    c                 C   s.   || _ |jj| _tj tj | j ¡d¡| _d S )NÚ__pycache__)	rS   r]   r^   rX   r.   r3   rE   r?   r`   )r   r9   r:   r   r   r   rb   ×   s    
z_InTreeCacheLocator.__init__c                 C   s   | j S r   rc   r   r   r   r   r-   Ü   s    z"_InTreeCacheLocator.get_cache_pathN)r#   r$   r%   rJ   rb   r-   r   r   r   r   ri   Ñ   s   ri   c                   @   s,   e Zd ZdZdd„ Zdd„ Zedd„ ƒZdS )	Ú_UserWideCacheLocatorzˆ
    A locator for functions backed by a regular Python module or a
    frozen executable, cached into a user-wide cache directory.
    c                 C   s@   || _ |jj| _tddd�}|j}|  |¡}tj 	||¡| _
d S )NÚnumbaF)ÚappnameÚ	appauthor)rS   r]   r^   rX   r   Úuser_cache_dirrI   r.   r3   rE   r`   )r   r9   r:   ÚappdirsÚ	cache_dirra   r   r   r   rb   æ   s    

z_UserWideCacheLocator.__init__c                 C   s   | j S r   rc   r   r   r   r   r-   î   s    z$_UserWideCacheLocator.get_cache_pathc                 C   sN   t j |¡sttddƒsd S | ||ƒ}z| ¡  W n tk
rH   Y d S X |S rM   )r.   r3   rY   rO   rP   r4   rZ   r[   r   r   r   r;   ñ   s    
z#_UserWideCacheLocator.from_functionN)r#   r$   r%   rJ   rb   r-   rK   r;   r   r   r   r   rk   à   s
   rk   c                   @   s<   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zed
d„ ƒZ	dS )Ú_IPythonCacheLocatorzT
    A locator for functions entered at the IPython prompt (notebook or other).
    c                 C   s2   || _ t |¡}t|tƒr"|| _n| d¡| _d S )Nzutf-8)rS   ÚinspectÚ	getsourceÚ
isinstanceÚbytesÚ_bytes_sourcerC   )r   r9   r:   Úsourcer   r   r   rb     s
    

z_IPythonCacheLocator.__init__c                 C   sB   zddl m} W n  tk
r0   ddlm} Y nX tj |ƒ d¡S )Nr   )Úget_ipython_cache_dirZnumba_cache)ZIPython.pathsry   ÚImportErrorZIPython.utils.pathr.   r3   rE   )r   ry   r   r   r   r-     s
    z#_IPythonCacheLocator.get_cache_pathc                 C   s   t  | j¡ ¡ S r   )rA   Úsha256rw   rD   r   r   r   r   r5     s    z%_IPythonCacheLocator.get_source_stampc                 C   s0   d  | j d¡d d… ¡}t |¡ ¡ d d… S )Nó    Té   é
   )rE   rw   Ú
splitlinesrA   r{   rD   )r   Z
firstlinesr   r   r   r6     s    z&_IPythonCacheLocator.get_disambiguatorc                 C   sZ   |  d¡s(tj tj |¡¡  d¡s(d S | ||ƒ}z| ¡  W n tk
rT   Y d S X |S )Nz	<ipython-Z
ipykernel_)Ú
startswithr.   r3   Úbasenamer?   r4   rZ   r[   r   r   r   r;   '  s    ÿþ
z"_IPythonCacheLocator.from_functionN)
r#   r$   r%   rJ   rb   r-   r5   r6   rK   r;   r   r   r   r   rr      s   
	rr   c                   @   sh   e Zd ZdZeeeegZdd„ Z	dd„ Z
edd„ ƒZedd	„ ƒZed
d„ ƒZedd„ ƒZedd„ ƒZdS )Ú	CacheImplzÃ
    Provides the core machinery for caching.
    - implement how to serialize and deserialize the data in the cache.
    - control the filename of the cache.
    - provide the cache locator
    c           
      C   sÀ   |j j| _z
|j}W n tk
r.   |j}Y nX t |¡}| jD ]}| 	||¡}|d k	r@ qnq@t
d||f ƒ‚|| _t |¡}tj tj |¡¡d }d||f }ttddƒ}	|  ||	¡| _d S )Nz:cannot cache function %r: no locator available for file %rr   z%s.%sÚabiflagsÚ )r]   r^   rX   r%   ÚAttributeErrorr#   rs   ÚgetfileÚ_locator_classesr;   ÚRuntimeErrorÚ_locatorr.   r3   Úsplitextr�   rO   rP   Úget_filename_baseÚ_filename_base)
r   r9   ÚqualnameÚsource_pathr8   ÚlocatorÚfilenameÚmodnameÚfullnamerƒ   r   r   r   rb   C  s&    



ÿ
zCacheImpl.__init__c                 C   s<   |  dd¡  dd¡}d}||| j ¡ tjd tjd |f S )Nú<r„   ú>z%s-%s.py%d%d%sr   é   )Úreplacer�   r6   rP   Úversion_info)r   r’   rƒ   Zfixed_fullnameÚfmtr   r   r   r‹   \  s      ÿzCacheImpl.get_filename_basec                 C   s   | j S r   )rŒ   r   r   r   r   Úfilename_based  s    zCacheImpl.filename_basec                 C   s   | j S r   )r‰   r   r   r   r   r�   h  s    zCacheImpl.locatorc                 C   s   dS )z$Returns the serialized form the dataNr   ©r   r   r   r   r   Úreducel  s    zCacheImpl.reducec                 C   s   dS )z4Returns the de-serialized form of the *reduced_data*Nr   )r   r   Zreduced_datar   r   r   Úrebuildq  s    zCacheImpl.rebuildc                 C   s   dS )zEReturns True if the given data is cachable; otherwise, returns False.Nr   rš   r   r   r   Úcheck_cachablev  s    zCacheImpl.check_cachableN)r#   r$   r%   rJ   r\   ri   rk   rr   r‡   rb   r‹   r)   r™   r�   r   r›   rœ   r�   r   r   r   r   r‚   7  s$   ý



r‚   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚCompileResultCacheImplz>
    Implements the logic to cache CompileResult objects.
    c                 C   s   |  ¡ S )z4
        Returns a serialized CompileResult
        )Z_reduce)r   r(   r   r   r   r›   �  s    zCompileResultCacheImpl.reducec                 C   s   t jj|f|žŽ S )z8
        Returns the unserialized CompileResult
        )r   r	   Z_rebuild©r   r   Úpayloadr   r   r   rœ   ‡  s    zCompileResultCacheImpl.rebuildc                 C   sf   d}t dd„ |jD ƒƒrd}n|jjr*d}|rbd|jj d¡d |f }t |t	| j
j| j¡ d	S d
S )z@
        Check cachability of the given compile result.
        Nc                 s   s   | ]}|j  V  qd S r   )Z	can_cache©Ú.0Úxr   r   r   Ú	<genexpr>’  s     z8CompileResultCacheImpl.check_cachable.<locals>.<genexpr>zas it uses lifted codezLas it uses dynamic globals (such as ctypes pointers and large global arrays)z&Cannot cache compiled function "%s" %sÚ.r<   FT)ÚanyZliftedZlibraryÚhas_dynamic_globalsZfndescr�   r@   ÚwarningsÚwarn_explicitr   r‰   rS   rX   )r   r(   Zcannot_cacher   r   r   r   r�   �  s    ÿ ÿz%CompileResultCacheImpl.check_cachableN)r#   r$   r%   rJ   r›   rœ   r�   r   r   r   r   rž   |  s   rž   c                       s<   e Zd ZdZdZdd„ Zdd„ Zdd„ Z‡ fd	d
„Z‡  Z	S )ÚCodeLibraryCacheImplz<
    Implements the logic to cache CodeLibrary objects.
    Nc                 C   s   |  ¡ S )z2
        Returns a serialized CodeLibrary
        )Zserialize_using_object_code©r   Zcodelibr   r   r   r›   §  s    zCodeLibraryCacheImpl.reducec                 C   s   |  ¡  |¡S )z6
        Returns the unserialized CodeLibrary
        )ÚcodegenZunserialize_libraryrŸ   r   r   r   rœ   ­  s    zCodeLibraryCacheImpl.rebuildc                 C   s   |j  S )z=
        Check cachability of the given CodeLibrary.
        )r§   r«   r   r   r   r�   ³  s    z#CodeLibraryCacheImpl.check_cachablec                    s&   t t| ƒ}| ||¡}d | j|g¡S )Nú-)rd   rª   r‹   rE   Ú_filename_prefix)r   r’   rƒ   re   Úresrf   r   r   r‹   ¹  s    
z&CodeLibraryCacheImpl.get_filename_base)
r#   r$   r%   rJ   r®   r›   rœ   r�   r‹   rh   r   r   rf   r   rª      s   rª   c                   @   sv   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zejdd„ ƒZdS )ÚIndexDataCacheFilezP
    Implements the logic for the index file and data file used by a cache.
    c                 C   sD   || _ d|f | _tj | j | j¡| _d|f | _|| _tj	| _
d S )Nz%s.nbiz%s.{number:d}.nbc)r`   Z_index_namer.   r3   rE   Ú_index_pathÚ_data_name_patternÚ_source_stamprl   Ú__version__Ú_version)r   r   r™   Úsource_stampr   r   r   rb   Ã  s    zIndexDataCacheFile.__init__c                 C   s   |   i ¡ d S r   )Ú_save_indexr   r   r   r   r"   Ë  s    zIndexDataCacheFile.flushc                 C   s~   |   ¡ }z|| }W nX tk
rl   t| ¡ ƒ}t d¡D ]}|  |¡}||kr: qVq:|||< |  |¡ Y nX |  ||¡ dS )z?
        Save a new cache entry with *key* and *data*.
        r•   N)	Ú_load_indexÚKeyErrorÚsetÚvaluesÚ	itertoolsÚcountÚ
_data_namer·   Ú
_save_data)r   Úkeyr   Ú	overloadsÚ	data_nameÚexistingÚir   r   r   ÚsaveÎ  s    
zIndexDataCacheFile.savec                 C   sF   |   ¡ }| |¡}|dkrdS z|  |¡W S  tk
r@   Y dS X dS )z0
        Load a cache entry with *key*.
        N)r¸   ÚgetÚ
_load_datarZ   )r   rÀ   rÁ   rÂ   r   r   r   Úloadá  s    
zIndexDataCacheFile.loadc              	   C   s†   z.t | jdƒ�}t |¡}| ¡ }W 5 Q R X W n tk
rF   i  Y S X || jkrVi S t |¡\}}td| jƒ || j	kr~i S |S dS )z|
        Load the cache index and return it as a dictionary (possibly
        empty if cache is empty or obsolete).
        Úrbz[cache] index loaded from %rN)
Úopenr±   ÚpicklerÈ   ÚreadÚFileNotFoundErrorrµ   Úloadsr   r³   )r   ÚfÚversionr   ZstamprÁ   r   r   r   r¸   ï  s    



zIndexDataCacheFile._load_indexc              	   C   sX   | j |f}|  |¡}|  | j¡�"}tj| j|dd� | |¡ W 5 Q R X td| jƒ d S )Nr<   )Úprotocolz[cache] index saved to %r)	r³   Ú_dumpÚ_open_for_writer±   rË   Údumprµ   Úwriter   )r   rÁ   r   rÏ   r   r   r   r·     s    

zIndexDataCacheFile._save_indexc              	   C   s@   |   |¡}t|dƒ�}| ¡ }W 5 Q R X t |¡}td|ƒ |S )NrÉ   z[cache] data loaded from %r)Ú
_data_pathrÊ   rÌ   rË   rÎ   r   )r   Únamer3   rÏ   r   Útupr   r   r   rÇ     s    


zIndexDataCacheFile._load_datac              	   C   sB   |   |¡}|  |¡}|  |¡�}| |¡ W 5 Q R X td|ƒ d S )Nz[cache] data saved to %r)rÒ   rÖ   rÓ   rÕ   r   )r   r×   r   r3   rÏ   r   r   r   r¿     s
    

zIndexDataCacheFile._save_datac                 C   s   | j j|d�S )N)Únumber)r²   Úformat)r   rÙ   r   r   r   r¾     s    zIndexDataCacheFile._data_namec                 C   s   t j | j|¡S r   )r.   r3   rE   r`   )r   r×   r   r   r   rÖ   "  s    zIndexDataCacheFile._data_pathc                 C   s   t |ƒS r   r   )r   Úobjr   r   r   rÒ   %  s    zIndexDataCacheFile._dumpc                 c   sŠ   t  ¡ jdd… }d||f }z,t|dƒ�}|V  W 5 Q R X t ||¡ W n: tk
r„   zt |¡ W n tk
r|   Y nX ‚ Y nX dS )z¦
        Open *filepath* for writing in a race condition-free way (hopefully).
        uuid4 is used to try and avoid name collisions on a shared filesystem.
        Né   z	%s.tmp.%sÚwb)	ÚuuidÚuuid4ÚhexrÊ   r.   r–   Ú	ExceptionÚunlinkrZ   )r   ÚfilepathÚuidZtmpnamerÏ   r   r   r   rÓ   (  s    z"IndexDataCacheFile._open_for_writeN)r#   r$   r%   rJ   rb   r"   rÅ   rÈ   r¸   r·   rÇ   r¿   r¾   rÖ   rÒ   Ú
contextlibÚcontextmanagerrÓ   r   r   r   r   r°   ¿  s   r°   c                   @   s~   e Zd ZdZdZdd„ Zdd„ Zedd„ ƒZd	d
„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zejdd„ ƒZdd„ ZdS )ÚCachea<  
    A per-function compilation cache.  The cache saves data in separate
    data files and maintains information in an index file.

    There is one index file per function and Python version
    ("function_name-<lineno>.pyXY.nbi") which contains a mapping of
    signatures and architectures to data files.
    It is prefixed by a versioning key and a timestamp of the Python source
    file containing the function.

    There is one data file ("function_name-<lineno>.pyXY.<number>.nbc")
    per function, function signature, target architecture and Python version.

    Separate index and data files per Python version avoid pickle
    compatibility problems.

    Note:
    This contains the driver logic only.  The core logic is provided
    by a subclass of ``CacheImpl`` specified as *_impl_class* in the subclass.
    Nc                 C   s\   t |ƒ| _|| _|  |¡| _| jj ¡ | _| jj ¡ }| jj	}t
| j||d�| _|  ¡  d S )N)r   r™   r¶   )ÚreprÚ_nameÚ_py_funcÚ_impl_classÚ_implr�   r-   r`   r5   r™   r°   Ú_cache_filer    )r   r9   r¶   r™   r   r   r   rb   V  s    
þzCache.__init__c                 C   s   d| j j| jf S )Nz<%s py_func=%r>)rg   r#   ré   r   r   r   r   Ú__repr__c  s    zCache.__repr__c                 C   s   | j S r   rc   r   r   r   r   r   f  s    zCache.cache_pathc                 C   s
   d| _ d S )NT©Ú_enabledr   r   r   r   r    j  s    zCache.enablec                 C   s
   d| _ d S )NFrï   r   r   r   r   r!   m  s    zCache.disablec                 C   s   | j  ¡  d S r   )rí   r"   r   r   r   r   r"   p  s    zCache.flushc              
   C   s4   |  ¡  |  ¡ � |  ||¡W  5 Q R £ S Q R X dS )zr
        Load and recreate the cached object for the given signature,
        using the *target_context*.
        N)ÚrefreshÚ!_guard_against_spurious_io_errorsÚ_load_overloadr   r   r   r   r   s  s    
zCache.load_overloadc                 C   s@   | j s
d S |  || ¡ ¡}| j |¡}|d k	r<| j ||¡}|S r   )rð   Ú
_index_keyr¬   rí   rÈ   rì   rœ   )r   r   r   rÀ   r   r   r   r   ró   ~  s    zCache._load_overloadc              	   C   s$   |   ¡ � |  ||¡ W 5 Q R X dS )zE
        Save the data for the given signature in the cache.
        N)rò   Ú_save_overloadr   r   r   r   r   ‡  s    
zCache.save_overloadc                 C   sR   | j s
d S | j |¡sd S | jj ¡  |  ||j¡}| j |¡}| j 	||¡ d S r   )
rð   rì   r�   r�   r4   rô   r¬   r›   rí   rÅ   )r   r   r   rÀ   r   r   r   rõ   Ž  s    zCache._save_overloadc              
   c   sR   t jdkrHz
d V  W qN tk
rD } z|jtjkr4‚ W 5 d }~X Y qNX nd V  d S )NÚnt)r.   r×   rZ   ÚerrnoÚEACCES)r   Úer   r   r   rò   ˜  s    

z'Cache._guard_against_spurious_io_errorsc                 C   s\   | j jj}| j jdk	r6tdd„ | j jD ƒƒ}t|ƒ}nd}dd„ }|| ¡ ||ƒ||ƒffS )a
  
        Compute index key for the given signature and codegen.
        It includes a description of the OS, target architecture and hashes of
        the bytecode for the function and, if the function has a __closure__,
        a hash of the cell_contents.
        Nc                 S   s   g | ]
}|j ‘qS r   )Úcell_contentsr¡   r   r   r   Ú
<listcomp>¯  s     z$Cache._index_key.<locals>.<listcomp>r|   c                 S   s   t  | ¡ ¡ S r   )rA   r{   rD   )r£   r   r   r   Ú<lambda>¶  r|   z"Cache._index_key.<locals>.<lambda>)rê   r]   Úco_codeÚ__closure__Útupler   Zmagic_tuple)r   r   r¬   Z	codebytesZcvarsZ	cvarbytesZhasherr   r   r   rô   ¦  s    

ÿzCache._index_key)r#   r$   r%   rJ   rë   rb   rî   r)   r   r    r!   r"   r   ró   r   rõ   rå   ræ   rò   rô   r   r   r   r   rç   =  s    
	

rç   c                   @   s   e Zd ZdZeZdS )ÚFunctionCachezF
    Implements Cache that saves and loads CompileResult objects.
    N)r#   r$   r%   rJ   rž   rë   r   r   r   r   r   »  s   r   r„   c                    sB   ˆt kst‚t  ˆ¡ G ‡fdd„dtƒ‰ G ‡ fdd„dtƒ}|S )zØ
    Create a Cache class for additional compilation features to cache their
    result for reuse.  The cache is saved in filename pattern like
    in ``FunctionCache`` but with additional *prefix* as specified.
    c                       s   e Zd Z” ZdS )z6make_library_cache.<locals>.CustomCodeLibraryCacheImplN)r#   r$   r%   r®   r   )Úprefixr   r   ÚCustomCodeLibraryCacheImplÐ  s   r  c                       s   e Zd ZdZ” ZdS )z(make_library_cache.<locals>.LibraryCachez�
        Implements Cache that saves and loads CodeLibrary objects for additional
        feature for the specified python function.
        N)r#   r$   r%   rJ   rë   r   )r  r   r   ÚLibraryCacheÓ  s   r  )Ú_lib_cache_prefixesÚAssertionErrorÚaddrª   rç   )r  r  r   )r  r  r   Úmake_library_cacheÆ  s
    
r  )3rJ   Úabcr   r   r   rå   r÷   rA   rs   r¼   r.   rË   rP   r0   rÞ   r¨   Znumba.misc.appdirsr   rl   Znumba.core.errorsr   Znumba.core.baser   Znumba.core.codegenr   Znumba.core.compilerr	   Z
numba.corer
   r   Znumba.core.serializer   r   r   r'   r*   ÚobjectrL   r\   ri   rk   rr   r‚   rž   rª   r°   rç   r   rº   r  r  r   r   r   r   Ú<module>   sJ   )9  7E$~~
