
    Upf                     F    d dl Z d dlmZ ddlmZ ddlmZmZ ddZddZ	dS )	    Nwraps   )get_op_result_or_op_results)TypeInsertionPointc                       fd}|S )Nc                 Z   t          j                  dk    rt          j        |           }d |j                                        D             }t          |          t          |j                  k    rt          d |D                       st          d| d|            j        j        |  t          j        d                   5   | t          j        d         j                   }d d d            n# 1 swxY w Y   t          t          j                  d                   5  Vg }t          |t          t          f          r|                    |           n||                    |            |           d d d            n# 1 swxY w Y   t                    S )Nr   c                     g | ]	}|j         
S  )
annotation).0ps     W/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/jaxlib/mlir/extras/meta.py
<listcomp>z>op_region_builder.<locals>.builder_wrapper.<locals>.<listcomp>   s    CCCaQ\CCC    c              3   @   K   | ]}t          |t                    V  d S N)
isinstancer   )r   ts     r   	<genexpr>z=op_region_builder.<locals>.builder_wrapper.<locals>.<genexpr>   s,      ;;
1d++;;;;;;r   zfor body_builder=zH either missing a type annotation or type annotation isn't a mlir type: )lenblocksinspect	signature
parametersvaluesall
ValueErrorappendr   list	argumentsr   tupleextendr   )body_buildersigtypesresultsresop	op_region
terminators        r   builder_wrapperz*op_region_builder.<locals>.builder_wrapper   s<   y  A%%#L11CCC3>+@+@+B+BCCCEE

c#.1111;;U;;;;; 2 !w<wwruww   $I#U++I,Q/00 	I 	I"lD)9!)<)F$G$GHG	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I D!1222677 	  	 %gt}55 (JJw''''(JJw'''
3	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  +2...s%   #C<<D D .AFFFr   )r+   r,   r-   r.   s   ``` r   op_region_builderr/      s0    / / / / / / /: r   c                 L      fdt                    fd            }|S )a  Decorator to define an MLIR Op specified as a python function.

    Requires that an `mlir.ir.InsertionPoint` and `mlir.ir.Location` are
    active for the current thread (i.e. established in a `with` block).

    Supports "naked" usage i.e., no parens if no args need to be passed to the Op constructor.

    When applied as a decorator to a Python function, an entry block will
    be constructed for the Op with types as specified **as type hints on the args of the function**.
    The block arguments will be passed positionally to the Python function.

    If a terminator is specified then the return from the decorated function will be passed
    to the terminator as the last statement in the entry block. Note, the API for the terminator
    is a (possibly empty) list; terminator accepting single values should be wrapped in a
    `lambda args: term(args[0])`

    The identifier (name) of the function will become:
    1. A single value result if the Op returns a single value;
    2. An OpResultList (as a list) if the Op returns multiple values;
    3. The Operation if the Op returns no results.

    See examples in tensor.py and transform.extras.
    c                  P     | i |}|j         d         }t          ||          S )Nr   )regionsr/   )argskwargsr+   r,   op_constructorr-   s       r   op_decoratorzregion_op.<locals>.op_decoratorF   s4    ^T,V,,JqM	 Y
;;;r   c                      t          |           dk    rAt          |          dk    r.t          | d                   r              | d                   S  | i |S )N   r   )r   callable)r3   r4   r6   s     r   maybe_no_argsz region_op.<locals>.maybe_no_argsL   sb    t99>>c&kkQ..8DG3D3D.!<<>>$q'***<0000r   r   )r5   r-   r:   r6   s   `` @r   	region_opr;   -   sY    2< < < < < < <1 1 1 1 1 r   r   )
r   	functoolsr   dialects._ods_commonr   irr   r   r/   r;   r   r   r   <module>r?      s   
        > > > > > > % % % % % % % %   B& & & & & &r   