7 ms·
Rustgo: Calling Rust from Go with near-zero overhead (2017)
- killercup 7y ago(2017)
- jzelinskie 7y agoFilippo also gave a talk at GothamGo on this subject: https://www.youtube.com/watch?v=eymMKjymgGA https://www.youtube.com/watch?v=eymMKjymgGA
- hu3 7y ago> I'll be upfront: I don't know Rust, and don't feel compelled to do my day-to-day programming in it. I wonder if this changed. A quick glance over the blog hints me towards a no.
- jaChEWAg 7y agoThat line pretty much sums up the experience a lot of devs feel towards Rust
- rapsey 7y agoOf course generally the ones who “don’t know it”. But then that probably holds true for all languages one does not know.
- ludamad 7y agoGeneral purpose languages are a tough sell these days. Rust is tailored towards a niche and that's OK
- Refefer 7y agoSystems Languages are considered niche these days?
- ludamad 7y agoBut it's not the first systems language, so it does need to carve a niche in that space
- smt88 7y agoWhat is Rust's niche? What excites me about it is that it is becoming a general purpose ecosystem. A few libs are missing, but that's changing rapidly.
- hombre_fatal 7y ago> Rust is tailored towards a niche and that's OK I encourage people to try writing run of the mill blocking code with Rust instead of diving immediately into futures and thread pools and streams just as if you were writing run of the mill Python. It's generally 1:1 equivalent to the code I would've written in another language. It's a general purpose programming language where most of the learning curve is in more advanced topics like concurrency, streams, and how to multiplex over thread pools. You can ignore them at the start, just like you can in Python.
- disinclination 7y agoI’ve been thinking recently about how the symbol “C” in “C programming language” literally stands for “3”. We out here like, “I’ve been getting really into this new language, 12,447. I think it might finally be the thing to replace 3 for me.”
- kbenson 7y agoExcept it wasn't the third. It was like something between the 50's and low 100's. There were lots of languages then, most being unpopular. C was just intended to be third in that very specific lineage, and I wouldn't be surprised to find it wasn't really third and just making the claim with its name.
- coldtea 7y ago>There were lots of languages then, most being unpopular. Not to mention several more advanced than C, Go, or even Rust... (Lisp, for one, Smalltalk for another)
- kbenson 7y agoWell, it depends on what you mean by advanced, and if you're just considering the language or language plus compiler/runtime, but I take your point, and mostly agree with it.
- Animats 7y agoI was a big fan of Rust at first. Then they went off into a weirdo approach to functional programming. That sent Rust to the niche in which Haskell lives.
- simias 7y agoYou'll have to be a bit more specific, I've been using the language for quite a long time now and I don't understand what you're referring to. I haven't noticed any obvious paradigm shift since 1.0.
- hombre_fatal 7y agoThis is how most devs feel about any language they don't already use. There are even HNers who regularly brag about having never taken Javascript, one of the most ubiquitous languages, seriously enough to build a nontrivial project or to appreciate its upsides. So it's not as damning as you seem to suggest.
- throwaway8879 7y agoFor web dev, the ecosystem isn't quite there yet. I've written a few utilities and toy APIs, but don't feel like the web ecosystem is was rich as it needs to be for a serious project. Actix comes close. A few others like Warp ND Gotham are interesting. I'm waiting for rocket to compile in stable, and pick up async. But yes, rust is definitely pretty cool, and I'm annoyed that I finally "understand" the language on my nth attempt at learning it, and still haven't found a good use case for it.
- parentheses 7y agoIt's a statement that is ~ 2 years old. I recently started learning it and like many things about it. I also haven't learned enough, so any borrow checker annoyance is likely a symptom of not knowing enough. So far, I like: - traits (similar to typeclasses) - support for functional programming - borrow checker keeping you aware of memory scoping - it's (apparently) fast and relatively lightweight
- hu3 7y agoRust is great. It's nice to have an efficient way to call Rust code from Go for when you need that extra speed and security. I was just curious if Filippo's stance changed about the language since he works with cryptography and security at Google. I'm not seeing Rust in his GitHub repo's https://github.com/FiloSottile https://github.com/FiloSottile
- galangalalgol 7y agoI've been considering using Julia and rust in this way. anyone tried that?
- blindseer 7y agoI've used it. Julia's ccall is so nice to work with once you have wrapped it in other functions. The hardest part was creating, finding, downloading and using the right library with it's dependencies during Julia's build step for a package.
- superdimwit 7y agoOut of curiosity, what sort of code aren't you able to write in Julia that you can in Rust?
- galangalalgol 7y agothe idea was more to get that extra bit of speed for profiled bottlenecks. not a need, more a want. benchmark game currently puts Julia on par with go, not rust. also it seems to forgo simd except for obvious cases with large arrays.
- FiloSottile 7y agoA nuance I wish I had expressed better in this article is that it's targeting functions that would otherwise be written in assembly: they'd have to be quick (not to undermine the scheduler) and non-recursive (not to blow the stack). For just calling larger Rust functions one can use cgo.
- scottlamb 7y ago+1. There's a reason cgo sets up another stack; calling into Rust instead of C doesn't change that. What are the consequences if you blow the stack in Go [edit: to clarify, I mean if your code in another language that doesn't understand Go's stack copying calling convention blows Go's stack]? Is there a guard page (so SIGSEGV) or does it just corrupt memory?
- Animats 7y agoIf you have to reverse-engineer the undocumented Go calling sequence to call Rust, you probably shouldn't be using that for security-critical crypto functions. The next time somebody changes something, there will be trouble. This is especially an issue in a garbage collected language. If the only reference to something was passed from Go to Rust, will Go's GC marker find it? If it doesn't, everything will work just fine, until someday a garbage collection happens at the wrong moment. In security critical code, that's probably exploitable if you can force a GC from another thread.
- yencabulator 7y ago> If the only reference to something was passed from Go to Rust, will Go's GC marker find it? No, and rightly so. I would expect https://golang.org/cmd/cgo/#hdr-Passing_pointers https://golang.org/cmd/cgo/#hdr-Passing_pointers to apply just as much here as with CGo (the criteria is "foreign allocator", not CGo).
- Animats 7y agoWhich is a problem here, because the OP is calling Rust from Go using the Go calling sequence. So Go's checking doesn't know it's calling non-Go code. There's a defined way to call C from Go, but the OP is not using that interface.
- yencabulator 7y agoIt's fine as long as you don't store Go pointers in non-Go memory. If the local variable is the last reference to the thing, https://golang.org/pkg/runtime/#KeepAlive https://golang.org/pkg/runtime/#KeepAlive makes sure the Go side doesn't drop it before the call is complete.
- Myrmornis 7y agoI've been finding learning Rust an extremely valuable experience and I really like the language. Also I don't have any experience with replacing assembly code with a higher-level language. But... If you're looking for a replacement for hand-crafted assembly, don't the strict lifetime-checker and borrow-checker make Rust a non-obvious choice? E.g. they might prevent you from doing certain memory access patterns that you actually explicitly want your assembly to do? (I.e. wouldn't C or C++ be more the thing?) Or do you just make liberal use of unsafe blocks where necessary? Or is it actually fine and appropriate to write {lifetime,borrow}-checker compliant replacements for hand-crafted assembly?
- heinrich5991 7y agoPrevious discussion: https://news.ycombinator.com/item?id=15017519 https://news.ycombinator.com/item?id=15017519 (68 comments)