-
-
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
instantiationInfo-like for plain proc #11689
Comments
…ite info alternative (nim-lang/Nim#11689)
while it "works", it doesn't work the way you're implying, eg: let gp1 = initFooGenericProc[int](2) # line 100
let gp2 = initFooGenericProc[float](2)
let gp3 = initFooGenericProc[int](2) you'll get:
which makes sense. Since a proc (non generic, or a generic proc with a given instantiation parameters, eg The only way to make this work for generics and procs (without introducing a wrapper template as @zah was suggesting here #7406 (comment)) is by making optional arguments instantiated at caller site instead of callee site, as I was mentioning in #7406 (comment) # maybe via a pragma, eg:
proc initFooProc(x: int, info = instantiationInfo() {.caller.}): Foo =
Foo(lineinfo: info) This is the approach used in D with callsiteMagicif @zah 's suggestion from #7406 (comment) isn't enough, you can automate it via a macro proc initFooProc(x: int, info: InstantiationInfo()): Foo {.callsiteMagic.}
Foo(lineinfo: info)
# with:
macro callsiteMagic(fun: untyped) =
# creates wrapper template with same name and arguments as `fun`; for above example it'd be:
# template initFooProc(x: int): untyped = initFooProc(x, instantiationInfo()) |
Related to #7406, #6469
instantiationInfo
works for generic proc, templates and macro but not for normal proc:It would be useful to have a
callInfo
magic that gives the same detail for logging or error reporting purpose. This can also include the proc name (as requested in #7406 and #8212).The Nim documentation encourages using the least powerful construct fit for purpose between proc/template/macro. This feature will make it easier to use proc when a library grows large enough to require call site information for error or logging purposes.
The text was updated successfully, but these errors were encountered: