add native option type - #7358
Merged
Merged
Conversation
This commit adds support for a native option type to replace the previous
approach that used unions with none types to indicate an option type.
When working on the type checker, we realized we needed to distinguish
between an untyped none inside a fusion unioned with other stuff vs a bona fide
option type. This change solves this problem and provides a better foundation
for option types.
The new vector.Option uses a simple tags pattern like unions but it does
not yet implement run-length encoding of the tags as is done with two-element
unions. This will affect the performance of the JSON read path (to CSUP)
and will be addressed in a future PR.
The SUP format now represents a some value using the rusty syntax some(val).
The value val is decorated inside the parens so a decorator need not come
after some() unless it's a named option type. We also improved the
SUP formatter so none decorators can be specified by a parent value
decorator as in "type foo={x?:int64} {x?:none}::foo".
SUP-decorated none values or none casts always imply an option type, i.e.,
none::string is equivalent to none::option(string). The SUP formatter uses the
shorter syntax.
We also added some() and unwrap() functions to the runtime. some() converts a
value to an option value and unwrap() extracts the underlying value from
the option type.
To reflect the format changes, we bumped the version numbers of CSUP and BSUP.
nwt
reviewed
Sep 28, 2026
nwt
reviewed
Sep 28, 2026
nwt
reviewed
Sep 28, 2026
nwt
approved these changes
Sep 28, 2026
Comment on lines
+478
to
+481
| switch vec.Kind() { | ||
| case vector.KindOption: | ||
| return vector.Apply(vector.ApplyRipOptions, func(vecs ...vector.Any) vector.Any { | ||
| switch vec := vecs[0].(*vector.Option).Any.(type) { |
Member
There was a problem hiding this comment.
This looks like another place where a type switch will prevent a panic on vector.Named.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit adds support for a native option type to replace the previous approach that used unions with none types to indicate an option type.
When working on the type checker, we realized we needed to distinguish between an untyped none inside a fusion unioned with other stuff vs a bona fide option type. This change solves this problem and provides a better foundation for option types.
The new vector.Option uses a simple tags pattern like unions but it does not yet implement run-length encoding of the tags as is done with two-element unions. This will affect the performance of the JSON read path (to CSUP) and will be addressed in a future PR.
The SUP format now represents a some value using the rusty syntax some(val). The value val is decorated inside the parens so a decorator need not come after some() unless it's a named option type. We also improved the SUP formatter so none decorators can be specified by a parent value decorator as in "type foo={x?:int64} {x?:none}::foo".
SUP-decorated none values or none casts always imply an option type, i.e., none::string is equivalent to none::option(string). The SUP formatter uses the shorter syntax.
We also added some() and unwrap() functions to the runtime. some() converts a value to an option value and unwrap() extracts the underlying value from the option type.
To reflect the format changes, we bumped the version numbers of CSUP and BSUP.