
    xKgm                     v   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 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.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z: d dl;m<Z<m=Z= d dl>m?Z?m@Z@mAZA  G d de?      ZB eB       ZCdeC_D        g dZE G d d edeE            ZF edg d      ZGd ZHd ZId+dZJ G d deK      ZL G d deM      ZN G d deO      ZPd  ZQ G d! d"eK      ZR G d# d$eR      ZS G d% d&eK      ZTdeSfd'ZUd(dddeSfd)ZVd* ZWy),    )
namedtupleN)event)utilserrors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                      e Zd Z eedd      Z eedd      Z eedd      Z eedd      Z eedd      Z	 eedd	      Z
 eedd
      Z eedd
      Z eedd
      Z eedd      Z eedd
      Z eedd
      Z eej$                   ej$                  d      d      Z eedd
      Z eedd
      Z eedd
      Z eej0                   ej0                  d      d
      Z eedd
      Z eej6                   ej6                  d      d
      Z eedd      Z eedd      Z eedd      Zy)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neverzTExtend 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   boolenable_loopliftenable_pyobjectenable_pyobject_looplift
enable_ssaforce_pyobjectrelease_gil
no_compile	debuginfoboundscheckforceinlineno_cpython_wrapperno_cfunc_wrapperr   ParallelOptionsauto_parallelnrtno_rewritesstrerror_modelFastMathOptionsfastmathnoaliasInlineOptionsinlinedbg_extend_lifetimesdbg_optnonedbg_directives_only     W/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/numba/core/compiler.pyr9   r9   +   s   !O
 /O
  &6 
 J
 ;N
 4K
 J
 I
 K
 EK
  
 
   ###E*
M C
 K
 K
   ###E*H
 G
 !!!'*F "< LK !.r_   r9   T)typing_contexttarget_contextentry_pointtyping_errortype_annotation	signature
objectmodeliftedfndesclibrarycall_helperenvironmentmetadatareload_initreferenced_envsc                   H    e Zd ZdZdZd Zd Zed        Ze	d        Z
d	dZy)
CompileResultzI
    A structure holding results from the compilation of a function.
    r^   c                 T   | j                   j                         }t        | j                        }| j                  }dx|_        |_        | j                         }|| j                  | j                  | j                  | j                  | j                  || j                  t        |      f	S )zA
        Reduce a CompileResult to picklable components.
        N)rj   serialize_using_object_coderT   re   ri   typemap	calltypes_find_referenced_environmentsrl   rf   rg   rh   rn   tuple)selflibdatatypeannri   ro   s        r`   _reducezCompileResult._reduce   s     ,,::<d**+,00)<<>d&6&6gt7G7Go&( 	(r_   c                     | j                   j                  }g }|j                  D ]P  }|j                  }|j	                  d      s!t        |      }|/|j                         s@|j                  |       R |S )z2Returns a list of referenced environments
        _ZN08NumbaEnv)rj   _final_moduleglobal_variablesname
startswithr   	can_cacheappend)rx   modro   gvgvnenvs         r`   rv   z+CompileResult._find_referenced_environments   sk     ll((&&B''C~~o.(-?}}'..s3 ' r_   c                 &   |	r|	D ]	  } |         |j                         j                  |      }|j                  |||      } | ||j                  ||||||||d d d |	|
      }|
D ](  }|j                   j	                  |j
                  |       * |S )N)rb   ra   rj   rl   rc   ri   re   rf   rg   rh   rd   rk   rm   rn   ro   )codegenunserialize_libraryget_executablera   set_envenv_name)clsrb   ry   ri   r   rf   rg   rh   rz   rn   ro   fnrj   cfunccrs                  r`   _rebuildzCompileResult._rebuild   s     ! " !((*>>wG--gvsC . = =  "!($&"!(!0$ #COO##CLL#6 # 	r_   c                 6    | j                   j                         S N)rb   r   rx   s    r`   r   zCompileResult.codegen  s    ""**,,r_   c                     t        | dt        |       j                   d| j                          | j                  j                  |dz          t        | d       y )NzDUMP  z  )tabzEND DUMP)printr:   r@   rc   rf   dump)rx   r   s     r`   r   zCompileResult.dump  sU    U4:../q1A1A0BCDd
+Xr_   N) )r@   rA   rB   __doc__	__slots__r{   rv   classmethodr   propertyr   r   r^   r_   r`   rq   rq      sF     I(   B - - r_   rq   _CompileResult_LowerResult)ri   rk   r   r   c                     t        | j                               }t        t              }||z
  }|rt        | ||z
  }|D ]  }d | |<   	 | d   }||j	                  d       | d<   | S )Nrd   )setkeys	CR_FIELDS	NameErrorwith_traceback)entriesr   fieldsetbadnamesmissingkerrs          r`   sanitize_compile_result_entriesr     sy    w||~D9~HhH""oG
  .
!C
"%"4"4T":Nr_   c                  .    t        |       } t        di | S Nr^   )r   rq   )r   s    r`   compile_resultr   &  s    -g6G#7##r_   Fc                 t   t         j                  j                  |       }t        j                  |      }t        j
                  |      }|j                  |      }|r4ddlm}  ||t        j                  d      i d      }|j                          t        j                  |      }	|	j                  |       |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   InterpreterByteCode	interpretnumba.core.inline_closurecallr   r   rP   runr	   PostProcessor)
funcinline_closures	emit_delsr   interpbcfunc_irr   inline_pass	post_procs
             r`   run_frontendr   +  s     ''55d;G$$W-F			7	+Br"GG+GS5H5H5O,.7&&w/IMM)Nr_   c                   $    e Zd ZdZddgZd Zd Zy)_CompileStatuszC
    Describes the state of compilation. Used like a C record.
    fail_reasoncan_fallbackc                      d | _         || _        y r   )r   r   )rx   r   s     r`   __init__z_CompileStatus.__init__H  s    (r_   c           
          g }| j                   D ].  }|j                  dj                  |t        | |                   0 dj	                  |      S )Nz{k}={v})r   vz, )r   r   formatgetattrjoin)rx   valsr   s      r`   __repr__z_CompileStatus.__repr__L  sF    AKK	((1a0@(AB  yyr_   N)r@   rA   rB   r   r   r   r   r^   r_   r`   r   r   B  s     /I)r_   r   c                       e Zd ZdZd Zy)_EarlyPipelineCompletionz@
    Raised to indicate that a pipeline has completed early
    c                     || _         y r   )result)rx   r   s     r`   r   z!_EarlyPipelineCompletion.__init__X  s	    r_   N)r@   rA   rB   r   r   r^   r_   r`   r   r   S  s    r_   r   c                       e Zd ZdZd Zd Zy)	StateDictz
    A dictionary that has an overloaded getattr and setattr to permit getting
    and setting key/values through the use of attributes.
    c                 >    	 | |   S # t         $ r t        |      w xY wr   )KeyErrorAttributeError)rx   attrs     r`   __getattr__zStateDict.__getattr__b  s+    	': 	' &&	's    c                     || |<   y r   r^   )rx   r   values      r`   __setattr__zStateDict.__setattr__h  s    T
r_   N)r@   rA   rB   r   r   r   r^   r_   r`   r   r   \  s    
'r_   r   c                 F   i }|j                   rd|d<   |j                  rd|d<   |j                  rd|d<   |j                  r|j                  |d<   |j                  r|j                  |d<   t        j                  |j                  |       }||d<    | j                  di |S )	zL
    Make a new target context from the given target context and flags.
    Tenable_debuginfoenable_boundscheck
enable_nrtrQ   rW   rU   r^   )	rK   rL   rR   rQ   rW   r   create_error_modelrU   	subtarget)	targetctxflagssubtargetoptionsrU   s       r`   _make_subtargetr   l  s     /3+,15-.yy)-&,1,?,?)~~',~~$--e.?.?KK&1]#92!122r_   c                   <    e Zd ZdZd Zd Zd
dZd Zd Zd Z	d	 Z
y)CompilerBasez4
    Stores and manages states for the compiler
    c                 2   t        j                          |j                          |j                          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                  _        t1               | j                  _        | j                  j2                  | j                  j*                  d<   i | j                  j*                  d<   t5        | j                  j                  j6                        | j                  _        y )Nparfor_diagnosticsparfors)r   )r
   reload_configrefreshr   state	typingctxr   r   rj   argsreturn_typer   localsr   r   r   rh   lifted_fromrt   ru   re   rm   rn   pipeliner   r   r   rE   status)rx   r   r   rj   r   r   r   r   s           r`   r   zCompilerBase.__init__  s{    	[
(

.y%@

$



!,

 

"

 

!

!

 

!%

!

#

%)

" 

!#

"

 ):(;

%JJ)) 	

01)+

I&*))99


r_   c                    t         j                  j                  |      | j                  _        t               j                  | j                         d| j                  _        d | j                  _        | j                         S r   )
r   r   r   r   r   r   run_passrh   r   _compile_bytecode)rx   r   s     r`   compile_extrazCompilerBase.compile_extra  s[    %66DDTJ

""4::.

!%

%%''r_   Nc                 b   |j                   | j                  _         || j                  _        || j                  _        || j                  _        | j                  j                  j
                  | j                  _        t               j                  | j                         | j                         S r   )
r   r   rh   r   r   	arg_countnargsr   r   _compile_ir)rx   r   rh   r   s       r`   
compile_irzCompilerBase.compile_ir  su    $__

"

!,

$

::--77

TZZ(!!r_   c                     t               )zGChild classes override this to customize the pipelines in use.
        )NotImplementedErrorr   s    r`   define_pipelineszCompilerBase.define_pipelines  s     "##r_   c                    t               j                  | j                  j                  j	                               5  | j                         }|D ]  }|j                  }| j                  j                  j                  d| j                  j                  j                  }t        d|d|       ||j                  i| j                  j                  d<   ||d   k(  }d}	 |j                  | j                         | j                  j                   n t3        d      d| j                  _        ||cddd       S | j                  j                  J | j                  j                  cddd       S # t        $ r}|j                   }Y d}~ pd}~wt"        $ rZ}t%        j&                         rt)        |t*        j,                        s||| j                  j.                  _        |r|Y d}~d}~ww xY w# 1 sw Y   yxY w)z4
        Populate and run compiler pipeline
        .z
Pipeline: z for pipeline_timesNz!All available pipelines exhausted)r7   enterr   r   copyr  pipeline_namer   modnamefunc_qualnamer   
exec_timesrm   r   r   r   r   	Exceptionr   use_new_style_errors
isinstancer   
NumbaErrorr   r   r   r   )rx   pmspmr  	func_nameis_final_pipelinereses           r`   _compile_corezCompilerBase._compile_core  s    ]  !1!1!6!6!89'')C " 0 0'+zz'9'9'A'A'+zz'9'9'G'GI	 }iHI9F9;9H

##$45$&#b'M! FF4::&zz}}0 1 4 $$GHH #'DJJ K :9N zz}}000zz}}Q :9  0 ((C   224&q&*;*;<45DJJ%%1( ) ' :9sO   B%G;"1E7#G; -G;7	G8 FG;G8AG3-G;3G88G;;Hc                 R    | j                   j                  J | j                         S )z>
        Populate and run pipeline for bytecode input
        r   r   r  r   s    r`   r   zCompilerBase._compile_bytecode  s)     zz!!)))!!##r_   c                 R    | j                   j                  J | j                         S )z8
        Populate and run pipeline for IR input
        r  r   s    r`   r  zCompilerBase._compile_ir  s)     zz!!---!!##r_   )r^   N)r@   rA   rB   r   r   r   r  r  r  r   r  r^   r_   r`   r   r     s,    (
T("$
,%\$$r_   r   c                       e Zd ZdZd Zy)CompilerzThe default compiler
    c                     | j                   j                  j                  r t        j	                  | j                         gS t        j                  | j                         gS r   )r   r   rH   DefaultPassBuilderdefine_objectmode_pipelinedefine_nopython_pipeliner   s    r`   r  zCompiler.define_pipelines  sG    ::**&AA$**MOO '??

KMMr_   N)r@   rA   rB   r   r  r^   r_   r`   r  r    s    Nr_   r  c                       e Zd ZdZed
d       Zedd       Ze	 dd       Zedd       Zedd       Z	edd       Z
edd       Zy	)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
    c                    t         }t        |      }|j                  |       }|j                  j	                  |j                         |j                  |       }|j                  j	                  |j                         |j                  |       }|j                  j	                  |j                         |j                          |S )z<Returns an nopython mode pipeline based PassManager
        )r!  r   define_untyped_pipelinepassesextenddefine_typed_pipeline!define_nopython_lowering_pipelinefinalize)r   r   dpbr  untyped_passestyped_passeslowering_passess          r`   r#  z+DefaultPassBuilder.define_nopython_pipeline  s    
 !44U;
		../007
		,,-??F
		//0
	r_   c                    t        |      }|j                  t        d       |j                  t        d       |j                  t        d       | j
                  j                  j                  r|j                  t        d       n|j                  t        d       |j                  t        d       |j                  t        d       |j                          |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   rQ   enabledr/   r.   r+   r)   r+  r   r   r  s      r`   r*  z4DefaultPassBuilder.define_nopython_lowering_pipeline/  s    
6I	K
N:	< 	M#34;;$$,,KK,.FGKK(9:
O%<=
)+DE
	r_   c                    t        |      }|j                  t        d       |j                  t        d       |j                  t        d       | j
                  j                  j                  r|j                  t        d       n|j                  t        d       |j                  t        d       |j                          |S )Nr1  r2  r3  r4  r5  r6  )r   r7  r0   r*   r%   r   rQ   r8  r/   r.   r+   r+  r9  s      r`   /define_parfor_gufunc_nopython_lowering_pipelinezBDefaultPassBuilder.define_parfor_gufunc_nopython_lowering_pipelineC  s     
6I	K
N:	< 	M#34;;$$,,KK,.FGKK(9:
O%<=
	r_   c                 H   t        |      }|j                  t        d       |j                  t        d       |j                  t        d       | j
                  j                  j                  r|j                  t        d       | j
                  j                  s|j                  t        d       | j
                  j                  j                  rB|j                  t        d       |j                  t        d       |j                  t        d       |j                          |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   r7  r$   r-   r,   r   rQ   r8  r'   rS   r&   r(   r1   r2   r+  r9  s      r`   r)  z(DefaultPassBuilder.define_typed_pipelineW  s     
)+>? 	%':; 	O%BC;;$$,,KK'BC{{&&KK(*=>;;$$,,KK
$89KK(.9KK-/CD
	r_   c                     t        |      }| j                  sJ |j                  t        d       |j                  t        d       |j                  t
        d       |j                          |S )r=  processing IRr>  rA  )r   r   r7  r   r$   r2   r+  r9  s      r`   define_parfor_gufunc_pipelinez0DefaultPassBuilder.define_parfor_gufunc_pipelineo  sV     }}}
L/2
)+>?
)+?@
	r_   c                 V   t        |      }t        j                  rO| j                  ,|j	                  t
        d       |j	                  t        d       |j	                  t        d       nN| j                  ,|j	                  t        d       |j	                  t        d       |j	                  t        d       |j	                  t        d       |j	                  t        d       | j                  j                  sB|j	                  t        d       |j	                  t        d       |j	                  t        d	       |j	                  t         d
       |j	                  t"        d       |j	                  t$        d       | j                  j                  s|j	                  t        d       |j	                  t&        d       |j	                  t(        d       | j                  j*                  r|j	                  t,        d       |j	                  t.        d       |j1                          |S )z0Returns an untyped part of the nopython pipelinezrvsdg frontendfix up argsrC  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_unrollssazLiteral propagation)r   r
   USE_RVSDG_FRONTENDr   r7  r#   r   r   r   r   r   r   rS   r   r   r   r!   r   r   r   r   rG   r    r"   r+  r9  s      r`   r&  z*DefaultPassBuilder.define_untyped_pipeline{  s    $$}}$M+;<I}5KKo6}}$-/CDI}5KKo6
K!78 	&>	@ {{&&KK02NOKK)>?KK)<=
(*BC 	->	@ 	$&BC{{&&KK)>?
&(>?
M#;<;;!!KK.
57LM
	r_   c                 f   t        |      }| j                  -|j                  t        d       |j                  t        d       n|j                  t
        d       |j                  t        d       |j                  t        d       |j                  t        d       |j                  t        d       |j                  t        d       |j                  t        d	       |j                  t        d
       |j                  t        d       |j                  t        d       |j                          |S )z:Returns an object-mode pipeline based PassManager
        rG  rF  r?  rC  zcanonicalize loop entryzcanonicalize loop exitzobject mode frontendrH  rI  r2  r3  zobject mode backend)r   r   r7  r   r   r-   r   r   r   r3   r   r   r*   r%   r4   r+  r9  s      r`   r"  z-DefaultPassBuilder.define_objectmode_pipeline  s     == KK)+?@KK	=1 KK)+>?
L/2 	)+DE
(*BC
&(>?
&>	@ 	->	@
N$JK
M#34
%'<=
	r_   N)nopython)nopython_lowering)parfor_gufunc_nopython_lowering)typed)parfor_gufunc_typed)untyped)object)r@   rA   rB   r   staticmethodr#  r*  r;  r)  rD  r&  r"  r^   r_   r`   r!  r!    s    	  $  & 9 &  . 	 	 1 1f  r_   r!  c	           	      @     || ||||||      }	|	j                  |      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   rj   pipeline_classr   s
             r`   r   r     s/    0 iG"K@H!!$''r_   r^   c           	         
 |	rt        j                  |      }d|_        
 f	d} ||j                         |      }d}|j                  sYt        j                         5  t        j
                  dt        j                         	  ||j                         |      }ddd       ||}|S |}|S   
|      }|j                  |      S # t        $ r Y ?w xY w# 1 sw Y   DxY w)zK
    Compile a function with the given IR.

    For internal use only.
    Tc           	      H   	  
	|      }|j                  |       S )Nr   rh   r   )r  )the_ir	the_flagsr   r   rj   rh   r   r   rV  r   r   r   s      r`   compile_localz!compile_ir.<locals>.compile_local  s>    %iG&*KFLH&&vf3> ' @ @r_   NignorerY  )
r  deepcopyrS   warningscatch_warningssimplefilterr   NumbaWarningr  r  )r   r   r   r   r   r   r   rh   r   is_lifted_looprj   rV  
norw_flagsr\  	norw_cresrw_crescresr   s   `` `` ``` ``      r`   r  r    s     ]]5)
!%
	@ 	@ "',,.*=	
   ((*%%h0C0CD+GLLNEBG + D  D ")Y"&UFD""76/: # < 	< ! 	 +*s*   .%C.C	C+(C.*C++C..C7c           	      F    t        | ||||||      }|j                  |      S )z 
    For internal use only.
    )r  r   )	r   r   rj   r   r   r   r   r   r   s	            r`   compile_internalri  +  s.    
 	9gk5&:H!!$''r_   )FF)Xcollectionsr   r  r_  numba.core.tracingr   
numba.corer   r   r   r   r	   r
   r   r   numba.parfors.parforr   numba.core.errorsr   numba.core.environmentr   numba.core.compiler_machineryr   numba.core.untyped_passesr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   numba.core.typed_passesr$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   numba.core.object_mode_passesr3   r4   numba.core.targetconfigr5   r6   r7   r9   DEFAULT_FLAGSrR   r   rq   r   r   r   r   rS  r   r  r   dictr   r   r   r  r!  r   r  ri  r^   r_   r`   <module>rw     sH   "   $' ' ' 2 + 5 5) ) ) ) ) )' ' ' ' '> E EvL vr  	(O J/; O d . +  $
.V "y   3*@$6 @$F
N| 
Nz z| #'x(< !d5H=<@(r_   