Meta data to structs and functions

Currently the language syntax is specially made for the zig parser and zig build system. I want to propose adding meta data to functions and structs (maybe also global variables but I leave that to the zig team) with options in the zig parser to read them. Taking inspiration from clojure metadata.

Expected usage:

  1. add the documentation comments to the meta data.
  2. give the community a jump start to make analysis software like if a function calls any non thread safe function or check if upgrading dependency would use a deprecated function
  3. if the zig team decides to make meta data extensible, community could define extra tags in the future like fine grain policy management (uses network)

Expected Problems:

  1. adds overhead and memory usage in the parsing stage and will degrade the speed
  2. if the zig team decides to make meta data extensible, it adds complexity to the implementation.
  3. is callconv a meta data or part of the function declaration? someone needs to decide
  4. breaking syntax. I think a function being public if part of the meta data so should ‘pub’ be removed?
  5. what syntax to use? I think clojure syntax is simple, has little clutter (in clojure) and doesn’t interfere with zig existing syntax (I am talking about adding ^{} for meta data before keyword, fn and struct) but I am biased

Finally I am simply trying to leverage the zig parse more because it is very fast and well built to give the community power to create better tools.

This idea feels like it is pretty mismatched from Zig and really belongs more in a dynamic gc language, it also seems quite a bit hidden/implicit instead of direct/explicit.

There have been proposals about tagging systems for adding annotations which may be closer aligned with Zig, but those haven’t really gotten of the ground either.

That said I find it difficult to imagine what exactly you want to use this for, maybe it would be more obvious if I had more experience with clojure.

Validation would be a use case for it, but I think I would rather have something that is designed to be for validation specifically, instead of a general meta data system.

1 Like