-
Notifications
You must be signed in to change notification settings - Fork 23
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
Make Sym "XXX:ObjectType" works with macros.getImpl
#176
Comments
Here is a related PR nim-lang/Nim#11526 |
|
and what is the wiser way to get pragmas from type/proc definition? currently, only getImpl able to return AST + pragmas. |
The |
something like |
Exactly. The default should be not to include them though for compatibility. |
I agree backward compatibility should not be compromised here. We can add more features to I think we reach consensus here. |
This RFC is stale because it has been open for 1095 days with no activity. Contribute a fix or comment on the issue, or it will be closed in 7 days. |
Make Sym "XXX:ObjectType" works with
macros.getImpl
Background story
We have 5 or 6
hasCustomPragma
related issues:misc issues:
ref/ptr issues:
4. nim-lang/Nim#12523
5. nim-lang/Nim#8457
6. status-im/nim-json-serialization#11 (using alternate implementation of
hasCustomPragma
from status-im/stew)This is about
macros.hasCustomPragma
. Current implementation ofhasCustomPragma
is barely readable.That is why we implement an alternate version of
hasCustomPragma
in nim-stew/macros.This new implementation of
hasCustomPragma
readability is far abovemacros.hasCustomPragma
and also easier to use when designing a serialization library.Issues no 1 to 3 practically can be eliminated easily.
However, issues no 4-6 remain the same for both implementation.
stdlib-hasCustomPragma
using various work-around to no avail.nim-stew-hasCustomPragma
actually very close to get it works.nim-stew-hasCustomPragma
approach is ignoring ref/ptr types altogether and only focused to regular object/tuple.The algorithm only use simple
getType
+getImpl
.This approach make the code simpler. So how we expect ref/ptr to works? use a template:
But, this approach unfortunately doesn't work.
Sym "objectName:ObjectType"
return nothing when you usegetImpl
.Using combination of
getType + getTypeImpl + getTypeInst + getImpl
only make it worse and make it messier.It also never reach the same usability compared to only use
getType
+getImpl
.Proposed solution
If we
getType
ref/ptr object, it will return synthetic symbolSym "objectName:ObjectType"
as a part of it's AST.Currently,
getImpl
will returnNilLit
on this symbol. As a user, I don't care much how the compiler internal works.Putting an AST to that synthetic symbol may have no use to the compiler itself, but as a user, who care?
If this synthetic symbol can works with
getImpl
, much of the problem mentioned above will be reduced.Of course, we also can use
dynamicBindSym
as a work around to relate theobjectName
back to it's ref/ptr type.But I prefer
getImpl
approach.Implementation
It only involves NimNode tree copy + add + assign. Not too hard I think.
When we use
getImpl
on this symbol, it will return impl AST as if a regular object's symbol does.Consequences
It will breaks some code. But I think very rare people depends on this
NilLit
return value.Benefits
stdlib-hasCustomPragma
andnim-stew-hasCustomPragma
can be fused easier to get more power.hasCustomPragma
can accept various type declarations such as:The text was updated successfully, but these errors were encountered: