16 ms·
The Road to Rust 1.0
- robin_reala 12y agoAdopting the channels system is interesting. Are there any other languages that have a scheduled release pattern like this?
- steveklabnik 12y agoI'm not aware of any, but if there are, I'd like to talk to them about their experiences doing so. :)
- howeman 12y agoGo sort of does this, though on longer timescales. Developers are at "tip". Actual releases are every 6 months, and before the release there is always at least one release candidate, and sometimes an actual beta.
- AlyssaRowan 12y agoIt'd be wonderful if they kept the ability to define that a certain destructor does zero memory. Sometimes, you need that.
- gpm 12y agoZeroing out memory isn't sufficient, as discussed here: http://www.daemonology.net/blog/2014-09-06-zeroing-buffers-is-insufficient.html http://www.daemonology.net/blog/2014-09-06-zeroing-buffers-i... That said, this was discussed on reddit[0], it sounds like there is a way to guarantee that you did zero out memory (but not necessarily copies of that memory, as discussed in the link above), and because Rust is intended to be memory safe, it's not as much of an issue if you don't/can't. http://www.reddit.com/r/rust/comments/2fnb82/zeroing_buffers_is_insufficient_why_c_is_insecure/ http://www.reddit.com/r/rust/comments/2fnb82/zeroing_buffers...
- AlyssaRowan 12y agoNot in C. Rust is, as you say, intended to be memory safe. That means it has the hope of getting it right.
- someone13 12y agoFWIW, you can implement the 'Drop' trait to provide a custom destructor, and then use, e.g. 'volatile_set_memory'[0] to zero out the memory of the object. This isn't subject to the same problems as C, AFAIK. [0] http://doc.rust-lang.org/std/intrinsics/fn.volatile_set_memory.html http://doc.rust-lang.org/std/intrinsics/fn.volatile_set_memo...
- strcat 12y agoYou would have to force the sensitive content to be dynamically allocated. All types in Rust can be moved via a shallow memcpy and that will leave around dead shallow copies. For example, `Vec<T>` will leave around dead versions of the values when it needs to do a reallocation that's not in-place.
- Ixiaus 12y ago> The key to all these changes has been a focus on the core concepts of ownership and borrowing. Initially, we introduced ownership as a means of transferring data safely and efficiently between tasks, but over time we have realized that the same mechanism allows us to move all sorts of things out of the language and into libraries. The resulting design is not only simpler to learn, but it is also much “closer to the metal” than we ever thought possible before. All Rust language constructs have a very direct mapping to machine operations, and Rust has no required runtime or external dependencies. Almost sounds like they borrowed this thinking from Exokernel design... I think Rust is shaping up to be a very exciting language.
- pacala 12y agoThe ownership idioms are very similar to idiomatic C++11 and std::unique_ptr. Which is to say that Rush has got an industrial strength safe memory management system. But Rust stands out because the rest of the language is such a joy to use, compared to pretty much any other 'systems' language out there. Congratulations to the team!
- wycats 12y agoOne of the cool things about the Rust ownership system is the lease/borrow system. Moving is cool, but much of the time you want to synchronously call another piece of code and give it a temporary (stack-frame-long) lease for that pointer. Rust starts with ownership, but makes it easy to ergonomically and safely lend out that ownership (including one-at-a-time mutable leases) of both stack and heap allocated pointers. I've been programming with Rust since last December, and I have had essentially zero segfaults coming from Rust code during that time frame, roughly equivalent to what I would have expected writing code in a language whose safety guarantees come with a runtime cost (GC or ARC).
- JoshTriplett 12y agoI used to describe my preferred family of languages as: - C when I absolutely had to (kernel/modules/plumbing). - Python for scripting and broad accessibility. - Haskell when I had the choice and I knew everybody who would work on the project. I was skeptical of Rust when it first came out, due in large part to the many different kinds of pointers it originally had, many of which involved significant manual memory management. But now, with a strong static type system, garbage collection, pattern matching, associated types, and many other features, Rust is looking like a serious contender to replace all three of those languages for me. Still waiting to see if it develops a strong following, community, and batteries-included library ecosystem, but I need to start doing more experiments with Rust. Disappointing to see yet another language-specific package management system (Cargo), though.
- steveklabnik 12y agoRust does not have any garbage collection, to be clear. All your other features are correct though :) (We have previously said "opt-in GC" but that was a lie. See https://news.ycombinator.com/item?id=8312327 https://news.ycombinator.com/item?id=8312327 for more.)
- JoshTriplett 12y agoYeah, I should have said that more clearly. Automatic memory management (never having to call free), not garbage collection. Which is arguably more awesome: whenever the compiler can figure out at compile time when you'll stop using memory, it can statically decide to reclaim it there.
- wycats 12y agoYes! The fact that Rust has zero-runtime-overhead automatic memory management is a big deal. I've been using Rust for almost a year, and it's been a source of great delight for me.
- haberman 12y agoI am a huge fan of no required GC, and of precise refcounting. But does Rust have anything on the roadmap to handle truly cyclic structures that don't lend themselves to a weak pointer approach?
- rubiquity 12y ago> Green threading: We are removing support from green threading from the standard library and moving it out into an external package. I only ever looked at Rust from a 500 foot view while toying with it at a Hackathon, but I had no clue it had so many different types of threading models. This seems like a step in the right direction, indeed. If Task is going to your unit of concurrent execution, as much transparency around that as possible is a good thing.
- masklinn 12y agoIt had just two: libgreen backed tasks with "green threads", libnative backed them with OS threads.
- rubiquity 12y agoDoes that mean every task will be an OS thread? Or are tasks handled by a runtime specific scheduler and will use a pool of threads for IO?
- hornetblack 12y agoGreen threading used to be default. And used libuv for io. Then native threading was avaliable. Then it became default. Now green threading is being moved out of builtin libs. Starting with green threads is really easy too: extern crate green; extern crate rustuv; #[start] fn start(argc: int, argv: *const *const u8) -> int { green::start(argc, argv, rustuv::event_loop, main) } fn main() { // this code is running in a pool of schedulers all powered by libuv } Edit: You can also start up a new libgreen scheduler pool at any time and add some native threads to the pool. So you can have some threads running with libgreen and some with libnative. (So you could theoretically embed a go program inside a rust program)
- MichaelGG 12y agoRust looks fantastic, and has a lot of things I wish I could do while in a higher level language like F#. I just wish Rust was a bit less verbose. Requiring, for instance, type annotations on function arguments because it's sometimes helpful is such a weird decision. Let the programmer decide when an annotation is needed. This gets annoying when you get into functions with complex arguments. Especially for local functions where the signature could be messy, but the limited scope means annotations just clutter things. I'm not sure why Rust forces us to compromise here.
- steveklabnik 12y agoEven in languages with whole-program inference, it's generally regarded as best practice to write out the types of your functions, hence Rust's choice here. You're right that there's a tradeoff. In general, Rust follows 'explicit over implicit.' > This gets annoying when you get into functions with complex arguments. Have you seen the where clauses yet? This should significantly help complex function declarations.
- MichaelGG 12y agoI just don't understand why there has to be a tradeoff. I just don't get why the compiler should decide on such a large thing, instead of letting the programmer do it. One can always be more explicit if one feels they're getting value from it. If someone wants to write a bunch of terse code, why stop them? Does the compiler gain a large benefit from not having to include this feature? Who loses by allowing users to do what they want? Comparing C# and F#, the extra annotations change the frequency in which I'll introduce an inner (local) function. For instance, here's a little helper in a piece of code I'm writing at the moment. It's part of a larger function and isn't exposed beyond 5 lines of code. let runWithLog f name = try run f name with ex -> logExn ex Used in: runWithLog "sessions" collectSessionStats runWithLog "visitors" collectVisitorStats Having to add "(f: string -> RunParams -> Whatever -> unit) (name: string)" almost doubles runWithLog helper yet provides no benefit. And this an extremely simple case! Once the arguments are generic, higher-order functions themselves, it gets quite noisy. Sure, if it's a top-level export, then maybe annotating is a good idea. But if it's limited in scope then what's the harm? Not that it'll change when I use Rust - there's nothing competing in this category. It'd just be nice if the language let the user decide on the style.
- doe88 12y agoWhat I think is an important feature of this language is the ease with which it can interact with other languages. Especially the possibility for Rust code to be called from foreign languages such as C very easily. I'm looking forward for even better support of iOS with the support of arm64, I think it is really important to offer an alternative. BTW is there an RFC on dynamically sized types? I can't find any, I'm looking to learn of it works.
- steveklabnik 12y ago> Especially the possibility for Rust code to be called from foreign languages such as C very easily. The second production deployment of Rust is a Ruby gem, written in C, that calls out to Rust. It's used in skylight.io, if you're curious. > BTW is there an RFC on dynamically sized types? IIRC, DST was before the RFC process even existed, it's just taken forever to implement. The Duke Nukem Forever of Rust. :) http://smallcultfollowing.com/babysteps/blog/2014/01/05/dst-take-5/ http://smallcultfollowing.com/babysteps/blog/2014/01/05/dst-... is what you want to read, IIRC.
- doe88 12y ago> IIRC, DST was before the RFC process even existed, it's just taken forever to implement. The Duke Nukem Forever of Rust. :) http://smallcultfollowing.com/babysteps/blog/2014/01/05/dst-.. http://smallcultfollowing.com/babysteps/blog/2014/01/05/dst-.... is what you want to read, IIRC. Thanks for the info and the link!
- wycats 12y ago> The second production deployment of Rust is a Ruby gem, written in C, that calls out to Rust. It's used in skylight.io, if you're curious. Yep! I'm one of the authors of that project. The fact that Rust provides automatic memory cleanup and the attendant safety without runtime overhead (even ARC has non-trivial runtime overhead) was a huge win for us, as was the transparent FFI. We were looking for a way to write fast code that was embeddable in a Ruby C extension with minimal runtime overhead and without a GC (two GCs in a single process is madness). We also wanted some guarantees that we wouldn't accidentally SEGV the Rails apps we were embedded in. Even last December, Rust was a clear winner for us. We've been shipping Rust code to thousands of customers for many months, and given the language instability, it's worked really well for us.
- 3289 12y agoIt seems that 1.0 is going to be a solid release. But the post-1.0 Rust is going to be even more exciting once they have added inheritance and subtyping which enable true polymorphic reuse!
- Rusky 12y agoWhy are trait objects not "true polymorphic reuse" already? Inheritance is pretty much just a performance and expression optimization to be avoided in most situations (and I believe is going to be in 1.0)
- strcat 12y agoObject inheritance is only useful in rare edge cases so your statement doesn't make much sense. Traits have default methods, inheritance and can be used as bounds on generics (no dynamic dispatch, type not lost) or as objects (dynamic dispatch / type erasure). What makes you think object inheritance is such a sure thing anyway? I don't expect either object inheritance or optional garbage collection to materialize, ever. In fact, I'd be pretty sad if the language was degraded with that extra complexity - I think it would be a worse situation than the mess that is C++. There would no longer be a shared idiomatic Rust.
- wtetzner 12y agoI think optional garbage collection might materialize, but I would imagine it would end up being a third-party library.
- kvark 12y agoI'm excited for the release too. Know many people who hesitate to touch Rust, even if interested, due to the fact language is still in active development. On minor concern though, I don't see how "where clauses" are simplifying the language. Looks like something that could be added after the release.
- steveklabnik 12y ago> On minor concern though, I don't see how "where clauses" are simplifying the language. Looks like something that could be added after the release. Where clasues simplify Rust code, they don't simplify the language itself. They're also important for associated items. For more: https://github.com/aturon/rfcs/blob/associated-items/active/0000-associated-items.md https://github.com/aturon/rfcs/blob/associated-items/active/...
- eCa 12y agoI haven't looked at Rust, but it seems from the outside that releasing a stable version of a language every six weeks is very aggresive?
- steveklabnik 12y agoContinuous deployment is common in the web world. It's true that it's aggressive, but we think it's going to have significant benefits.
- pbsd 12y agoPeople tend to expect more stability from a systems language than a web one. Can I trust that my Rust 1.0 code will work, unchanged, 20 years from now? If not, the language is likely to remain in the enthusiast realm.
- steveklabnik 12y agoTo be clear, Rust is following SemVer, and the six-week releases are 1.x versions. So they should be backwards compatible. There's no current timeline for a 2.x.
- eCa 12y agoYes, I'm not saying it's a bad thing. It does imho put a lot more pressure on the language developers than a cd'd web app, with regards to backwards compatibility and such. (With ~10 releases a year there's bound to be accidental breakage that passes the beta period.) Ambitious might have been a better word than aggresive..
- wycats 12y agoI'm sure that seemed true about web browsers too. The trick is feature flagging all new API surface and only including flagged code when it's deemed stable.
- hadoukenio 12y agoStill sitting on the fence as to which language I should pick up on next - the only contenders are C++11 and Rust. How does Rust compare with C++11 as a language? C++11 seems to (in some ways) have caught up with what Rust has to offer (compared to older C++ versions) e.g. smart pointers, concurrency and regexes part of the standard library
- pcwalton 12y agoRust is memory-safe; C++11 is not.
- Q6T46nT668w6i3m 12y agoC++ is useful when learning Rust since a lot of documentation assumes the reader is familiar with C++ and there’s plenty of C++ documentation that has no pre-requisites.
- jmgrosen 12y agoHmm. I learned Rust without any C++ knowledge (though I did have a fair amount of experience with C), and it was pretty easy. Recently I've had to start writing some C++ (to my dismay), and it has not been so easy... the language is really complex.
- wycats 12y agoI think things have changed :) Steve Klabnik has been doing a ton of work on the docs, and that has brought a lot of "coming from an HLL" perspective to them.
- jmgrosen 12y agoHm, I learned it more than a year ago now (and have kept up), so it was before Steve's time :) Also, I'm coming mainly from a C background, not higher-level language.
- 12y ago
- egonschiele 12y agoCould someone lay out the advantages of Rust over C/C++/Dart/Go/other languages that cater to a similar space?
- whyever 12y agoAFAIK Rust is the only language that offers memory safety without garbage collection.
- st3fan 12y agoSwift
- dbaupp 12y agoReference counting is just another form of garbage collection, http://www.cs.virginia.edu/~cs415/reading/bacon-garbage.pdf http://www.cs.virginia.edu/~cs415/reading/bacon-garbage.pdf
- fanf2 12y agoWhat about Ada?
- whyever 12y agoI'm not sure about Ada, because I never used it, but it seems to have some lifetime checking comparable to Rust's borrow checker. However, it also seems less powerful (in Rust you can specify the lifetime explicitly if need be, in Ada it seems you would have to give up safety).
- _pmf_ 12y agoC++11's std::unique_ptr and std::shared_ptr are also nice features. Does Rust provide more guarantees?
- deleted 12y ago[deleted]
- sriku 12y agoThis is all good. No higher kinded types for v1.0?
- steveklabnik 12y agoNope. We're pretty sure they'll be backwards compatible, and there are too many other outstanding issues (eg, syntax) and too little time. Lots of us want them though!
- spott 12y agoThere isn't an RFC for them, at least that I could find. Have they just not gotten that far in terms of thought?
- steveklabnik 12y agoThat's right, there hasn't even been enough work for an RFC.
- jroesch 12y agoI think one of the core challenges is how traits play with HKTs. You can only allow for the defining of HKed type parameters and type arguments so many ways, but it becomes more complicated when dealing with the resolution of traits around HKTs. In Haskell for ex. there is no `Self` so the type class can easily be dispatched on a higher kinded type without needing a receiver type. In Rust `Self` must currently be fully applied as it is resolved from a value directly: `value.trait_method` and we pick our instance based on value's type. If we want to implement Functor (Mappable or w/e) we need to come up with another approach. I've thought about a few but they seem to play best with multi-dispatch + associated types + where clauses. I'm hoping to finish the RFC once all these features land and I can actually hack a prototype, instead of scribbling on paper.
- bjz_ 12y ago> I'm hoping to finish the RFC once all these features land and I can actually hack a prototype, instead of scribbling on paper. This would be amazing. One of the big issues blocking HKTs has been that though many folks want it there hasn't really been anyone willing to champion it yet. No pressure though - it is a tough problem.
- tomdale 12y agoWe've been using Rust in production for Skylight (https://www.skylight.io https://www.skylight.io) for many months now, and we've been very happy with it. Being one of the first to deploy a new programming language into production is scary, and keeping up with the rapid changes was painful at times, but I'm extremely impressed with the Rust team's dedication to simplifying the language. It's much easier to pick up today than it was 6 months ago. The biggest win for us is how low-resource the compiled binaries are. Skylight relies on running an agent that collects performance information from our customers' Rails apps (à la New Relic, if you're more familiar with that). Previously, we wrote the agent in Ruby, because it was interacting with Ruby code and we were familiar with the language. However, Ruby's memory and CPU performance are not great, especially in long-running processes like ours. What's awesome about Rust is that it combines low-level performance with high-level memory safety. We end up being able to do many more stack allocations, with less memory fragmentation and more predictable performance, while never having to worry about segfaults. Put succinctly, we get the memory safety of a GCed language with the performance of a low-level language like C. Given that we need to run inside other people's processes, the combination of these guarantees is extremely powerful. Because Rust is so low-level, and makes guarantees about how memory is laid out (unlike e.g. Go), we can build Rust code that interacts with Ruby using the Ruby C API. I'm excited to see Rust continue to improve. Its combination of high-level expressiveness with low-level control is unique, and for many use cases where you'd previously use C or C++, I think Rust is a compelling alternative.
- alelefant 12y agoI've never built a Rails app, so perhaps there's something simple that I'm missing (I'm mostly a C# guy), but how would I use Skylight to monitor my on-premise application? The pricing makes it seems like a hosted service. I would have expected some sort of profiler to be needed on the server and then perhaps a centralized location for the data to be pushed to for display. The design of the site is great and I'm mostly curious because it sounds like something I wish was available in the .NET world!
- tomdale 12y agoThanks for asking. If you're interested in the nitty-gritty, Yehuda and I gave a talk on the architecture behind Skylight at RailsConf: http://www.confreaks.com/videos/3394-railsconf-how-to-build-a-smart-profiler-for-rails http://www.confreaks.com/videos/3394-railsconf-how-to-build-... The short version is that the agent runs on your servers and collects information from your Rails app using the ActiveSupport::Notifications instrumentation built in to the framework. We serialize that into a protobuf that's transmitted via IPC to a background daemon (written in Rust). That daemon batches multiple reports into a single payload that is sent to the Skylight servers, where we use Storm and Cassandra to process the requests, and periodically do aggregate roll-ups. Unlike New Relic, Skylight gives you access to the entire distribution of response times, not just the average response time. (According to DHH, averages are "useless.")[1] This ends up being a lot of data, and a lot of CPU-intensive processing, which is why we sell it as a hosted service. [1]: https://signalvnoise.com/posts/1836-the-problem-with-averages https://signalvnoise.com/posts/1836-the-problem-with-average...
- austinz 12y agoCongratulations to the Rust team! Can't wait to start learning the language and building stuff using it. I'm looking to learn about how Rust's refcounting memory management works (and how it differs from how, e.g. Objective-C or Swift's runtime-based reference counting works), mostly for personal edification. Can anyone point me to any good resources?
- steveklabnik 12y agoIs worth noting that you don't reach for reference counting by default in Rust: your reach for references, then boxes, THEN Arc. You can find documentation on these types here: http://doc.rust-lang.org/guide-pointers.html http://doc.rust-lang.org/guide-pointers.html
- austinz 12y agoAwesome! Thanks.
- eddyb 12y agoWell, you wouldn't go for Arc (atomic RC) unless you need to share data across tasks (threads), within the same task you can use Rc. This is different from shared_ptr in C++ which is always atomic and LLVM has to try hard (in clang, no idea what GCC does) to eliminate some redundant ref-counts. Oh and since Rc is affine, you only ref-count when you call .clone() on it or you let it fall out of scope. Most of the time you can pass a reference to the contents, or, if you need to sometimes clone it, a reference to the Rc handle, avoiding ref-counting costs.
- steveklabnik 12y agoThat's true, thanks.
- burntsushi 12y agoSteve already told you that refcounting isn't reached for by default, and I wanted to share an anecdote to emphasize that. I've written a regex library, CSV parser, command line arg parser, elastic tabs and quickcheck in Rust. Behold: $ find ./ -type f -name '*.rs' -print0 | xargs -0 grep Rc $ I've definitely reached for it a few times as an escape hatch, but I've always ended up finding a cleaner approach to persist without it. Of course, there are plenty of legitimate uses of refcounting. I just haven't hit them yet. :-)
- MoOmer 12y ago> We are removing support for green threading from the standard library and moving it out into an external package. This allows for a closer match between the Rust model and the underlying operating system, which makes for more efficient programs. That's an interesting move in comparison to Go, which multiplexes coroutines onto threads.
- pcwalton 12y agoIt's more systems-like. We don't pay any overhead for calling into C code, and M:N scheduling doesn't really provide advantages over 1:1 scheduling when you don't have a GC (and even when you do, the differences are fairly negligible on modern Linux).
- ngrilly 12y agoWith 1:1 scheduling, how do you limit stack size to something reasonable (a few kB per thread), which is necessary when you need to launch tens of thousands of threads?
- dbaupp 12y agoIf you know you only need a small amount of stack size, you can set the stack size to be small via the task builder: http://doc.rust-lang.org/master/std/task/struct.TaskBuilder.html#method.stack_size http://doc.rust-lang.org/master/std/task/struct.TaskBuilder....
- ngrilly 12y agoThanks for the link. But what if I don't know the stack size in advance? I guess the model with a stack that starts small and grows on demand is only possible with M:N scheduling, not with 1:1 native scheduling?
- deleted 12y ago[deleted]
- forrestthewoods 12y agoWhen will it be pleasant to use on windows?
- cdnsteve 12y agoCan rust be used to power http endpoints like a REST API? Or is it more designed to be system type daemon stuff? I guess I don't fully understand the marketing of it, however I haven't ever written anything in C or C++ either.
- tmzt 12y agoThere are already a number of libraries and frameworks that implement an HTTP setver in Rust, though things seem to be coalescing around Teepee. http://chrismorgan.info/blog/introducing-teepee.html#main http://chrismorgan.info/blog/introducing-teepee.html#main There are few REST api libraries as well.
- molixiaoge 12y agogreat
- toolslive 12y agoHow difficult is it to start from a huge C++ codebase and start adding new features in Rust? How bad is such an idea? I know there is interoperability, but those are toy examples, does anybody have real life experiences?
- deleted 12y ago[deleted]
- illumen 12y agoDoes it use the GPU, memory compression, code rewriting, automatic vectorisation, multiple cores, or any other performance techniques from the last 10 years?
- dbaupp 12y agoRust is a low-level language so everything user-space can be implemented, and the main (and only) compiler rustc uses an industrial strength optimiser (LLVM) which has support for automatic vectorisation. Furthermore, the type system is designed to be very good for high-performance concurrency. See http://blog.theincredibleholk.org/blog/2012/12/05/compiling-rust-for-gpus/ http://blog.theincredibleholk.org/blog/2012/12/05/compiling-... for an example of using Rust on a GPU, and I can only imagine that it has become easier since then.
- alkonaut 12y agoHopefully the tooling will take off once the language stabilizes. Using a "newish" language is a total exercise in frustration when you are a spoiled kid who expects an IDE to come with your language configured, and a nice big play button for running your first program. For a language to take off, it badly needs a very good (ideally "official") development experience, such as a custom eclipse impl, or a very good IntelliJ plugin. When a dev experience comes with batteries included it lowers the treshold substantially from just "use whatever text editor you like and compile on command line, here is a readme".
- Chirono 12y agoWait, they've got rid of unique pointers? When did that happen? They were there a couple of months ago. That was one of my favourite language features...
- andrewaylett 12y agoMy understanding is that they're still there, just as part of the standard library rather than as a language feature.
- steveklabnik 12y agoThat's correct. What used to be ~T is now Box<T>. We say 'boxes' instead of 'unique pointers' now.
- theavocado 12y agoWhen I first looked at Rust, I recall being very confused about the distinctions between crate, package, module, and library. It seemed like an area which could use some simplification.
- steveklabnik 12y ago"Package" and "library" are two words that mean the same thing. They're more generic terms for "crate," which is Rust specific. "module"s are ways of splitting up your code inside a crate: one crate has many modules, and each module belongs to one crate.
- theavocado 12y agoThanks, Steve! Have not yet had a chance to go through the new guide, but looking forward to it!
- steveklabnik 12y agoAny time. There'll be a full guide to the module system when I get some time...