-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
ability to create primitive types from TypeInfo, but not necessarily aggregate types #2907
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
Comments
Could this be conveyed by another name that |
Bikeshedding Disclaimer
|
We can categorize types by whether their type info contains a bounded amount of information, and whether they refer to another type. An error set's type info contains a slice of possible errors, so that's an unbounded amount of information. An optional type contains another type, so that's a recursive type. The list of types is taken from the docs on
[1] I'm not counting the [2] The in-memory space used by a union is bounded, but the type info is effectively the same as a struct's type info. [3] I'm pretty sure ArgTuple should have [4] EnumLiteral might store the identifier characters, which is kinda unbounded, This proposal seems to be attempting to exclude the ✔️ ✔️ cases, which means we're missing Type, Enum, and EnumLiteral. The term "primitive type" to me means types that are bounded and non-recursive. This includes the types you can express with a single keyword in zig ( My definition of primitive types also includes Opaque types, which are quite the special case. The OP comment "(this would replace I think there's a good argument to be able to construct pointer types with some builtin function, because pointer types have so much metadata ( |
Should the const MyPointerType = @Type(builtin.TypeInfo.Pointer {
.size = builtin.TypeInfo.Pointer.Size.One,
.is_const = false,
.is_volatile = false,
.alignment = 1,
.child = u8,
.is_allowzero = false,
}); Or should we require this? const MyPointerType = @Type(builtin.TypeInfo {
.Pointer = builtin.TypeInfo.Pointer {
.size = builtin.TypeInfo.Pointer.Size.One,
.is_const = false,
.is_volatile = false,
.alignment = 1,
.child = u8,
.is_allowzero = false,
}
); Note that it shouldn't be much more code to implement. |
Implementation here: #3111 |
This is mostly done thanks to @marler8997. The types left to implement are:
|
This comment has been minimized.
This comment has been minimized.
I'm not certain that we should allow |
I think this is already true, you can do something like fn SomeType() type {
return if (comptime function())
struct { const A = 1; const B = 2; }
else
struct { const A = 2; };
} |
I agree, you basically need to be a zig compiler (or at least comptime engine) to correctly do completions etc, adding aggregate type reification does make it slightly more diffciult but not by a huge degreee. Personally I would be okay with generating any aggregate type as long as you cannot generate functions in its namespace but I do get the arguments against it. Having enum reification alone will aready let metaprogramming code do a lot more without introducing really surprising behavior. |
This is fully implemented now. |
We have the
@reify
proposal here: #383. One of the reasons it's not accepted yet is that it's big and scary and has some pretty serious implications for how complicated zig code is allowed to be.This is a proposal which is a subset of #383 with a smaller scope, which is a builtin function (and I'm going to suggest a different name here)
@Type
which turnsbuiltin.TypeInfo
into atype
. In this proposal, if you try to make a struct, you get a compile error "unable to create struct type". The list of supported types would be:@IntType
)@OpaqueType
)@Vector
)This issue is a prerequisite to #383.
The text was updated successfully, but these errors were encountered: