Skip to content

add native option type - #7358

Merged
mccanne merged 4 commits into
mainfrom
native-option
Sep 28, 2026
Merged

mccanne merged 4 commits into
mainfrom
native-option

Conversation

@mccanne

@mccanne mccanne commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator

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.

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.
Comment thread cmd/super/ztests/terminal-output-format.yaml Outdated
Comment thread runtime/sam/expr/function/downcast.go
Comment thread runtime/vam/expr/function/upcast.go Outdated
Comment thread runtime/vcache/option.go Outdated
Comment thread runtime/ztests/expr/function/some.yaml
Comment thread sup/ztests/named-none.yaml
Comment thread sio/arrowio/writer.go
Comment thread sup/analyzer.go Outdated
Comment thread sup/analyzer.go Outdated
Comment thread sup/analyzer.go Outdated
Comment thread value.go Outdated
Comment thread value.go Outdated
Comment thread type.go Outdated
Comment thread fuser.go Outdated
Comment thread vector/vbuild/option.go Outdated
Comment thread vector/option.go Outdated
Comment thread vector/option.go Outdated
Comment thread vector/union.go Outdated
Comment thread complex.go Outdated
Comment thread context.go Outdated
Comment thread runtime/vam/expr/downcast.go Outdated
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) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like another place where a type switch will prevent a panic on vector.Named.

@mccanne
mccanne merged commit d9de27f into main Sep 28, 2026
4 checks passed
@mccanne
mccanne deleted the native-option branch September 28, 2026 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants