News for hackers. Stuff that matters.
Re:Rust means never having to close a socket by shadowmint on Tuesday October 07, 2014 @09:00PM (#8424829)
> If you use `nokogiri` in Ruby and get a segfault, that is a bug in nokogiri. It is not an indication that Ruby is unsafe.

Rust has a strict definition of safety; not all rust code for fills that guarantee.

We're not talking fast and loose here. These are absolute definitions.

You can write safe code that crashes in rust. That absolutely violates the safety guarantee whatever the reason for it.

> This is in the process of being eliminated

No it's not.

    Keep dynamic drop semantics, by having each function maintain a (potentially empty) 
    set of auto-injected boolean flags for the drop obligations for the function that need 
    to be tracked dynamically (which we will call "dynamic drop obligations").
What's happening is some of the run time overhead is being reduced.
Re:Rust means never having to close a socket by dbaupp on Tuesday October 07, 2014 @10:35PM (#8425052)
> No it's not.

> What's happening is some of the run time overhead is being reduced.

I believe wycats was responding specifically to

> Rust uses 'drop flags', which are extra bytes at the end of struct instances in memroy, to track objects and keep meta information about them to determine if they should be dropped.

And these are being eliminated. That is the drop flag will be entirely separate to the struct instance, and will only be injected into stack frames where there is a conditional branch in which a value is moved out in one, but not the other, e.g.

  let x = some_value;
  if condition { drop(x); } else { /* do nothing */ }
then `x` will get a drop flag as a single bit (or byte) on the stack. If the code is changed to

  if condition { drop(x); } else { drop(x) }
there will be no drop flag, and no overhead.

Furthermore, placing the value on to the heap, e.g. `box some_value`, will not have an associated drop flag for `some_value`, that is, eliminating the byte that is currently stored with it.

Re:Rust means never having to close a socket by shadowmint on Tuesday October 07, 2014 @11:19PM (#8425177)
Whatever, there are still drop flags (on the stack instead, sure), and still dynamic runtime checks for drops.

The points I was making is that 'zero cost' memory management isn't 100% zero cost. The drop checker does incur some basic dynamic runtime costs.

To be 'zero cost' drop behaviour would be determined at compile time.

Re:Rust means never having to close a socket by dbaupp on Tuesday October 07, 2014 @11:28PM (#8425196)
The behaviour is determined at compile time, with runtime cost only introduced if it is absolutely needed (when one branch drops, and another doesn't), and, even then, it can be avoided, by manually forcing a drop of the value in every branch.
Re:Rust means never having to close a socket by wycats on Tuesday October 07, 2014 @09:30PM (#8424908)
> You can write safe code that crashes in rust. That absolutely violates the safety guarantee whatever the reason for it.

You can write Ruby code that calls into unsafe C code and SEGVs. This is a bug in the C code you called. It should have exposed a safe interface.

You can write Rust code that calls into clearly delineated unsafe code and SEGVs. This is a bug in the unsafe code you called. It should have exposed a safe interface.

Anything to the contrary is a misunderstanding of the purpose and role of unsafe code in Rust, and endangers the entire ecosystem, just as it would endanger the Ruby ecosystem if it were seen as normal for C extensions to SEGV the safe Ruby process.

Re:Rust means never having to close a socket by shadowmint on Tuesday October 07, 2014 @10:32PM (#8425043)
I'm not arguing any of these points.

I'm just saying there are these two misconceptions:

    - if you write safe rust code, your code can't segfault
This isn't true if your code path contains any unsafe code.

    - Rust code can't segfault
This isn't true at all.

Sure, if it does segfault its a bug in the c code / unsafe code.

You're absolutely correct.

...but bugs aren't deliberate. Obviously no one is going to deliberately expose a c api that has segfaults in it.

The misconception is that if you're using rust you're safe from the bugs that other programmers may have made... which is not true.

There's a trust chain involved; if you depend on a library you trust it's bug free and won't delete your harddisk and crash your program, but there's a difference between trusting a library is not malicious, and trusting a library is bug free.

If you have to trust the library is bug free, you're really no better off than using C++ are you?

...but people keep saying that if you use rust then there are certain types of safety that are guaranteed by the language: http://doc.rust-lang.org/reference.html#behavior-considered-..., regardless of programmer bugs.

It's just not true.

Once again, I'm not arguing that safety is good or bad or whatever. My assertion is very very specific:

Rust code written 100% safely can crash if it has a dependency that uses unsafe code.

The assertion that 100% safely written rust code with arbitrary dependencies can't crash is false.

Re:Rust means never having to close a socket by kibwen on Tuesday October 07, 2014 @10:49PM (#8425095)

  > If you have to trust the library is bug free, you're 
  > really no better off than using C++ are you?
This is a pretty far-out argument. For any programming language and environment, unless every dependency of your program including the compiler and runtime can be proven correct via formal verification, you will be susceptible to bugs. That doesn't imply that all code in the world is topologically as unsafe as C++. I can segfault Python if I try hard enough, and that's a bug in Python. Likewise I can segfault safe Rust code if I try hard enough, and that's a bug in Rust. I don't believe that anyone is really of the misconception that the mere use of Rust absolves you from the bugs of others, because that same person would have to believe that Rust somehow makes all bugs impossible, including bugs in C code that Rust calls into.

So let me give everyone a source to cite on Wikipedia:

"Rust does not keep C code from segfaulting." ~ kibwen

Re:Rust means never having to close a socket by dbaupp on Tuesday October 07, 2014 @10:40PM (#8425070)
> The misconception is that if you're using rust you're safe from the bugs that other programmers may have made... which is not true.

Of course it's not true, but the libraries you're using will (hopefully, for the most part) be written in Rust, which increases the level of trust.

> There's a trust chain involved; if you depend on a library you trust it's bug free and won't delete your harddisk and crash your program, but there's a difference between trusting a library is not malicious, and trusting a library is bug free.

> If you have to trust the library is bug free, you're really no better off than using C++ are you?

The libraries are written in Rust, so have all the benefits of that. It is nonsense to say that "libraries can have bugs so you might as well use C++".

Re:Rust means never having to close a socket by shadowmint on Tuesday October 07, 2014 @11:02PM (#8425131)
> It is nonsense to say that "libraries can have bugs so you might as well use C++".

My argument is that if you assert 'rust is 100% safe' then you must assert, all your dependencies are bug free.

If you can somehow magically assert 'all my code is bug free', that would be great... but if so, you wouldn't need the borrow checker at all would you?

(I'm certainly not endorsing using C++ :P I'm specifically talking to the assertion that rust code can be safe, as per the definition of safety in the guide, that certain operations are impossible; certainly, and absolutely, rust code is safer and more trust worthy (imo) than c/c++ code... but you've got to be reasonable about what you're arguing. 'rust is magical and can never crash' turns up in blog posts a lot)

Re:Rust means never having to close a socket by kibwen on Tuesday October 07, 2014 @11:21PM (#8425181)

  > 'rust is magical and can never crash' turns up in blog 
  > posts a lot
The next time that you see someone doing this, please correct them. Misinformation does none of us any favors.
Re:Rust means never having to close a socket by kbenson on Wednesday October 08, 2014 @12:19PM (#8427733)
I believe that's what started this entire thread.

...there are two things in this article which are, I'd say, 'common misconceptions' about rust.

Re:Rust means never having to close a socket by akavel on Wednesday October 08, 2014 @05:34AM (#8426055)
I don't understand -1s to the parent post; it's important to remember and be aware of limitations and dangerous areas in a language (or any other tool). And shadowmint tries to describe them in very civilized and calmly assertive way. I find his posts, as well as the counterarguments (like those from pcwalton and wycats), massively educative and informative. I absolutely can't understand why someone would like to see them fade out and disappear. I see the thread as exactly a kind of educated, professional argument that is so valuable on HN. And in such, being partially wrong or incorrect in some aspect is not something "bad" and "requiring censorship", but rather opportunity for straightening by others with a side effect of educating the larger community, isn't it?
Re:Rust means never having to close a socket by anonbanker on Wednesday October 08, 2014 @02:06PM (#8428405)
Upvoted grandparent based on this post.
Re:Rust means never having to close a socket by nwmcsween on Tuesday October 07, 2014 @10:06PM (#8424978)
'Unsafe' is a bad term, effect is much better and it is most definitely a rust issue. If the language doesn't have a way of dealing with effects it won't be able to handle them. Rust is honestly a more safe c++ and in my opinion not an alternative for c.
Re:Rust means never having to close a socket by wycats on Tuesday October 07, 2014 @10:16PM (#8424991)
I don't know what this means. I stand by my upstream comment.
Re:Rust means never having to close a socket by TheHydroImpulse on Wednesday October 08, 2014 @12:42PM (#8427860)
Algebraic effects system.