HNHacker News
TopNewBestAskShowJobs

aturon

1,554 karma · joined September 15, 2014

submissionscomments
aturon··on Rust in 2016
There's an O'Reilly book in the works: http://www.amazon.com/Programming-Rust-Jim-Blandy/dp/1491927...

And The Rust Programming Language (https://doc.rust-lang.org/book) is on its way to paper publication.

The newly minted Rustonomicon (https://doc.rust-lang.org/nightly/nomicon/) that covers deeper aspects of Rust is hopefully destined for the same.

aturon··on Rust in 2016
I definitely agree, this is a pain point in Rust today, and it's something the core team would like to address. You might glance at the thread here for some of the tradeoffs: https://internals.rust-lang.org/t/implicit-widening-polymorp...

If we can reach consensus on a design, such a feature can be easily implemented. I'd love to see an RFC on the topic (https://github.com/rust-lang/rfcs)!

aturon··on Rust in 2016
Not yet, but Nick Cameron (@nrc) has been holding talks with many IDE makers and plans to launch a "Rust IDE initiative" very soon.
aturon··on Pre-Pooping Your Pants with Rust
Rust's basic guarantee has been, and continues to be: unless code uses `unsafe`, it is guaranteeed to be memory safe. The issue under discussion doesn't change that -- it's largely about what such `unsafe` code is allowed to do and assume. I've laid this out in a bit more detail in a comment below (https://news.ycombinator.com/item?id=9447938)
aturon··on Pre-Pooping Your Pants with Rust
Please see my comment below (https://news.ycombinator.com/item?id=9447938) -- a key point is that, as always, you have to write `unsafe` to get memory unsafety in Rust, period. This is Rust's core guarantee. The issue being reported here is a safety problem caused by a particular use of `unsafe` blocks. The debate is largely about what unsafe blocks should or shouldn't be able to assume.
aturon··on Pre-Pooping Your Pants with Rust
Please see my comment below (https://news.ycombinator.com/item?id=9447938). If this were a problem for Rust's basic memory safety guarantees, we'd certainly consider delaying release. There are also ways to pursue the `Leak` approach in the future backwards-compatibly.
aturon··on Pre-Pooping Your Pants with Rust
Please see my comment below (https://news.ycombinator.com/item?id=9447938). There is no risk to Rust's basic safety guarantees here, and there are several ways forward (including introducing things like `Leak` backwards-compatibly later on).
aturon··on Pre-Pooping Your Pants with Rust
I want to clarify a couple of points:

Most important, this API problem does not break Rust's basic safety guarantee. That is, you must write unsafe code to violate memory safety.

If Rust's basic memory safety guarantee were at risk, the core team would absolutely consider delaying the release, or doing whatever else was needed to address it! We must never allow memory safety violations in safe code, no matter how obscure the bug that leads to them.

So this is a question of writing "safe" APIs that hide uses of `unsafe`. What precise assumptions are you allowed to make within such code?

As it is, we are taking this API issue very seriously, and making sure that we explore all of the options available. We have already yanked the affected APIs, while we determine the best way forward.

There are known ways to safely re-introduce the (relatively few) places in the standard library where unsafe code was using this pattern. Gankro talks about one in the post; you can see a proposal here (https://github.com/rust-lang/rfcs/pull/1084) for the `scoped` API.

The basic issue here is about a tension between a couple of different APIs, as Gankro explained in the post. In particular:

- `Rc` has been part of Rust for a long, long time, and is a fundamental systems programming tool.

- APIs like `scoped` and `drain_range` would like to use RAII for ergonomics and consistency, but this is either not possible (`scoped`) or subtle (`drain_range`) given `Rc`. In either case, these APIs use `unsafe` internally, so it's all about what that unsafe code can assume.

Furthermore, there is not a strong consensus about how best to resolve these issues, even if we had all the time in the world. Currently there are at least three camps:

- Stick with the status quo (perhaps marking `mem::forget` safe to reflect that reality). Safe code can assume no leakage, but unsafe code needs to take extra care (and sometimes avoid the RAII pattern). This is already the case for a large number of other properties, as Gankro points out. Leakage in safe code can never lead to memory unsafety; it is just a vanilla bug, and Rust doesn't prevent you from making bugs.

- Introduce something like `Leak`, meaning that you have to explicitly ask for a given type to be guaranteed not to leak through things like `Rc` cycles. While that allows you to write APIs like `scoped` and `drain_range` easily using RAII, you need to be aware of the marker, and make sure to use it for such types. Worse, though, is the interaction with trait objects: depending on the design, you may have to write `Box<MyTrait + Leak>` to be able to store the trait object behind an `Rc`, and that `Leak` bound needs to be present for the entire chain of APIs leading up to that point.

- Restrict `Rc` in some way, perhaps to `'static` data, thereby ruling out (a class of) leaks for all types. It's not completely clear how much fallout this would involve. The compiler currently relies on non-`'static` reference cells, and this change would likely force channels to use a `'static` bound as well, thereby defeating much of the purpose of the `scoped` API in the first place.

Finally, it's worth noting that at least one version of the `Leak` proposal can be added backwards-compatibly, later on, so there is potentially plenty of time to explore that approach if we feel the complexity is worth it.

I believe that Niko Matsakis (also on the core team) is planning to write a blog post explaining all of the above in much greater detail.

aturon··on Reference cycle bug in Rust's scoped threads
To be clear, the basic concept of scoped threads is fine, and this unsoundness was a result of explicitly `unsafe` code.

The specific API chosen, however, used RAII guards to "guarantee" that the parent thread joined on the child thread within a certain scope. Unfortunately, it's possible to subvert the RAII guard by placing it within a ref-counted cycle, which results in its destructor never being run.

For the moment, the API is being moved back to "unstable" status.

We are considering a variety of ways to address the problem, including:

* Avoiding RAII guards in the API, instead using explicit closures to guarantee that the threads join.

* Introducing a way of marking types as "unsafe to leak", thereby allowing us to continue using the RAII-style API, but preventing use of the guard within reference counted pointers (which can leak).

aturon··on Fearless concurrency with Rust
What's going on here is a bit of shorthand. If you don't use the shorthand, the signature looks like:

    fn access<'a, T: Send>(guard: &'a mut MutexGuard<T>) -> &'a mut T;
This says that the incoming borrow and the returned borrows have identical scopes (officially called "lifetimes" in Rust; 'a here is a lifetime variable.) It's a very typical pattern: if you return some borrowed data, it generally comes from a borrow you were given, and the shorthand allows you to leave this implicit in cases where it's clear.

EDIT FOR CLARITY: in particular, you're saying that if you take a "sublease" from something you've already borrowed, that sublease is valid for no longer than the original lease. So for example if you borrow a field out of a borrowed structure, the access to the field can last no longer than you had access to the original structure. In this case, we're saying that access to the data lasts no longer than the lock is held.

I'd recommend http://blog.skylight.io/rust-means-never-having-to-close-a-s... if you want to get a bit more of a feel for how this works.

The details about the shorthand are here: https://github.com/rust-lang/rfcs/pull/141

aturon··on Fearless concurrency with Rust
The key is that the MutexGuard is responsible for unlocking (and it does so automatically on destruction). That way, you're tying the scope for the &mut reference to the scope in which the lock is actually held.
aturon··on Rust 1.0: Status report and final timeline
That's not quite right. In the non-move case, the capture is inferred per upvar. See my other comment for details (https://news.ycombinator.com/item?id=9047766)
aturon··on Rust 1.0: Status report and final timeline
> The way variables are captured from the environment into the closure is controlled by the "move" keyword. If the "move" keyword precedes a closure expression, then variables from the environment are moved into the closure, which takes ownership of them.

Note: if you don't specify `move`, then the captures are determined in the usual way:

`|| v.len()` captures `v` via an immutable borrow

`|| v.push(0)` captures `v` via a mutable borrow

`|| v.into_iter()` captures `v` by moving it

aturon··on Rust 1.0: Status report and final timeline
> That said, I'm not sure what the exact reason was for choosing the syntax, as that was before my time.

I think the reason is just that it's very concise, and lightweight closure syntax makes things like `Option::map` feel like first-class parts of the language. The closure you pass just sort of seamlessly "blends in".

Note that having especially sugary here is not so uncommon, for example Haskell has `\x -> blah` for Rust's `|x| blah`.

I'm personally very happy that the closure syntax is as concise as it is.

aturon··on Rust 1.0: Status report and final timeline
There's a core team (https://github.com/rust-lang/rust/wiki/Note-core-team) responsible for final decisions on the direction of the language and libraries. Proposed changes go through a public RFC process (https://github.com/rust-lang/rfcs#what-the-process-is), including those proposed by members of the core team -- which are frequently revised or even rejected as part of this process. See for example the path API RFC (https://github.com/rust-lang/rfcs/pull/474).

PRs can be reviewed by anyone from a large pool of reviewers. PRs that introduce new features etc. have to come after an RFC is approved, however.

The core team includes Huon Wilson, Yehuda Katz, and Steve Klabnik, none of whom work for Mozilla (though the latter two have done some contracting work). We hope to continue expanding to include other stakeholders.

EDIT: Steve tells me he's currently working as a "seasonal employee" at Mozilla for doing Rust docs, but it's a short term thing.

aturon··on Rust 1.0: Status report and final timeline
There has been a lot of work on `std`, but it's largely been consistency, cleanup and cutting APIs down -- though the recent path and IO reforms are more substantial, which is why we decided to put out another alpha before finalizing them.
aturon··on Graydon Hoare on Rust 1.0.0-alpha
The renaming to "old_io" is purely to make updating code clearer easier -- it does not indicate a massive redesign.

The final API will actually be quite similar to the existing std::io in most respects. It fixes a few longstanding complaints, reorganizes the modules into a flatter hierarchy, and renames to match conventions elsewhere. These are tweaks and polish, not a complete rethink.

Where there are deeper changes (e.g. introducing OsString), we are codifying trends that are already in place (e.g. the env_as_bytes function).

In general, the changes to IO also all make the design more conservative, following traditional APIs more closely, exposing fewer high-level abstractions, and removing questionable APIs.

For most applications, updating will just be a matter of updating names and imports.

aturon··on Announcing Rust 1.0 Alpha
This is a very old post, but you can encode many uses of typestate pretty easily: http://pcwalton.github.io/blog/2012/12/26/typestate-is-dead/

It'd be great for someone to write a more up-to-date version of this post!

aturon··on Rust 1.0: Scheduling the trains
I completely agree that a strong standard library is essential, and we've been working very hard over the last months to set explicit conventions, revamp APIs, and generally get Rust's standard library into a 1.0 state.

You shouldn't read much into the "experimental" tags right now; they're part of an API stability tracking system that is heavily in flux at the moment. In particular, for most of the modules you mentioned, only the module name itself has not been marked "stable", while the contents have been. For example, if you look at the Vec type itself:

http://static.rust-lang.org/doc/master/std/vec/struct.Vec.ht...

you'll see that most methods are unstable or stable, rather than experimental. (The "experimental" status is currently the default, to help us keep track of API "stabilization" progress.)

This stability tracking is part of our general story about API compatibility; you can read more at

http://blog.rust-lang.org/2014/10/30/Stability.html

These markers won't take on their full meaning until we ship 1.0.

For 1.0, all of the APIs you mentioned will be "stable", and indeed most of their internals already are. Over the next few weeks, we'll be updating stability markers to reflect the API scrutiny and design work that we've been doing.

More generally, for all but a couple of the modules listed at

http://static.rust-lang.org/doc/master/std/index.html?search...

we have already performed a detailed scrutiny of the API, and have either landed changes needed for 1.0 or will do so very soon. Most truly experimental APIs have already been deprecated or removed.

For IO in particular, you can read a very recent RFC that proposes the final set of API changes for 1.0:

https://github.com/rust-lang/rfcs/pull/517

Hope that helps!

aturon··on Rust 1.0: Scheduling the trains
> By far the biggest demand for HKT is from people who are requesting Haskell-like do-notation for error handling.

That hasn't been my experience -- we are constantly running into cases in the libraries where we need HKT to express signatures in traits. The simplest example is talking about iterator return types, which often need to depend on a lifetime. See the collections reform RFC (https://github.com/aturon/rfcs/blob/collections-conventions/...) for details on that example. There are many, many others.

I suspect that HKT's role in Rust will be much more about extending the trait system for generic programming, rather than full-blown monadic programming.

aturon··on Rust 1.0: Scheduling the trains
We do plan to add some version of this RFC, but made a careful decision about not including it for 1.0. It will not completely change the error-handling design, but rather empower it with additional, finer-grained control.

It's possible that we will add at least the `?` notation to replace `try!` before 1.0 final; it remains to be seen.

aturon··on Rust 1.0: Scheduling the trains
The team has actually been pretty careful to design in a HKT-compatible way. While there isn't a fully-fleshed out design yet for Rust, there are designs in other languages, and we've looked at their pitfalls to make sure we can avoid them.

For example, see https://github.com/rust-lang/rfcs/pull/213#issuecomment-6575...

← PreviousPage 2 of 2