U
    ø¾|eæ[  ã                   @   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
   ÚDEBUG_CACHEÚprint)ÚmsgÚargs© r   úO/var/www/website-v5/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/   r4   ÚabspathÚdirnameÚsplitÚhashlibÚsha1ÚencodeÚ	hexdigestÚjoin)r9   r;   r4   ÚsubpathZ	parentdirÚhashedr   r   r   Úget_suitable_cache_subpath‰   s
    z(_CacheLocator.get_suitable_cache_subpathN)r$   r%   r&   Ú__doc__r5   r   r.   r6   r7   Ú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   r6   ¡   s    z._SourceFileBackedLocatorMixin.get_source_stampc                 C   s
   t | jƒS r   )ÚstrÚ_linenor   r   r   r   r7   ª   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/   r4   Úexistsr5   ÚOSError©r9   r:   r;   r   r   r   r   r<   ­   s    
z+_SourceFileBackedLocatorMixin.from_functionN)r$   r%   r&   rJ   r6   r7   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/   r4   rF   r
   Ú	CACHE_DIRÚ_cache_path)r   r:   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<   )r9   r:   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/   r4   rF   r@   r`   )r   r:   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)ÚappnameZ	appauthor)rS   r]   r^   rX   r   Zuser_cache_dirrI   r/   r4   rF   r`   )r   r:   r;   ZappdirsZ	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/   r4   rY   rO   rP   r5   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_sourcerD   )r   r:   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.pathsru   ÚImportErrorZIPython.utils.pathr/   r4   rF   )r   ru   r   r   r   r.     s
    z#_IPythonCacheLocator.get_cache_pathc                 C   s   t  | j¡ ¡ S r   )rB   Úsha256rs   rE   r   r   r   r   r6     s    z%_IPythonCacheLocator.get_source_stampc                 C   s0   d  | j d¡d d… ¡}t |¡ ¡ d d… S )Nó    Té   é
   )rF   rs   Ú
splitlinesrB   rw   rE   )r   Ú
firstlinesr   r   r   r7     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-Ú
ipykernel_)Ú
startswithr/   r4   Úbasenamer@   r5   rZ   r[   r   r   r   r<   '  s    ÿþ
z"_IPythonCacheLocator.from_functionN)
r$   r%   r&   rJ   rb   r.   r6   r7   rK   r<   r   r   r   r   rn      s   
	rn   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$   ro   ÚgetfileÚ_locator_classesr<   ÚRuntimeErrorÚ_locatorr/   r4   Úsplitextr   rO   rP   Úget_filename_baseÚ_filename_base)
r   r:   ÚqualnameÚsource_pathr9   Ú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�   r7   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   rn   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
        )Ú_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	   Ú_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   )Ú	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)ÚanyÚliftedÚlibraryÚhas_dynamic_globalsÚfndescr‹   rA   Ú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
        )Úserialize_using_object_code©r   Zcodelibr   r   r   r™   §  s    zCodeLibraryCacheImpl.reducec                 C   s   |  ¡  |¡S )z6
        Returns the unserialized CodeLibrary
        )ÚcodegenÚ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‰   rF   Ú_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/   r4   rF   Ú_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   Únamer4   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   r4   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/   r4   rF   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`   r6   r—   r¶   Ú_cache_filer!   )r   r:   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�   r5   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   ÚerrnoZ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>rx   c                 S   s   t  | ¡ ¡ S r   )rB   rw   rE   )r¤   r   r   r   Ú<lambda>¶  rx   z"Cache._index_key.<locals>.<lambda>)rð   r]   Úco_codeÚ__closure__Útupler   Úmagic_tuple)r   r   r±   Z	codebytesZcvarsZ	cvarbytesÚ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ý   rB   ro   rÂ   r/   rÑ   rP   r1   rä   r¬   Znumba.misc.appdirsr   rl   Únumba.core.errorsr   Únumba.core.baser   Znumba.core.codegenr   Únumba.core.compilerr	   Ú
numba.corer
   r   Znumba.core.serializer   r   r   r(   r+   ÚobjectrL   r\   ri   rk   rn   r€   rœ   r®   r¶   rí   r  rÀ   r  r  r   r   r   r   Ú<module>   sJ   )9  7E$~~
