Live data from Hacker News

Announcing Rust 1.20

blog.rust-lang.org

151–160 of 277 posts

Re: Announcing Rust 1.20

#151

Earlier quoted context omitted.

You often don't need it at all; fn foo(x: f32) { println!("{}", x); } fn main() { let x = 5.0; foo(x); } It will look at the signature for foo, and infer that x must be f32.

Whoa! Isn't this kind of inference dangerous? It seems that whichever call comes first is used to infer the type, so a single added line of code can change the type of a variable… fn foo32(x: f32) { println!("{}", x); } fn foo64(x: f64) { println!("{}", x); } fn bar64() { let x = 5.0; // f64 foo64(x); foo32(x); } fn bar32() { let x = 5.0; // f32, not f64 foo32(x); foo64(x); }

Rust doesn't have coercions like C, so both of those fail to compile because using x: f64 with foo32 is an error for the first one and similarly x: f32 with foo64 for the second.

Re: Announcing Rust 1.20

#152

Earlier quoted context omitted.

I don't know the precise history, but at one point, it did have a "gc" type, which I believe was demarcated by the `@` sigil. So, for example, `@T` was a garbage collected pointer to `T`. IIRC, the actual garbage collector was simplistic, and was mostly just reference counting under the hood. At some point (in 2014, I think), the GC type went away. Since then, there has never been any serious talk of adding an option…

This is pretty accurate; however, a very long time ago there was a tracing GC!

Are you sure? I thought @ was reference counted in 0.6 and then removed after. Was it before that?

Re: Announcing Rust 1.20

#153

Earlier quoted context omitted.

I'd take a similar approach. After all `unsafe` use cases include the implementation of data structures.

I've argued this issue before. The answer isn't generics, Coq, or some fancy type system nobody will understand or use properly. There are only a few inherent trouble spots in pure Rust code safety. The big two are: - Partially initialized arrays. "Vec" has to be unsafe because growing an array involves uninitialized slots. You just need a way to say "this array is initialized from 0..N only", where N is in a data st…

A hashmap being implemented on top of vectors is a pretty common implementation. Not sure what Rust uses though.

Re: Announcing Rust 1.20

#154

Earlier quoted context omitted.

I'd take a similar approach. After all `unsafe` use cases include the implementation of data structures.

I've argued this issue before. The answer isn't generics, Coq, or some fancy type system nobody will understand or use properly. There are only a few inherent trouble spots in pure Rust code safety. The big two are: - Partially initialized arrays. "Vec" has to be unsafe because growing an array involves uninitialized slots. You just need a way to say "this array is initialized from 0..N only", where N is in a data st…

Good Map implemented on top of Vec: https://github.com/bluss/ordermap

Re: Announcing Rust 1.20

#155
post #153

Earlier quoted context omitted.

I've argued this issue before. The answer isn't generics, Coq, or some fancy type system nobody will understand or use properly. There are only a few inherent trouble spots in pure Rust code safety. The big two are: - Partially initialized arrays. "Vec" has to be unsafe because growing an array involves uninitialized slots. You just need a way to say "this array is initialized from 0..N only", where N is in a data st…

A hashmap being implemented on top of vectors is a pretty common implementation. Not sure what Rust uses though.

Problem is avoiding having to do Vec>

Re: Announcing Rust 1.20

#156
post #152

Earlier quoted context omitted.

This is pretty accurate; however, a very long time ago there was a tracing GC!

Are you sure? I thought @ was reference counted in 0.6 and then removed after. Was it before that?

I don't have any citation beyond "Graydon told me one time". It was like, very very long ago, possibly before @T even existed.

Re: Announcing Rust 1.20

#157

Earlier quoted context omitted.

You often don't need it at all; fn foo(x: f32) { println!("{}", x); } fn main() { let x = 5.0; foo(x); } It will look at the signature for foo, and infer that x must be f32.

Whoa! Isn't this kind of inference dangerous? It seems that whichever call comes first is used to infer the type, so a single added line of code can change the type of a variable… fn foo32(x: f32) { println!("{}", x); } fn foo64(x: f64) { println!("{}", x); } fn bar64() { let x = 5.0; // f64 foo64(x); foo32(x); } fn bar32() { let x = 5.0; // f32, not f64 foo32(x); foo64(x); }

That code doesn't compile. :) If you're ever curious about something like this, feel free to use the online playground, like so: https://play.rust-lang.org/?gist=c3c93fb796d5fa79f829baa3dec...

Here's the compiler error that you'd get:

    error[E0308]: mismatched types
     --> src/main.rs:7:13
      |
    7 |       foo32(x);
      |             ^ expected f32, found f64
    
    error[E0308]: mismatched types
      --> src/main.rs:13:13
       |
    13 |       foo64(x);
       |             ^ expected f64, found f32

Re: Announcing Rust 1.20

#158
post #129
post #3

Interestingly, because Firefox chooses to use stable Rust exclusively, this is the version of Rust that will be used to deliver Quantum when Firefox 57 releases on November 14 (by which time Rust 1.21 will be out (releasing October 12), but Firefox 57 will be in beta by September 20).

Are there any blogs about how Rust is integrated into Firefox (a mostly C++ program) - i.e. how the Rust runtime is invoked, garbage collection etc?

It's not a blog, but Rust Belt Rust 2017 [1] (a conference I help organize) will have a talk "The Story of Stylo: Replacing Firefox's CSS engine with Rust" [2]. The conference is in Columbus, Ohio, and is reasonably priced.

[1]: http://rust-belt-rust.com/ [2]: http://rust-belt-rust.com/sessions.html

Re: Announcing Rust 1.20

#159

Earlier quoted context omitted.

I used to be a huge fan of C++. I loved how you could work with a somewhat OO language while still wielding dark powers like: manual memory management, mix-n-match polymorphism (aka. virtual inheritance ), templates, type-erasing. Then I got a full time job working with a large C++ codebase. Since then I've been dealing with: - uninitialized variables / members - NULL checks - buffer overflows, especially with C-stri…

That's my main beef with C++. You read a book and it's beautiful - no uninitialized memory, safety, no C arrays/strings, RAII everywhere, it's clean, fast.....then you get to the "real world" and realize that 99% of C++ programmers are pretty f###ing horrible at their job and should've just stuck to naked C because at least then you'd be able to pin-point the bugs easier. So C++ is a wonderful language - in a world t…

But isn't that the case with basically ANY programming language? Once its use becomes widespread, escaping the confines of the highly skilled early adapters, you can be sure a whole lot of dodgy code will be written in it.

Re: Announcing Rust 1.20

#160

Earlier quoted context omitted.

I'd take a similar approach. After all `unsafe` use cases include the implementation of data structures.

I've argued this issue before. The answer isn't generics, Coq, or some fancy type system nobody will understand or use properly. There are only a few inherent trouble spots in pure Rust code safety. The big two are: - Partially initialized arrays. "Vec" has to be unsafe because growing an array involves uninitialized slots. You just need a way to say "this array is initialized from 0..N only", where N is in a data st…

> The answer isn't generics, Coq, or some fancy type system nobody will understand or use properly.

The solution is a formal semantics for unsafe Rust, so that programmers can prove that their unsafe Rust code is safe to use by whatever means they prefer. (Mine would be by hand.)

---

Reply to dmix:

A formal semantics doesn't have to be particularly fancy, although in Rust's case, it will in most likelihood not be straightforward either.

Post reply on HN