U
    ?h4m                    @   sJ  d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZ d dl	mZm
Z
mZmZmZmZmZ d dlmZ d dlmZmZmZ d dlmZmZmZmZ d dlZd add ZG d	d
 d
Ze Z[dd Z dd Z!dd Z"dd Z#dd Z$dd Z%dd Z&dd Z'dd Z(dd Z)dd  Z*d!d" Z+d#d$ Z,d%d& Z-d'd( Z.d)d* Z/i Z0d+d, Z1d-d. Z2d/d0 Z3i Z4d1d2 Z5i Z6d3d4 Z7d5d6 Z8d7d8 Z9d9d: Z:dd;d<Z;dd=d>Z<i Z=d?d@ Z>g Z?dAdB Z@e?Ae@ dCdD ZBg ZCdEdF ZDdGdH ZEi ZFi ZGdIdJ ZHddKdLZIdMdN ZJdOdP ZKdQdR ZLdSdT ZMi ZNdUdV ZOi ZPddWdXZQdYdZ ZRdd[d\ZSdd]d^ZTi ZUdd`daZVi ZWddbdcZXddde ZYdfdg ZZdhdi Z[djdkdldmdndodpdqdrdsdtdudvdwgZ\dxdy Z]i Z^ddzd{Z_d|d} Z`d~d Zadd Zbdd ZcG dd dedZedd Zfdd Zgdd ZhdddZii ZjdehfddZkdd Zldd ZmdddZndd Zodd Zpdd Zqdd Zrdd Zsdd Ztdd Zudd Zvdd Zwdd Zxdd Zydd Zzdd Z{dd Z|dd Z}dd Z~dd Zdd Zdd Zdd Zdd Zdd ZddÄ Zddń ZddǜddɄZdd˄ Zdd̈́ Zddτ Zddф Zddӄ ZddՄ Zddׄ Zddل ZdS )    N)
_Intrinsic)typestypingiranalysispostprocrewritesconfig)	signature)compute_live_mapcompute_use_defscompute_cfg_from_blocks)TypingErrorUnsupportedErrorNumbaPendingDeprecationWarningCompilerErrorc                 C   s   | d t t }td a|S )N.   )str_unique_var_count)prefixvar r   E/var/www/html/venv/lib/python3.8/site-packages/numba/core/ir_utils.pymk_unique_var   s    r   c                   @   s&   e Zd Zd	ddZdd Zdd ZdS )
	_MaxLabelr   c                 C   s
   || _ d S N_value)selfvaluer   r   r   __init__$   s    z_MaxLabel.__init__c                 C   s   |  j d7  _ | j S )Nr   r   )r   r   r   r   next'   s    z_MaxLabel.nextc                 C   s   t || j| _d S r   )maxr   )r   Znewvalr   r   r   update+   s    z_MaxLabel.updateN)r   )__name__
__module____qualname__r!   r"   r$   r   r   r   r   r   #   s   
r   c                 C   s*   d}| t | }||kr|S |d7 }qdS )zl Get a new var name with a given prefix and
        make sure it is unused in the given variable table.
    r   r   N)r   )r   	var_tablecurr   r   r   r   get_unused_var_name3   s
    r*   c                   C   s   t  S r   )_the_max_labelr"   r   r   r   r   
next_label?   s    r,   c	           %         s  g d}	t j}
t|trt|dkr>|d }t| }nt|}	ttd }rrt j	
t j|	|j<  fdd|D }tj| }t|| }| |}t j	
t j|	}
t|dr|| |||| ||
S ttd }rt jt|j< tdt }t|| }tj|d	 }ttd
 }rjttj|j< t|| }t|}ttd }rt j||j< t|t jt jfr|jdkrt| }t|| }n,|dkrd}tj|| }t|| }tj |||gd }|rt|j !| |
t j|gi }|j"dkrf|j#ddn||_$|||< |j"dkrd|j#dd}ttd }r|j#dd|j< t|| }tj|d }ttd } rttj%| j< t||  }!tj | |gd }"|r>| j !| |gi ||"< t|"| }#&|||||!|#g n t|| }$&||||$g S )zgenerate an array allocation with np.empty() and return list of nodes.
    size_var can be an int variable or tuple of int variables.
    lhs_typ is the type of the array being allocated.
    r   r   z
$tuple_varc                    s   g | ]}t | qS r   )convert_size_to_var).0slocoutscopetypemapr   r   
<listcomp>X   s   zmk_alloc.<locals>.<listcomp>__allocate__	$np_g_varnpemptyz$empty_attr_attrz$np_typ_var boolZbool_r   FClayoutz$empty_c_varasfortranarrayz$asfortran_array_attr)'r   intp
isinstancetuplelenr-   r   Varr   
containersUniTuplenameExprbuild_tupleAssignappendhasattrr6   miscModulenumpyGlobalgetattrget_np_ufunc_typr9   r   Z	functionsZNumberClassZ
NPDatetimeZNPTimedeltaunitConstcallget_call_typer?   copy_return_typer@   extend)%	typingctxr4   	calltypeslhssize_vardtyper3   r1   Zlhs_typZndimsZsize_typZ	tuple_varZ	new_sizesZ
tuple_callZtuple_assigng_np_varg_npg_np_assignZempty_attr_callattr_varattr_assignZ	dtype_strZtyp_varZtypename_constZtyp_var_assignZnp_typ_getattrZ
alloc_callZcacZempty_c_typZempty_c_varZempty_c_assignZasfortranarray_attr_callZafa_attr_varZafa_attr_assignZasfortranarray_callZasfortranarray_assignZalloc_assignr   r0   r   mk_allocC   s    
 




  
   re   c                 C   sd   t | trPt|td|}|r,tj||j< tt	| |||}|
| |S t | tjs`t| S )Nz$alloc_size)rB   intr   rE   r   r   rA   rH   rK   rU   rL   AssertionError)r^   r4   r3   r1   nodesnew_sizeZsize_assignr   r   r   r-      s    

r-   c                 C   sX   t jjjD ]\}}|| kr
|  S q
t jjjD ]\}}|| kr.|  S q.td| ddS )z7get type of the incoming function from builtin registryztype for func z
 not foundN)r   Znpydeclregistryglobals	templatesbuiltin_registryRuntimeErrorfunckvr   r   r   rS      s    

rS   c                 C   sx  t |td|}tt| |j< t dt|}t |||}	t| |||||\}
}t j	
||d|}| |j t tjgt| i ||< t |td|}tjtj| |j< t |||}t j	||}ttjtj||< t |td|}tjtj| |j< t |||}t |td|}tjtj| |j< t |||}t d|}t ||}|
|	||||g |_|S )zpmake a block that initializes loop range and iteration variables.
    target label in jump needs to be set.
    z$range_g_varranger   z$range_c_varz	$iter_var$phi)r   rE   r   get_global_func_typrs   rH   rQ   rK   _mk_range_argsrI   rV   rW   r   Contextr   rA   rD   	iterators	RangeTypegetiterr
   range_iter64_typeZrange_state64_typeZRangeIteratorTypeJumpBlockbody)r4   startstopstepr\   r3   r1   Zg_range_varZg_rangeZg_range_assignZ	arg_nodesargsZ
range_callZrange_call_varZrange_call_assignZ	iter_callZiter_varZiter_call_assignphi_varZ
phi_assignZjump_headerZrange_blockr   r   r   mk_range_block   s@    
    r   c                 C   sl  g }t |tjr|}nPt |ts$tt|td|}| rFtj| |j< t	t
||||}|| |dkr|dkr||gfS t |tjr|}	nPt |tstt|td|}	| rtj| |	j< t	t
|||	|}
||
 |dkr||	|gfS t |tjr
|}nTt |tstt|td|}| r>tj| |j< t	t
||||}|| ||	||gfS )Nz$range_stopr   r   z$range_startz$range_step)rB   r   rE   rf   rg   r   r   rA   rH   rK   rU   rL   )r4   r   r   r   r3   r1   rh   Z
g_stop_varZstop_assignZg_start_varZstart_assignZ
g_step_varZstep_assignr   r   r   rw      s<    



rw   c                 C   s6   t jjjD ]\}}|| kr
|  S q
td| dS )z2get type variable for func() from builtin registryzfunc type not found {}N)r   rl   rm   rk   rn   formatro   r   r   r   rv     s    
rv   c                 C   s4  t |td|}tjtjtj| |j< t j	
||}ttjtjtjtj||< t |||}t |td|}tj| |j< t j	||}	t |	||}
t |td|}tj| |j< t j	||}t |||}t |td|}tj| |j< t |||}t |dd|}t ||}||
|||g|_|S )zqmake a block that is a loop header updating iteration variables.
    target labels in branch need to be set.
    z$iternext_varz$pair_first_varz$pair_second_varrt   ru   )r   rE   r   r   rF   ZPairrA   booleanrH   rI   iternextr
   r|   rK   
pair_firstZpair_secondBranchr~   r   )r4   r   r\   r3   r1   Ziternext_varZiternext_callZiternext_assignZpair_first_varZpair_first_callZpair_first_assignZpair_second_varZpair_second_callZpair_second_assignZ	phi_b_varZphi_b_assignbranchZheader_blockr   r   r   mk_loop_header!  sB     
  r   c                 C   sB   i }| D ]4}| dd dd dd}||ks4t|||< q|S )zXreturns a dictionary for conversion of variable names to legal
    parameter names.
    ___$r   )replacerg   )varnamesZvar_mapr   new_namer   r   r   legalize_namesF  s    
r   c                 C   s   dd }i }t | || |S )z<create a mapping from variable names to their ir.Var objectsc                 S   s   | || j < | S r   rH   )r   namevarr   r   r   get_name_var_visitT  s    
z.get_name_var_table.<locals>.get_name_var_visit)
visit_vars)blocksr   r   r   r   r   get_name_var_tableR  s    r   c                 C   s>   i }|  D ]\}}||kr|||< qdd }t| || dS )zCreplace variables (ir.Var to ir.Var) from dictionary (name -> name)c                 S   s8   t | tjst| j|kr4t| j|| j | j} q| S r   )rB   r   rE   rg   rH   r3   r1   )r   namedictr   r   r   replace_named  s    
z'replace_var_names.<locals>.replace_nameN)itemsr   )r   r   Znew_namedictlrr   r   r   r   replace_var_names\  s    
r   c                 C   sX   t | tjst| j| krT|| j j| jks4t|| j }t|j|j|j} q| S r   )rB   r   rE   rg   rH   keysr3   r1   )r   vardictZnew_varr   r   r   replace_var_callbackl  s    
r   c                 C   s8   i }|  D ]\}}||jkr|||< qt| t| dS )zEreplace variables (ir.Var to ir.Var) from dictionary (name -> ir.Var)N)r   rH   r   r   )r   r   Znew_vardictr   r   r   r   r   replace_varsu  s
    

r   c                 C   s   t | t| d S r   )visit_vars_stmtr   )stmtr   r   r   r   replace_vars_stmt  s    r   c                 C   s   t | t|S r   )visit_vars_innerr   )noder   r   r   r   replace_vars_inner  s    r   c                 C   s*   |   D ]}|jD ]}t||| qqdS )zWgo over statements of block bodies and replace variable names with
    dictionary.
    N)valuesr   r   )r   callbackcbdatablockr   r   r   r   r     s    
r   c                    s  t  D ]$\}}t| |r||    d S qt| tjr^t| j | _t| j | _n"t| tjr~t| j	 | _	nt| tj
rt| j | _nt| tjrt| j | _nt| tjrt| j | _nt| tjrt| j | _nt| tjr6td | j| j}t| }|j	| _nJt| tjrht| j | _t| j | _nt| tjrt| j | _t| j | _t| j | _nt| tjrt| j | _t| j | _nt| tjrt| j | _t| j | _t| j | _nht| tjrXt| j | _t| j | _t| j | _n(t| tjr fdd| jD | _n d S )Nc                    s   g | ]}t | qS r   r   r.   xr   r   r   r   r5     s     z#visit_vars_stmt.<locals>.<listcomp>)visit_vars_extensionsr   rB   r   rK   r   targetr    ArgrH   ReturnRaise	exceptionr   condr}   DelrE   r1   ZDelAttrattrZSetAttrZDelItemindexStaticSetItem	index_varSetItemZPrintr   )r   r   r   tfr   r   r   r   r     sT    
r   c                    s   t | tjr | S t | tr4 fdd| D S t | trVt fdd| D S t | tjr| j D ]}t| j|  | j|< qlnt | tj	rt| j
 | _
| S )Nc                    s   g | ]}t | qS r   r   r.   nr   r   r   r5     s     z$visit_vars_inner.<locals>.<listcomp>c                    s   g | ]}t | qS r   r   r   r   r   r   r5     s     )rB   r   rE   listrC   rI   Z_kwsr   r   Yieldr    )r   r   r   argr   r   r   r     s    


r   c           
      C   s   i }|   D ]\}}d}|jrZ|jd }|jD ]*}t  D ]\}}t||r:|||}	q:q.t|tjrt|j| |j|jd< t|tjrt|j	|j
| |j| |j|jd< |||| < q|S )z>add an offset to all block labels and jump/branch targets
    Nru   )r   r   add_offset_to_labels_extensionsrB   r   r}   r   r1   r   r   truebrfalsebr)
r   offset
new_blocksr   bterminstTr   f_maxr   r   r   add_offset_to_labels  s$    


 
r   c           	      C   sv   d}|   D ]d\}}d }|jrd|jd }|jD ]4}t  D ]&\}}t||r:||}||kr:|}q:q.||kr|}q|S )Nr   ru   )r   r   find_max_label_extensionsrB   )	r   	max_labelr   r   r   r   r   r   r   r   r   r   find_max_label  s    


r   c           	      C   s   t | t| d } i }t| }t }d}|D ]}|||< |d7 }q,|D ]}| | }d}|jrf|jd }t|tjrt||j |j	|jd< t|tj
rt
|j||j ||j |j	|jd< |||| < qF|S )zFmakes the labels in range(0, len(blocks)), useful to compare CFGs
    r   r   Nru   )r   r   find_topo_orderdictr   rB   r   r}   r   r1   r   r   r   r   )	r   r   
topo_orderZl_mapidxr   Zt_noder   r   r   r   r   flatten_labels
  s,    

 
r   c                 C   s>   |   D ]0}g }|jD ]}t|tjs|| q||_qdS )zremove ir.Del nodesN)r   r   rB   r   r   rL   r   r   new_bodyr   r   r   r   remove_dels'  s    
r   c                 C   sN   |   D ]@}g }|jD ]*}t|tjr6t|jtjr6q|| q||_qdS )zremove ir.Arg nodesN)r   r   rB   r   rK   r    r   rL   r   r   r   r   remove_args2  s    
r   c                 C   s:   d}t | j| j| |||r d}q|r6t| }|  dS )zS Performs dead code elimination and leaves the IR in a valid state on
    exit
    FTN)remove_deadr   	arg_namesr   PostProcessorrun)func_irr4   	alias_maparg_aliasesZdo_post_proc	post_procr   r   r   dead_code_elimination>  s     
r   c                 C   s@  t | }t| }t|| |j|j}t| \}	}
|dks>|dkrPt| |||\}}tjdkrt	d| t	d| t	d| t	d| t	d|j t	d|j t
| }d	}|  D ]\}}d
d |j D }tjdkrt	d|| ||D ]0\}}tjdkrt	d|||  ||| O }q|t|||	|||||O }q|S )zdead code elimination using liveness and CFG info.
    Returns True if something has been removed, or False if nothing is removed.
    Nr   zargs:z
alias map:zarg_aliases:z	live_map:zusemap:zdefmap:Fc                 S   s   h | ]
}|j qS r   r   r.   rr   r   r   r   	<setcomp>e  s     zremove_dead.<locals>.<setcomp>   zremove_dead processing blockzsucc live_map)r   r   r   ZusemapZdefmapget_call_tablefind_potential_aliasesr	   DEBUG_ARRAY_OPTprintsetr   r   
terminator	list_vars
successorsremove_dead_block)r   r   r   r4   r   r   cfgZusedefsZlive_map
call_tabler   	alias_setremovedlabelr   livesZout_blk_datar   r   r   r   M  s@    





   r   c              	   C   sb  d}| j g}	t| jdd D ].}
tjdkr8td|
 t }||@ }|D ]}||| O }qJ||B |B }t|
tkrtt|
 }||
||||||}
|
dkrtjdkrtd d}qt	|
t
jr2|
j}|
j}|j|krt|||rtjdkrtd d}qt	|t
jr2|j|jkr2tjdkr,td d}qt	|
t
jrf|
j|krftjdkr`td d}qt	|
t
jr|
jj}||krtjdkrtd qt|
tjkrtjt|
 }||
\}}||8 }||O }nn|dd	 |
 D O }t	|
t
jrDt	|
jt
jr8d
d	 |
j D }|j|krD||j n||j |	|
 q|	  |	| _|S )zremove dead code using liveness info.
    Mutable arguments (e.g. arrays) that are not definitely assigned are live
    after return of function.
    FNru   r   r   zStatement was removed.Tc                 S   s   h | ]
}|j qS r   r   r   r   r   r   r     s     z$remove_dead_block.<locals>.<setcomp>c                 S   s   h | ]
}|j qS r   r   r   r   r   r   r     s     )r   reversedr   r	   r   r   r   typeremove_dead_extensionsrB   r   rK   r   r    rH   has_no_side_effectrE   r   r   r   Zir_extension_usedefsr   rI   removerL   reverse)r   r   r   r   r   r   r   r4   r   r   r   Zalias_livesZinit_alias_livesrr   Zlives_n_aliasesr   r]   rhsrH   Zdef_funcZusesZdefsZrhs_varsr   r   r   r   x  s    


  



r   c                 C   s0   t |dkr,|dd  dtgkr,|d dkS dS )N   r   randomr   >   seedshuffleF)rD   rP   )r   r   	call_listr   r   r   remove_dead_random_call  s     r  c                 C   s  ddl m}m} ddlm} t| tjr| jdkr| j	j
}||ksR|| g krVdS || }|dtgks|tgks|dtgks|dtgks|d	tgks||jgks||gks|d
tgks|dtgks||jgks|dtgks|tgks|tgkrdS t|d tr*|d jdks&|d jdkr*dS ddlm} ddlm}	 t|d |rj|d j}
|
|	krjdS tD ]}|| ||rn dS qndS t| tjr| jdkr| jj
|kS t| tjrdS t| tjr| jdkrdS dS )za Returns True if this expression has no side effects that
        would prevent re-ordering.
    r   )array_analysisparfor)prangerV   Fr9   Zstencillogr_   r  ZpndindexceilTZempty_inferredZunsafe_empty_inferred)CPUDispatcher)dot_3_mv_check_argsinplace_binopr   )Znumba.parforsr  r  Znumba.misc.specialr  rB   r   rI   oprp   rH   rP   slicenumbaZ
wrap_indexZinternal_prangemathr#   rf   r   _nameZnumba.core.registryr  Znumba.np.linalgr  py_funcremove_call_handlersr]   r   )r   r   r   r  r  r  	func_namer  r  r  r  r   r   r   r   r     sp    





	





r   c                 C   s   t | tjr| jdkr| jj}||ks2|| g kr6dS || }|tgks|dtgks|dtgks|dtgks|t	gks|t
gkrdS tD ]}|| ||r dS qdS | jdks| jdkrdS t | tjrdS dS )	z Returns True if every time this expression is evaluated it
        returns the same result.  This is not the case for things
        like calls to numpy.random.
    rV   Fr	  r9   r
  Tr{   r   )rB   r   rI   r  rp   rH   r  rP   r  r#   rf   is_pure_extensionsr   )r   r   r   r  r  r   r   r   r   is_pure
  s6    




r  c                 C   s   | dkr|dkrdS dS )NrP   )r9   TFr   )module_namer  r   r   r   is_const_call&  s    r  c                 C   s$   | |kr| S t t||  }|d S )Nr   )sortedr   )rr   r   Z	v_aliasesr   r   r   get_canonical_alias0  s    r  c              	      s  |dkri }|dkr*t  fdd|D }t|j|_dddg}|  D ]}|jD ]}t|tkrtt| }	|	|| ||| t|t	j
rT|j}
|jj}t| rqTt|
t	jr||
jkrt||
j|| t|
t	jr|
jdks|
jdkrt||
jj|| t|
t	jr2|
jd	kr2t||
jj|| t|
t	jrj|
jd
krj|
jdkrjt||
jj|| t|
t	jr|
jd
kr|
jdkr|
jj|krt||
jj|| t|
t	jrT|
jdkrTtt||
 }|dkrqT|\}}|tkr
t| }|||
j|| |dkr4||kr4t||
jd j|| t|t	jrT||krTt||j|| qTqHt|}|D ]F}|| D ]}||  || O  < qv|| D ]}|| ||< qqj||fS )zCfind all array aliases and argument aliases to avoid remove as deadNc                 3   s   | ]}t | s|V  qd S r   )is_immutable_type)r.   ar4   r   r   	<genexpr>=  s     
 z)find_potential_aliases.<locals>.<genexpr>ravelZ	transposeZreshapecastgetitemstatic_getitemr  rR   )r   ctypesZflat)shaperV   rP   r   )r   build_definitionsr   _definitionsr   r   r   alias_analysis_extensionsrB   r   rK   r    r   rH   r  rE   
_add_aliasrI   r  r]   r   guardfind_callnamealias_func_extensionsr   rX   deepcopy)r   r   r4   r   r   r   Znp_alias_funcsblinstrr   exprr]   ZfdeffnamefmodZ
alias_funcZold_alias_maprr   wr   r  r   r   7  sj    





r   c                 C   sX   ||kr| |  n@||kr&t ||< | |kr8t || < ||  |  ||   | d S r   )addr   )r]   r   r   r   r   r   r   r*  }  s    

r*  c                 C   sL   |d ks| |krdS ||  }t |tjtjjtjjfr:dS |tjkrHdS dS )NFT)rB   r   NumberZscalarsZ_NPDatetimeBasery   rz   string)r   r4   typr   r   r   r    s    
r  c                 C   s   t | }| }t| ||}|\}}}}}	d}
t|	}|
|kr|  D ]p}||krVqHdd ||D }|	|d   ||< |D ]}||  |	| M  < q|| || ||  B |	|< qH|}
t|	}q8tjdkrt	d|	 ||	fS )zcompute copy propagation information for each block using fixed-point
     iteration on data flow equations:
     in_b = intersect(predec(B))
     out_b = gen_b | (in_b - kill_b)
    Nc                 S   s   g | ]\}}|qS r   r   )r.   iZ_dr   r   r   r5     s     z"copy_propagate.<locals>.<listcomp>r   r   zcopy propagate out_copies:)
r   entry_pointinit_copy_propagate_datarX   r.  r   predecessorsr	   r   r   )r   r4   r   entryZc_data
gen_copies
all_copieskill_copies	in_copies
out_copiesZ	old_pointZ	new_pointr   Zpredecspr   r   r   copy_propagate  s,    



rD  c                    s.  t | |\}}t  | D ]\}} || O  qi }| D ]\}}	t ||<  D ]n\}
}|
|| kst||| kr|| |
|f dd |	D }|
|f|	krT|
|ks||krT|| |
|f qTq> fdd|  D }t ||< i }|  D ] }|| || ||  B ||< q|| ||< | |||fS )zHget initial condition of copy propagation data flow for each block.
    c                 S   s   h | ]\}}|qS r   r   )r.   r]   r   r   r   r   r     s     z+init_copy_propagate_data.<locals>.<setcomp>c                    s   i | ]}|   qS r   )rX   )r.   r   r?  r   r   
<dictcomp>  s      z,init_copy_propagate_data.<locals>.<dictcomp>)get_block_copiesr   r   r5  r   )r   r=  r4   r>  
extra_killr   r/   r@  r   gen_setr]   r   assignedrA  rB  r   rE  r   r;    s4    


r;  c                 C   s  i }i }|   D ]\}}i }t ||< |jD ]}t  D ]\}}	t||r<|	||\}
}|
D ]\}}|||< q`i }|  D ]6\}}||kr||kr|||< ||kr~|| | q~|}||  |O  < q<t|tjr.|jj	}t|j
tjr|j
j	}|| || kr||kr|||< q.t|j
tjr|j
jdkr|j
jj	}|| }t|tjs|tjks|| | i }|  D ]>\}}||kr||kr|||< ||kr|| | q|}|| | q.t|  }|||< q||fS )z2get copies generated and killed by each block
    r  )r   r   r   copy_propagate_extensionsrB   r5  r   rK   r   rH   r    rE   rI   r  r]   r   r6  r7  )r   r4   Zblock_copiesrH  r   r   Zassign_dictr   r   r   rI  kill_setr]   r   Znew_assign_dictr   r   Zin1_varZin1_typZ	block_cpsr   r   r   rG    s`    






rG  c              	      s\  |dkrg }|   D ]@\}} fdd|| D }|jD ]
}	t|	tkrltt|	 }
|
|	| ||| n&t|	tjrt|	j||	_n
t	|	| t
|	|| t  D ]v\}}
t|	|r|
|	|\}}|D ]\}}| krʈ | ||< q|   D ]&\}}||ks|j|kr|| qqt|	tjrt|	jtjr|	jj}|	jj}||kr|| || kr| kr | ||< n||d g }|  D ] \}}|j|kr|| q|D ]}||d qt|	tjr:t|	jtjs:|	jj}||d g }|  D ] \}}|j|kr|| q|D ]}||d q2q:||   q|S )zEapply copy propagation to IR: replace variables when copies availableNc                    s   i | ]\}}| | qS r   r   )r.   r   r   name_var_tabler   r   rF  .  s      z(apply_copy_propagate.<locals>.<dictcomp>)r   r   r   apply_copy_propagate_extensionsrB   r   rK   r   r    r   fix_setitem_typerK  rX   rH   poprE   r   rL   rZ   )r   rA  rN  r4   r\   save_copiesr   r   Zvar_dictr   r   r   rI  rL  r]   r   r   r   Zlhs_killrq   rr   r   rM  r   apply_copy_propagate$  sf      


rS  c                 C   s   t | tjtjfsdS || jj }||  jd }t |tjj	rLt |tjj	sPdS |j
dkr|j
dkr|j|j
d}|||  jd ||  jd f||  _dS )zCopy propagation can replace setitem target variable, which can be array
    with 'A' layout. The replaced variable can be 'C' or 'F', so we update
    setitem call type reflect this (from matrix power test)
    Nr   Ar>   r   r   )rB   r   r   r   r   rH   r   r   npytypesArrayr?   rX   )r   r4   r\   Zt_typZs_typZ	new_s_typr   r   r   rP  f  s*    
rP  c                 C   s\   t jdkrX| j}|dkr|n|| _| jj}td||f dd |   td || _dS )zqDebug print function IR, with an optional blocks argument
    that may differ from the IR's original blocks.
    r   Nz	IR %s: %sP   -z(----------------------------------------)r	   r   r   func_idfunc_qualnamer   centerdump)r   titler   Z	ir_blocksrH   r   r   r   dprint_func_ir  s    
r^  c                    sF   dkrt g t  fdd      S )z{find topological order of blocks such that true branches are visited
    first (e.g. for_break test in test_dataflow).
    Nc                    sp   | krl |  j|  }|  jd }t|tjrB|j|jg}|D ]}| |fjkrF | qF	|  d S )Nru   )
r5  _succsr   rB   r   r   r   r   Z_back_edgesrL   )r   succsZ	last_instdest_dfs_recr   r   Z
post_orderseenr   r   rc    s    


z!find_topo_order.<locals>._dfs_rec)r   r   r:  r   )r   r   r   rb  r   r     s    r   Tc                 C   s  |dkri }|dkri }|r&t | }nt|  }t|D ]}t| | jD ]}t|tjr|jj	}|j
}t|tjr|jdkrg ||jj	< t|tjr|jdkr||kr|| |j |||j
j	< ||kr|| }	||	 |j |	||j
j	< t|tjrB||kr || |j
 ||krB|| }	||	 |j
 t|tjr||krj|| |j
 ||kr|| }	||	 |j
 t|tjr||kr|| |j	 |||j	< ||kr|| }	||	 |j	 t D ]"\}
}t||
r|||| qqNq:||fS )zAreturns a dictionary of call variables and their references.
    NrV   rR   )r   r   r   r   r   rB   r   rK   r   rH   r    rI   r  rp   rL   r   rQ   FreeVarrE   call_table_extensionsr   )r   r   Zreverse_call_tableZtopological_orderingorderr   r   r]   r   Zcall_varr   r   r   r   r   r     sZ    







r   c                 C   s   |dkri }|   D ]}|jD ]}t|tjr~|jj}|j}t|tjr\|j	dkr\|j
||< t|tjr~t|jtr~|j||< t
 D ]\}}t||r||| qqq|S )z>returns a dictionary of tuple variables and their values.
    NrJ   )r   r   rB   r   rK   r   rH   r    rI   r  r   rU   rC   tuple_table_extensions)r   Ztuple_tabler   r   r]   r   r   r   r   r   r   get_tuple_table  s    



ri  c                 C   s.   t  }t| tjtjtjfr*|| jj |S r   )	r   rB   r   rK   r   r   r5  r   rH   )r   Zwritesr   r   r   get_stmt_writes  s    rj  c                 C   s   t | }d}|  D ]\}}t|jd tjr|}q|dkrP|| || i }t|dd}|D ]}|	 ||< qd| 
 D ]F}|j}t|tjr||j |_t|tjr~||j |_||j |_q~i }	|  D ]\}
}||
 }||	|< q|	S )zrename labels of function body blocks according to topological sort.
    The set of labels of these blocks will remain unchanged.
    ru   T)r   )r   r   rB   r   r   r   r   rL   r  rQ  r   r   r}   r   r   r   r   )r   r   return_labelr   r   Z	label_mapZ
all_labelsr   r   r   rq   Z	new_labelr   r   r   rename_labels  s0    


rl  c                    s   t  } fdd}tt|  }t }|D ]l} | jd }||}d}|D ]8\}	}
 |	 }t|jd tj	rt

||jd< qTd}qT|r0|| q0|D ]
} |= qt  t S )z@transform chains of blocks that have no loop into a single blockc                    s(    |  }t |jdko&t|jd tjS Nr   r   )rD   r   rB   r   r   )r   r   r   r   r   find_single_branch-  s    z(simplify_CFG.<locals>.find_single_branchr   Tru   F)r   r   filterr   r   r   r<  rB   r   r}   rX   r5  merge_adjacent_blocksrl  )r   r   ro  Zsingle_branch_blocksZmarked_for_delr   r   r<  Zdelete_blockrC  qr   r   rn  r   simplify_CFG)  s&    
rs  minr#   sumprodZmeanr   ZstdZcumsumZcumprodZargmaxZargminZargsortZnonzeror   c                    s  | j }i }t|}|D ]}|| }g }	|jD ]}
t|
tjrt|
jtjr|
jj	}|
j}|j
dkr4|jtkr4t |jj	 tjjr4|
j}|j}|||< |j}|j}t|td|}tjt |j	< tdt|}t|||}||_|	| |g| j|j	< tt|j}t|} | | |< |j
dkr|jj	|kr||jj	 }||}|jd t|j } fdd|j D } |jj	 !| |j	 gt"| |||< |g|j |_|	|
 q.|	|_qd S )NrR   r7   r8   rV   c                    s   i | ]\}}| |j  qS r   r   )r.   rH   rr   r  r   r   rF  u  s      z+canonicalize_array_math.<locals>.<dictcomp>)#r   r   r   rB   r   rK   r    rI   r   rH   r  r   arr_mathr   rU  rV  r3   r1   rE   r   rN   rO   rP   rQ   rL   r(  rR   rS   rQ  rp   r   rD   kwsrW   r   )r   r4   r\   r[   r   Zsaved_arr_argr   r   r   r   r   r]   r   Zarrr3   r1   r`   ra   rb   rp   func_typZold_sigZargtypsZkwtypsr   r  r   canonicalize_array_mathJ  s\    

 


  rz  c           	      C   s$  |dkrt  }|  D ]}|jD ]}t|tjrH||jj|j	jf t|tj
rj||jj|jjf t|tjr|jj}|j}t|tjr|jdkr||jj|j	jf t|tjr|jdkr|j	}|dkst|r|jj}||jj|f t D ]\}}t||r||| qq"q|S )z8returns a set of arrays accessed and their indices.
    Nr#  r$  )r   r   r   rB   r   r   r5  r   rH   r   r   r   rK   r    rI   r  is_slice_indexarray_accesses_extensionsr   )	r   Zaccessesr   r   r]   r   r   r   r   r   r   r   get_array_accesses  s,    

r}  c                 C   s6   t | trdS t | tr2| D ]}t |tr dS qdS )z0see if index is a slice index or has slice in itTF)rB   r  rC   )r   r9  r   r   r   r{    s    


r{  c           	      C   s   t | }t }t|  D ]}||kr(q| | }t||}t|dkrLq|d d }||krbqt||}t||}t|dks|d d |krq| | }|j  | j|j7  _| |= |	| |}q>qd S rm  )
r   r   r   r   r   rD   r<  r   rQ  r5  )	r   r   r   r   r   r`  r,   predsZ
next_blockr   r   r   rq    s,    

rq  c           	      C   s   |si S i }i }|D ]\\}}| ds|j dr|j|krtd|}|||j< |||< ||j}|||< qt| | |S )zS
    restores variable names of user variables after applying copy propagation
    r   z${})
startswithrH   r   r   rQ  r   )	r   rR  r4   Zrename_dictvar_rename_mapr  r   r   r8  r   r   r   restore_copy_var_names  s    


r  c           	      C   s   t | j|\}}t| j}t| j||||}t| j||}d|krJi |d< |d | tjdkrlt| d t	| j| j
| | t| j| _tjdkrt| d d S )Nr  r   zafter copy propzafter simplify)rD  r   r   rS  r  r$   r	   r   r^  r   r   rs  )	r   r4   r\   metadataZin_cpsr   rN  rR  r  r   r   r   simplify  s&    



r  c                   @   s   e Zd ZdS )GuardExceptionN)r%   r&   r'   r   r   r   r   r    s   r  c                 C   s   | st dS )z?
    Raise GuardException if the given condition is False.
    Nr  )r   r   r   r   require  s    r  c                 O   s(   z| ||W S  t k
r"   Y dS X dS )z
    Run a function with given set of arguments, and guard against
    any GuardException raised by the function by returning None,
    or the expected return results if no such exception was raised.
    Nr  )rp   r   kwargsr   r   r   r+    s    r+  c                 K   s.   z| j |f|W S  tk
r(   tY nX dS )zm
    Same as func_ir.get_definition(name), but raise GuardException if
    exception KeyError is caught.
    N)get_definitionKeyErrorr  )r   rH   r  r   r   r   r    s    r  c                 C   s   |dkrt t}|  D ]n}|jD ]b}t|tjrd|jj	}|
|g }|g krX|||< ||j t|tkr$tt| }||| q$q|S )zBuild the definitions table of the given blocks by scanning
    through all blocks and instructions, useful when the definitions
    table is out-of-sync.
    Will return a new definition table if one is not passed.
    N)collectionsdefaultdictr   r   r   rB   r   rK   r   rH   getrL   r    r   build_defs_extensions)r   Zdefinitionsr   r   rH   Z
definitionr   r   r   r   r'    s    

r'  c                 C   s(  t t|tjo|jdk |j}|| |}g }d}t|tjtjfrzdddg}d}	|D ] }
t|j	|
rXt
|j	|
}	 qzqX|	rt|	tst||	 |j	}t|tr|j}t|drJ|j}|dk	}|o|dkp|d}|r
tt|	r
|t
t|	kr
|dg7 }n>ttj|	r8|t
tj|	kr8|d	dg7 }n|rt|| n*|jj}|d
kr`d}|dkr
|| q
q2t|tjr|jdkr|j	}||j |r|j|kr||j }t|tjs|d |fS || |}q2|dk	rdt||fS tq2|d dt|dd fS )az  Try to find a call expression's function and module names and return
    them as strings for unbounded calls. If the call is a bounded call, return
    the self object instead of module name. Raise GuardException if failed.

    Providing typemap can make the call matching more accurate in corner cases
    such as bounded call on an object which is inside another object.
    rV   NrH   r  r%   r&   rP   znumpy.r  Zbuiltin_function_or_methodbuiltinmodulerR   r   r   r   )r  rB   r   rI   r  rp   rQ   re  rM   r    rR   r   r  rL   r   Z_defnr&   r  rP   r  	__class__r%   r   rH   r   rO   joinr   )r   r1  r4   Zdefinition_findercalleeZ
callee_defattrsobjr   r    keyZdef_valmod_nameZmod_not_noneZnumpy_toplevel
class_namer8  r   r   r   r,  4  sj    








r,  c                 C   sN   t t|tj t| |}t t|tj dddg}t |j|k |j|jfS )zCheck if a variable is constructed via build_tuple or
    build_list or build_set, and return the sequence and the
    operator, or raise GuardException otherwise.
    Note: only build_tuple is immutable, so use with care.
    rJ   Z
build_listZ	build_set)r  rB   r   rE   r  rI   r  r   )r   r   var_defZ	build_opsr   r   r   find_build_sequence  s    

r  c                 C   s:   t t|tj t| |}t t|tjtjtjf |jS )zvCheck if a variable is defined as constant, and return
    the constant value, or raise GuardException otherwise.
    )	r  rB   r   rE   r  rU   rQ   re  r    )r   r   r  r   r   r   
find_const  s    
r  c                 C   s  ddl m} t| dr| j}n t| dr0| j}ntd| t||}	t|	j	 t
|	j	t |	_	t|	j	 }
t|
 t|	j	}i }| D ]\}}t|||< qt|	j	| |r
||||	|d\}}}}dd |D }|D ]}|| q|| || |	S )	a  
    Compile a function or a make_function node to Numba IR.

    Rename variables and
    labels to avoid conflict if inlined somewhere else. Perform type inference
    if typingctx and other typing inputs are available and update typemap and
    calltypes.
    r   )typed_passescode__code__zfunction type not recognized {}Nc                 S   s   g | ]}| d r|qS )arg.)r  )r.   Zvnamer   r   r   r5     s     
 z'compile_to_numba_ir.<locals>.<listcomp>)
numba.corer  rM   r  r  NotImplementedErrorr   get_ir_of_coder   r   r   r+   r"   r#   r   r$   r   r   r   r   Ztype_inference_stagerQ  )Zmk_funcglblsr[   	targetctxZarg_typsr4   r\   r  r  f_irr   r(   Znew_var_dictrH   r   Z	f_typemapZf_return_typeZf_calltypesr   r   r  r   r   r   compile_to_numba_ir  s<    






    

r  c           	   
   C   sd   | j dddd}d| d| d| d| d| 
}i }t||| |d	  }| |_| j |_|S )
a   
    Creates a function from a code object. Args:
    * fcode - the code object
    * func_env - string for the freevar placeholders
    * func_arg - string for the function args (e.g. "a, b, c, d=None")
    * func_clo - string for the closure args
    * glbls - the function globals
    <r   >zdef closure():
z
	def (z):
		return (z
)
	return closure)co_namer   execr  r%   )	fcodefunc_envfunc_argfunc_clor  Zsanitized_co_nameZ	func_textr1   r   r   r   r   _create_function_from_code_obj  s    	"
r  c                    s&  t |j}ddd t|D }ddd t|D }ddd t|jD }t||||| }ddlm   |}G  fd	d
d
t	}||j
}	tjd|	 i }
ddl}|jj||jjd|
}|  ddlm} ddlm} | }| }||	 ||	 t|}|d |S )zG
    Compile a code object to get its IR, ir.Del nodes are emitted
    
c                 S   s   g | ]}d | qS )z	c_%d = Noner   r.   r9  r   r   r   r5     s     z"get_ir_of_code.<locals>.<listcomp>,c                 S   s   g | ]}d | qS zc_%dr   r  r   r   r   r5     s     c                 S   s   g | ]}d | qS )zx_%dr   r  r   r   r   r5     s     r   compilerc                       s   e Zd Z fddZdS )z%get_ir_of_code.<locals>.DummyPipelinec                    sF      | _d | j_d | j_d | j_|| j_d | j_d | j_d | j_d S r   )	Z	StateDictstater[   r  r   r   r4   return_typer\   )r   r  r  r   r   r!     s    
z.get_ir_of_code.<locals>.DummyPipeline.__init__N)r%   r&   r'   r!   r   r  r   r   DummyPipeline  s   r  zbefore-inferenceNF)ReconstructSSA)PreLowerStripPhisT)rD   co_freevarsr  rs   co_argcountr  r  r  Zrun_frontendobjectr  r   Zrewrite_registryapplyZnumba.core.inline_closurecallcoreZinline_closurecallZInlineClosureCallPasscpuZParallelOptionsr   Znumba.core.untyped_passesr  Znumba.core.typed_passesr  Zrun_passr   r   )r  r  nfreer  r  r  r   r   r  r  Zswappedr  Zinline_passr  r  Zreconstruct_ssaZphistripr   r   r  r   r    s:    




  



r  c                 C   sL   | j D ]@}t|tjrt|jtjr|jj}|t|k s<t|| |_qdS )z,
    Replace ir.Arg(...) with variables
    N)	r   rB   r   rK   r    r   r   rD   rg   )r   r   r   r   r   r   r   replace_arg_nodes  s    
r  c                 C   s   |   D ]}|jsq|j}t|tjr|j  |j }t|tjr`t|jtj	r`|jj
dkshtd|jt|jj||j |jt||j qdS )zN
    Return return statement by assigning directly to target, and a jump.
    r!  zinvalid return castN)r   r   r   rB   r   r   rQ  rK   r    rI   r  rg   rL   r1   r}   )r   r   rk  r   r   Z	cast_stmtr   r   r   replace_returns   s     


r  c                    s   |d j }|d j}t|td|}	tjt |	j	< t
dt|}
t|
|	|}tj|	| |}t|td|}t|}| |j	< t|||}tj||d|} fdd|D }|||i }|||< t|||}|||gS )Nr   r7   r8   z$np_attr_attrr   c                    s   g | ]} |j  qS r   r   r   r  r   r   r5   D  s     zgen_np_call.<locals>.<listcomp>)r3   r1   r   rE   r   r   rN   rO   rP   rH   rQ   rK   rI   rR   rS   rV   rW   )Zfunc_as_strrp   r]   r   r[   r4   r\   r3   r1   r`   ra   rb   Znp_attr_callrc   Zfunc_var_typrd   Znp_callZ	arg_typesry  Z	np_assignr   r  r   gen_np_call3  s"    


r  c                 C   s$   t | d |jD ]}t d| qd S )N:z    )r   r   )r   r   r   r   r   r   
dump_blockJ  s    

r  c                 C   s    |   D ]\}}t|| qd S r   )r   r  )r   r   r   r   r   r   dump_blocksO  s    r  c                 C   s"   t | tjo t| ddo | jdkS )z3true if expr is unary or binary operator or getitemr  F)ZunaryZbinopr  r#  r$  )rB   r   rI   rR   r  )r1  r   r   r   is_operator_or_getitemS  s
    
r  c                 C   s   t | pt| S )z8stmt is getitem assignment or setitem (and static cases))
is_getitem
is_setitemr   r   r   r   is_get_setitemY  s    r  c                 C   s&   t | tjo$t | jtjo$| jjdkS )z6true if stmt is a getitem or static_getitem assignmentr"  )rB   r   rK   r    rI   r  r  r   r   r   r  ^  s
    
r  c                 C   s   t | tjtjfS )z/true if stmt is a SetItem or StaticSetItem node)rB   r   r   r   r  r   r   r   r  d  s    r  c                 C   sH   t | r$| jjdkr| jjS | jjS t| rDt| tjr>| jS | jS dS )z?get index variable for getitem/setitem nodes (and static cases)r#  N)	r  r    r  r   r   r  rB   r   r   r  r   r   r   index_var_of_get_setitemh  s    r  c                 C   s^   t | r(| jjdkr|| j_qZ|| j_n2t| rLt| tjrD|| _qZ|| _nt	d
| d S )Nr#  z0getitem or setitem node expected but received {})r  r    r  r   r   r  rB   r   r   
ValueErrorr   )r   Z	new_indexr   r   r   set_index_var_of_get_setitemx  s    

r  c                 C   sj   t | tsdS | j}t|dks,|d tkr0dS t| ds>dS t| dd}t |tsXdS tdd |D S )	z check if c is a namedtuple classFr   r   _make_fieldsNc                 s   s   | ]}t |tV  qd S r   )rB   r   )r.   r   r   r   r   r    s     z&is_namedtuple_class.<locals>.<genexpr>)rB   r   	__bases__rD   rC   rM   rR   all)cbasesfieldsr   r   r   is_namedtuple_class  s    


r  c                    s   | j  | j}tj||d} j|d}| tj|||d  fdd|D }tjj||d|d}	 j|d}
| tj|
|	|d t	|D ]<\}} 
|}tjj|
|d|d	}| tj|||d q| tj||d
 | S )zFill *newblock* to call *callee* with arguments listed in *inputs*.
    The returned values are unwrapped into variables in *outputs*.
    The block would then jump to *label_next*.
    r    r1   r1   r   r    r1   c                    s   g | ]}  |qS r   	get_exactr.   rH   r3   r   r   r5     s     z(fill_block_with_call.<locals>.<listcomp>r   )rp   r   rx  r1   N)r    r   r   r1   r   r1   )r3   r1   r   rU   	make_temprL   rK   rI   rV   	enumerater  r$  r}   )Znewblockr  
label_nextinputsoutputsr1   fnZfnvarr   ZcallexprZcallresr9  r2   r   r#  r   r  r   fill_block_with_call  s$    

 r  c                    st   | j }| j  fddt|D }t||D ].\}}tj|| d}| tj|| d q,| tj| d | S )z
    Fill a new block *block* that unwraps arguments using names in *inputs* and
    then jumps to *label_next*.

    Expected to use with *fill_block_with_call()*
    c                    s    g | ]\}}t j|| d qS ))rH   r   r1   )r   r   )r.   r9  rq   r  r   r   r5     s   z(fill_callee_prologue.<locals>.<listcomp>)r3   rH   r1   r  r  )	r3   r1   r  zipr   rE   rL   rK   r}   )r   r  r  r3   r   ZanameZavaltmpr   r  r   fill_callee_prologue  s    
r  c                    sh   | j  | j} fdd|D }tjj||d} j|d}| tj|||d | tj||d | S )z
    Fill a new block *block* to prepare the return values.
    This block is the last block of the function.

    Expected to use with *fill_block_with_call()*
    c                    s   g | ]} j |d qS )r   r  r  r  r   r   r5     s     z(fill_callee_epilogue.<locals>.<listcomp>)r   r1   r  r  r  )	r3   r1   r   rI   rJ   r  rL   rK   r   )r   r  r1   valsZtupexprtupr   r  r   fill_callee_epilogue  s    r  c                 C   sx   t | |}t|tjtjfr"|jS t|tjrp|jdkrpt| |j}zt	||j
}|W S  tk
rn   tY nX tdS )zhCheck if a variable is a global value, and return the value,
    or raise GuardException otherwise.
    rR   N)r  rB   r   rQ   re  r    rI   r  find_outer_valuerR   r   AttributeErrorr  )r   r   dfnZprev_valvalr   r   r   r    s    

r  c                 C   s  g }| j D ]B}||kr
t|| tjjr
|| jdkr
d|}t|| jq
| j	
 D ]j}|tjD ]V}t|jtjr|jjdkr|j}t|dd}|dk	rt|dddk	rd}	d}
q|j}	d	|	 }
nd
}	d}
d|	|
f }t||jjt|jtjtjfrn|j}t|dd}|dkr$qjd}t|tjrF|tjtjhk}|s\t|dddk}|rn||j t|jtjr>|jjdkr>|jjdkr>|jjj}t|| tjrqj| |}tt | |}|r|d dkrtt!|d }t!"|t!j#sjt!"|t!j$rqj|%dr dnd|}t&d||jdt|jtjr||j'j }d}t|ddst|tj(tj)frt&|||jj|f |jdt|jtj*rj| j+sjd}t||jdqjqXt,|dkrd}d-dd |D }t|| dS ) a&  
    Helper function to walk IR and raise if it finds op codes
    that are unsupported. Could be extended to cover IR sequences
    as well as op codes. Intended use is to call it as a pipeline
    stage just prior to lowering to prevent LoweringErrors for known
    unsupported features.
    i  a'  Tuple '{}' length must be smaller than 1000.
Large tuples lead to the generation of a prohibitively large LLVM IR which causes excessive memory pressure and large compile times.
As an alternative, the use of a 'list' is recommended in place of a 'tuple' as lists do not suffer from this problem.Zmake_functionr  Nr  z$<creating a function from a closure>r:   z(%s) z<could not ascertain use case>zNumba encountered the use of a language feature it does not support in this context: %s (op code: make_function not supported). If the feature is explicitly supported it is likely that the result of the expression %sis being used in an unsupported manner.r    Fr  Zgdb_internalrR   viewr   rP   r   r   z'{}' zZ'view' can only be called on NumPy dtypes, try wrapping the variable {}with 'np.<dtype>()'r  zThe use of a %s type, assigned to variable '%s' in globals, is not supported as globals are considered compile-time constants and there is no known way to compile a %s type as a constant.	reflectedz0The use of generator expressions is unsupported.av  Calling either numba.gdb() or numba.gdb_init() more than once in a function is unsupported (strange things happen!), use numba.gdb_breakpoint() to create additional breakpoints instead.

Relevant documentation is available here:
https://numba.readthedocs.io/en/stable/user/troubleshoot.html#using-numba-s-direct-gdb-bindings-in-nopython-mode

Conflicting calls found at:
 %sr  c                 S   s   g | ]}|  qS r   )Z	strformatr   r   r   r   r5   f  s     z0raise_on_unsupported_feature.<locals>.<listcomp>).r   rB   r   rF   rG   countr   r   r1   r   r   
find_instsr   rK   r    rI   r  rR   r  rQ   re  pytypesFunctionTyper  ZgdbZgdb_initrL   r   rH   rV  r  r+  r,  rP   Z
issubdtypeintegerZfloatingr  r   r   ZDictTypeZListTyper   Zis_generatorrD   r  )r   r4   Z	gdb_callsZarg_namemsgblkr   r  r  Zuser1  foundr   ZdfZcntyZvardescrbufr   r   r   raise_on_unsupported_feature  s    




r  c           
      C   s|   |  D ]n\}}|jr|dr| j}|dd }| jj}t|tj	rLdnd}d}d||||f }	t
t|	|d qd S )	Nr  r   r   r   r   zrhttps://numba.readthedocs.io/en/stable/reference/deprecation.html#deprecation-of-reflection-for-list-and-set-typesz
Encountered the use of a type that is scheduled for deprecation: type 'reflected %s' found for argument '%s' of function '%s'.

For more information visit %sr  )r   r  r  r1   splitrY  rZ  rB   r   Listwarningswarnr   )
r   r4   rH   r  r1   r   r2  Ztynameurlr  r   r   r   warn_deprecatedj  s    

r  c                    sV   g  fdd|}|dk	rN|j }D ]}t||d}|s. qRq.|S ndS dS )ac  
    This returns the python function that is being getattr'd from a module in
    some IR, it resolves import chains/submodules recursively. Should it not be
    possible to find the python function being called None will be returned.

    func_ir - the FunctionIR object
    node - the IR node from which to start resolving (should be a `getattr`).
    c                    sv   t | dddkrNd| j z | j} W n tk
rD   Y d S X | S t| tjtj	frrt| jt
jrr| S d S )Nr  FrR   r   )rR   insertr   r  r    r  rB   r   rQ   re  r  
ModuleType)modr   Zgetattr_chainresolve_modr   r   r	    s    z-resolve_func_from_module.<locals>.resolve_modNF)r    rR   )r   r   r  Zdefnr   r   r  r   resolve_func_from_module  s    	r
  c                 C   sL   | j  D ]<}dd |tjD }|r
d|d  }t||d jdq
dS )z8
    Enforce there being no ir.Del nodes in the IR.
    c                 S   s   g | ]}|qS r   r   r   r   r   r   r5     s     z#enforce_no_dels.<locals>.<listcomp>zIllegal IR, del found at: %sr   r  N)r   r   r  r   r   r   r1   )r   r  Zdelsr  r   r   r   enforce_no_dels  s
    r  c                 C   sL   | j  D ]<}dd |jddD }|r
d|d  }t||d jdq
dS )	z=
    Enforce there being no ir.Expr.phi nodes in the IR.
    c                 S   s   g | ]}|qS r   r   r   r   r   r   r5     s     z#enforce_no_phis.<locals>.<listcomp>phi)r  zIllegal IR, phi found at: %sr   r  N)r   r   Z
find_exprsr   r1   )r   r  Zphisr  r   r   r   enforce_no_phis  s
    r  c                 C   s   t dd |  D dkS )zGCheck the given mapping of ir.Block for containing a single scope.
    c                 S   s   h | ]
}|j qS r   r  )r.   r  r   r   r   r     s     z(legalize_single_scope.<locals>.<setcomp>r   )rD   r   rn  r   r   r   legalize_single_scope  s    r  znumba.core.compiler.Flags)flagsc                 C   s.   t |  t|  t| }|jd|jd dS )z4
    This checks that the IR presented is legal
    T)Zextend_lifetimesN)r  r  r   r   r   Zdbg_extend_lifetimes)r   r  r   r   r   r   check_and_legalize_ir  s    
r  c              	      s  | j }t|j}g }|jD ]n}z |}W n* tk
rV   d| }t|| jdY nX t|tj	rr|
|j qd| }t|| jdqddd t|D }ddd t|D }	t|jd	}
|j} | j}|d
k	r0t|tr fdd|D }t|n fdd|jD }t|t}
||
 dfddtD }|
rfddt|
D }|d7 }|d|7 } jjj}t||||	|S )z
    Converts a code object from a `make_function.code` attr in the IR into a
    python function, caller_ir is the FunctionIR of the caller and is used for
    the resolution of freevars.
    z\Cannot capture a constant value for variable '%s' as there are multiple definitions present.r  zbCannot capture the non-constant value associated with variable '%s' in a function that may escape.r  c                 S   s   g | ]\}}d ||f qS )z
	c_%d = %sr   )r.   r9  r   r   r   r   r5     s     z0convert_code_obj_to_function.<locals>.<listcomp>r  c                 S   s   g | ]}d | qS r  r   r  r   r   r   r5     s     r   Nc                    s   g | ]}  |jqS r   r  r    r   	caller_irr   r   r5     s     c                    s   g | ]}  |jqS r   r  r   r  r   r   r5     s   c                    s   g | ]}d  |  qS )z%sr   r  )co_varnamesr   r   r5     s     c                    s$   g | ]}d  |  | f qS )z%s = %sr   r  )r  kwarg_defaults_tupnargsr   r   r5     s   z, )r  rD   r  r  r  r   r1   rB   r   rU   rL   r    r  r  rs   r   r  r  defaultsrC   r   rY  rp   __globals__r  )Zcode_objr  r  r  Zfreevarsr   Zfreevar_defr  r  r  Zn_kwargsZ	n_allargsZkwarg_defaultsdr  Zkw_constr  r   )r  r  r  r  r   convert_code_obj_to_function  sX    


	




r  c                 C   s   i }|   D ],}|j}|jD ]}| D ]}|||< q(qq|   D ]8}|j}| D ]$\}}|j|jkrT|j|j| qTqBdS )aa  Fixes the mapping of ir.Block to ensure all referenced ir.Var are
    defined in every scope used by the function. Such that looking up a variable
    from any scope in this function will not fail.

    Note: This is a workaround. Ideally, all the blocks should refer to the
    same ir.Scope, but that property is not maintained by all the passes.
    N)r   r3   r   r   r   rH   	localvarsdefine)r   Zused_varr  r3   r   r   r   r   r   fixup_var_define_in_scope	  s    	
r  c                 C   sJ   | j }||kr| S |jj D ] }|j|jkr|j|j| q|| _ | S )z5Transfer the ir.Block to use the given ir.Scope.
    )r3   r  Z_conr   rH   r  )r   r3   Z	old_scoper   r   r   r   transfer_scope&	  s    r  c                 C   s   t | tjS r   )rB   r   Z	EnterWithr  r   r   r   is_setup_with6	  s    r  c                 C   s   t | tjS r   )rB   r   Z
Terminatorr  r   r   r   is_terminator:	  s    r   c                 C   s   t | tjS r   )rB   r   r   r  r   r   r   is_raise>	  s    r!  c                 C   s   t | tjS r   )rB   r   r   r  r   r   r   	is_returnB	  s    r"  c                 C   s   t | tjS r   )rB   r   ZPopBlockr  r   r   r   is_pop_blockF	  s    r#  )NNN)NNN)NN)N)N)N)NNT)N)N)N)NNNNN)rP   r  r   r  r  r  r  Znumba.core.extendingr   r  r   r   r   r   r   r	   Znumba.core.typing.templatesr
   Znumba.core.analysisr   r   r   Znumba.core.errorsr   r   r   r   rX   r   r   r   r+   r*   r,   re   r-   rS   r   rw   rv   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  rL   r   r  r  r  r)  r-  r  r   r*  r  rD  r;  rK  rG  rO  rS  rP  r^  r   rf  r   rh  ri  rj  rl  rs  rw  rz  r|  r}  r{  rq  r  r  	Exceptionr  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  r
  r  r  r  r  r  r  r  r  r   r!  r"  r#  r   r   r   r   <module>   s   $s%'%
	

3  

(W
0  
F%%= 
B


9
%     6

!

M	      
.8{$

D