Comments (7)
This is very bad idea, because all the implicit conversions of target procedure arguments or return value can create confusion when reading compiler's errors.
Compiler will show you types which was converted by "macro code", while you do not see this conversion in your source.
For example:
proc a(): int {.async.}
got transformed implicitly to proc a(): Future[int]
and now all compiler errors will be about Future[int]
value, but not about int
.
So current small inconvenience will become much more annoying. As an alternative we can remove silent conversion of procedures without return values to Future[void]
and show an error.
from nim-chronos.
compiler errors
isn't this something that the macro could help with? basically, could it output did you forget "await"?
in the right places?
if the objective of async/await
is to make async code look like sync code (which most async frameworks seem to want to do), then decorating things with Future
works against that goal - specially if you want to introduce other types like tuple
and Option
, it quickly gets very noisy - things that you would "naturally" do in sync code become very verbose.
from nim-chronos.
I support this change. The same question was discussed in a Nim RFC and someone correctly pointed out that you cannot avoid the type discrepancy - it will be either present in eyes of the caller or in the eyes of the implementer:
proc foo(): Future[int] {.async.} =
result = 10 # How come the result is not a `Future`? That's what the signature says!
In the end, Nim has code generation features and we must learn to accept that. What this means it that when you start using a library, your first step should be to read the published documentation. You have to be aware that certain features such as custom pragmas may affect the generated code and you must develop the Nim survival skills to deal with this. I can promise you that the tools at your disposal will become better in the future.
There is a particular objective measure that gets improved with this change. It reduces the erroneous "degrees of freedom" of the API. It's no longer possible to produce certain compilation errors (oh, I forgot to add the Future
type).
from nim-chronos.
Its very easy to remove all this result
replacements and force people to use complete
and fail
explicitly. And i really like such change, but i really dislike proposal to perform implicit conversions and produce many nonsense compile time errors, because compiler will start mention Future[T]
but you will not see Future[T]
in your procedures and so for you this errors messages will have no sense.
from nim-chronos.
@arnetheduck because async
macro is untyped we can't get type information, and becasue we do not have type information its very hard to show meaningful error. And we are not talking here about await
in right places we are talking about modification of procedure's return value.
from nim-chronos.
how hard would it be to introduce an experimental macro that does this (async2
or whatever)? ie to play around with the syntax without committing to it..
from nim-chronos.
@arnetheduck all the logic of result value happens here in asyncmacro2.asyncSingleProc
.
This part is responsible for verification of return value:
https://github.com/status-im/nim-chronos/blob/master/chronos/asyncmacro2.nim#L164-L181
This part is responsible for creation of internal result Future[T] object.
https://github.com/status-im/nim-chronos/blob/master/chronos/asyncmacro2.nim#L187-L193
And last transformation which transforms proc foo() {.async.}
=> proc foo(): Future[void]
.
https://github.com/status-im/nim-chronos/blob/master/chronos/asyncmacro2.nim#L255-L259
from nim-chronos.
Related Issues (20)
- compiler error on simple async proc HOT 1
- asyncloop `isCounterLeaked` returns incorrect value?
- chronos is not available in Nim Playground? HOT 2
- httpclient: The content of HostHeader is incorrect when redirecting to a different host HOT 1
- Write to `Future.internalValue` directly in macro-translated code
- `getAcceptInfo` can raise an unlisted exception: ref ValueError HOT 2
- Apparent garbage collect of localCopy in datagram sendTo before data gets send in writeDatagramLoop HOT 2
- Cycle-based memory Leak under --mm:arc HOT 1
- chronos/threadsync errors when compiling documentation
- bug: TokenBucket update calculates wrong with lastUpdate timestamp HOT 1
- Reading a file asynchronously? HOT 1
- Async proc: both Option[seq[T]] and Opt[seq[T]] as return type and one of the params is generic, failed to compile with Nim-devel HOT 1
- Completing `Futures` in refc may have unexpected behavior HOT 1
- `cancelAndWait` on `or` triggers deadlock
- `SIGSEGV` in `asyncTest`-derived scenario (also, in `asyncTest`) HOT 5
- Can't compile on GCC 14
- ambiguous identifier: `'Result'` HOT 2
- Change header size limits HOT 2
- Its impossible to specify Future[T].Raising([]) as argument.
- What is the intended method for catching exceptions raised from asyncCheck'd Futures? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nim-chronos.