-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Refactor json macro #12391
Refactor json macro #12391
Conversation
@dom96: Since it was mostly you who wrote the json macro, I would like to hear your opinion about these chages first from you. I removed most of it, but the test cases stood the same for the most part. |
Good one! What was the reason you picked overloading over a typed macro? |
@B3liever well, to be precise, I did use typed macros. You probably ask why I replaced the logic to select the deserializer with overload resolution. And the short answer is, because it is much simpler to implement. I saw quite some complicated logic in the old macro to detect types based on names and other patterns. And they were almost correct bot not entirely correct and there could be corner cases that nobody thought about that would just not work. And while I was thinking about how to implement this, I also thought: "Hey, we have a correct type matching mechanism in the language, it is called overload resolution". So eventually I decided to throw this weird and complicated logic all away and replace it with something where I know that it works. It turned out to work quite well. |
This is great, thanks! This should help with things like https://github.com/nim-lang/Nim/pull/11416/files I believe. |
Hey perhaps you can play with this Also since you already use macros in order to support object variants you must already know that overload resolution doesn't magically work in all cases. |
Well, I know there are problems with overload resolution, but I don't think it will be a problem with this specific setup. Btw nice work on your
|
Thanks for your valuable feedback! I appreciate it, will try to fix some of these issues, when I have time. |
87423df
to
b44bddc
Compare
This PR is finished now. |
@@ -1,3 +1,3 @@ | |||
Loading Nim Runtime support. | |||
NimEnumPrinter: lookup global symbol 'NTI_z9cu80OJCfNgw9bUdzn5ZEzw_ failed for tyEnum_MyOtherEnum_z9cu80OJCfNgw9bUdzn5ZEzw. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this JSON PR have changes to gdb?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea I know it isn't clean. But I used gdb and fixed it along the way. Then I was too lazy to split the PR up into different parts as the changes in gdb and json were interleaved.
Edit: Btw your review comes a little bit too late. This PR is already merged.
* closes nim-lang#12316 * make tjsonmacro work at js target * closes nim-lang#12289 * closes nim-lang#11988 * also fixed gdb related stuff
Refactor json
to
macro, it is now based on overloading. I did this because I wanted to fix #12316 and saw that it was a structural problem of theto
macro. Basically this is a big cleanup.createJsonIndexer
,getEnum
,toIdentNode
orworkaroundMacroNone
became obsolete and have been removed.postProcess
) are gone. It is now all a signle pass.json.to
fails withref Bar
#12316, code like that just works now.if cond(jsonNode["fieldA"]["fieldB"]["kind"]): doSometing(jsonNode["fieldA"]["fieldB"]["kind"])
are not generated like this anymore. But I didn't measure it.