---
# System prepended metadata

title: 'Iterator IR: best practices'
tags: [discussion]

---

# Iterator IR: best practices

###### tags: `discussion`

[TOC]

## Tasks

- Move `itir_makers` to a common place to be used everywhere [✔]
- Utilities to deal with unique symbol name creation (TODO, still unclear who or how to implement)

## Discussion and conventions

- **Issue:** Should we promote `itir_makers` from `ffront` to more general `ITIR makers` to be used everywhere?
    - **Decision**
        - Yes. Let's move it to `next.iterator` package
        - Let's rename unneeded `something__` symbols (two underscores at the end) to just `something_` (one underscore)
        - Let's use `itir_makers` for new passes, but we don't need to refactor all existing passes.


- **Decision**
    - Many passes have the same `is_<something>() -> Typeguard[something]` functions (e.g. `is_applield_lift`) implemented and they should be defined only once and reused everywhere.

- **Issue**: utilities for dealing with symbol creation are currently hidden in some passes (e.g. double-check lowering for symbol clashes (lifted_lambda construction), double-check fuse_maps
    
    - **Decision**: Let's define these utilities only once and reuse from all passes.
        - Idea: `make_unique_name(preferred_name: str, existing_names: Collection[SymbolTable | Collection[str]], collision_resolver: Callable[[str, Collection[str]], str] = str_append) -> str`
        - Idea: look for proposal from @egparedes for naming scheme (maybe one of the scalar if stmt PR). Something like `{preferred_name}{some_unicode_character}{incresing_number}`.

            ```
            Python unicode symbols for identifiers:
                - xid_start  =  all characters in id_start after NFKC normalization, that is general categories Lu, Ll, Lt, Lm, Lo, Nl, and the underscore
                - xid_continue  =  all characters in id_continue after NFKC normalization, that is all chars in id_start plus characters in the categories Mn, Mc, Nd, Pc 

            Unicode symbols per class: https://www.compart.com/en/unicode/category

            https://www.compart.com/en/unicode/U+10307: 𐌇
            https://www.compart.com/en/unicode/U+10318: 𐌘

            https://www.compart.com/en/unicode/U+A788: ꞈ

            https://www.compart.com/en/unicode/U+141E: ᐞ
            https://www.compart.com/en/unicode/U+1421: ᐡ
            https://www.compart.com/en/unicode/U+1506: ᔆ
            https://www.compart.com/en/unicode/U+15B0: ᖰ
            https://www.compart.com/en/unicode/U+15B1: ᖱ
            https://www.compart.com/en/unicode/U+15B2: ᖲ
            https://www.compart.com/en/unicode/U+15B3: ᖳ
            https://www.compart.com/en/unicode/U+1601: ᘁ
            https://www.compart.com/en/unicode/U+166E: ᙮
            https://www.compart.com/en/unicode/U+167F: ᙿ

            varꞈ2
            varᔆ2
            varᐞ2
            varᘁ3
            var᙮3
            varᙿ2
            ```

        - Idea: `_generate_unique_symbol()` from `inline_lifts.py` at https://github.com/GridTools/gt4py/blob/64d8311e6dd473db4cb532ec6ed21bc05a32a1cf/src/gt4py/next/iterator/transforms/inline_lifts.py#L26


[itir-frontend-tests](https://hackmd.io/46Oa6MspRoSTiFozHzun5A#itir-frontend-tests)