essential-contributions / pint

Pint, the constraint-based programming language for declarative blockchains
Apache License 2.0
17 stars 3 forks source link

Add front-end support for unions and `match` expressions and declarations. #872

Closed otrho closed 1 month ago

otrho commented 1 month ago

This PR has most of the changes needed for unions and match.

It does not have ABI generation nor validation testing. There are no documentation changes yet either.

I have been working on this for several weeks and have made pretty much all of the design and implementation decisions unilaterally, and so many of these choices need to be reviewed, particularly before we document it.

To get an example of how unions and both match expressions and match declarations work presently you can take a look at the E2E tests, especially unions/simple.pnt.

https://github.com/essential-contributions/pint/blob/948b540067db248f0296942a658815e1c577b36e/pintc/tests/unions/simple.pnt

I think perhaps if it's OK we could merge this PR and add issues for all the remaining work. Contracts which use unions won't compile (due to missing ABI) but since we're still pre-release I'd like to get it in since it'd getting too big and merge conflicts are an issue.

The main reason I didn't implement ABI output was I made an attempt and frankly got quite lost. I'll need some help to understand what is required there.

There are still a couple of design issues to work out too. Especially around storage -- do we allow unions in storage at all? Also, do we allow match bindings to shadow each other? Perhaps, since they're local in scope.

otrho commented 1 month ago

While working on this I decided #874 and #875 are needed. Unions make these issues worse.