-
-
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
=>
doesn't work with {.async.} (neither js nor c)
#17254
Comments
Why should example 1 work? Since(using int/auto) when true:
import std/async
import std/sugar
let fn3 = proc(a:int): int {.async.} = 1234 doesn't work? At least the returned type should be specified for async procs when true:
import std/async
import std/sugar
let fn3 = proc(a:int): Future[int] {.async.} = result = 1234 |
is there a reason why the declared return type in async procs needs to be If it introduces ambiguities (eg cases where let fn3 = proc(a:int): int {.async2.} = 1234 and then this could work: let fn2 = (a:int) {.async2.} => 0 (async2 can be bikeshedded) |
I guess that's a historical issue. It should do the wrap or so. |
so the main question is whether we can relax async to allow T and Future[T] or we need async2 that requires T (and generates Future[T]) |
The real issue here is once again that |
that's just too extreme. Without them many things would not be possible. Yes, they have caveats, and no they can't be removed or replaced by alternatives in many cases (at least not without some language changes), I can provide examples if needed (also, it's unclear whether you mean "immediate" macros/templates where all params are untyped, or just untyped params to macros) That said, some macros could be changed to use typed instead of untyped, and it's quite possible that async (in async and asyncjs) could be changed to typed, TBD (implementation does look hacky and improvable, eg things like Here's a quick and dirty POC that works and could be turned into a robust solution: when true: # D20210621T120527
import std/async
import std/sugar
import std/macros
macro async2(a): untyped =
result = a.copyNimTree
let body = result[6]
result[3][0] = quote do:
Future[typeof(`body`)]
result[4] = quote do: {.async.}
result[6] = quote do: result = `body`
echo result.repr
let fn3 = proc(a:int): int {.async2.} = 1234
let fn4 = (b: int) {.async2.} => 12 |
I'm interested yes. For the cases I came up with it starts to work out once we added an annotation like "in m(x) the 'x' will be a scope injected symbol name" |
again, you need to clarify whether you mean "immediate" macros/templates where all params are untyped, or just untyped params to macros, or untyped params in general but here are typical cases where untyped is needed:
even in this category of use cases, it doesn't help in cases like There are plenty other examples things that mitigate
|
Nope, it's a conscious decision. The procedure type should reflect the type that is actually returned, a |
Wouldn't a solution here be to simply make |
this is arguably more hacky than introducing a |
Doesn't convince me all that much. That you need to be aware of macro expansions is a price I'm willing to pay for a simplified macro system. |
Example 1
Current Output:
Error: implementation of ':anonymous' expected
Example 2
Current Output:
Error: Expected return type of 'Future' got 'auto'
Proposed Solution
see #17254 (comment) which is a working POC
Additional Information
The text was updated successfully, but these errors were encountered: