-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add support for defining procedural macros #2315
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
Conversation
20f788d
to
ee30008
Compare
@matklad I need some help with this - I like the approach of splitting My current work was in https://github.com/DJMcNab/rust-analyzer/tree/proc-nameres-saved - I was trying to rebase but ended up in a state where Github thought the PR head was upstream master so closed the PR. |
which include procedural macros through FnDef
This shouldn't be the case: we shouldn't have proc-macro crates in the
crate graph, we should only have compiled proc-macros themselves (probably
directly in the crate graph). In other words, the definition of a proc
macro is, in general, unknowable, because it lives in a completely separate
compilation session. Proc macros should be another kind of Def, which
hasn't source attributes, and can only be used to transform tokens.
…On Sat, 23 Nov 2019 at 14:31, Daniel McNab ***@***.***> wrote:
@matklad <https://github.com/matklad> I need some help with this - I like
the approach of splitting MacroDef by
FnLike(Builtin/Declarative/Procedural)/Attribute(Builtin/Procedural)/Derive(Builtin/Procedural),
but I'm not sure how to work with FromSource for that. You said in #2248
(comment)
<#2248 (comment)>
that we shouldn't have a node in ra_syntax for MacroDefs which include
procedural macros through FnDef, but FromSource for MacroDef requires
some ast type which represents it. Should I just use ModuleItem?
My current work was in
https://github.com/DJMcNab/rust-analyzer/tree/proc-nameres-saved - I was
trying to rebase but ended up in a state where Github thought the PR head
was upstream master so closed the PR.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2315>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AANB3M373Z6GURYFBMMOCNLQVEICPANCNFSM4JPIVX5A>
.
|
But surely from an IDE point of view, the only way to define a proc macro is using a function with a |
This can't work, because IDE can't magically compile this function to a proc macro. The IDE should learn about proc-macros the same way compiler learns about them: by dynamically loading
|
That is, in the proc_macros: FxHashMap<String, PathBuf> // points to .so |
If we go the WATT route, we should use not the SO, but the |
I'm not sure. I might have to throw in the towel on this - I'm not certain I know how I would implement this within your vision |
Uhu, sorry for not really digging into this this time: I'd love to do some design work here, but my design-bandwidth is exhausted by the hir split at the moment. I think the rough plan should work as follows:
The most important bit here is that we never actually look at the source code of a proc_macro crate, we only work with compiled representation of proc macros. |
I think the external process should accept an absolute path of a proc-macro : e.g. |
Continues #688.
TODO:
FnLike
) macros in nameresDerive
macros (and expand them, possibly in a separate PR)Copy
as that should be simplest)Attribute
macrosCopy
macro Support declarative macros 2.0 #2248