Skip to content

Proposal: procedural comptime type manipulation #2890

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
distractedlambda opened this issue Jul 13, 2019 · 3 comments
Closed

Proposal: procedural comptime type manipulation #2890

distractedlambda opened this issue Jul 13, 2019 · 3 comments
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@distractedlambda
Copy link

I'm rather new to Zig, so apologies if this is something that's already in the works or has already been discussed before.

I was surprised and happy to see the @field() builtin function, but it seems like only the start of what could be a much larger set of features. In particular:

  • The ability to enumerate, inspect, and look up all public members of a type, not just fields.
  • The ability to add and remove members, fields, enum cases, etc. from types. Since types are immutable, this would probably take the form of builtins that produce new anonymous types from existing ones.

There are a number of use cases I can think of:

  • Automatically parsing and generating type definitions for schemas for external markup languages at comptime.
  • Postprocessing the struct from an @cImport and generating a new "glue" interface. For instance, a comptime OpenGL extension loader generator that learns about available procedures by browsing the Zig definitions generated from the headers.
  • Any embedded DSL where you need to generate types with computed member names.
@hryx
Copy link
Contributor

hryx commented Jul 13, 2019

Related: #383

@andrewrk andrewrk added the proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. label Jul 16, 2019
@andrewrk andrewrk added this to the 0.6.0 milestone Jul 16, 2019
@komuw
Copy link

komuw commented Jul 16, 2019

probably also related; #2907

@andrewrk
Copy link
Member

I believe this is a duplicate of #383.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

No branches or pull requests

4 participants