
    ǄgC                     n    d dl mZ d dlmZ  G d de      Z G d de      Z e       Zej                  Z	y)    )defaultdict)configc                   $    e Zd ZdZddZd Zd Zy)Rewritez8Defines the abstract base class for Numba rewrites.
    Nc                      y)z+Constructor for the Rewrite class.
        N )selfstates     d/home/mcse/projects/flask_80/flask-venv/lib/python3.12/site-packages/numba/core/rewrites/registry.py__init__zRewrite.__init__
   s     	    c                      y)z]Overload this method to check an IR block for matching terms in the
        rewrite.
        Fr   )r	   func_irblocktypemap	calltypess        r   matchzRewrite.match   s     r   c                     t        d      )zgOverload this method to return a rewritten IR basic block when a
        match has been found.
        z Abstract Rewrite.apply() called!)NotImplementedErrorr	   s    r   applyzRewrite.apply   s     ""DEEr   )N)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r      s    
Fr   r   c                   6    e Zd ZdZ eddg      Zd Zd Zd Zy)RewriteRegistryz+Defines a registry for Numba rewrites.
    zbefore-inferencezafter-inferencec                 ,    t        t              | _        y)ziConstructor for the rewrite registry.  Initializes the rewrites
        member to an empty list.
        N)r   listrewritesr   s    r   r   zRewriteRegistry.__init__!   s     $D)r   c                 N      j                   vrt        d       fd}|S )zf
        Decorator adding a subclass of Rewrite to the registry for
        the given *kind*.
        zinvalid kind c                     t        | t              st        dj                  |             j                     j                  |        | S )Nz {0} is not a subclass of Rewrite)
issubclassr   	TypeErrorformatr    append)rewrite_clskindr	   s    r   do_registerz-RewriteRegistry.register.<locals>.do_register.   sH    k73 B I I!! " "MM$&&{3r   )_kindsKeyError)r	   r(   r)   s   `` r   registerzRewriteRegistry.register'   s,    
 t{{"677	 r   c                    || j                   v sJ |j                  j                  }|j                         }| j                  |   D ]3  } ||      }t        |j                               }|s(|j                         \  }}	|j                  |j                  |	|j                  |j                        }
|
rt        j                  st        j                  r>t        d       t        d|j                  z         |	j!                          t        d       |j#                         }|||<   |j%                  ||f       t        j                  st        j                  r|j!                          t        d       |r6 |j                         D ]  \  }}	|	||   k7  s|	j'                            ddlm} |j-                  |j                        }|j/                          y)zGiven a pipeline and a dictionary of basic blocks, exhaustively
        attempt to apply all registered rewrites to all basic blocks.
        F______________________________________________________________________zREWRITING (%s):<____________________________________________________________r   )postprocN)r*   r   blockscopyr    r   itemspopr   r   r   r   DEBUGDUMP_IRprintr   dumpr   r&   verify
numba.corer0   PostProcessorrun)r	   r(   r
   r1   
old_blocksr'   rewrite	work_listkeyr   matches	new_blockr0   	post_procs                 r   r   zRewriteRegistry.apply6   sn    t{{"""%%[[]
==. 	(K!%(GV\\^,I&]]_
U!--uemm(-9||v~~h/+2F2FFG

h 'I"+F3K$$c9%56||v~~!(h 		(* !,,. 	JC
3'	 	(**5==9	r   N)	r   r   r   r   	frozensetr*   r   r,   r   r   r   r   r   r      s'    *,=>?F*(r   r   N)
collectionsr   r:   r   objectr   r   rewrite_registryr,   register_rewriter   r   r   <module>rI      s?    # Ff F,Bf BJ #$ #,, r   