8 ms·
Rust 1.32 released
- timClicks 8y agoAlthough I'm somewhat embarrassed to admit, I bet that dbg! is going to be extremely helpful in my Rust programming. Really appreciate that the team is taking time to consider "trivial" usability/ergonomics additions to the language.
- ainar-g 8y agodbg! looks neat. It made me wonder if any of the statically typed compiled languages have an equivalent of Ruby's binding.pry or JS's debugger call? That is, something like x = foo(); invoke_debugger(); // An interactive console appears here. y = bar(x)
- xtian 8y agogdb or lldb provide debugger functionality for native code, but you don’t set breakpoints programmatically.
- roblabla 8y agoYou can, actually. At least in x86 asm, you just have to add an int3 instruction to get a breakpoint (requires OS support of course).
- steveklabnik 8y agoIn theory you could inline assembly "int 3" or the like, but I'm not really aware of anyone doing things like this directly.
- simias 8y agoWell for "regular" code if you want a breakpoint it makes more sense to use the debugger anyway. If you generate machine code however (for a JIT for instance) it's definitely a useful trick since adding debugger support for generated code, while possible, is often pretty tricky and non-portable.
- klibertp 8y agoThe "statically typed" part is not a big issue (there are many statically-typed languages with REPLs, after all), but "compiled" could be. For example, while you can stick a read-eval-print-loop anywhere in your code when using Racket, you can't see any non-top-level bindings there, because they may or may not be there during runtime. The compiler is free to inline or fold or remove any such binding at will (as long as the behavior of the program remains the same). There's a debugger for Racket, and it's also possible to use it programmatically, but you cannot just call it like `debugger;` in JavaScript: you need to recompile a module so that it uses (a lot of) heavy instrumentation and only then you can set a breakpoint, also from the inside. I'd expect something like this: https://github.com/krixano/Lydrige https://github.com/krixano/Lydrige to have it easy in this regard - it's a statically-typed but interpreted language.
- jcranmer 8y agoOn x86 systems, a breakpoint is implemented by replacing the byte with the "int3" instruction. For Unix systems, this is the SIGTRAP signal. So invoke_debugger() that boils down to asm("int3") would suffice, if you were already on a debugger. Well, the trouble is knowing if you need to spawn a debugger. On Windows, there's a nice API for checking if you're being debugged (IsDebuggerPresent). On Linux, you have to read /proc/self/status to see if there is somebody running ptrace on you. On other Unixes, well, the only trick is trying to spawn another process to ptrace you and hope it works. It is possible, just tricky.
- lzybkr 8y agoVisual C++ has the __debugbreak() intrinsic function. If you have JIT debug enabled, you will be prompted to attach your debugger to the process when hitting such a breakpoint.
- SCHiM 8y agoI use this sometimes with some C/C++ code. Mostly, if I want a break somewhere I do this: *(int*)0 = 1; Which will result in a crash, I attach my debugger, run the code and if it reaches that line it will break and I can inspect everything I want. It's easier than adding a __asm(int3) because it's cross platform. On windows for example it's not possible to perform inline assembly in x64 builds, and compiler intrinsics are not portable.
- xxpor 8y agoOne thing I noticed: ne means native endianness. It's probably because I'm used to C, but I'd have preferred he for host endianness and ne for network order endianness.
- tropo 8y agoThe naming is far worse than that. For example, from_ne_bytes seems to imply that bytes could have an endianness. That would require bitwise addressing.
- xyzzyz 8y agoA byte cannot have endiannes, but bytes can, and that's how I think one should read that name.
- abainbridge 8y agoWellll, the DSP I used to work on had 24-bit bytes. When we saved a data structure onto the SD card (that had 8-bit bytes) we had to decide what endianness to write the byte in. :-)
- kevindqc 8y agoI don't understand? Isn't that to convert from an array of bytes to a native type? So those bytes need to be in a specific order (in this case, native endianness)? Do you mean someone could get confused because they think 1 byte has endianness? Well then maybe they shouldn't touch these functions since they don't understand what is endianness. It's weird that they have these methods on a u8 though. Probably just comes automatically because it's an integer type so they prefer to have a consistent API? It seems to come from a macro used to define those primitive int types: https://doc.rust-lang.org/stable/src/core/num/mod.rs.html#3862 https://doc.rust-lang.org/stable/src/core/num/mod.rs.html#38...
- tropo 8y agoAccording to the naming, yes indeed 1 byte has endianness. I know that isn't the intention. It isn't unheard of for 1 byte to have endianness. To be specific, we can call it "bit endianness". It matters when serializing bits to go over a wire, such as when bit-banging I2C or SPI. An array doesn't normally have endianness either. I guess you could have a programming language that does the indexing backwards, with 0 at the end of the array. I've never heard of such a thing existing. Compare this with a endianness functions typically used in C. We get ntohl for example. The size is specified by the "l", the argument is of type "long", and the return value is of type "long". No bytes are involved in that interface. Compare with what the Linux kernel uses. Again, no bytes are anywhere to be seen. Functions like cpu_to_le32 take and return 32-bit values. It looks like Rust is doing things Python-style, which is a scary thought. Instead of providing distinct ways to change endianness and to interpret data as integers, the functionality is crammed into one interface.
- nixpulvis 8y agoLOL, my dyslexia confused me pretty bad with `dbg!` I was expecting this to hook into GDB somehow, and got really excited. It's still very neat, I'll be using it a lot I'm sure. Reminds me of https://github.com/reem/rust-inspect https://github.com/reem/rust-inspect a little bit. I'm also quite happy with the uniform path work that's landed. Rust now has easily one of the best namespace management's I've used in a programming language. Cheers!
- alexandernst 8y agoWhy every release of Rust appears on HN? (meanwhile Python, Node, Ruby, Perl, PHP, etc... don't enjoy that same treatment)
- kbenson 8y agoOften the others (at least some of them) do get posted too. It's just a matter of what gets traction.
- steveklabnik 8y agoOther languages' releases do get submitted. I just checked Ruby, Python, and Node, and all their last releases were submitted and got some upvotes, but not a ton of discussion.
- kenhwang 8y agoThe Christmas release cycle of Ruby probably doesn't help either ;)
- blattimwind 8y agohttps://news.ycombinator.com/item?id=18753132 https://news.ycombinator.com/item?id=18753132 https://news.ycombinator.com/item?id=18264462 https://news.ycombinator.com/item?id=18264462 https://news.ycombinator.com/item?id=16370792 https://news.ycombinator.com/item?id=16370792 https://news.ycombinator.com/item?id=17412695 https://news.ycombinator.com/item?id=17412695 https://news.ycombinator.com/item?id=15269723 https://news.ycombinator.com/item?id=15269723 ...
- empath75 8y agoRust is just doing more that's interesting for folks here to talk about.
- kzrdude 8y agoI think a lot of Rust people are on HN
- 8y ago
- kbenson 8y agoWow, it's been a while since I caught one of these announcements, and I have to say those those additions looks pretty awesome. I myself am a print debugger, and the dbg macro looks like a major quality of life improvement in that regard. The default removal of jemalloc should greatly cut down on binary size as well, if I understand correctly. I've dabbled in Rust, but haven't had a major reason to use it for anything yet. I'm looking forward to when that time comes.
- adwhit 8y ago> I myself am a print debugger In Rust, everyone is a print debugger. The only thing that really goes wrong in normal code (once it compiles) is "why is this value not what I expect?". Dropping down into GDB is way overkill.
- CryZe 8y agoNot when you have a proper IDE setup where building + running it in debugging session are all done with a single action. I've done print debugging for a long time, and here and there it still makes sense, but I've found that it's honestly worth putting in the effort once per (decently sized) project to just set up the IDE properly. And honestly once you have done it once, it's mostly just copy pasting the same config from project to project.
- sgrove 8y agoJust wanted to say that your rust projects are a blast to watch from afar on twitter. You've done seemingly really crazy things with Rust + Zelda Wind Waker. Thank you for sharing your hacks!
- colemickens 8y agoI so deeply hate that there is so much good content on Twitter that is simply lost if I don't happen to login on the given day. God forbid I'm not on the platform at all. It's so weird how RSS + Blog is a better experience for everyone, except advertisers. Anyway, I'm super curious what someone is doing with Rust and Zelda. How do I learn more without Twitter? Looks like this might be it? and then maybe I'm just missing out on images and videos that are only in some ephemeral tweet? https://github.com/CryZe/WindWakerBetaQuest https://github.com/CryZe/WindWakerBetaQuest
- roadbeats 8y agoI’m waiting for async/await... that will start the party!
- steveklabnik 8y agoYou and many others... the lang team has been hard at work. We want it to ship, but we also want to get it right. It will be a huge deal, for sure.
- parley 8y agoI'm waiting eagerly too, thanks for all the hard work you do! I read somewhere in all the discussions that Carl was hesitant to go all-in on futures 0.3 (those are definitely landing in std, right?) in tokio before some additional ergonomics had landed, possibly some language feature among them but I may misremember... Do you know the list of things and possibly their tracking issues? Futures in std, async/await, etc, something something more? Would love to be able to keep track and follow along :)
- steveklabnik 8y agoNo problem, though I don't work on this aspect at all, to be clear :) > (those are definitely landing in std, right?) Yes. > Do you know the list of things and possibly their tracking issues? https://areweasyncyet.rs/ https://areweasyncyet.rs/ :D
- parley 8y agoHa, that was a superb answer, thanks! :D I'll be checking that site! I know you may not have your fingers in this particular flower pot, so the "you" was directed at the entire Rust community. However, while we're here you still get a big personal thanks -- your Rust for Rubyists got me hooked those years back and the docs/book (1st ed and then 2nd ed with Carol) work you've done since is nothing short of amazing -- and with these latest developments I hope you find a great place to continue your work <3
- 8y ago
- deleted 8y ago[deleted]
- est31 8y agoJust recently I was looking at example code of an edition 2018 crate and what I feared actually happened: I didn't know any more which crates this example code used, because extern crate statements were missing. So yaay more manual figuring out I guess...
- steveklabnik 8y agoThe only example crate used is `jemallocator`, which still has an entry in Cargo.toml, and still has `jemallocator` in the source code.
- est31 8y agoOh sorry, this isn't about the blog post but about the experience I had so far with the 2018 edition. The blog post is great. Glad to see dbg!, ? in macros, and be/le/etc. stable. Also looking forward to 1.33 which will stabilize duration_from_milis.
- steveklabnik 8y agoAh, it's all good, no worries :)
- mrath 8y agoBut you can see it from Cargo.toml, isn't it? I found extern crate statements unnecessary verbosity. I am happy it is now optional.
- the_duke 8y agoI never understood this argument: you just have to look in Cargo.toml. Yes, for multi-target (eg lib + bin, ..) it can be a little more work to look it up. But the new system is SO much more convenient to use overall.
- est31 8y agoFor lib.rs in libraries or main.rs in binary only crates this works great. But if you have multiple examples, then each example can use any dev-dependency it wants and any of the normal dependencies. It's super hard to figure out which crates are needed to add to make an example compile locally. To give a concrete example, please look at this [1] Cargo.toml and this [2] example and try to figure out the crates its using. I've highlighted them in Cargo.toml, to show how irregular the use is [3]. We don't have test-only or binary only dependencies yet. They would make this a bit easier. I want to focus on the code I'm writing, not onto figuring out which crates I need to include. On the bright side though, the system is still better than what C++ got which is not knowing from which header a particular symbol came from :). [1]: https://github.com/djc/quinn/blob/e555d11a430b9760d149a2765998734b6acfcd4d/quinn/Cargo.toml https://github.com/djc/quinn/blob/e555d11a430b9760d149a27659... [2]: https://github.com/djc/quinn/blob/e555d11a430b9760d149a2765998734b6acfcd4d/quinn/examples/client.rs https://github.com/djc/quinn/blob/e555d11a430b9760d149a27659... [3]: https://gist.github.com/est31/7cb33e8a6b63c8798381bdb5e91a145a https://gist.github.com/est31/7cb33e8a6b63c8798381bdb5e91a14...
- KeyboardFire 8y agoIt's funny that this is the first time I've seen a language explicitly condone "print debugging." It's one of those things that everyone says you're not supposed to do and then does anyway. Does any other language have a similar feature?
- the_duke 8y agoThe person who proposed it is a (previous) Haskell developer. The dbg! macro is definitely inspired by https://hackage.haskell.org/package/base-4.12.0.0/docs/Debug-Trace.html https://hackage.haskell.org/package/base-4.12.0.0/docs/Debug....
- SilasX 8y agoHow so? In Rust, the macro is just a very thin wrapper around some output formatting boilerplate. In Haskell, it exists because you'd otherwise have to change the type of the function to add print-debug statements.
- the_duke 8y agoBecause it can be used to wrap any expression. I haven't seen a debug function that returns the value again anywhere else.
- eslaught 8y agoIt was definitely in Arc first, and probably in other lisps before that: https://github.com/arclanguage/anarki/blob/master/arc.arc#L1628-L1631 https://github.com/arclanguage/anarki/blob/master/arc.arc#L1... Edit: Yes, it's in Common Lisp too, so it goes back at least to the 1980s and probably further. http://www.lispworks.com/documentation/HyperSpec/Body/f_wr_pr.htm http://www.lispworks.com/documentation/HyperSpec/Body/f_wr_p...
- yxhuvud 8y agoThe debug printing method p in Ruby have been returning it's argument for years now. Dbg seems possibly better for the usecase though as you get the location as well.
- frio 8y agoNot that I use Rust for more than toy projects, and not that the choice of allocator makes (any) difference for those... but I'm stoked to see the system allocator used by default now. Tiny binaries are good binaries.
- ChrisSD 8y agoHow's the documentation coming along? I've had to take a break from it because so far I've only been able to use if for hobby projects. Coming back to Rust for me often means bouncing around different editions of the docs (especially if FFI is involved) and searching blog posts, forums and my own old code to try to remember how to do things. But then of course the language has changed or best practice has so it's all out of date.
- Hortinstein 8y agoI think it has come along really well. I started trying to learn it a few years ago, but going through the official documentation that was recently revised has been a breath of fresh air. Went from one of the most confusing experiences to one of my favorite. Highly recommend starting here https://doc.rust-lang.org/book/index.html https://doc.rust-lang.org/book/index.html
- house_atr 8y agoConst generics const generics const generics const generics
- AceJohnny2 8y agoTypo note: > literal mactches against literals of any type;
- steveklabnik 8y agoThank you! https://github.com/rust-lang/blog.rust-lang.org/commit/a775ba5b8b07fa65f4c20fa77a2ac6b1e72c9e3d https://github.com/rust-lang/blog.rust-lang.org/commit/a775b... (will be deployed in a few minutes)
- AceJohnny2 8y agoOh it's just MD on Github. ... of course it is. Noted for next time ;)
- claireb88 8y ago> This is servicable
- winstonewert 8y agoSo, the question I have is, should I switch my projects back to jemalloc? Are there are guidelines for determining where it makes sense and where it doesn't? (Obviously to get the fully correct answer for my project, I should benchmark, but how do I know if its even worth going to the effort of that?)
- nickbee 8y agoIt depends. In the gamedev industry, we noticed performance improvements when switching the allocator. But “should” is relative. You probably won’t get a 2x boost from it. But you might notice some improvements. It’s worth trying if you can test it quickly. Software best practices are like flossing: good in the long term, but probably not crucial to keeping your bite.
- majewsky 8y agoI'm not incredibly familiar with gamedev, but I would expect most allocations in games to be performed by small-object allocators on top of the general-purpose allocator, so the choice of general-purpose allocator should not make that much of a difference, should it?
- jake_the_third 8y agoAs of the time of this post, the official standalone installer page incorrectly lists 1.30.0 as the latest stable release. For users who prefer or need standalone installers, please use the URL templates bellow to download your packages until this issue has been resolved. The URL template for normal rust installers is: * https://static.rust-lang.org/dist/rust-1.32.0-{TARGET-TRIPPLE}.{EXT} * https://static.rust-lang.org/dist/rust-1.32.0-{TARGET-TRIPPLE}.{EXT}.asc The URL template for additional compilation target installers (`x86_64-unknown-linux-musl`, `wasm32-unknown-unknown`, ..etc) is: * https://static.rust-lang.org/dist/rust-std-1.32.0-{TARGET-TRIPPLE}.{EXT} * https://static.rust-lang.org/dist/rust-std-1.32.0-{TARGET-TRIPPLE}.{EXT}.asc To avoid a very long post (and a lot of scrolling), the list of links to all target installers supported by rust has been omitted from this post. Refer to the complete list of supported platforms in https://forge.rust-lang.org/platform-support.html https://forge.rust-lang.org/platform-support.html. The file extension for auxiliary target installers is `.tar.gz` (or `.tar.xz`) for all targets including Windows. Note: Due to a known bug, browsing the complete list of all installers is not available on https://static.rust-lang.org https://static.rust-lang.org. It is however still possible to access dated repositories via the following URL template: https://static.rust-lang.org/dist/YYYY-MM-DD/ https://static.rust-lang.org/dist/YYYY-MM-DD/ Installers for the current stable release of rust can be browsed at https://static.rust-lang.org/dist/2019-01-17/ https://static.rust-lang.org/dist/2019-01-17/ Cheers!
- jackblack8989 8y agoPlug- Use QtCreator for a nice Rust GUI
- mlevental 8y agowhat? how?
- krzat 8y agoWhat is the status on incremental compilation and code completion?
- knowThySelfx 8y agoI love Rust too. But lately, been getting the feeling that its trying to do "everything". Hope it doesn't end up the C++ way. Don't get me wrong, dbg macro isn't one of them. Heavy user of print debugger here.
- est31 8y agoUsing the literal fragment specifier in serde-big-array already to reduce code size if possible: https://github.com/est31/serde-big-array/commit/c6e5669ffe65116afb521d6fd489501d775e0abe https://github.com/est31/serde-big-array/commit/c6e5669ffe65...