BT

Rust 1.9 Improves Error Handling and Compile Time

| by Sergio De Simone Follow 14 Followers on Jun 03, 2016. Estimated reading time: 1 minute |

A new exception handling API in the recently announced Rust 1.9 adds more control when dealing with cross-thread exception propagation. The new version also brings better compiler performance when deciding variable equality.

As mentioned, a new catch_unwind API available in std::panic allows developers to better control the stack unwinding process triggered by an exception, which is used in Rust to handle unexpected problems. Rust philosophy in such cases is “failing fast”, which means bringing the raising thread to a halt after unwinding its stack. Other threads however, are left untouched and are allowed to continue running until they try to communicate with the panicked thread, in which case they will need to do some kind of recovery. By using catch_unwind developers will be able to catch a panic and convert it into a common error within the failing thread:

let result = panic::catch_unwind(|| {
    panic!("oh no!");
});
assert!(result.is_err());

This should be most useful in two scenarios:

  • When embedding Rust in other languages. In this case unwinding is likely to produce a segmentation fault at the language boundary.
  • When, for example, creating libraries to manage threads. In this case, instead of halting the failing thread, it could be preferable to communicate the error to the client.

It is worth noting that stack unwinding is currently the only strategy for handling panic in Rust, but this is going to change in the future. Indeed, a new “abort” strategy will allow to avoid paying the cost of stack unwinding when that may be preferable.

The new Rust version also brings better compiler performance when deciding whether two variables are equal. Markus Westerlind, submitter of the PR, claims an impressive improvement in certain cases, going from a complexity of O(n!) to (O(n). As Westerlind explained on Reddit, although n is usually small, subtle differences in code may make n blow up. In such cases, as demonstrated in Westerlind’s combine library, Rust 1.9 is going to provide a big performance improvement.

Rust 1.9 also contributes to stabilizing more library functions, including networking, encoding, and pointer handling functions.

You can find more details about Rust 1.9 in the official announcement.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT