
    |hh                     r   S r SSKJrJr  SSKrSSKrSSKrSSKrSSKrSSK	r	SSK
Jr  SSKrSSKrSSKrSSKrSSKrSSKrSSKJr  SSKrSSKJr  SSKrSSKJr  SSKJr  SS	KJr  SS
KJr  SSK J!r!J"r"  SSK#J$r$  S r% " S S\S9r& " S S\&5      r' " S S\S9r( " S S\)5      r* " S S\*\(5      r+ " S S\*\(5      r, " S S\,5      r- " S S\*\(5      r. " S S \(5      r/ " S! S"\*\(5      r0 " S# S$\S9r1 " S% S&\15      r2 " S' S(\15      r3 " S) S*\)5      r4 " S+ S,\&5      r5 " S- S.\55      r6\7" S//5      r8S0 r9g)1z+
Caching mechanism for compiled functions.
    )ABCMetaabstractmethodN)floor)AppDirs)Path)NumbaWarning)BaseContext)CodeLibrary)CompileResult)configcompilerdumpsc                 N    [         R                  (       a  X-  n [        U 5        g g N)r   DEBUG_CACHEprint)msgargss     L/home/james-whalen/.local/lib/python3.13/site-packages/numba/core/caching.py
_cache_logr   "   s    jc
     c                   ~    \ rS rSr\\S 5       5       r\S 5       r\S 5       r\S 5       r	\S 5       r
\S 5       rSrg	)
_Cache(   c                     g)zG
The base filesystem path of this cache (for example its root folder).
N selfs    r   
cache_path_Cache.cache_path*       r   c                     g)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_contexts      r   load_overload_Cache.load_overload1   r"   r   c                     g)z,
Save the overload for the given signature.
Nr   r   r%   datas      r   save_overload_Cache.save_overload9   r"   r   c                     g)z
Enable the cache.
Nr   r   s    r   enable_Cache.enable?   r"   r   c                     g)z
Disable the cache.
Nr   r   s    r   disable_Cache.disableE   r"   r   c                     g)z
Flush the cache.
Nr   r   s    r   flush_Cache.flushK   r"   r   r   N)__name__
__module____qualname____firstlineno__propertyr   r    r'   r,   r/   r2   r5   __static_attributes__r   r   r   r   r   (   s      
    
  
  
  r   r   )	metaclassc                   B    \ rS rSr\S 5       rS rS rS rS r	S r
Srg	)
	NullCacheR   c                     g r   r   r   s    r   r    NullCache.cache_pathS   s    r   c                     g r   r   r$   s      r   r'   NullCache.load_overloadW       r   c                     g r   r   )r   r%   cress      r   r,   NullCache.save_overloadZ   rE   r   c                     g r   r   r   s    r   r/   NullCache.enable]   rE   r   c                     g r   r   r   s    r   r2   NullCache.disable`   rE   r   c                     g r   r   r   s    r   r5   NullCache.flushc   rE   r   r   N)r7   r8   r9   r:   r;   r    r'   r,   r/   r2   r5   r<   r   r   r   r?   r?   R   s-     r   r?   c                   n    \ rS rSrSrS r\S 5       r\S 5       r\S 5       r	\
S 5       r\
S 5       rS	rg
)_CacheLocatorg   z4
A filesystem locator for caching a given function.
c                     U R                  5       n[        R                  " USS9  [        R                  " US9R                  5         g )NT)exist_ok)dir)get_cache_pathosmakedirstempfileTemporaryFileclose)r   paths     r   ensure_cache_path_CacheLocator.ensure_cache_pathl   s5    ""$
D4(4(..0r   c                     g)z1
Return the directory the function is cached in.
Nr   r   s    r   rU   _CacheLocator.get_cache_pathr   r"   r   c                     g)zc
Get a timestamp representing the source code's freshness.
Can return any picklable Python object.
Nr   r   s    r   get_source_stamp_CacheLocator.get_source_stampx   r"   r   c                     g)z
Get a string disambiguator for this locator's function.
It should allow disambiguating different but similarly-named functions.
Nr   r   s    r   get_disambiguator_CacheLocator.get_disambiguator   r"   r   c                     [         e)zM
Create a locator instance for the given function located in the
given file.
)NotImplementedErrorclspy_funcpy_files      r   from_function_CacheLocator.from_function   s
     "!r   c                 J   [         R                  R                  U5      n[         R                  R                  U5      n[         R                  R	                  U5      S   n[
        R                  " UR                  5       5      R                  5       nSR                  XE/5      $ )zGiven 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).
_)
rV   r[   abspathdirnamesplithashlibsha1encode	hexdigestjoin)ri   rk   r[   subpath	parentdirhasheds         r   get_suitable_cache_subpath(_CacheLocator.get_suitable_cache_subpath   sq     www'''//$'GGMM'*2.	 gnn./99;xx+,,r   r   N)r7   r8   r9   r:   __doc__r\   r   rU   ra   rd   classmethodrl   r|   r<   r   r   r   rP   rP   g   sp    1  
     " " - -r   rP   c                   4    \ rS rSrSrS rS r\S 5       rSr	g)_SourceFileBackedLocatorMixin   zZ
A cache locator mixin for functions which are backed by a well-known
Python source file.
c                     [        [        SS5      (       a%  [        R                  " [        R                  5      nO [        R                  " U R
                  5      nUR                  UR                  4$ NfrozenF)getattrsysrV   stat
executable_py_filest_mtimest_sizer   sts     r   ra   ._SourceFileBackedLocatorMixin.get_source_stamp   sJ    3%(((B'B {{BJJ&&r   c                 ,    [        U R                  5      $ r   )str_linenor   s    r   rd   /_SourceFileBackedLocatorMixin.get_disambiguator   s    4<<  r   c                     [         R                  R                  U5      (       d  g U " X5      n UR                  5         U$ ! [         a     g f = fr   )rV   r[   existsr\   OSErrorri   rj   rk   r   s       r   rl   +_SourceFileBackedLocatorMixin.from_function   sN    ww~~g&&7$	""$   		s   A 
AAr   N)
r7   r8   r9   r:   r~   ra   rd   r   rl   r<   r   r   r   r   r      s%    
'! 
 
r   r   c                   B   ^  \ rS rSrSrS rS r\U 4S j5       rSr	U =r
$ )UserProvidedCacheLocator   zX
A locator that always point to the user provided directory in
`numba.config.CACHE_DIR`
c                     X l         UR                  R                  U l        U R	                  U5      n[
        R                  R                  [        R                  U5      U l
        g r   )r   __code__co_firstlinenor   r|   rV   r[   rx   r   	CACHE_DIR_cache_path)r   rj   rk   cache_subpaths       r   __init__!UserProvidedCacheLocator.__init__   sG    ''6677@77<<(8(8-Hr   c                     U R                   $ r   r   r   s    r   rU   'UserProvidedCacheLocator.get_cache_path       r   c                 r   > [         R                  (       d  g [        [        U 5      nUR	                  X5      $ r   )r   r   superr   rl   )ri   rj   rk   parent	__class__s       r   rl   &UserProvidedCacheLocator.from_function   s-    /5##G55r   r   r   r   )r7   r8   r9   r:   r~   r   rU   r   rl   r<   __classcell__r   s   @r   r   r      s'    I  6 6r   r   c                   $    \ rS rSrSrS rS rSrg)InTreeCacheLocator   zb
A locator for functions backed by a regular Python module with a
writable __pycache__ directory.
c                     X l         UR                  R                  U l        [        R
                  R                  [        R
                  R                  U R                   5      S5      U l        g )N__pycache__)	r   r   r   r   rV   r[   rx   rr   r   )r   rj   rk   s      r   r   InTreeCacheLocator.__init__   sB    ''6677<<(FVr   c                     U R                   $ r   r   r   s    r   rU   !InTreeCacheLocator.get_cache_path   r   r   r   N)r7   r8   r9   r:   r~   r   rU   r<   r   r   r   r   r      s    
W
 r   r   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )InTreeCacheLocatorFsAgnostic   z
A locator for functions backed by a regular Python module with a
writable __pycache__ directory. This version is agnostic to filesystem differences,
e.g. timestamp precision with milliseconds.
c                 F   > [         TU ]  5       n[        US   5      US   4$ )Nr      )r   ra   r   )r   r   r   s     r   ra   -InTreeCacheLocatorFsAgnostic.get_source_stamp   s'    W%'RU|RU""r   r   )r7   r8   r9   r:   r~   ra   r<   r   r   s   @r   r   r      s    # #r   r   c                   4    \ rS rSrSrS rS r\S 5       rSr	g)UserWideCacheLocator   z|
A locator for functions backed by a regular Python module or a
frozen executable, cached into a user-wide cache directory.
c                     X l         UR                  R                  U l        [	        SSS9nUR
                  nU R                  U5      n[        R                  R                  XE5      U l
        g NnumbaF)appname	appauthor)r   r   r   r   r   user_cache_dirr|   rV   r[   rx   r   r   rj   rk   appdirs	cache_dirr   s         r   r   UserWideCacheLocator.__init__   sV    ''66'U;**	77@77<<	Ar   c                     U R                   $ r   r   r   s    r   rU   #UserWideCacheLocator.get_cache_path   r   r   c                     [         R                  R                  U5      (       d  [        [        SS5      (       d  g U " X5      n UR                  5         U$ ! [         a     g f = fr   )rV   r[   r   r   r   r\   r   r   s       r   rl   "UserWideCacheLocator.from_function  s^    w''73%+H+H 7$	""$   		s   A 
A$#A$r   N)
r7   r8   r9   r:   r~   r   rU   r   rl   r<   r   r   r   r   r      s&    
B   r   r   c                   @    \ rS rSrSrS rS rS rS r\	S 5       r
Srg	)
IPythonCacheLocatori  zL
A locator for functions entered at the IPython prompt (notebook or other).
c                     X l         [        R                  " U5      n[        U[        5      (       a  X0l        g UR                  S5      U l        g )Nzutf-8)r   inspect	getsource
isinstancebytes_bytes_sourcerv   )r   rj   rk   sources       r   r   IPythonCacheLocator.__init__  s=     ""7+fe$$!'!'w!7Dr   c                      SSK Jn  [        R
                  R                  U" 5       S5      $ ! [         a	    SSKJn   N7f = f)Nr   )get_ipython_cache_dirnumba_cache)IPython.pathsr   ImportErrorIPython.utils.pathrV   r[   rx   )r   r   s     r   rU   "IPythonCacheLocator.get_cache_path   s<    
	A; ww||13]CC  	A@	As   - A A c                 ^    [         R                  " U R                  5      R                  5       $ r   )rt   sha256r   rw   r   s    r   ra   $IPythonCacheLocator.get_source_stamp,  s     ~~d001;;==r   c                     SR                  U R                  R                  S5      S S 5      n[        R                  " U5      R                  5       S S $ )Nr   T   
   )rx   r   
splitlinesrt   r   rw   )r   
firstliness     r   rd   %IPythonCacheLocator.get_disambiguator/  sI     XXd00;;DA"1EF
~~j)335cr::r   c                 &   UR                  S5      (       dQ  [        R                  R                  [        R                  R	                  U5      5      R                  S5      (       d  g U " X5      n UR                  5         U$ ! [         a     g f = f)Nz	<ipython-
ipykernel_)
startswithrV   r[   basenamerr   r\   r   r   s       r   rl   !IPythonCacheLocator.from_function8  s{     {++ww 89DD\RR7$	""$   		s   1B 
BB)r   r   N)r7   r8   r9   r:   r~   r   rU   ra   rd   r   rl   r<   r   r   r   r   r     s0    8
D>;  r   r   c                   J    \ rS rSrSrS r\S 5       rS rS r	\
S 5       rSrg	)
ZipCacheLocatoriH  zH
A locator for functions backed by Python modules within a zip archive.
c                    X l         UR                  R                  U l        U R	                  U5      u  U l        U l        [        SSS9nUR                  nU R                  U5      n[        R                  R                  XE5      U l        g r   )r   r   r   r   _split_zip_path	_zip_path_internal_pathr   r   r|   rV   r[   rx   r   r   s         r   r   ZipCacheLocator.__init__M  sr    ''66.2.B.B7.K++ 'U;**	77@77<<	Ar   c           	      $   [        U 5      n[        UR                  5       Hb  u  p#UR                  S5      (       d  M  [	        [        UR                  S US-    6 5      n[	        [        UR                  US-   S  6 5      nXE4s  $    [        S5      e)N.zipr   zNo zip file found in path)r   	enumeratepartsendswithr   
ValueError)rk   r[   ipartzip_pathinternal_paths         r   r   ZipCacheLocator._split_zip_pathY  s    G} ,GA}}V$$tTZZ!a%%89: #D$**QUW*=$> ?..	 -
 455r   c                     U R                   $ r   r   r   s    r   rU   ZipCacheLocator.get_cache_pathc  r   r   c                 r    [         R                  " U R                  5      nUR                  UR                  4$ r   )rV   r   r   r   r   r   s     r   ra    ZipCacheLocator.get_source_stampf  s'    WWT^^${{BJJ&&r   c                      SU;  a  g U " X5      $ )Nr   r   rh   s      r   rl   ZipCacheLocator.from_functionj  s     7$$r   )r   r   r   r   r   N)r7   r8   r9   r:   r~   r   staticmethodr   rU   ra   r   rl   r<   r   r   r   r   r   H  s?    
B 6 6 ' % %r   r   c                       \ rS rSrSr\\\\\	/r
S rS r\S 5       r\S 5       r\S 5       r\S 5       r\S	 5       rS
rg)	CacheImplip  z
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                 *   UR                   R                  U l         UR                  n[        R                  (       a  / n[        R                  R                  S5       H  nUR                  5       nSU;   a7  UR                  SS5      u  pV [        R                  " U5      n[        Xv5      nO+[!        5       R#                  U5      nUc  [        SU S35      eUR%                  U5        M     OU R&                  n[(        R*                  " U5      n
U H  nUR-                  X5      nUc  M    O   [        SU< SU
< 35      eXl        [(        R*                  " U5      n[0        R2                  R5                  [0        R2                  R7                  U5      5      S	   nU< SU< 3n[        [8        S
S5      nU R;                  X5      U l        g ! [         a    UR
                  n GNf = f! [        [        4 a  n	[        SU S35      U	eS n	A	ff = f)N,.r   zFailed to import 'z8' specified via NUMBA_CACHE_LOCATOR_CLASSES env variablezUnknown cache locator class: 'zcannot cache function z : no locator available for file r   abiflags )r   r   r   r9   AttributeErrorr7   r   CACHE_LOCATOR_CLASSESrs   striprsplit	importlibimport_moduler   r   RuntimeErrorglobalsgetappend_locator_classesr   getfilerl   _locatorrV   r[   splitextr   r   get_filename_base_filename_base)r   rj   qualnamelocator_classeslocator_class_pathmodule_path
class_namemoduleri   esource_pathlocatorfilenamemodnamefullnamer  s                   r   r   CacheImpl.__init__  s   ''66	(++H
 '' O&,&B&B&H&H&M"%7%=%=%?",,.@.G.GQ.O+K^!*!8!8!E%f9 ")--(:;C{*-KL^K_ `V ,V W W&&s+# 'N& #33O oog."C''=G" #
 08+ G H H ??7+''""277#3#3H#=>qA%x03
B/"44XHW  	(''H	( (8 ^*-?@R?S TV ,V W\]^^s)   G !G-G*)G*-H=HHc                     UR                  SS5      R                  SS5      nSnXCU R                  R                  5       [        R                  S   [        R                  S   U4-  $ )N<r  >z%s-%s.py%d%d%sr   r   )replacer&  rd   r   version_info)r   r)  r  fixed_fullnamefmts        r   r  CacheImpl.get_filename_base  si     "))#r2::3Cdll&D&D&F&&q)3+;+;A+>J J 	Jr   c                     U R                   $ r   )r  r   s    r   filename_baseCacheImpl.filename_base  s    """r   c                     U R                   $ r   )r  r   s    r   r&  CacheImpl.locator  s    }}r   c                     g)z$Returns the serialized form the dataNr   r   r+   s     r   reduceCacheImpl.reduce       	r   c                     g)z4Returns the de-serialized form of the *reduced_data*Nr   )r   r&   reduced_datas      r   rebuildCacheImpl.rebuild  r<  r   c                     g)zEReturns True if the given data is cachable; otherwise, returns False.Nr   r9  s     r   check_cachableCacheImpl.check_cachable  r<  r   )r  r   r  N)r7   r8   r9   r:   r~   r   r   r   r   r   r  r   r  r;   r4  r&  r   r:  r?  rB  r<   r   r   r   r  r  p  s     	!0IdJ # #        r   r  c                   *    \ rS rSrSrS rS rS rSrg)CompileResultCacheImpli  z6
Implements the logic to cache CompileResult objects.
c                 "    UR                  5       $ )z$
Returns a serialized CompileResult
)_reduce)r   rG   s     r   r:  CompileResultCacheImpl.reduce  s     ||~r   c                 D    [         R                  R                  " U/UQ76 $ )z(
Returns the unserialized CompileResult
)r   r   _rebuildr   r&   payloads      r   r?  CompileResultCacheImpl.rebuild  s      %%..~HHHr   c                 p   Sn[        S UR                   5       5      (       a  SnOUR                  R                  (       a  SnU(       al  SUR                  R
                  R                  S5      S   < SU< 3n[        R                  " U[        U R                  R                  U R                  5        g	g
)z0
Check cachability of the given compile result.
Nc              3   B   #    U  H  oR                   (       + v   M     g 7fr   )	can_cache).0xs     r   	<genexpr>8CompileResultCacheImpl.check_cachable.<locals>.<genexpr>  s     41;;s   zas it uses lifted codezLas it uses dynamic globals (such as ctypes pointers and large global arrays)z Cannot cache compiled function "r  ro   z" FT)anyliftedlibraryhas_dynamic_globalsfndescr  rs   warningswarn_explicitr   r  r   r   )r   rG   cannot_cacher   s       r   rB  %CompileResultCacheImpl.check_cachable  s     44443L\\--PLkk**005b9<IC""3#'==#9#94<<Ir   r   N)	r7   r8   r9   r:   r~   r:  r?  rB  r<   r   r   r   rE  rE    s    Ir   rE  c                   B   ^  \ rS rSrSrSrS rS rS rU 4S jr	Sr
U =r$ )	CodeLibraryCacheImpli  z4
Implements the logic to cache CodeLibrary objects.
Nc                 "    UR                  5       $ )z"
Returns a serialized CodeLibrary
)serialize_using_object_coder   codelibs     r   r:  CodeLibraryCacheImpl.reduce  s     2244r   c                 @    UR                  5       R                  U5      $ )z&
Returns the unserialized CodeLibrary
)codegenunserialize_libraryrK  s      r   r?  CodeLibraryCacheImpl.rebuild  s     %%';;GDDr   c                 $    UR                   (       + $ )z-
Check cachability of the given CodeLibrary.
)rX  rb  s     r   rB  #CodeLibraryCacheImpl.check_cachable	  s     ....r   c                    > [        [        U 5      nUR                  X5      nSR                  U R                  U/5      $ )N-)r   r_  r  rx   _filename_prefix)r   r)  r  r   resr   s        r   r  &CodeLibraryCacheImpl.get_filename_base  s:    +T2&&x:xx..455r   r   )r7   r8   r9   r:   r~   rm  r:  r?  rB  r  r<   r   r   s   @r   r_  r_    s*     5E/6 6r   r_  c                   ~    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS r\R"                  S 5       rSrg)IndexDataCacheFilei  zH
Implements the logic for the index file and data file used by a cache.
c                     Xl         U< S3U l        [        R                  R	                  U R                   U R                  5      U l        U< S3U l        X0l        [        R                  U l
        g )Nz.nbiz.{number:d}.nbc)r   _index_namerV   r[   rx   _index_path_data_name_pattern_source_stampr   __version___version)r   r    r4  source_stamps       r   r   IndexDataCacheFile.__init__  sT    %'4677<<(8(8$:J:JK9F"H)))r   c                 &    U R                  0 5        g r   )_save_indexr   s    r   r5   IndexDataCacheFile.flush!  s    r   c                 6   U R                  5       n X1   nU R                  XB5        g! [         af    [        UR                  5       5      n[        R
                  " S5       H  nU R                  U5      nXE;  d  M    O   WX1'   U R                  U5         Nf = f)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existingr   s          r   saveIndexDataCacheFile.save$  s     $$&		(!I 		(  	(9++-.H__Q' OOA.	, ( 'INY'	(s   ( AB<BBc                     U R                  5       nUR                  U5      nUc  g U R                  U5      $ ! [         a     gf = f)z 
Load a cache entry with *key*.
N)r  r  
_load_datar   )r   r  r  r  s       r   loadIndexDataCacheFile.load7  sO     $$&	MM#&		??9-- 		s   8 
AAc                 z    [        U R                  S5       n[        R                  " U5      nUR	                  5       nSSS5        WU R                  :w  a  0 $ [        R                  " W5      u  pE[        SU R                  5        X@R                  :w  a  0 $ U$ ! , (       d  f       Na= f! [
         a    0 s $ f = f)zd
Load the cache index and return it as a dictionary (possibly
empty if cache is empty or obsolete).
rbNz[cache] index loaded from %r)
openrt  pickler  readFileNotFoundErrorrx  loadsr   rv  )r   fversionr+   stampr  s         r   r  IndexDataCacheFile._load_indexE  s    
	d&&- ++a.vvx . dmm# I!<<-143C3CD&&& I# .- ! 	I	s-   B+ 'BB+ 
B($B+ (B+ +B:9B:c                 :   U R                   U4nU R                  U5      nU R                  U R                  5       n[        R
                  " U R                  USS9  UR                  U5        S S S 5        [        SU R                  5        g ! , (       d  f       N%= f)Nro   )protocolz[cache] index saved to %r)	rv  _dump_open_for_writert  r  dumprx  writer   )r   r  r+   r  s       r   r|  IndexDataCacheFile._save_index^  sv    !!9,zz$!!$"2"23qKKq26GGDM 4 	.0@0@A 43s   2B
Bc                     U R                  U5      n[        US5       nUR                  5       nS S S 5        [        R                  " W5      n[        SU5        U$ ! , (       d  f       N2= f)Nr  z[cache] data loaded from %r)
_data_pathr  r  r  r  r   )r   namer[   r  r+   tups         r   r  IndexDataCacheFile._load_dataf  sS    t$$668D ll4 0$7
	 s   A
A)c                     U R                  U5      nU R                  U5      nU R                  U5       nUR                  U5        S S S 5        [	        SU5        g ! , (       d  f       N= f)Nz[cache] data saved to %r)r  r  r  r  r   )r   r  r+   r[   r  s        r   r  IndexDataCacheFile._save_datan  sR    zz$t$!!$'1GGDM (-t4 ('s   A
A)c                 4    U R                   R                  US9$ )N)number)ru  format)r   r  s     r   r  IndexDataCacheFile._data_nameu  s    &&--V-<<r   c                 V    [         R                  R                  U R                  U5      $ r   )rV   r[   rx   r   )r   r  s     r   r  IndexDataCacheFile._data_pathx  s    ww||D,,d33r   c                     [        U5      $ r   r   )r   objs     r   r  IndexDataCacheFile._dump{  s    Szr   c              #   P  #    [         R                  " 5       R                  SS nU< SU< 3n [        US5       nUv   SSS5        [        R
                  " X15        g! , (       d  f       N%= f! [         a)     [        R                  " U5        e ! [         a     e f = ff = f7f)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.tmp.wb)	uuiduuid4hexr  rV   r.  	Exceptionunlinkr   )r   filepathuidtmpnamer  s        r   r  "IndexDataCacheFile._open_for_write~  s      jjls#!)3/
	gt$ %JJw) %$  			'"   		sW   ,B&A0 A A0 B&
A-)A0 0
B#;BB#
BB#BB##B&)r   ru  rs  rt  rv  rx  N)r7   r8   r9   r:   r~   r   r5   r  r  r  r|  r  r  r  r  r  
contextlibcontextmanagerr  r<   r   r   r   rq  rq    sY    *)&2B5=4  r   rq  c                       \ rS rSrSrSrS rS r\S 5       r	S r
S rS	 rS
 rS rS rS r\R$                  S 5       rS rSrg)Cachei  a   
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                 v   [        U5      U l        Xl        U R                  U5      U l        U R                  R
                  R                  5       U l        U R                  R
                  R                  5       nU R                  R                  n[        U R                  UUS9U l        U R                  5         g )N)r    r4  ry  )repr_name_py_func_impl_class_implr&  rU   r   ra   r4  rq  _cache_filer/   )r   rj   ry  r4  s       r   r   Cache.__init__  s    ']
%%g.
::--<<>zz))::<

00-9I9I<I;GI 	r   c                 T    SU R                   R                  < SU R                  < S3$ )Nr,  z	 py_func=r-  )r   r7   r  r   s    r   __repr__Cache.__repr__  s    $(NN$;$;TZZHHr   c                     U R                   $ r   r   r   s    r   r    Cache.cache_path  s    r   c                     SU l         g )NT_enabledr   s    r   r/   Cache.enable  s	    r   c                     SU l         g )NFr  r   s    r   r2   Cache.disable  s	    r   c                 8    U R                   R                  5         g r   )r  r5   r   s    r   r5   Cache.flush  s     r   c                     UR                  5         U R                  5          U R                  X5      sSSS5        $ ! , (       d  f       g= f)zZ
Load and recreate the cached object for the given signature,
using the *target_context*.
N)refresh!_guard_against_spurious_io_errors_load_overloadr$   s      r   r'   Cache.load_overload  s6     	 335&&s; 655s	   <
A
c                     U R                   (       d  g U R                  XR                  5       5      nU R                  R	                  U5      nUb  U R
                  R                  X$5      nU$ r   )r  
_index_keyrf  r  r  r  r?  )r   r%   r&   r  r+   s        r   r  Cache._load_overload  sX    }}ooc#9#9#;<$$S)::%%n;Dr   c                 z    U R                  5          U R                  X5        SSS5        g! , (       d  f       g= f)z5
Save the data for the given signature in the cache.
N)r  _save_overloadr*   s      r   r,   Cache.save_overload  s*     335* 655s   ,
:c                 T   U R                   (       d  g U R                  R                  U5      (       d  g U R                  R                  R	                  5         U R                  XR                  5      nU R                  R                  U5      nU R                  R                  X25        g r   )
r  r  rB  r&  r\   r  rf  r:  r  r  )r   r%   r+   r  s       r   r  Cache._save_overload  st    }}zz((..

,,.ooc<<0zz  &c(r   c              #      #    [         R                  S:X  a   S v   g S v   g ! [         a)  nUR                  [        R                  :w  a  e  S nAg S nAff = f7f)Nnt)rV   r  r   errnoEACCES)r   r$  s     r   r  'Cache._guard_against_spurious_io_errors  sF     77d?   77ell* +s*   A" A
AAAAAc                 N   U R                   R                  R                  nU R                   R                  bE  [	        U R                   R                   Vs/ s H  oDR
                  PM     sn5      n[        U5      nOSnS nXR                  5       U" U5      U" U5      44$ s  snf )z
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.
r   c                 J    [         R                  " U 5      R                  5       $ r   )rt   r   rw   )rR  s    r   <lambda>"Cache._index_key.<locals>.<lambda>  s    7>>!,668r   )r  r   co_code__closure__tuplecell_contentsr   magic_tuple)r   r%   rf  	codebytesrR  cvars	cvarbyteshashers           r   r  Cache._index_key  s     MM**22	==$$0DMM4M4MN4Mq??4MNOE eII8((*VI->-3I->-A B 	B Os   B")r  r   r  r  r  r  )r7   r8   r9   r:   r~   r  r   r  r;   r    r/   r2   r5   r'   r  r,   r  r  r  r  r  r<   r   r   r   r  r    sp    , KI    !<+)  Br   r  c                       \ rS rSrSr\rSrg)FunctionCachei  z>
Implements Cache that saves and loads CompileResult objects.
r   N)r7   r8   r9   r:   r~   rE  r  r<   r   r   r   r  r    s     )Kr   r  r  c                    ^ ^ T [         ;  d   e[         R                  T 5         " U 4S jS[        5      m " U4S jS[        5      nU$ )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                      > \ rS rSr Y rSrg)6make_library_cache.<locals>.CustomCodeLibraryCacheImpli&  r   N)r7   r8   r9   r:   rm  r<   )prefixs   r   CustomCodeLibraryCacheImplr  &  s	    !r   r  c                       > \ rS rSrSr Y rSrg)(make_library_cache.<locals>.LibraryCachei)  zu
Implements Cache that saves and loads CodeLibrary objects for additional
feature for the specified python function.
r   N)r7   r8   r9   r:   r~   r  r<   )r  s   r   LibraryCacher   )  s    	 1r   r  )_lib_cache_prefixesaddr_  r  )r  r  r  s   ` @r   make_library_cacher    sC     ,,,,F#"%9 "1u 1 r   ):r~   abcr   r   r  r  rt   r  r   r  mathr   rV   r  r   rX   r  rZ  numba.misc.appdirsr   zipfilepathlibr   r   numba.core.errorsr   numba.core.baser	   numba.core.codegenr
   numba.core.compilerr   
numba.corer   r   numba.core.serializer   r   r   r?   rP   objectr   r   r   r   r   r   r   r  rE  r_  rq  r  r  r  r  r  r   r   r   <module>r     sK  
 (        	  
    &    * ' * - ' &'w 'T *6-g 6-rF @6<m 6, 6  	##5 	#8- @4- 4n&%3] &%P_' _D!Y !H69 6>{ {|{BF {B|)E ) 2$i r   