U
    9%eq                     @   sf  d dl mZ d dlZd dlZd dlmZ d dlmZmZm	Z	m
Z
mZmZmZmZmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+ d d
l,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z; d dl<m=Z=m>Z> d dl?m@Z@mAZAmBZB G dd de@ZCeC ZDdeD_EdddddddddddddddgZFG dd  d ed!eFZGed"ddd#d$gZHd%d& ZId'd( ZJdeDi fd)d*ZKdCd,d-ZLG d.d/ d/eMZNG d0d1 d1eOZPG d2d3 d3eQZRd4d5 ZSG d6d7 d7eMZTG d8d9 d9eTZUG d:d; d;eMZVdeUfd<d=ZWd>dd+deUfd?d@ZXdAdB ZYdS )D    )
namedtupleN)event)	utilserrorstypinginterpreterbytecodepostprocconfigcallconvcpu)ParforDiagnostics)CompilerError)lookup_environment)PassManager)ExtractByteCodeTranslateByteCode	FixupArgsIRProcessingDeadBranchPruneRewriteSemanticConstantsInlineClosureLikesGenericRewritesWithLiftingInlineInlinablesFindLiterallyCallsMakeFunctionToJitFunctionCanonicalizeLoopExitCanonicalizeLoopEntryLiteralUnrollReconstructSSARewriteDynamicRaises!LiteralPropagationSubPipelinePassRVSDGFrontend)NopythonTypeInferenceAnnotateTypesNopythonRewritesPreParforPass
ParforPassDumpParforDiagnosticsIRLegalizationNoPythonBackendInlineOverloadsPreLowerStripPhisNativeLoweringNativeParforLowering"NoPythonSupportedFeatureValidationParforFusionPassParforPreLoweringPass)ObjectModeFrontEndObjectModeBackEnd)TargetConfigOptionConfigStackc                   @   sf  e Zd ZeedddZeedddZeedddZeedddZeedddZ	eedd	dZ
eedd
dZeedd
dZeedd
dZeedddZeedd
dZeedd
dZeejedddZeedd
dZeedd
dZeedd
dZeejedd
dZeedd
dZeejedd
dZeedddZeedddZeedddZeedddZ dS )FlagsFzEnable loop-lifting)typedefaultdocz!Enable pyobject mode (in general)z(Enable pyobject mode inside lifted loopsTz
Enable SSAz-Force pyobject mode inside the whole functionz&Release GIL inside the native functionTODOz7Force inlining of the function. Overrides _dbg_optnone.zEnable automatic parallel optimization, can be fine-tuned by
taking a dictionary of sub-options instead of a boolean, see parfor.py for
detailpythonneverr   backendzTExtend variable lifetime for debugging. This automatically turns on with debug=True.z\Disable optimization for debug. Equivalent to adding optnone attribute in the LLVM Function.zDMake debug emissions directives-only. Used when generating lineinfo.N)!__name__
__module____qualname__r6   boolZenable_loopliftenable_pyobjectZenable_pyobject_looplift
enable_ssaforce_pyobjectZrelease_gilZ
no_compile	debuginfoboundscheckZforceinlineZno_cpython_wrapperZno_cfunc_wrapperr   ParallelOptionsauto_parallelnrtno_rewritesstrerror_modelZFastMathOptionsfastmathZnoaliasZInlineOptionsinlineZtarget_backendZdbg_extend_lifetimesZdbg_optnoneZdbg_directives_only rQ   rQ   R/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/numba/core/compiler.pyr8   +   s   r8   Ttyping_contexttarget_contextentry_pointtyping_errortype_annotation	signature
objectmodeliftedfndesclibrarycall_helperenvironmentmetadatareload_initreferenced_envsc                   @   sF   e Zd ZdZdZdd Zdd Zedd Ze	d	d
 Z
dddZdS )CompileResultzI
    A structure holding results from the compilation of a function.
    rQ   c              
   C   sT   | j  }t| j}| j}d |_|_|  }|| j| j| j	| j
| j|| jt|f	S )zA
        Reduce a CompileResult to picklable components.
        N)r\   Zserialize_using_object_coderM   rW   r[   typemap	calltypes_find_referenced_environmentsr^   rX   rY   rZ   r`   tuple)selflibdatatypeannr[   ra   rQ   rQ   rR   _reduce   s    

   zCompileResult._reducec                 C   sN   | j j}g }|jD ]6}|j}|drt|}|dk	r| r|| q|S )z2Returns a list of referenced environments
        Z_ZN08NumbaEnvN)r\   Z_final_moduleZglobal_variablesname
startswithr   Z	can_cacheappend)rg   modra   gvZgvnenvrQ   rQ   rR   re      s    

z+CompileResult._find_referenced_environmentsc                 C   sv   |	r|	D ]
}|  q|  |}||||}| ||j||||||||d d d |	|
d}|
D ]}|j |j| q\|S )N)rT   rS   r\   r^   rU   r[   rW   rX   rY   rZ   rV   r]   r_   r`   ra   )codegenZunserialize_libraryget_executablerS   Zset_envenv_name)clsrT   rh   r[   rp   rX   rY   rZ   ri   r`   ra   fnr\   cfunccrrQ   rQ   rR   _rebuild   s0    zCompileResult._rebuildc                 C   s
   | j  S N)rT   rq   rg   rQ   rQ   rR   rq     s    zCompileResult.codegen c                 C   sD   t | dt| j d| j  | jj|d d t | d d S )NzDUMP  z  )tabzEND DUMP)printr9   r@   rU   rX   dump)rg   r}   rQ   rQ   rR   r     s     zCompileResult.dumpN)r{   )r@   rA   rB   __doc__	__slots__rj   re   classmethodrx   propertyrq   r   rQ   rQ   rQ   rR   rb      s   
!
rb   Z_CompileResult_LowerResultrv   rp   c                 C   sd   t |  }t t}|| }|r(t| || }|D ]}d | |< q4| d }|d k	r`|d | d< | S )NrV   )setkeys	CR_FIELDS	NameErrorwith_traceback)entriesr   ZfieldsetZbadnamesmissingkerrrQ   rQ   rR   sanitize_compile_result_entries  s    
r   c                  K   s   t | } tf | S ry   )r   rb   )r   rQ   rQ   rR   compile_result-  s    r   c              
   C   sZ   ddl m} t }tj|dd}|||" t||| ||||W  5 Q R  S Q R X dS )zp
    Compile the function in an isolated environment (typing and target
    context).
    Good for testing.
    r   )
cpu_targetr   )targetN)Znumba.core.registryr   r   Contextr   Z
CPUContextZnested_contextcompile_extra)funcargsreturn_typeflagslocalsr   	typingctx	targetctxrQ   rQ   rR   compile_isolated2  s     r   Fc           
      C   sp   t j| }t|}t j|d}||}|rXddlm} ||t	
di d}|  t|}	|	| |S )a  
    Run the compiler frontend over the given Python function, and return
    the function's canonical Numba IR.

    If inline_closures is Truthy then closure inlining will be run
    If emit_dels is Truthy the ir.Del nodes will be emitted appropriately
    )func_idr   )InlineClosureCallPassF)r   FunctionIdentityfrom_functionr   ZInterpreterZByteCodeZ	interpretZnumba.core.inline_closurecallr   r   rI   runr	   ZPostProcessor)
r   Zinline_closuresZ	emit_delsr   Zinterpbcfunc_irr   Zinline_passZ	post_procrQ   rQ   rR   run_frontendB  s    	

 

r   c                   @   s(   e Zd ZdZddgZdd Zdd ZdS )	_CompileStatuszC
    Describes the state of compilation. Used like a C record.
    fail_reasoncan_fallbackc                 C   s   d | _ || _d S ry   )r   r   )rg   r   rQ   rQ   rR   __init___  s    z_CompileStatus.__init__c                 C   s4   g }| j D ]}|dj|t| |d q
d|S )Nz{k}={v})r   vz, )r   rm   formatgetattrjoin)rg   valsr   rQ   rQ   rR   __repr__c  s    
z_CompileStatus.__repr__N)r@   rA   rB   r   r   r   r   rQ   rQ   rQ   rR   r   Y  s   r   c                   @   s   e Zd ZdZdd ZdS )_EarlyPipelineCompletionz@
    Raised to indicate that a pipeline has completed early
    c                 C   s
   || _ d S ry   )result)rg   r   rQ   rQ   rR   r   o  s    z!_EarlyPipelineCompletion.__init__N)r@   rA   rB   r   r   rQ   rQ   rQ   rR   r   j  s   r   c                   @   s    e Zd ZdZdd Zdd ZdS )	StateDictz
    A dictionary that has an overloaded getattr and setattr to permit getting
    and setting key/values through the use of attributes.
    c                 C   s,   z
| | W S  t k
r&   t|Y nX d S ry   )KeyErrorAttributeError)rg   attrrQ   rQ   rR   __getattr__y  s    
zStateDict.__getattr__c                 C   s   || |< d S ry   rQ   )rg   r   valuerQ   rQ   rR   __setattr__  s    zStateDict.__setattr__N)r@   rA   rB   r   r   r   rQ   rQ   rQ   rR   r   s  s   r   c                 C   sp   i }|j rd|d< |jr d|d< |jr.d|d< |jr>|j|d< |jrN|j|d< t|j| }||d< | jf |S )zL
    Make a new target context from the given target context and flags.
    TZenable_debuginfoZenable_boundscheckZ
enable_nrtrJ   rO   rN   )	rG   rH   rK   rJ   rO   r   Zcreate_error_modelrN   Z	subtarget)r   r   ZsubtargetoptionsrN   rQ   rQ   rR   _make_subtarget  s    

r   c                   @   sJ   e Zd ZdZdd Zdd Zddd	Zd
d Zdd Zdd Z	dd Z
dS )CompilerBasez4
    Stores and manages states for the compiler
    c                 C   s   t   |  |  t | _|| j_t||| j_|| j_|| j_	|| j_
|| j_|| j_d | j_d | j_d | j_d | j_d | j_d | j_d | j_d | j_i | j_g | j_| | j_t | j_| jj| jjd< i | jjd< t| jjjd| j_d S )Nparfor_diagnosticsZparfors)r   )r
   Zreload_configrefreshr   stater   r   r   r\   r   r   r   r   r   r   r   rZ   lifted_fromrc   rd   rW   r_   r`   pipeliner   r   r   rD   status)rg   r   r   r\   r   r   r   r   rQ   rQ   rR   r     s:    

zCompilerBase.__init__c                 C   s6   t j|| j_t | j d| j_d | j_| 	 S )NrQ   )
r   r   r   r   r   r   run_passrZ   r   _compile_bytecode)rg   r   rQ   rQ   rR   r     s
    zCompilerBase.compile_extrarQ   Nc                 C   sF   |j | j_ || j_|| j_|| j_| jjj| j_t | j | 	 S ry   )
r   r   rZ   r   r   	arg_countnargsr   r   _compile_ir)rg   r   rZ   r   rQ   rQ   rR   
compile_ir  s    
zCompilerBase.compile_irc                 C   s
   t  dS )zGChild classes override this to customize the pipelines in use.
        N)NotImplementedErrorrz   rQ   rQ   rR   define_pipelines  s    zCompilerBase.define_pipelinesc                 C   s  t  | jj ` |  }|D ]}|j}d| jjj| jjj	f }t
d||f  ||ji| jjd< ||d k}d}z$|| j | jjdk	rW  q*W q$ tk
r } z|j}W Y 
 q*W 5 d}~X Y q$ tk
r } z0t rt|tjs||| jj_|r|W 5 d}~X Y q$X q$tdd| j_|dk	rL|W  5 Q R  S | jjdk	s^t| jjW  5 Q R  S W 5 Q R X dS )z4
        Populate and run compiler pipeline
        z%s.%szPipeline: %s for %sZpipeline_timesNz!All available pipelines exhausted)r7   Zenterr   r   copyr   pipeline_namer   modnameZfunc_qualnamer   Z
exec_timesr_   r   rw   r   r   	Exceptionr   Zuse_new_style_errors
isinstancer   Z
NumbaErrorr   r   r   r   AssertionError)rg   pmspmr   	func_nameZis_final_pipelinereserQ   rQ   rR   _compile_core  sD    



zCompilerBase._compile_corec                 C   s   | j jdkst|  S )z>
        Populate and run pipeline for bytecode input
        Nr   r   r   r   rz   rQ   rQ   rR   r     s    zCompilerBase._compile_bytecodec                 C   s   | j jdk	st|  S )z8
        Populate and run pipeline for IR input
        Nr   rz   rQ   rQ   rR   r     s    zCompilerBase._compile_ir)rQ   N)r@   rA   rB   r   r   r   r   r   r   r   r   rQ   rQ   rQ   rR   r     s   *

.r   c                   @   s   e Zd ZdZdd ZdS )CompilerzThe default compiler
    c                 C   sJ   g }| j jjs |t| j  | j jjs4| j jjrF|t| j  |S ry   )	r   r   rF   rm   DefaultPassBuilderdefine_nopython_pipeliner   r   define_objectmode_pipeline)rg   r   rQ   rQ   rR   r     s    

zCompiler.define_pipelinesN)r@   rA   rB   r   r   rQ   rQ   rQ   rR   r     s   r   c                   @   sr   e Zd ZdZedddZedddZedd	d
ZedddZedddZ	edddZ
edddZdS )r   z
    This is the default pass builder, it contains the "classic" default
    pipelines as pre-canned PassManager instances:
      - nopython
      - objectmode
      - interpreted
      - typed
      - untyped
      - nopython lowering
    nopythonc                 C   s`   t }t|}|| }|j|j || }|j|j || }|j|j |  |S )z<Returns an nopython mode pipeline based PassManager
        )r   r   define_untyped_pipelineZpassesextenddefine_typed_pipeline!define_nopython_lowering_pipelinefinalize)r   rk   Zdpbr   Zuntyped_passesZtyped_passesZlowering_passesrQ   rQ   rR   r   6  s    


z+DefaultPassBuilder.define_nopython_pipelinenopython_loweringc                 C   st   t |}|td |td |td | jjjrD|td n|t	d |t
d |td |  |S )N3ensure features that are in use are in a valid form$ensure IR is legal prior to loweringannotate typesnative parfor loweringnative loweringnopython mode backendzdump parfor diagnostics)r   add_passr0   r*   r%   r   rJ   enabledr/   r.   r+   r)   r   r   rk   r   rQ   rQ   rR   r   I  s    
z4DefaultPassBuilder.define_nopython_lowering_pipelineparfor_gufunc_nopython_loweringc                 C   sh   t |}|td |td |td | jjjrD|td n|t	d |t
d |  |S )Nr   r   r   r   r   r   )r   r   r0   r*   r%   r   rJ   r   r/   r.   r+   r   r   rQ   rQ   rR   /define_parfor_gufunc_nopython_lowering_pipeline]  s    
zBDefaultPassBuilder.define_parfor_gufunc_nopython_lowering_pipelinetypedc                 C   s   t |}|td |td |td | jjjrB|td | jj	sV|t
d | jjjr|td |td |td |  |S )	/Returns the typed part of the nopython pipelinenopython frontendremove phis nodeszinline overloaded functionszPreprocessing for parforsnopython rewriteszconvert to parforszfuse parforsparfor prelowering)r   r   r$   r-   r,   r   rJ   r   r'   rL   r&   r(   r1   r2   r   r   rQ   rQ   rR   r   q  s    

z(DefaultPassBuilder.define_typed_pipelineparfor_gufunc_typedc                 C   sB   t |}| jst|td |td |td |  |S )r   processing IRr   r   )r   r   r   r   r   r$   r2   r   r   rQ   rQ   rR   define_parfor_gufunc_pipeline  s    
z0DefaultPassBuilder.define_parfor_gufunc_pipelineuntypedc                 C   s.  t |}tjr>| jdkr0|td |td |td n.| jdkr`|td |td |td |t	d |t
d | jjs|td |td	 |td
 |td |td |td | jjs|td	 |td |td | jjr|td |td |  |S )z0Returns an untyped part of the nopython pipelineNzrvsdg frontendfix up argsr   analyzing bytecodezHandle with contexts(inline calls to locally defined closureszrewrite semantic constantszdead branch pruningr   zrewrite dynamic raises(convert make_function into JIT functionszinline inlinable functionszfind literally callszhandles literal_unrollZssazLiteral propagation)r   r
   ZUSE_RVSDG_FRONTENDr   r   r#   r   r   r   r   r   r   rL   r   r   r   r!   r   r   r   r   rE   r    r"   r   r   rQ   rQ   rR   r     s@    


z*DefaultPassBuilder.define_untyped_pipelineobjectc                 C   s   t |}| jdkr,|td |td n|td |td |td |td |t	d |t
d	 |td
 |td |td |td |  |S )z:Returns an object-mode pipeline based PassManager
        Nr   r   r   r   zcanonicalize loop entryzcanonicalize loop exitzobject mode frontendr   r   r   r   zobject mode backend)r   r   r   r   r   r-   r   r   r   r3   r   r   r*   r%   r4   r   r   rQ   rQ   rR   r     s(    
z-DefaultPassBuilder.define_objectmode_pipelineN)r   )r   )r   )r   )r   )r   )r   )r@   rA   rB   r   staticmethodr   r   r   r   r   r   r   rQ   rQ   rQ   rR   r   +  s    
 3r   c	           
      C   s   || ||||||}	|	 |S )aD  Compiler entry point

    Parameter
    ---------
    typingctx :
        typing context
    targetctx :
        target context
    func : function
        the python function to be compiled
    args : tuple, list
        argument types
    return_type :
        Use ``None`` to indicate void return
    flags : numba.compiler.Flags
        compiler flags
    library : numba.codegen.CodeLibrary
        Used to store the compiled code.
        If it is ``None``, a new CodeLibrary is used.
    pipeline_class : type like numba.compiler.CompilerBase
        compiler pipeline
    )r   )
r   r   r   r   r   r   r   r\   pipeline_classr   rQ   rQ   rR   r     s       r   rQ   c              	      s   |	rt |}d|_ f	dd}||  |}d}|jst < tdtj z||  |}W n tk
r   Y nX W 5 Q R X |dk	r|}n|}|S  |}|j	|dS dS )zK
    Compile a function with the given IR.

    For internal use only.
    Tc                    s$    |}|j | dS )Nr   rZ   r   )r   )Zthe_irZ	the_flagsr   	r   r\   rZ   r   r   r   r   r   r   rQ   rR   compile_local!  s       z!compile_ir.<locals>.compile_localNignorer   )
r   deepcopyrL   warningscatch_warningssimplefilterr   ZNumbaWarningr   r   )r   r   r   r   r   r   r   rZ   r   Zis_lifted_loopr\   r   Z
norw_flagsr   Z	norw_cresZrw_cresZcresr   rQ   r   rR   r     s4    


   r   c           	      C   s   t | ||||||}||S )z 
    For internal use only.
    )r   r   )	r   r   r\   r   r   r   r   r   r   rQ   rQ   rR   compile_internalE  s       r  )FF)Zcollectionsr   r   r  Znumba.core.tracingr   Z
numba.corer   r   r   r   r   r	   r
   r   r   Znumba.parfors.parforr   Znumba.core.errorsr   Znumba.core.environmentr   Znumba.core.compiler_machineryr   Znumba.core.untyped_passesr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   Znumba.core.typed_passesr$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   Znumba.core.object_mode_passesr3   r4   Znumba.core.targetconfigr5   r6   r7   r8   ZDEFAULT_FLAGSrK   r   rb   r   r   r   r   r   r   r   r   r   dictr   r   r   r   r   r   r   r  rQ   rQ   rQ   rR   <module>   s   ,TD
 R

	  ? 
   
@