You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Make std_options a comptime struct instead of a namespace #14432
acceptedThis proposal is planned.proposalThis issue suggests language modifications. If it also has the "accepted" label then it is planned.standard libraryThis issue involves writing Zig code for the standard library.
I'm a fan of this, and at present it poses no immediate problems.
But I think it should at least be noted, this would likely complicate the addition of any stdlib option whose type is a function with a generic return type, since that can't be expressed as a standalone type for a struct field type. Ditto for a function for which we want the error set to be inferred.
IMO that isn't actually a strong argument against the proposal, because I can't actually imagine any use cases where any of that would be really necessary, so despite that, I'm in favor of this change.
The reason I went with a namespace instead of a struct instance is io_mode depends on event_loop being defined and the type of event_loop depends on io_mode but if that is cleared then I'd also be in favor of this.
The reason I went with a namespace instead of a struct instance is io_mode depends on event_loop being defined and the type of event_loop depends on io_mode but if that is cleared then I'd also be in favor of this.
I oppose this proposal because of the problems of self-referential declarations. Makes it pretty much impossible to depend on std.options in generic code that might implement some of its own std_options, whereas this is possible with declarations.
Additionally if there are options that let you declare types and implementations of those types, you'd be forced into the annoying pattern of specifying ?*anyopaque like std.builtin.Type is forced to do for default field values.
acceptedThis proposal is planned.proposalThis issue suggests language modifications. If it also has the "accepted" label then it is planned.standard libraryThis issue involves writing Zig code for the standard library.
Activity
InKryption commentedon Jan 23, 2023
I'm a fan of this, and at present it poses no immediate problems.
But I think it should at least be noted, this would likely complicate the addition of any stdlib option whose type is a function with a generic return type, since that can't be expressed as a standalone type for a struct field type. Ditto for a function for which we want the error set to be inferred.
IMO that isn't actually a strong argument against the proposal, because I can't actually imagine any use cases where any of that would be really necessary, so despite that, I'm in favor of this change.
Vexu commentedon Jan 23, 2023
The reason I went with a namespace instead of a struct instance is
io_modedepends onevent_loopbeing defined and the type ofevent_loopdepends onio_modebut if that is cleared then I'd also be in favor of this.pfgithub commentedon Jan 24, 2023
Ah, that's unfortunate
Assuming blocking io can't ever have an event loop, a tagged union could be used:
Or io_mode could be removed entirely:
If blocking io is allowed to have an event loop, I'm not sure how to resolve the dependency without it being messy
Luexa commentedon Feb 3, 2023
I oppose this proposal because of the problems of self-referential declarations. Makes it pretty much impossible to depend on
std.optionsin generic code that might implement some of its ownstd_options, whereas this is possible with declarations.Additionally if there are options that let you declare types and implementations of those types, you'd be forced into the annoying pattern of specifying
?*anyopaquelikestd.builtin.Typeis forced to do for default field values.andrewrk commentedon Apr 9, 2023
Accepted as long as we can solve the issue that @Vexu mentioned.
rohlem commentedon Jul 7, 2023
@pfgithub I'm not sure what issue remains with a tagged union approach.
Is this what you considered being messy?: