Skip to content

Source transformation API (comptime? macro?) #2082

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
binary132 opened this issue Mar 21, 2019 · 2 comments
Closed

Source transformation API (comptime? macro?) #2082

binary132 opened this issue Mar 21, 2019 · 2 comments
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@binary132
Copy link

binary132 commented Mar 21, 2019

Hello, I believe this is tangentially but not directly related to issue #2029. 2029 may be a subset of this question, in fact.

A friend has recently been introducing me to Julia's interesting macro-like tools for inspecting the lowered / macro-expanded / LLVM / native transformations their runtime JIT performs on interpreted source code. It's fascinating what they are doing. For a couple of examples of what it enables -- https://github.com/jrevels/Cassette.jl and http://blog.rogerluo.me/2018/10/23/write-an-ad-in-one-day/

I think that some such tools would be useful for Zig. Offering some API and well-defined datatypes around expansion / inspection of source transforms performed by the Zig compiler would supercharge much more than debugging. If the API is accessible to comptime fns, this could open up incredible metaprogramming features to library contributors. If the API is simply to link various stages in the self-hosted compiler, I suppose I could tolerate it with minimal complaint.

This would also open the door to a wide variety of well-designed static analysis tooling.

Perhaps this is out of scope of the design of the language, but it struck me as a fascinating feature.

@andrewrk andrewrk added this to the 0.5.0 milestone Mar 21, 2019
@andrewrk andrewrk added the proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. label Mar 21, 2019
@AlexKotik
Copy link

We can also look at Haxe as an example of powerfull metaprogramming features. For example I've always been facinated by their build-macros that allow modification of types at compile time, here is a little example: https://code.haxe.org/category/macros/build-static-field.html

@andrewrk
Copy link
Member

Not planned. If the needed metaprogramming is too complicated to express with zig's existing comptime features then the suggested solution is code generation with the build script.

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

3 participants