Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Flashing Twelve
Mar 20, 2007

Jsor posted:

It turns out the answer was "use Rc<RefCell<blah>>". That was a fun, if somewhat frustrating, adventure. I eventually went back to the recursive code because it turns out the iterative code had almost no benefit -- the stack overflows at pretty much the same point whether I'm using a homebrewed stack or a recursive one, which I definitely didn't expect!

Yeah, the shittiest part of learning Rust is hammering nails into your dick trying to write data structure stuff. It's trivial in other languages, but writing them in (safe) Rust requires a decent understanding of its complex memory model, so it's a pretty bad place to start off. Rc and RefCell are usually enough to cover the gaps the borrow checker can't handle if you're cool with the overhead associated with them. If you're not, or you have a situation that's difficult to solve in safe Rust (doubly-linked list is one), don't be afraid to drop to unsafe{} . The standard library (which is written in Rust) uses it extensively.

Adbot
ADBOT LOVES YOU

Flashing Twelve
Mar 20, 2007

Jsor posted:

Rust's runtime debugging really needs some work, though. If you have an erroneous `unwrap` you helpfully get the line number of the source code for Option it calls panic! on rather than the actual part of your code. This would be fine if RUST_BACKTRACE wasn't utterly useless on non-Linux systems, on my Windows machine it helpfully prints:

code:
thread '<main>' panicked at 'panic', main.rs:2
stack backtrace:
   0:           0x43bc4b - <unknown>
   1:           0x443eae - <unknown>
   2:           0x40555c - <unknown>
   3:           0x401592 - <unknown>
   4:           0x40151f - <unknown>
   5:           0x443948 - <unknown>
   6:           0x42ea11 - <unknown>
   7:           0x44384d - <unknown>
   8:           0x4016ea - <unknown>
   9:           0x4013b4 - <unknown>
  10:           0x4014e7 - <unknown>
  11:     0x7ffa905a2d91 - <unknown>
This is just a "hello, panic!" program, basically. Panics first thing in main.

Gee, thanks, Rust, I learned so much. It's a good thing 98% of your Rust bugs the compiler catches, and 1.5% are logic errors that result in incorrect computations. Runtime panics happen so rarely this is at least tolerable. I can mostly get around it by always using expect instead of unwrap and making sure each possible panic has a unique error message.

Yeah Windows debugger stack traces were working fine a little while back but ever since I upgraded to 1.4 beta and on it's been broken. Bit of a pain, unwrap isn't ideal and all but it's great for testing/prototyping. Tooling is definitely something Rust is lacking in at the moment.

One of the Mozilla Rust guys lists his predictions for Rust in 2016. Better tooling is high up on that. Personally Visual Rust fully fleshed out would be a breaking point for me, decent IDE support and VS's debugger would be a multiplier on my productivity for sure.

Flashing Twelve
Mar 20, 2007


After a bit of looking around, there's a pretty simple workaround to this. Run it in gdb, enter 'break rust_panic', and when it hits the breakpoint 'bt' for a stacktrace. Apparently rust_panic is specifically there so you can place breakpoints on panics, which is pretty neat.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply