
    shʱ                        S SK Jr  S SKrS SKrS SKJrJ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  S SKJrJrJrJrJrJrJrJr  S S	KJrJrJr  S S
KJ r J!r!  S SK"J#r#  S SK$J%r%  S SK&J'r'J(r(J)r)J*r*J+r+  S SK,J-r-  \R\                  " \R^                  " S5      5      r0\0r1\0r2 " S S\35      r4\Rj                  S 5       r6 " S S\35      r7 " S S\35      r8S r9 " S S\35      r:\Rj                  S 5       r;\;" 5         g)    )defaultdictN)permutations	takewhile)contextmanager)cached_property)ir)Constant)typesutils	datamodel	debuginfofuncdescconfigcgutilsimputils)eventerrorstargetconfig)_dynfunc
_helperlib)global_compiler_lock	PythonAPI)user_functionuser_generatorbuiltin_registryimpl_ret_borrowedRegistryLoader)builtins   c                   N    \ 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g)OverloadSelector   a  
An object matching an actual signature against a registry of formal
signatures and choosing the best candidate, if any.

In the current implementation:
- a "signature" is a tuple of type classes or type instances
- the "best candidate" is the most specific match
c                      / U l         0 U l        g N)versions_cacheselfs    c/Users/tiagomarins/Projetos/claudeai/copy_bank/venv/lib/python3.13/site-packages/numba/core/base.py__init__OverloadSelector.__init__%   s        c                     U R                   R                  U5      nUc  U R                  U5      nX R                   U'   U$ r%   )r'   get_find)r)   sigouts      r*   findOverloadSelector.find*   s7    kkooc";**S/C"KK
r-   c                     U R                  U5      nU(       a  X R                  U5         $ [        R                  " U  SU 35      e)Nz, )_select_compatible_best_signaturer   NumbaNotImplementedError)r)   r1   
candidatess      r*   r0   OverloadSelector._find1   sE    ,,S1
22:>??11TF"SE2BCCr-   c                 l    0 nU R                    H!  u  p4U R                  X15      (       d  M  XBU'   M#     U$ )z<
Select all compatible signatures and their implementation.
)r&   _match_arglist)r)   r1   r2   ver_sigimpls        r*   r6   #OverloadSelector._select_compatible8   s8     !]]MG""700#G + 
r-   c                 v  ^^ U R                  U5      u  nm[        U5      S:  a  TUS      m[        [        UU4S jU5      5      n[        U5      S:  a_  SR	                  [        U5      S9/nU H  nUSR	                  XQU   5      /-  nM     [
        R                  " SR                  U5      5      eUS   $ )z2
Returns the best signature out of the candidates
   r   c                    > TU    T:H  $ r%    )x
firstscore
genericitys    r*   <lambda>2OverloadSelector._best_signature.<locals>.<lambda>J   s    JqMZ,Gr-   z{n} ambiguous signatures)nz
{0} => {1}
)_sort_signatureslenlistr   formatr   NumbaTypeErrorjoin)r)   r9   orderedsamemsgr1   rE   rF   s         @@r*   r7    OverloadSelector._best_signatureB   s     #33J?w<!#GAJ/J	"G")+ ,D4y1}1883t98EFCL//_EFFC  ++DIIcN;;qzr-   c                    ^ [        [        5      m[        UR                  5       SS9 H*  u  p#U R	                  X#S9nU(       d  M  TU==   S-  ss'   M,     [        UR                  5       U4S jS9nUT4$ )z
Sort signatures in ascending level of genericity.

Returns a 2-tuple:

    * ordered list of signatures
    * dictionary containing genericity scores
   )r)formal_argsactual_argsrA   c                    > TU    $ r%   rC   )rD   rF   s    r*   rG   3OverloadSelector._sort_signatures.<locals>.<lambda>d   s	    *Q-r-   )key)r   intr   keysr<   sorted)r)   r9   thisothermatchedrQ   rF   s         @r*   rK   !OverloadSelector._sort_signaturesS   ss     !%
'
(9Q?KD))d)NGw4 A% 	 @ *0GH
""r-   c                 F   U(       aU  [        US   [        R                  5      (       a3  [        U5      [        U5      -
  S-   nUSS US   R                  4U-  -   n[        U5      [        U5      :w  a  g[        X5       H  u  pEU R                  XE5      (       a  M    g   g)z
Returns True if the signature is "matching".
A formal signature is "matching" if the actual signature matches exactly
or if the formal signature is a compatible generic signature.
rA   NFT)
isinstancer
   VarArgrL   dtypezip_match)r)   rX   rY   ndiffformalactuals         r*   r<   OverloadSelector._match_arglistg   s     :k"ou||DD$s;'77!;E%cr*k"o.C.C-E-MMK{s;//!+;NF;;v.. < r-   c                    X:X  a  g[         R                  U:X  a  g[        U[        5      (       aX  [	        U[         R
                  5      (       a8  [        U[        5      (       a  [	        X!5      (       a  g[        X!5      (       a  gg g g )NT)r
   Anyrf   type
issubclassType)r)   rl   rm   s      r*   rj   OverloadSelector._match{   sm    YY& %%*VUZZ*H*H&$''Jv,F,FF++ ,	 +I%r-   c                     [        U[        5      (       d   X45       eU R                  R                  X!45        U R                  R                  5         g)z2
Add a formal signature and its associated value.
N)rf   tupler&   appendr'   clear)r)   valuer1   s      r*   rw   OverloadSelector.append   sB     #u%%3|3%c\*r-   )r'   r&   N)__name__
__module____qualname____firstlineno____doc__r+   r3   r0   r6   r7   rK   r<   rj   rw   __static_attributes__rC   r-   r*   r"   r"      s5    
D"#((r-   r"   c                     [         R                  " S[        S5      5        [        R                  [
        R                  4 H7  n U R                  5        H   u  pSU-   n[         R                  " X25        M"     M9     [        R                  R                  R                  5        H^  n[        U[        5      (       d  M  [        U[        5      (       d  M1  [         R                  " SUR                  -  [        U5      5        M`     g)zE
Execute once to install special symbols into the LLVM symbol table.
_Py_NoneStructNnumba_zPyExc_%s)ll
add_symbolidr   	c_helpersr   itemsr   r   __dict__valuesrf   rq   rr   BaseExceptionr{   )r   py_name	c_addressc_nameobjs        r*   _load_global_helpersr      s     MM"BtH- !**H,>,>?	"+//"3G'FMM&, #4 @ ~~&&--/c4  Z]%C%CMM*5r#w? 0r-   c                   V   \ rS rSrSrSrSrSrSr\	R                  r
\S 5       r\R                  S 5       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SS.S jrS rS rS rS r\S 5       r\ S 5       r!\ S 5       r"S r#S r$S r%S r&S r'S r(S r)SjS jr*SjS jr+S r,S r-S  r.S! r/S" r0SkS# jr1S$ r2S% r3S& r4S' r5S( r6SkS) jr7SkS* jr8S+ r9S, r:S- r;S. r<SlS0 jr=S1 r>S2 r?S3 r@S4 rAS5 rBS6 rCS7 rDS8 rES9 rFS: rGS; rHS< rIS= rJS> rKS? rLS@ rMSA rNSB rOSmSC jrPSD rQSE rRSkSF jrSSG rTSH rUSI rVSJ rWSK rXSL rY0 S4SM jrZ0 SS/4SN jr[0 4SO jr\SP r]SQ r^SR r_SS r`ST raSU rbSnSV jrcSoSW jrdSpSX jreSkSY jrfSZ rgS[ rhSkS\ jriS] rjS^ rkS_ rlS` rmSa rnSb roSc rpSd rq\Se 5       rr\sSf 5       rtSg ruSh rvSirwg)qBaseContext   a  

Notes on Structure
------------------

Most objects are lowered as plain-old-data structure in the generated
llvm.  They are passed around by reference (a pointer to the structure).
Only POD structure can live across function boundaries by copying the
data.
Fc                 \    [         R                  b  [         R                  $ U R                  $ r%   )r   BOUNDSCHECK_boundscheckr(   s    r*   enable_boundscheckBaseContext.enable_boundscheck   s&    )%%%   r-   c                     Xl         g r%   )r   )r)   ry   s     r*   r   r      s    !r-   Nc                    [        5         [        R                  U l        Xl        SSKJn  X l        X2   U l        0 U l	        [        [        5      U l        [        [        5      U l        [        [        5      U l        [        5       U l        [        5       U l        0 U l        0 U l        0 U l        S U l        / U l        SU l        [.        R0                  U l        U R5                  5         g )Nr   )target_registryF)r   r   MACHINE_BITSaddress_sizetyping_contextnumba.core.target_extensionr   target_nametarget_registriesr   r"   _defns	_getattrs	_setattrs_casts_get_constants_generatorsspecial_opscached_internal_func_pid_codelib_stackr   r   default_managerdata_model_managerinit)r)   r   r   r   s       r*   r+   BaseContext.__init__   s    !..,?!%- !"23$%56$%56&(.0$&!	 !"+";"; 			r-   c                     g)z#
For subclasses to add initializer
NrC   r(   s    r*   r   BaseContext.init       r-   c                     U R                  5         U R                  [        5        U R                  R	                  5         g)za
Refresh context with new declarations from known registries.
Useful for third-party extensions.
N)load_additional_registriesinstall_registryr   r   refreshr(   s    r*   r   BaseContext.refresh  s5     	'') 	./ 	##%r-   c                     g)zD
Load target-specific registries.  Can be overridden by subclasses.
NrC   r(   s    r*   r   &BaseContext.load_additional_registries  r   r-   rC   abi_tagsuidc                ,    [         R                  " XX4S9$ )z
Perform name mangling.
r   )r   default_mangler)r)   namer
   r   r   s        r*   manglerBaseContext.mangler  s     ''hPPr-   c                     UR                   $ )zGet the environment name given a FunctionDescriptor.

Use this instead of the ``fndesc.env_name`` so that the target-context
can provide necessary mangling of the symbol to meet ABI requirements.
)env_name)r)   fndescs     r*   get_env_nameBaseContext.get_env_name"  s     r-   c                     X!R                   ;  aZ  [        R                  " U[        R                  US9nSUl        [        R                  " UR                  R                  5      Ul	        UR                   U   $ )a<  Declare the Environment pointer as a global of the module.

The pointer is initialized to NULL.  It must be filled by the runtime
with the actual address of the Env before the associated function
can be executed.

Parameters
----------
module :
    The LLVM Module
envname : str
    The name of the global variable.
)r   common)
globalsllvmirGlobalVariabler   	voidptr_tlinkageget_null_valuerq   pointeeinitializer)r)   moduleenvnamegvs       r*   declare_env_globalBaseContext.declare_env_global*  sX     ..(&&vw/@/@wOB!BJ$33BGGOODBN~~g&&r-   c                 D    [         R                  " U R                  U5      $ r%   )r   	ArgPackerr   )r)   fe_argss     r*   get_arg_packerBaseContext.get_arg_packer?  s    ""4#:#:GDDr-   c                 D    [         R                  " U R                  U5      $ r%   )r   
DataPackerr   )r)   fe_typess     r*   get_data_packerBaseContext.get_data_packerB  s    ##D$;$;XFFr-   c                     [         er%   NotImplementedErrorr(   s    r*   target_dataBaseContext.target_dataE  s    !!r-   c                     [        5       $ )z>
All module attrs are constant for targets using BaseContext.
)rv   r(   s    r*   nonconst_module_attrs!BaseContext.nonconst_module_attrsI  s    
 wr-   c                 2    SSK Jn  U" X R                  5      $ )Nr   )
NRTContext)numba.core.runtime.contextr   
enable_nrt)r)   r   s     r*   nrtBaseContext.nrtP  s    9$00r-   c                     [         R                   " U 5      nUR                  5        H;  u  p4[        X#5      (       d  [        SR	                  U5      5      e[        X#U5        M=     UR                  5       U R                  5       La  0 Ul        U$ )Nzunknown option {0!r})copyr   hasattr	NameErrorrN   setattrcodegenr   )r)   kwsr   kvs        r*   	subtargetBaseContext.subtargetU  sn    iioIIKDA3?? 6 = =a @AACA   ;;=.')C$
r-   c                     U R                   U   nU R                  UR	                  S5      5        U R                  UR	                  S5      5        U R                  UR	                  S5      5        U R                  UR	                  S5      5        U R                  UR	                  S5      5        g! [         a    [        U5      nX R                   U'    Nf = f)z`
Install a *registry* (a imputils.Registry instance) of function
and attribute implementations.
	functionsgetattrssetattrscasts	constantsN)	r   KeyErrorr   insert_func_defnnew_registrations_insert_getattr_defn_insert_setattr_defn_insert_cast_defn_insert_get_constant_defn)r)   registryloaders      r*   r   BaseContext.install_registry`  s    
	0%%h/F 	f66{CD!!&":"::"FG!!&":"::"FGv77@A&&v'?'?'LM  	0#H-F)/X&	0s   B2 2#CCc                 X    U H$  u  p#nU R                   U   R                  X$5        M&     g r%   )r   rw   )r)   defnsr>   funcr1   s        r*   r  BaseContext.insert_func_defnp  s'    $ODKK$$T/  %r-   c                 X    U H$  u  p#nU R                   U   R                  X$5        M&     g r%   )r   rw   r)   r  r>   attrr1   s        r*   r   BaseContext._insert_getattr_defnt  '    $ODNN4 ''2  %r-   c                 X    U H$  u  p#nU R                   U   R                  X$5        M&     g r%   )r   rw   r  s        r*   r   BaseContext._insert_setattr_defnx  r  r-   c                 P    U H   u  p#U R                   R                  X#5        M"     g r%   )r   rw   r)   r  r>   r1   s       r*   r  BaseContext._insert_cast_defn|  s     IDKKt) r-   c                 P    U H   u  p#U R                   R                  X#5        M"     g r%   )r   rw   r  s       r*   r  %BaseContext._insert_get_constant_defn  s"    ID&&t1 r-   c                 j    [        X#5      nU R                  U   R                  XDR                  5        g r%   )r   r   rw   	signature)r)   r  r   libsr>   s        r*   insert_user_function BaseContext.insert_user_function  s'    V*D  ~~6r-   c                 |    [        U[        R                  5      (       d   e[        X#5      nX$4U R                  U'   g r%   )rf   r
   	Generatorr   r   )r)   gentygendescr  r>   s        r*   insert_generatorBaseContext.insert_generator  s5    %1111g,")-r-   c                     U R                   U	 g)zT
Remove user function *func*.
KeyError is raised if the function isn't known to us.
N)r   )r)   r  s     r*   remove_user_function BaseContext.remove_user_function  s    
 KKr-   c                     UR                    Vs/ s H  nU R                  U5      PM     nnU R                  UR                  5      n[        R                  " XC5      nU$ s  snf r%   )argtypesget_argument_typerestyper   FunctionType)r)   r   atyr)  r+  fntys         r*   get_external_function_type&BaseContext.get_external_function_type  sa    %0. **3/. 	 0 ((8""750s   Ac                    U R                   R                  UR                  UR                  5      n[        R
                  " XUR                  5      nU R                   R                  XBR                  UR                  UR                  S9  UR                  (       aQ  UR                  R                  S5        UR                  R                  S5        UR                  R                  S5        U$ )N)noaliasalwaysinlinenoinlineoptnone)	call_convget_function_typer+  r)  r   get_or_insert_functionmangled_namedecorate_functionargsr2  inline
attributesadddiscard)r)   r   r   r.  fns        r*   declare_functionBaseContext.declare_function  s    ~~//P++F&:M:MN(([[&//SYSaSa(b==MMn-MM!!*-MM!!),	r-   c                     U R                  U5      n[        R                  " XUR                  5      nUR                  (       d   e[        UR                  UR                  5       H  u  pVSU-  Ul        M     U$ )Nzarg.%s)r/  r   r8  r9  is_declarationri   r;  r   )r)   r   r   r.  r@  akavs          r*   declare_external_function%BaseContext.declare_external_function  sd    ..v6++F&:M:MN    &++rww/FBmBG 0	r-   c                     [         nSU-  n[        R                  " UR                  S5      S-   5      nU R	                  XU5      n[
        R                  " Xc5      $ )z<
Insert constant *string* (a str object) into module *mod*.
z	.const.%szutf-8    )GENERIC_POINTERr   make_bytearrayencodeinsert_unique_constr	   bitcast)r)   modstring
stringtyper   textr   s          r*   insert_const_stringBaseContext.insert_const_string  sT     %
V#%%fmmG&<w&FG%%c6//r-   c                     [         nSU=(       d    [        U5      -  n[        R                  " U5      nU R	                  XU5      n[
        R                  " Xd5      $ )z>
Insert constant *byte* (a `bytes` object) into module *mod*.
z	.bytes.%s)rK  hashr   rL  rN  r	   rO  )r)   rP  bytesr   rR  rS  r   s          r*   insert_const_bytesBaseContext.insert_const_bytes  sO     %
d1d5k2%%e,%%c6//r-   c                 x     UR                  U5      nU$ ! [         a    [        R                  " XU5      s $ f = f)z[
Insert a unique internal constant named *name*, with LLVM value
*val*, into module *mod*.
)
get_globalr   r   global_constant)r)   rP  r   valr   s        r*   rN  BaseContext.insert_unique_const  s@    
	%B I  	;**3c::	;s    !99c                 <    U R                   U   R                  5       $ r%   )r   r*  r)   tys     r*   r*  BaseContext.get_argument_type  s    &&r*<<>>r-   c                 <    U R                   U   R                  5       $ r%   )r   get_return_typera  s     r*   re  BaseContext.get_return_type  s    &&r*::<<r-   c                 <    U R                   U   R                  5       $ )z
Get a LLVM data representation of the Numba type *ty* that is safe
for storage.  Record data are stored as byte array.

The return value is a llvmlite.ir.Type object, or None if the type
is an opaque pointer (???).
r   get_data_typera  s     r*   ri  BaseContext.get_data_type  s     &&r*88::r-   c                 <    U R                   U   R                  5       $ r%   )r   get_value_typera  s     r*   rl  BaseContext.get_value_type  s    &&r*99;;r-   c                 `    U R                   U   R                  X5      nUR                  XdUS9  g)z
Pack value into the array storage at *ptr*.
If *align* is given, it is the guaranteed alignment for *ptr*
(by default, the standard ABI alignment).
)alignN)r   as_datastore)r)   builderrb  ry   ptrro  datavals          r*   
pack_valueBaseContext.pack_value  s/     ))"-55gEg%0r-   c                 D    U R                   U   nUR                  XU5      $ )z
Unpack value from the array storage at *ptr*.
If *align* is given, it is the guaranteed alignment for *ptr*
(by default, the standard ABI alignment).
)r   load_from_data_pointer)r)   rr  rb  rs  ro  dms         r*   unpack_valueBaseContext.unpack_value  s'     $$R(((u==r-   c                      U R                   R                  U45      nU" XX#5      $ ! [         a    [        SU< S35      ef = f)zE
Return a LLVM constant representing value *val* of Numba type *ty*.
zCannot lower constant of type '')r   r3   r   )r)   rr  rb  r^  r>   s        r*   get_constant_generic BaseContext.get_constant_generic  sL    	T&&++RE2Dr//" 	T%b&RSS	Ts	   $' Ac                 &    U R                  SX5      $ )z`
Same as get_constant_generic(), but without specifying *builder*.
Works only for simple types.
N)r~  )r)   rb  r^  s      r*   get_constantBaseContext.get_constant  s     ((r77r-   c                 X    U R                  U5      n[        U[        R                  5      $ r%   )rl  r	   r   	Undefinedr)   rb  ltys      r*   get_constant_undefBaseContext.get_constant_undef  s%    !!"%V--..r-   c                 <    U R                  U5      n[        US 5      $ r%   )rl  r	   r  s      r*   get_constant_nullBaseContext.get_constant_null
  s    !!"%T""r-   Tc                 V   Uc   eUR                  5       n[        U[        R                  5      (       a!  UR	                  U5      nU R
                  U   nOUnU R
                  U   n [        UR                  UR                  5      X5      $ ! [        R                   a     Of = f[        U[        R                  5      (       a,   U R                  [        U5      U5      $ ! [         a     Of = fU(       a   U R                  5         U R                  XSS9$ [        SU< U< 35      e)z
Return the implementation of function *fn* for signature *sig*.
The return value is a callable with the signature (builder, args).
F)
_firstcallNo definition for lowering )as_functionrf   r
   Callableget_impl_keyr   
_wrap_implr3   r;  r   r8   rs   get_functionrq   r   r   )r)   r@  r1   r  r\   	overloadss         r*   r  BaseContext.get_function  s   
 oob%..))//#&CC(ICC(I	innSXX6BB.. 		b%**%%((b377&  LLN$$R$??!sC"PQQs$   ($B B$#B$C" "
C/.C/c                 &    U R                   U   S   $ )	
        r   )r   )r)   r!  s     r*   get_generator_descBaseContext.get_generator_desc0  s     &q))r-   c                 b    U R                   U   S   nU R                  [        USS5      5        U$ )r  rA   r  rC   )r   add_linking_libsgetattr)r)   r!  ress      r*   get_generator_implBaseContext.get_generator_impl5  s5     u%a(gc6267
r-   c                 H    U R                  U5      UR                  :X  d   eU$ r%   )rl  rq   )r)   rr  r   rb  s       r*   get_bound_functionBaseContext.get_bound_function<  s$    ""2&#((222
r-   c                 J  ^ ^^ X4T R                   ;  n[        U[        R                  5      nU(       ae  U(       a^  T R                  R                  X5      mTb  [        T[        R                  5      (       a  g[        UR                  U5      mUUU 4S jnU$ T R                  U   n UR                  U45      $ ! [        R                   a     Of = fT R                  S   n UR                  U45      $ ! [        R                   a     Of = f[        SU< SU< 35      e)z
Get the getattr() implementation for the given type and attribute name.
The return value is a callable with the signature
(context, builder, typ, val, attr).
Nc                 D   > TR                  UTT5      n[        XTU5      $ r%   )r~  r   )	contextrr  typr^  r  llvalattrtypyvalr)   s	         r*   imp$BaseContext.get_getattr.<locals>.impS  s&     55gvuME,WvuMMr-   r  .)r   rf   r
   Moduler   resolve_module_constantsDummyr  pymodr   r3   r   r8   r   )	r)   r  r  
const_attr	is_moduler  r  r  r  s	   `      @@r*   get_getattrBaseContext.get_getattr@  s	    [(B(BB
sELL1	 ((AA#LF~FEKK!@!@ 		40N 
 NN4(		>>3&)).. 		 NN4(		>>3&)).. 		 "T"RSSs$   *B< <CC&C8 8DDc                   ^ ^^ [        TR                  5      S:X  d   eTR                  S   nTR                  S   nUU U4S jnT R                  T   n U" UR                  X445      5      $ ! [        R
                   a     Of = fT R                  S   n U" UR                  X445      5      $ ! [        R
                   a     Of = f[        SU< ST< SU< 35      e)	z
Get the setattr() implementation for the given attribute name
and signature.
The return value is a callable with the signature (builder, args).
rV   r   rA   c                    >^  UU UU4S jnU$ )Nc                    > T" TU TUT5      $ r%   rC   )rr  r;  r  r>   r)   r1   s     r*   wrapped>BaseContext.get_setattr.<locals>.wrap_setattr.<locals>.wrappedr  s    D'3d;;r-   rC   )r>   r  r  r)   r1   s   ` r*   wrap_setattr-BaseContext.get_setattr.<locals>.wrap_setattrq  s    < <Nr-   Nr  r  z = )rL   r;  r   r3   r   r8   r   )r)   r  r1   r  valtyr  r  s   ```    r*   get_setattrBaseContext.get_setattrg  s     388}!!!hhqk	 NN4(			| <==.. 		 NN4(			| <==.. 		 "%($#7 8 	8s$   A- -BBB/ /CCc                 >    U R                   U   R                  X5      $ )z7
Argument representation to local value representation
)r   from_argumentr)   rr  rb  r^  s       r*   get_argument_valueBaseContext.get_argument_value  s      &&r*88FFr-   c                 >    U R                   U   R                  X5      $ )z;
Return value representation to local value representation
)r   from_returnr  s       r*   get_returned_valueBaseContext.get_returned_value  s      &&r*66wDDr-   c                 >    U R                   U   R                  X5      $ )z:
Local value representation to return type representation
)r   	as_returnr  s       r*   get_return_valueBaseContext.get_return_value  s      &&r*44WBBr-   c                 >    U R                   U   R                  X5      $ )zKPrepare local value representation as argument type representation
        )r   as_argumentr  s       r*   get_value_as_argument!BaseContext.get_value_as_argument  s      &&r*66wDDr-   c                 >    U R                   U   R                  X5      $ r%   )r   rp  r  s       r*   get_value_as_dataBaseContext.get_value_as_data  s    &&r*227@@r-   c                 >    U R                   U   R                  X5      $ r%   )r   	from_datar  s       r*   get_data_as_valueBaseContext.get_data_as_value  s    &&r*44WBBr-   c                 >    U R                  XU5      nUR                  $ )z4
Extract the first element of a heterogeneous pair.
)make_helperfirstr)   rr  r^  rb  pairs        r*   
pair_firstBaseContext.pair_first  s      S1zzr-   c                 >    U R                  XU5      nUR                  $ )z5
Extract the second element of a heterogeneous pair.
)r  secondr  s        r*   pair_secondBaseContext.pair_second  s      S1{{r-   c           	      B   U[         R                  L a  U R                  U5      $ X4:X  d  U[         R                  :X  a  U$  U R                  R                  X445      nU" XX4U5      $ ! [        R                   a#    [        R                  " SU< SU< SU< 35      ef = f)z
Cast a value of type *fromty* to type *toty*.
This implements implicit conversions as can happen due to the
granularity of the Numba type system, or lax Python semantics.
zCannot cast z to z: )r
   
_undef_varr  rp   r   r3   r   r8   )r)   rr  r^  fromtytotyr>   s         r*   castBaseContext.cast  s     U%%%))$//^tuyy0J	B;;##VN3DvS99.. 	B11.4dC@B B	Bs   %A' '7Bc                 z   Uu  pVUu  pxU R                   R                  XV5      n	U	c   eU R                  XXY5      n
U R                  XXi5      nU R                   R                  U5      nUR	                  U R                   X40 5      nU R                  X5      nU R                  [        USS5      5        U" XU45      $ )z
Compare the given LLVM values of the given Numba types using
the comparison *key* (e.g. '==').  The values are first cast to
a common safe conversion type.
r  rC   )r   unify_typesr  resolve_value_typeget_call_typer  r  r  )r)   rr  r\   r)  r;  atbtrF  bvrb  cavcbvr.  cmpsigcmpfuncs                  r*   generic_compareBaseContext.generic_compare  s       ,,R4~~iiR,iiR,""55c:##D$7$7"2F##D1ggvr:;wc
++r-   c                     U R                  U[        R                  " U5      5      n[        R                  Ul        UR                  5       $ r%   )r  r
   Optionalr   	false_bitvalid	_getvalue)r)   rr  valtypeoptvals       r*   make_optional_noneBaseContext.make_optional_none  s9    !!'5>>'+BC((!!r-   c                     U R                  U[        R                  " U5      5      n[        R                  Ul        X4l        UR                  5       $ r%   )r  r
   r  r   true_bitr  datar  )r)   rr  r  ry   r  s        r*   make_optional_valueBaseContext.make_optional_value  s>    !!'5>>'+BC''!!r-   c                     U R                   R                  [        5      nUR                  U R                   U40 5      nU R	                  XE5      nU" X45      $ )z<
Return the truth value of a value of the given Numba type.
)r   r  boolr  r  )r)   rr  r  r^  r.  r1   r>   s          r*   is_trueBaseContext.is_true  sS     ""55d;  !4!4sfbA  +GV$$r-   c                    UR                   R                  n UR                  U   nU$ ! [         aN    [        R
                  " XRU5      nU(       a,  U R                  (       a  [        R                  S:X  a  SUl	         U$ f = f)z
Get a global value through its C-accessible *name*, with the given
LLVM type.
If *dllimport* is true, the symbol will be marked as imported
from a DLL (necessary for AOT compilation under Windows).
win32	dllimport)
functionr   r   r   r   add_global_variableaot_modesysplatformstorage_class)r)   rr  r  r   r	  r   r   s          r*   get_c_valueBaseContext.get_c_value  st     !!((	/%B
 		  	/,,V$?BT]]s||w/F#. 			/s   ) AB Bc           	          [        X45       VVs/ s H  u  pVU R                  XU5      PM     nnnUR                  X$5      nU$ s  snnf r%   )ri   r  call)r)   rr  calleeargtysr;  rb  argretvals           r*   call_external_function"BaseContext.call_external_function  sN    "6020GB **7<0 	 2f+2s   Ac                 <    U R                   U   R                  5       $ r%   rh  )r)   r  s     r*   get_function_pointer_type%BaseContext.get_function_pointer_type   s    &&s+99;;r-   c                 "    UR                  X#US9$ )N)cconv)r  )r)   rr  funcptrr;  r  s        r*   call_function_pointer!BaseContext.call_function_pointer  s    ||G|77r-   c                     UR                   n[        n[        R                  " [        R                  " S5      U/5      n[
        R                  " X5S5      nUR                  Xb/5      $ )N    puts)r   rK  r   r,  IntTyper   r8  r  )r)   rr  rS  rP  cstringr.  r$  s          r*   print_stringBaseContext.print_string  sP    nn!""6>>"#5yA--c@||D&))r-   c                 t    UR                   nU R                  U[        U5      5      nU R                  X5        g r%   )r   rT  strr'  )r)   rr  rS  rP  cstrs        r*   debug_printBaseContext.debug_print  s/    nn''SY7'(r-   c                 4   UR                   n[        U[        5      (       a  U R                  XB5      nOUn[        R
                  " [        R                  " S5      [        4SS9n[        R                  " XFS5      nUR                  Xu4[        U5      -   5      $ )Nr#  T)var_argprintf)r   rf   r*  rT  r   r,  r%  rK  r   r8  r  rv   )r)   rr  format_stringr;  rP  r+  r.  r@  s           r*   r0  BaseContext.printf  sz    nnmS))++C?D D""6>>"#57ISWX++Cx@||B%+ 566r-   c                     UR                    VVs/ s H  u  p#U R                  U5      PM     nnn[        R                  " U5      $ s  snnf )zB
Get the LLVM struct type for the given Structure class *struct*.
)_fieldsrl  r   LiteralStructType)r)   struct_r   fieldss        r*   get_struct_typeBaseContext.get_struct_type  s@     6<^^D^TQ$%%a(^D''// Es   Ac                 6    [        U R                  5       S 5      $ r%   )r	   get_dummy_typer(   s    r*   get_dummy_valueBaseContext.get_dummy_value#  s    ++-t44r-   c                     [         $ r%   )rK  r(   s    r*   r<  BaseContext.get_dummy_type&  s    r-   c                 ^   SSK Jn  [           U R                  5       nUR	                  UR
                  5      nUcj  [        R                  " 5       n	UR                  5       nU	(       a>  U	R                  5       n
U
R                  S5      (       a  U
R                  (       a  SUl        SUl        SUl        SUl        UR                  U R                   U UX#R"                  UR$                  UUS9nU R&                  R)                  UR*                  5        UsSSS5        $ ! , (       d  f       g= f)z
Invoke the compiler to compile a function to be used inside a
nopython function, but without generating code to call that
function.

Note this context's flags are not inherited.
r   )compilerNr   T)locals)
numba.corerB  r   r   create_libraryr{   r   ConfigStackFlagstopis_setr   
no_compileno_cpython_wrapperno_cfunc_wrappercompile_internalr   r;  return_typeactive_code_libraryadd_linking_librarylibrary)r)   rr  r>   r1   rC  flagsrB  r   rQ  cstk	tls_flagscress               r*   _compile_subroutine_no_cache(BaseContext._compile_subroutine_no_cache)  s     	(!llnG,,T]];G}#//1 ( $
I ''..9==$(	#E'+E$%)E",,T-@-@$-4-188-0__e4:	 - <D $$88F1 "!!s   DD
D,c                    UR                   U[        U R                  5      4nU(       d  SnOKUR                  (       a  U[	        S UR                   5       5      -  nU R
                  R                  U5      nUc   U R                  XUUUS9n	XR
                  U'   U R
                  U   n	U R                  R                  U	R                  5        U	$ )z
Compile the function *impl* for the given *sig* (in nopython mode).
Return an instance of CompileResult.

If *caching* evaluates True, the function keeps the compiled function
for reuse in *.cached_internal_func*.
Nc              3   8   #    U  H  oR                   v   M     g 7fr%   )cell_contents).0cs     r*   	<genexpr>1BaseContext.compile_subroutine.<locals>.<genexpr>_  s     "M<Lq??<Ls   )rC  rR  )__code__rq   error_model__closure__rv   r   r/   rV  rO  rP  rQ  )
r)   rr  r>   r1   rC  rR  caching	cache_keycachedrU  s
             r*   compile_subroutineBaseContext.compile_subroutineO  s     ]]Cd.>.>)?@	F U"MD<L<L"MMM	..229=F>44WC<B;@ 5 BD 48%%i0((3  44T\\Br-   c                 ^    U R                  XX55      nU R                  XR                  X45      $ )zN
Like compile_subroutine(), but also call the function with the given
*args*.
)re  call_internalr   )r)   rr  r>   r1   r;  rC  rU  s          r*   rM  BaseContext.compile_internall  s-    
 &&wcB!!';;BBr-   c                    U R                  XX45      u  pV[        R                  " XR                  5         U R                  R                  X5        SSS5        [        R                  " XX5U5      nU$ ! , (       d  f       N(= f)zz
Given the function descriptor of an internally compiled function,
emit a call to that function with the given arguments.
N)call_internal_no_propagater   if_unlikelyis_errorr6  return_status_propagater   fix_returning_optional)r)   rr  r   r1   r;  statusr  s          r*   rh  BaseContext.call_internalt  se    
 55gsQ  //:NN227C ; --dS#N
	 ;:s   A33
Bc                     UR                   nU R                  XR5      nU R                  R                  XUR                  UR
                  U5      u  pxXx4$ )z`Similar to `.call_internal()` but does not handle or propagate
the return status automatically.
)r   rA  r6  call_functionrN  r;  )	r)   rr  r   r1   r;  llvm_modr@  rp  r  s	            r*   rk  &BaseContext.call_internal_no_propagate  sM    
 >>""84nn2273688TC{r-   c                    U R                  5       nU R                  R                  UR                  UR                  5      nUR                  XU5      nU R                  R                  XUR                  UR                  U5      u  p[        R                  " XR                  5         U R                  R                  X5        SSS5        [        R                  " XX8U	5      n	U	$ ! , (       d  f       N(= f)a  
Insert a function call to an unresolved symbol with the given *name*.

Note: this is used for recursive call.

In the mutual recursion case::

    @njit
    def foo():
        ...  # calls bar()

    @njit
    def bar():
        ... # calls foo()

    foo()

When foo() is called, the compilation of bar() is fully completed
(codegen'ed and loaded) before foo() is. Since MCJIT's eager compilation
doesn't allow loading modules with declare-only functions (which is
needed for foo() in bar()), the call_unresolved injects a global
variable that the "linker" can update even after the module is loaded by
MCJIT. The linker would allocate space for the global variable before
the bar() module is loaded. When later foo() module is defined, it will
update bar()'s reference to foo().

The legacy lazy JIT and the new ORC JIT would allow a declare-only
function be used in a module as long as it is defined by the time of its
first use.
N)r   r6  r7  rN  r;  insert_unresolved_refrs  r   rl  rm  rn  r   ro  )
r)   rr  r   r1   r;  r   r.  r@  rp  r  s
             r*   call_unresolvedBaseContext.call_unresolved  s    @ ,,.~~//J**7$?nn2273688TC  //:NN227C ; --dS#N
	 ;:s   'C%%
C3c                     [         er%   r   )r)   r  r   envs       r*   get_executableBaseContext.get_executable  s    !!r-   c                     [        X5      $ r%   r   )r)   rr  s     r*   get_python_apiBaseContext.get_python_api  s    ''r-   c                 `   U R                   (       a  UR                  U5      nUR                  U5      n[        U[        R
                  5      (       a  UR                  nU R                  U R                  U5      5      nX5-  (       a&  SR                  XUS9n[        R                  " U5      egg)z8
Assumes offset starts from a properly aligned location
z*{rec}.{attr} of type {type} is not aligned)recr  rq   N)strict_alignmentoffsettypeofrf   r
   NestedArrayrh   get_abi_alignmentri  rN   r   rO   )r)   rectypr  r  elemtyro  rS   s          r*   sentry_record_alignment#BaseContext.sentry_record_alignment  s       ]]4(F]]4(F&%"3"344  **4+=+=f+EFE~BII J 8++C00  !r-   c                 .    [         R                  " X5      $ )z)
Get a helper class for the given *typ*.
)r   create_struct_proxy)r)   r  kinds      r*   get_helper_classBaseContext.get_helper_class  s     **355r-   c                 2    U R                  X%5      nU" XX4S9$ )N)ry   ref)r  )r)   rr  r  ry   r  r  clss          r*   _make_helperBaseContext._make_helper  s    ##C.477r-   c                 $    U R                  XX4SS9$ )zV
Get a helper object to access the *typ*'s members,
for the given value or reference.
ry   )r  r  )r)   rr  r  ry   r  s        r*   r  BaseContext.make_helper  s    
   u HHr-   c                 $    U R                  XUSS9$ )zZ
As make_helper(), but considers the value as stored in memory,
rather than a live value.
r   )r  r  r  )r)   rr  r  r  s       r*   make_data_helperBaseContext.make_data_helper  s    
   3V DDr-   c                 0    SSK Jn  UR                  U5      $ )Nr   arrayobj)numba.npr  
make_array)r)   r  r  s      r*   r  BaseContext.make_array  s    %""3''r-   c                 4    SSK Jn  UR                  " U40 UD6$ )z
Populate array structure.
r   r  )r  r  populate_array)r)   arrkwargsr  s       r*   r  BaseContext.populate_array  s     	&&&s5f55r-   c                 r    [        U[        R                  5      (       d   U5       eU R                  XU5      $ )zC
Get a helper object to access the given complex numbers' members.
)rf   r
   Complexr  )r)   rr  r  ry   s       r*   make_complexBaseContext.make_complex  s3     #u}}--2s2-e44r-   c                 t    U R                  U5      n[        U5       H  u  pVUR                  XFU5      nM     U$ )z<
Create a tuple of the given *typ* containing the *values*.
)r  	enumerateinsert_value)r)   rr  r  r   tupir^  s          r*   
make_tupleBaseContext.make_tuple  s<     %%c*'FA&&s3C (
r-   c           
      ,   U R                  UR                  5      nSnU R                  (       a  UR                  S;  d  UR                  U:  ae  UR
                  R                  nU R                  X[        [        U5      5      S9nU R                  U[        U5      [        [        U5      5      S9nOUR                  UR                  S9n	[        R                  " [        R                  " S5      [!        U	R                  5      5      n
[        R"                  " USU
5      nU R%                  U5      Ul        SnU R)                  [*        R,                  5      nUR.                   Vs/ s H"  oR1                  [*        R,                  U5      PM$     nn[        R                  " X5      nUR2                   Vs/ s H"  oR1                  [*        R,                  U5      PM$     nn[        R                  " X5      nU R5                  U5      " X5      nU R1                  [*        R,                  UR                  R6                  5      nU R9                  UUR;                  UUR                  R                  5      UUUUSS9  UR=                  5       $ s  snf s  snf )	z
Create an array structure reifying the given constant array.
A low-level contiguous array constant is created in the LLVM IR.
i@B FC)info)orderr    z.const.array.dataN)r   shapestridesitemsizeparentmeminfo)ri  rh   allow_dynamic_globalslayoutnbytesctypesr   add_dynamic_addrr*  rq   r   flattenr   create_constant_arrayr   r%  	bytearrayr]  r  ro  rl  r
   intpr  r  r  r  r  r  rO  r  )r)   rr  r  arydatatype
size_limitdataptrr   rt_addrflatconstsllintps	shapevalscshape
stridevalscstridescaryintp_itemsizes                      r*   make_constant_arrayBaseContext.make_constant_array  s   
 %%cii0
&&4'3::
+BjjooG((DM@R(SD++GRW3tCy>+RG ;;SZZ;0D 226>>!3DiPTPYPYFZ[F**74GPD//9DJG $$UZZ0?ByyIy!&&uzz15y	I..vA ADL1''

A6
L00D s#D2))%**cii6H6HID!(tyy~~!F"($,%2#*$( 	 	* ~~' J Ms   ()J7)Jc                    U R                   (       d   S5       e[        U[        5      (       d   S5       eUR                  nU R	                  [
        R                  5      nU R                  [
        R                  U5      R                  U5      nSR                  U5      n[        R                  " XEU5      nSUl        Xhl        UR                  U5      $ )z
Returns dynamic address as a void pointer `i8*`.

Internally, a global variable is added to inform the lowerer about
the usage of dynamic addresses.  Caching will be disabled.
z#dyn globals disabled in this targetzdyn addr not of int typeznumba.dynamic.globals.{:x}linkonce)r  rf   r]   r   rl  r
   voidptrr  uintpinttoptrrN   r   r  r   r   load)	r)   rr  intaddrr  rP  	llvoidptraddrsymnamer   s	            r*   r  BaseContext.add_dynamic_addr7  s     ))P+PP)'3''C)CC'nn''6	  g6??	J.55g>((A  
||Br-   c                     [        U[        R                  5      (       d   S5       eUR                  U R                  5      $ )z%
Get the ABI size of LLVM type *ty*.
Expected LLVM type)rf   r   rs   get_abi_sizer   ra  s     r*   get_abi_sizeofBaseContext.get_abi_sizeofL  s6     "fkk**@,@@*t//00r-   c                     [        U[        R                  5      (       d   S5       eUR                  U R                  5      $ )z*
Get the ABI alignment of LLVM type *ty*.
r  )rf   r   rs   r  r   ra  s     r*   r  BaseContext.get_abi_alignmentS  s8     "fkk**@,@@*##D$4$455r-   c                     g)z4
Get preferred array alignment for Numba type *ty*.
r#  rC   )r  rb  s     r*   get_preferred_array_alignment)BaseContext.get_preferred_array_alignmentZ  s    
 r-   c                     g)z?Run target specific post-lowering transformation here.
        NrC   )r)   rP  rQ  s      r*   post_loweringBaseContext.post_loweringa  r   r-   c                     [         e)zCreate a LLVM module

The default implementation in BaseContext always raises a
``NotImplementedError`` exception. Subclasses should implement
this method.
r   )r)   r   s     r*   create_moduleBaseContext.create_modulee  s
     "!r-   c                      U R                   S   $ )z$Get the active code library
        re   )r   r(   s    r*   rO  BaseContext.active_code_libraryn  s     ""2&&r-   c              #      #    U R                   R                  U5         Sv   U R                   R                  5         g! U R                   R                  5         f = f7f)z5Push the active code library for the context
        N)r   rw   pop)r)   libs     r*   push_code_libraryBaseContext.push_code_libraryt  sG      	""3'	&##%D##%s   A> AAAc                 P    U R                   nU H  nUR                  U5        M     g)zHAdd iterable of linking libraries to the *active_code_library*.
        N)rO  rP  )r)   r  colibr  s       r*   r  BaseContext.add_linking_libs~  s'     ((C%%c* r-   c                     [        U  S35      e)a  Get the ufunc implementation for a given ufunc object.

The default implementation in BaseContext always raises a
``NotImplementedError`` exception. Subclasses may raise ``KeyError``
to signal that the given ``ufunc_key`` is not available.

Parameters
----------
ufunc_key : NumPy ufunc

Returns
-------
res : dict[str, callable]
    A mapping of a NumPy ufunc type signature to a lower-level
    implementation.
z does not support ufuncr   )r)   	ufunc_keys     r*   get_ufunc_infoBaseContext.get_ufunc_info  s    " "TF*A"BCCr-   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )rC   r%   )T)F)ry   )NNry   )NN)xr{   r|   r}   r~   r   r  implement_powi_as_math_callimplement_pow_as_math_callenable_debuginfor   	DIBuilderpropertyr   setterr   auto_parallelr  r`  r  fastmathenvironmentr   r+   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r#  r&  r/  rA  rG  rT  rY  rN  r*  re  ri  rl  ru  rz  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r'  r,  r0  r9  r=  r<  rV  re  rM  rh  rk  rx  r|  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rO  r   r  r  r  r   rC   r-   r*   r   r      s   	  #(!& ##I ! !
 " " J M H K " H K F>
&$
 02t Q'*EG " "   1 1	N 033*270
	00
?=;<1>T8/# RD*
%TN8>GECE
ACB$,&"
"% <8*)
705 GI+/$L =?d#': AC C
	*X"(1$68IE(651 f *16" ' '
 & &+Dr-   r   c                   4    \ rS rSrSrS rS	S jrS rS rSr	g)
r  i  z
A wrapper object to call an implementation function with some predefined
(context, signature) arguments.
The wrapper also forwards attribute queries, which is important.
c                 f    [        U5      U l        U R                  5       U l        X l        X0l        g r%   )_wrap_missing_loc	_callable_imp_context_sig)r)   r  r  r1   s       r*   r+   _wrap_impl.__init__  s&    *3/NN$		r-   Nc                     U R                  U R                  XR                  X#S9nU R                  R                  [	        U SS5      5        U$ )N)locr  rC   )r  r  r  r  r  )r)   rr  r;  r  r  s        r*   __call___wrap_impl.__call__  s>    iiw		4iI&&wtVR'@A
r-   c                 .    [        U R                  U5      $ r%   )r  r  )r)   items     r*   __getattr___wrap_impl.__getattr__  s    tyy$''r-   c                 2    S[        U R                  5      -  $ Nz<wrapped %s>)reprr
  r(   s    r*   __repr___wrap_impl.__repr__  s    T^^ 444r-   )r
  r  r  r  r%   )
r{   r|   r}   r~   r   r+   r  r  r  r   rC   r-   r*   r  r    s    
(5r-   r  c                 L    [         R                  " U 5      nSUR                  ;   $ )z.Does function *fn* take ``loc`` argument?
    r  )r   pysignature
parameters)r@  r1   s     r*   _has_locr    s#     

B
CCNN""r-   c                   &    \ rS rSrS rS rS rSrg)r	  i  c                     Xl         g r%   r  )r)   r@  s     r*   r+   _wrap_missing_loc.__init__  s    	r-   c                    ^ U R                   m[        T5      (       d,  U4S jnSnU H  n [        TU5      n[        XU5        M     U$ T$ ! [         a     M1  f = f)zYWrap function for missing ``loc`` keyword argument.
Otherwise, return the original *fn*.
c                  6   > UR                  S5        T" U 0 UD6$ )Nr  )r  )r;  r  r@  s     r*   wrapper+_wrap_missing_loc.__call__.<locals>.wrapper  s    

5!4*6**r-   )r{   r  )r  r  r  r   AttributeError)r)   r&  attrsr  r^  r@  s        @r*   r  _wrap_missing_loc.__call__  sj     YY||+ 'E0!"d+C G3/  NI & s   A
AAc                      SU R                   -  $ r  r"  r(   s    r*   r  _wrap_missing_loc.__repr__  s    		))r-   r"  N)r{   r|   r}   r~   r+   r  r  r   rC   r-   r*   r	  r	    s    4*r-   r	  c                  N    S n S n[         R                  R                  X5        g)z)Initial event triggers for LLVM lock
    c                  0    [         R                  " S5        g Nznumba:llvm_lock)r   start_eventrC   r-   r*   enter_fn-_initialize_llvm_lock_event.<locals>.enter_fn  s    +,r-   c                  0    [         R                  " S5        g r/  )r   	end_eventrC   r-   r*   exit_fn,_initialize_llvm_lock_event.<locals>.exit_fn  s    )*r-   N)r   ffiregister_lock_callback)r1  r5  s     r*   _initialize_llvm_lock_eventr9    s     -+ FF!!(4r-   )<collectionsr   r   r  	itertoolsr   r   
contextlibr   	functoolsr   llvmliter   r   llvmlite.irr	   llvmlite.bindingbindingr   rD  r
   r   r   r   r   r   r   r   r   r   r   numbar   r   numba.core.compiler_lockr   numba.core.pythonapir   numba.core.imputilsr   r   r   r   r   numba.cpythonr   PointerTyper%  rK  PYOBJECTvoid_ptrobjectr"   runoncer   r   r  r  r	  r9  rC   r-   r*   <module>rL     s    #  
 - % % !    ^ ^ ^ 2 2 & 9 *' ' #$$V^^A%67uv up @ @&oD& oDb5 50# *  *F 	5 	5  r-   