-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
remove @Type
from the language, replacing it with individual type-creating builtins
#10710
Comments
I've really enjoyed the change: the symmetry with |
EDIT 2024: My original comment here was based on not seeing any benefit to this change. I now see a benefit, namely, splitting up the API allows Zig to more accurately represent what can be "reified". With this I'm in favor of the change. Below is my original comment. This change doesn't really seem like much of a win or loss to me since both mechanisms can be implemented in terms of the other. We could either keep P.S. If there really is benefit to splitting up |
I really like this change, as it removes both unnecessary features from |
If we are going this way, then there could be a case for not having /// @Float
switch (bits) {
16 => f16,
32 => f32,
64 => f64,
80 => f80,
128 => f128,
}
/// @Array
if (m_sentinel) |sen| [size:sen]T else [size]T
|
If we did do this, we could very well make helper functions in |
I personally really like the completeness of the current interface. Putting it in With the current interface, the simplest |
I don't think completeness for the sake of completeness is really that great; currently, as outlined in the proposal, all this completeness does is create two ways to declare a lot of types, in ways that add no utility to
That is already the case with status quo; in what way would this differ, except in reducing redundancy?
What do you mean exactly? The capability to do these things isn't being made exclusive to
I'd like to ask, why would it be more likely to lead to a feature gap in previously-correct code, in such a scenario? And in what way would the example of |
I like most of this change's effects but I think it's a pretty significant downside that you can no longer do |
both should be avoided in favor of proper optionals. |
given how simple their construction, i think even having |
@apppppppple |
(long text with individual replies)
Well, okay, that sounds like a difference in preference/perspective.
The particular use case I was thinking of is similar to what @apppppppple wrote:
It's valid to say "no code does this in practice", or bring arguments of why code shouldn't do this in practice, but having to switch on
The construct
My point was that if I need a utility function instead of
Keeping
I was originally thinking of the scenario of adding a new kind of type (not that we need one). The previous builtins, like switch(@typeInfo(T)){
else => unreachable,
.Int => |int_info| {
comptime var new_info = int_info;
new_info.bits *= 2; // agnostic to all other fields,
return @Int(new_info);
}
} I might have been too pessimistic when referencing EDIT: In that case my point amounts to not seeing the benefit of removing the builtin over implementing it in userland code. |
I think a better solution would be to keep the status quo and just add convenient wrappers for This issue can be solved by a better API which in this case could be provided in the "userspace" of the language (through code accessible to the end user). I don't see why we should complicate the language with more builtins. It doesn't seem like the simplest solution in this case. |
* std.meta: correct use of `default_value` in reification. stage1 accepted a wrong type for `null`. * Sema: after instantiating a generic function, if the return type ends up being a comptime-known type, then we return an error, undoing the generic function instantiation, and making a comptime function call instead. - We also needed to clean up the dependency graph in this case. * Sema: reified enums set tag_ty_inferred to false since an integer tag type is provided. This is a limitation of the `@Type` builtin which will be addressed with #10710. * Sema: fix resolveInferredErrorSet incorrectly calling ensureFuncBodyAnalyzed on generic functions.
There are a few things that can't be reimplemented in the language itself at present: https://gist.github.com/tauoverpi/e8fc90d44659d86a0ac25dc7fb1081bc But it isn't much. |
@tauverpi I think the idea was to use the newly proposed P.S. your Pointer implementation is impressive nonetheless :) |
@marler8997 Yes, those which use However |
For simple cases I can imagine a workaround of |
What about the result of |
I want to suggest that the intention of this change could be accomplished by limiting the allowable set of That keeps the I'd even offer that it's less conceptual burden for the learner: I don't have strong feelings on the subject, it just struck me as the simplest thing which would achieve the stated objective, and I hadn't seen it discussed. It does appear to solve every bullet point in the motivation section, although not the hunch, which I can't speak to one way or the other. |
Motivation
As noted in #10705 (comment), here are some reasons that
@Type
is janky:@Type(.Opaque)
should be avoided in favor ofopaque {}
.@Type(.Void)
should be avoided in favor ofvoid
@Type(.Type)
should be avoided in favor oftype
@Type(.Bool)
should be avoided in favor ofbool
@Type(.NoReturn)
should be avoided in favor ofnoreturn
.@Type(.ComptimeFloat)
should be avoided in favor ofcomptime_float
@Type(.ComptimeInt)
should be avoided in favor ofcomptime_int
@Type(.Undefined)
is equivalent to@TypeOf(undefined)
and it is unclear which is preferred, and that is a problem.@Type(.Null)
is equivalent to@TypeOf(null)
and it is unclear which is preferred, and that is a problem.@Type(.EnumLiteral)
is equivalent to@TypeOf(.foo)
and I guess the@Type
one is slightly better.@Type( .{ .Optional = .{ .child = T } })
should be avoided in favor of?T
.@Type( .{ .ErrorUnion = .{ .error_set = E, .payload = T } })
should be avoided in favor ofE!T
.@Type(.BoundFn)
should be avoided@Type(.{ .Vector = .{ .len = len, .child = T }})
sucks,@Vector(len, child)
is way better. and please don't suggest to reach intostd.meta
to use basic primitive types of the language.Also, after living with
@Type
for a couple years now, I just have a feeling about it and I feel that I don't like it. I liked the old way better.Proposed Changes
This is a reversal of #2907. This proposal is to do the following things:
@Type
@Int
@Float
@Pointer
@Array
@Struct
@Enum
@Union
Related Issues
The text was updated successfully, but these errors were encountered: