-
-
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
Callsite as experimental #11864
Callsite as experimental #11864
Conversation
I'm all for removing redundant features, but as I was mentioning here #11805 (comment) there are cases where Before #11822 (which needed a compiler patch to implement it relied on template aliasImpl(extra, exp, name) =
template exp2()=exp
extra
macro name(): untyped = # overload with 0 args
let c = callsite() # here's where I needed `callsite`
result = getAst(exp2())
if kind(c) == nnkCall: result = newCall(result)
else: doAssert kind(c) == nnkIdent
macro name(arg0: untyped, args: varargs[untyped]): untyped = # overload with > 0 args
result = newCall(getAst(exp2()), arg0)
for ai in items(args): result.add ai
macro alias*(def: untyped): untyped = # entry point
let (name, exp) = splitDefinition(def) # from #11824
var extra: NimNode
# caveat: doesn't work with, for example; `macro foo(a=1, b=21): untyped`: compiles(foo) fails
if exp.kind == nnkIdent:
extra = quote do:
static: assert declared(`exp`)
else:
extra = quote do:
static: assert compiles(`exp`)
result = getAst(aliasImpl(extra, exp, name)) Note: proc t():auto=42
alias:ta=t
# assert ta() == t() # what we would like to have
assert ta()() == t() # what we have instead: violates what an alias should be: something that
# can be used in same way as original symbol noteeven that implementation wasn't working in important cases (and probably has non-negligible compile time cost), hence the need for #11822 which works in all cases and should have 0 compile time overhead. Obviously if #11822 is merged I won't miss would the following be possible
|
494c4b3
to
e4291d7
Compare
@krux02 can you rebase this onto the latest devel? |
This pull request has been automatically marked as stale because it has not had recent activity. If you think it is still a valid PR, please rebase it on the latest devel; otherwise it will be closed. Thank you for your contributions. |
This PR pushes
callsite()
to the experimental state. This means that the compiler only needs to generate any of thedeepCopy
tries fornOrig
, when the featurecallsite
is actually requested. This PR also refactors a lot of code, so that it does not require callsite anymore.These are the two major reasons to remove it.
related branch: callsite-lineinfo
Edit:
A common use case is to use
callsite
just to get line information from the macro invocation. When callsite disappears entirely, code like that breaks. I think a better solution would be ifcallsite
would return an empty node, but with the line information that is requested.