Skip to content

Programmatic type construction with @infoType #2906

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

Closed
marler8997 opened this issue Jul 16, 2019 · 1 comment
Closed

Programmatic type construction with @infoType #2906

marler8997 opened this issue Jul 16, 2019 · 1 comment

Comments

@marler8997
Copy link
Contributor

marler8997 commented Jul 16, 2019

The ability to modify/infer types from other types is a key feature of generic programming. It is proposed that the langauge add support to programmitcally create types from comptime TypeInfo structs with the @infoType function, i.e.

assert(u8 == @infoType(@import("builtin").TypeInfo.Int { .is_signed = false, .bits = 8, }));

@infoType is the inverse of the @typeInfo function and it's signature would be:

@infoType(comptime info: @import("builtin").TypeInfo) type

The following comment describes how this feature can be used to implement the SliceType and ArrayPointerType functions which take an array/pointer type and return either the slice or array pointer variation of it while preserving the const/volatile/allowzero properties:

#2782 (comment)

The point being that without programmatic generation of types, the code requires 2^N cases to return a type where N is the number of properties for that type (i.e. const/volatile/allowzero). See the comment in the above link for further clarification.

@andrewrk
Copy link
Member

This is #383

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

No branches or pull requests

2 participants