Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User-defined types: Tracking issue #156

Closed
8 tasks done
mark-koch opened this issue Mar 6, 2024 · 0 comments · Fixed by #295
Closed
8 tasks done

User-defined types: Tracking issue #156

mark-koch opened this issue Mar 6, 2024 · 0 comments · Fixed by #295
Assignees
Labels
enhancement New feature or request

Comments

@mark-koch mark-koch self-assigned this Mar 6, 2024
@mark-koch mark-koch added the enhancement New feature or request label Mar 6, 2024
github-merge-queue bot pushed a commit that referenced this issue Jul 24, 2024
This is the feature branch for enabling struct field access and mutation
of linear fields.

Closes #276, closes #280, and closes #156. 

The difficult bit is that we want to track linearity of individual
struct fields separately (akin to Rust's partial moves):

```python
@guppy.struct
class MyStruct:
   q1: qubit
   q2: qubit
   x: int

def main(s: MyStruct):
   q = h(s.q1)
   t = h(s.q2)    # Using s.q2 is fine, only s.q1 has been used
   y = s.x + s.x  # Classical fields can be used multiple times
   use(s)         # Error: Linear fields of s have already been used
   ...
```

This is the plan:

* We introduce a new notion called `Place`: A place is a description for
a storage location of a local value that users can refer to in their
program. Roughly, these are values that can be lowered to a static wire
within the Hugr and are tracked separately when checking linearity.
* For the purposes of this PR, a place is either a local variable or a
field projection of another place that holds a struct. I.e. places are
paths `a.b.c.d` of zero or more nested struct accesses. In the future,
indexing into an array etc will also become a place.
* During type checking, we figure out which AST nodes correspond to
places and annotate them as such
* For linearity checking, we run a liveness analysis pass that tracks
usage and assignment of places across the CFG. This way, linearity of
different struct fields is tracked individually.
* When compiling to Hugr, we keep track of a mapping from places to
wires/ports


Tracked PRs:

* #288: Precursor PR to generalise our program analysis framework to run
on places in the future.
* #289: Adds the `Place` type and implements the type checking logic to
turn `ast.Name` and `ast.Attribute` nodes into places.
* #290: Update linearity checker to operate on places instead of
variables
* #291: Lower places to Hugr
* #292: Some missing pieces to handle nested functions correctlt
* #293
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant