-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Language Support: C# Macros (Compilation time methods) #1911
Comments
@prasannavl |
@AdamSpeight2008 Was a bit disappointed when my search for macros in GitHub issues yielded none. Function templates seem appropriate! Nice, shall give it a thorough read soon. |
Some inspiration could be drawn from Nemerle - a fringe but stable .NET language: https://github.com/rsdn/nemerle/wiki/Macros-tutorial https://github.com/rsdn/nemerle/wiki/Nemerle-macros-intro This is a relatively large repository using Nemerle - Nitra - an upcoming awesome language workbench by JetBrains: https://github.com/JetBrains/Nitra |
We are now taking language feature discussion on https://github.com/dotnet/csharplang for C# specific issues, https://github.com/dotnet/vblang for VB-specific features, and https://github.com/dotnet/csharplang for features that affect both languages. See also dotnet/csharplang#107 |
Macros are extremely powerful, but can introduce unnecessary complications, when not done right.
Currently, the only way to have this level of functionality is to do messy post-compile IL rewrites, and/or Debug conditionals to a certain extent, for conditional codes.
Addition of macros in the way its expressed in Rust-Lang where the evaluations happen during compile time, and produce code could be extremely powerful, and could be realized neatly with Roslyn. Rust-Lang expresses them very succinctly as a part of the language itself (almost in-differentiable from calling methods)
This could potentially replace all mixin tweaks currently used, but without any of the run time-performance hit.
I haven't thought much on the implementation, but if this seems to be an area of interest for the core team, implementation discussions here could be started off here. Meanwhile, in comparison with Rust itself which provides a clean implementation that works with pattern matching at its crux, the key detail would be in how the handoff to Roslyn happens, and how the resulting tree is created by Roslyn with type-safety.
The text was updated successfully, but these errors were encountered: