---
# System prepended metadata

title: Eve refactoring and enhancements
tags: [functional cycle 8]

---

# Eve refactoring and enhancements 

###### tags: `functional cycle 8`

[TOC]

## Goal

Some design and implementation issues as well as missing functionality have been indentified in the Eve infrastructure during the implementation of the GTC cartesian pipeline. This project aims to refactor and enhance Eve to get rid of the issues and add useful new features.

## Appetite

1-2 Developers. Full cycle. -> Enrique

## Tasks

- Complete existing Datamodels implementation (1.5-2 weeks):
    + Remove `pydantic` dependency
    + Decide between `attrs` and `dataclasses` based implementations as foundation for _Datamodels_.
    + Update existing typing utils to deal with changes introduced in newer Python versions (e.g. `GenericAlias`, `Self`, variadic generics, etc.) and improve the integral _canonical_ representation of types and efficiency of `isinstance()` checks for `Protocol`s,
    + (Optional) implementation of JSON-like serialization (using `cattrs` or similar `dataclasses` utilities).

- Redesign base `Node` class (1-2 days):
    + Migrate `Node` to _Datamodels_. 
    + Implement a child iteration _protocol_ as a magic method defined by subclasses (e.g. `__iter_children__`). This will also makes explicit the differentiation  between _leaf_ nodes and _internal_ nodes, no matter if they are simple or aggregated (e.g. standard collections) types.
    + Add explicit content-based hash (from the new _architecture_ proposal design) working for mutable and immutable nodes (e.g. `__content_hash__` or `content_id`).

- Enhance `Visitor`s implementation (1-2 days):
    + Reimplement the current `Visitors` _context_ strategy as simple `Visitor`s traits augmenting the `visit()` method.
    + (Optional) add function dispatcher-based visitor for trivially extensible visitors without subclassing.

- Implement the `Pass` and `PassManager` infrastructure from the new _architecture_ proposal design (1-1.5 weeks):
    + `Pass`, `Analysis` and `LogPoint` interfaces.
    + Automatic caching of analysis results.

- (Optional) add extensible implementation of `Pattern Matching` and rewrite rules, including the following components (1-1.5 weeks):
    - (Composable) protocols: `Matcher`, `Transformer`
    - Intermediate and capture results objects: `CaptureNamespace`, `Result`
    - EDSL-like interface for specification

- (Optional) definition of a standard dialect with nodes representing core MLIR concepts (_operation_, _block_, _region_, _vtype_, _result_, node constraints) (2-3 days).


## Potential _rabbit holes_

- Due to the many limitations of the Python `typing` annotations, trying to make the static type checkers understand and validate the code might be very time-consuming or impossible, specially for generic Datamodels.


## No Gos
- The implementation of all the flavors of `pydantic` validators (_pre/post_, _root/field_) might be tricky and time-consuming for corner cases and it adds too much unnecessary complexity. Therefore, aiming for a 100% compatible replacement of current cartesian GT4Py should be considered unfeasible and a no-goal.


# Progress

## Tasks

- [ ] Complete existing Datamodels implementation (1.5-2 weeks)
    - [X] Update typing tools
        - [X] Transform typingx to extended_typing module using module-level `__getattr__` and `__dir__`
        - [X] Factorize differences between 3.8 and 3.10 (e.g. `GenericAlias`)
        - [X] Refactor canonicalization utils
    - [X] Pick base implementation for Datamodels (dataclasses vs attrs)
    - [X] Finalize implementation of Datamodels
        - [X] Support for validators
    - [ ] Refactor tests (WIP)
- [ ] Redesign base Node class (1-2 days) (WIP)
    - [ ] Refactor Node class hierarchy
    - [ ] Delete pydantic
- [ ] Improve Visitors (1 day)
    - [ ] Refactor context managers as visitor traits
- [ ] Pattern Matching (Optional)
    - [ ] Prototyping... 
- [ ] Pass Manager (not going to happen) 
