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

Optional values and big typecheck refactor #118

Merged
merged 3 commits into from
Mar 12, 2025
Merged

Conversation

tertsdiepraam
Copy link
Contributor

Where do I even begin...

The initial goal was to implement optional values. I've done this by adding an Optional[T] enum. But that introduced the issue that we didn't support type parameters yet! So that had to be done first. And that spiraled out of control.

So here's a summary of functional changes:

  • We now support T?, Foo[A, B, C], ! and record types in any place that needs a type expression, instead of only supporting paths.
  • Enums now support multiple fields on a variant (closing Enums should be able to have more than 1 field #104).
  • While it is not (yet) possible to create these types in Roto, enums can now have type parameters. So far, only Optional and Verdict have this, but the mechanism is generalized.
  • Optional values are now supported. The type of an optional value is T? which is identical to Optional[T], which is just an enum with two variants. There's no automatic conversion from T to T? and no special operators (yet). But you can construct them and match on them. They can also safely be passed to and from Rust. (Resolves part of Optional values #117)
  • Verdicts are now regular enums, because they no longer need special handling. This means you can now match on them (closing Verdict needs to be an enum we can match on #103).
  • Semi-accidentally I fixed Accept/reject with a semicolon fails to compile #88.
  • You no longer have to pass pointer_bytes in many places.
  • There was an issue that explicit return of reference types didn't work in functions. That's fixed now.
  • Types can now be transformed before they are passed to Roto. This is currently used for turning Option into Optional (which has a fixed layout) and back. This might be important for other types later too.

Internally some things are cleaner now:

  • All types are now referenced by name, even primitives and verdicts are no longer treated specially in many places.
  • These names can have type arguments that are unified.
  • We can retrieve the definition of types to get more information (i.e whether it is a primitive, or whether it is an enum or a record).
  • Layout calculation is put into a separate module and much cleaner now! I'm quite proud of this one!
  • Because we now have proper parsing of complex type expressions, the parser uses the same thing for parsing the type declarations.

@tertsdiepraam
Copy link
Contributor Author

Making this a draft so I can do a bit more documentation on this.

@tertsdiepraam tertsdiepraam marked this pull request as ready for review March 12, 2025 14:02
@tertsdiepraam
Copy link
Contributor Author

Changed my mind, the documentation will be separate. I'm working on that now. To keep going, I'll merge this.

@tertsdiepraam tertsdiepraam merged commit 6e5e6dd into main Mar 12, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant