Hacker News new | past | comments | ask | show | jobs | submit login

> Any normal function call can do these things.

A normal function cannot switch threads.

   foo();   // executed on thread 1
   doSomeIO().await; 
   bar();   // possibly continued on thread 2
Now if foo() does some native calls that write some data to thread-local storage and bar() relies on that storage - that can make a huge impact on correctness. Rust is a systems programming language, so details like that matter.



surely lifetimes and the borrow checker are a better way to statically check for these sort of issues than relying on await side effects? What if an await is inadvertently introduced later inside your (implicit) critical section?


The borrow checker does catch those issues. But it it does not do whole-program analysis. It analyzes code locally, by looking at signatures of functions being called.

And also being forced to read distant code to understand if given snippet is correct would be a maintainability nightmare.

I've had enough problems dealing with Java exceptions which are allowed to pop up from anywhere and are not visible in the code.


What I mean is that if preserving invariants across function calls is important enough that an async call can break it, you want the invariant to be enforced statically by the compiler and you do not want to rely on visual inspection of the source to confirm lack of reentrancy.

Once you do that, you do not need a call site annotation that a function can be preempted as the compiler will check it for you.

Rust is uniquely equipped to enforce these guarantees.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: