36 ms·
Rust 1.47
- Deukhoofd 6y agoIs it really a good idea to target a release candidate of LLVM in the Stable branch by default? I can understand wanting to benefit from new features, but I wouldn't want production code to be running on something that LLVM does not yet consider ready for release.
- pornel 6y agoRust tends to exercise code paths in LLVM that clang doesn't, so from Rust's perspective LLVM was never particularly stable (e.g. pointer aliasing has been broken in LLVM for years). In that case it's better to get fixes for known bugs in LLVM ASAP.
- adamch 6y agoIt's a little thing, but one of my favourite parts of any Rust release is seeing which stdlib functions become `const`. The ergonomics of build-time evaluation are slowly improving, and I'm very excited to slowly do less at runtime!
- k__ 6y agoWhat does "becoming const" mean?
- Ygg2 6y agoMeans that functions are evaluated at compile time. However in this case, these are const generics, so you no longer need to use macro to generate [char;1],[char;2]... You just write [char; N] where N is const. Compiler determines which values of N are used and generates for them an appropriate version.
- steveklabnik 6y agocan be, you can call them at runtime too. And to be clear, const generics aren't stable yet, they're being used as an implementation detail of the standard library here, you cannot yet use them on stable in your code.
- Nullabillity 6y ago> However in this case, these are const generics, so you no longer need to use macro to generate [char;1],[char;2]... Const generics still aren't stable. I believe the GP was talking about the list of new `const fn`s in the release (near the bottom of the post).
- happythomist 6y agoI believe it's similar to "constexpr" in C++ -- it means those functions can now be evaluated at compile time.
- deleted 6y ago[deleted]
- dahfizz 6y agohttps://doc.rust-lang.org/reference/items/functions.html#const-functions https://doc.rust-lang.org/reference/items/functions.html#con... Basically, const functions can be used in places regular functions can't because they are directly "run" by the compiler at compile time.
- mden 6y agoConst values are inlined at compile time wherever they are used. Const functions let you run code to define const values. This code will be run at compile time before the const values are inlined. For example let's say you have a constant for PI but you need 2*PI. You could do the multiplication in const context, meaning the multiplication will happen during compilation and not execution. Slowly more and more of the language is becoming usable in const context so more advanced things can be done during compile time.
- colejohnson66 6y agoWell, if you need `2*PI`, there’s now `f32::TAU` and `f64::TAU` :) You’re still correct though
- hinkley 6y agoI like that const functions occupy a space between a normal function and hygienic macros. You can avoid writing out lookup tables long-form where the entries are very predictable. For instance you could write a base64 encoder and decoder without putting ["a", "b", "c"... ] in your code base, and then have to worry if you accidentally put "D" in there twice. The typical alternative in other languages is to evaluate this at startup time, which adds latency to your program. Compile-time function evaluation is also one of the features of the Jai programming language. If you can't get people to use your language, getting them to steal all your features is a good consolation prize.
- jsheard 6y ago> If you can't get people to use your language, getting them to steal all your features is a good consolation prize. It's difficult to use Jai as long as it only exists on Jonathan Blows computer, he still hasn't released it
- pjmlp 6y agoThe problem with "const of all things" is that you will get enough free time to prepare a big meal.
- jsheard 6y agoIn many cases the functions being constified were already evaluated during compilation where possible though, the compile time cost was already sunk. Making them const just formally guarantees the compiler can evaluate them at compile time which makes them useful in more contexts.
- pjmlp 6y ago"constexpr of all things" kind of proves the point in compile times, and so far Rust isn't fairing much better in that regard.
- creata 6y agoCan't the Rust compiler cache the evaluated outputs?
- pjmlp 6y agoIn theory yes, with the current LLVM toolchain doesn't look like it.
- vlang1dot0 6y agoLLVM has nothing to do with `const` evaluation in Rust. `const` evaluation happens at the MIR level which participates in incremental compilation.
- pjmlp 6y ago> cache the evaluated outputs Was the point of my answer.
- 6y ago
- scudd 6y agoCan increase in use of `const fn`'s create a noticeable decrease in compile times? As someone whose never worked on compilers, I'm not really sure what the magnitude of that processing time is in relation to everything else.
- jsheard 6y agoThe compiler would already evaluate most of this stuff at compile time, you just weren't allowed to rely on it until now. e.g. char::is_ascii_alphabetic() was made const in 1.47, but 1.46 would already run it at compile time: https://godbolt.org/z/hWf65f https://godbolt.org/z/hWf65f The difference is in 1.47 you can use the result to assign something that must be known at compile time.
- li4ick 6y agoJust how prevalent is Rust in the industry? I remember trying it out back in 2014 and saw nothing of interest, as a Haskell user. A lot of the main "selling points" of Rust are getting introduced in C++. Also, what is it about Rust that gets automatic top view on HN?
- adamnemecek 6y agoThe fact that you can actually ship an app. I've been writing my app (it's an IDE for music http://ngrid.io http://ngrid.io) in Rust after trying it in cpp and swift and it's a joy to use. Haskell is cool and all but every time I tried it, I spent too much tle with package management for example. Also you can't really ship an app in Haskell.
- LandR 6y agoI dont know Haskell, why can't you ship an app in Haskell?
- nine_k 6y agoYou totally can. I use pandoc regularly (though some would say it's a "utility" and not an "app").
- adamnemecek 6y agoI mean like a desktop app.
- nine_k 6y agoxmonad? :) Frankly, I did nit see people releasing proper desktop apps for some time now :( Electron apps do not count.
- diath 6y agoWhat is "ship an app" supposed to even mean here? Being able to build a binary for distribution? Both Swift and C++ can do that, and likely Haskell too.
- oconnor663 6y agoThe "you can't print arrays larger than 32" thing was a common papercut for beginners. You could usually work around it with slices, but until now that's been yet another thing to memorize on day 1 or week 1. It only takes a couple of papercuts to go from "this is challenging but fun" to "this is pointlessly frustrating", so I'm always very happy when one of the big ones gets fixed.
- The_rationalist 6y agoWhat about printing vectors? (array dynamically sized) What other kind of traits are useful for arrays?
- shakow 6y agoVectors can already be printed. Vectors types are only dependent on the contained elements, whereas Arrays types depend (until const generics come) both on the size of the array and the contained elements. So whereas a generic implementation of Display for Vec of any length was possible, Arrays required one implementation of Debug per possible length of the array.
- vvanders 6y agoIt gets really annoying on no_std, which makes me happy to see this making progress in the language.
- brundolf 6y agoFortunately under normal circumstances it's almost always better to use a Vec anyway, and this is encouraged by the Book. Having done projects in Rust for the past ~2 years I didn't even know this limitation existed, because I hardly ever use plain arrays.
- steveklabnik 6y agoIMHO, it's a chicken and egg kind of thing; it's way easier to use Vecs because arrays really need const generics to actually be useful. I am interested to see how this balance changes. I know for my no_std work, const generics for arrays can't come fast enough.
- offtop5 6y agoStupid question, but will Rust ever have a non strict mode. I'm used to writing C# , Python and JS. Rust seems to be overally punishing
- munchbunny 6y agoFor the types of stuff Rust is often used for, the strictness is a feature.
- elliebike 6y agoNo, because that's not really the point of Rust. You make the sacrifice of a "punishing" compiler, and spending more time writing code, but you gain software that's more likely to be "correct", safe, and not leak memory. Really, as in all things computers, it depends what your set of requirements are as to what trade offs you make
- snazz 6y agoAlthough I haven't verified this myself—I'm not much of a Rust wizard—I've heard that Rust's type system and borrow checker allows you to spend less time total, because your debugging time drops significantly.
- ben-schaaf 6y agoVerifying that would be incredibly difficult/impossible but I've personally found that rust has on multiple occasions prevented me from making a mistake that would have cost likely hours to debug that I was instead able to fix in a few minutes.
- matt_kantor 6y agoFans of static type checking use that as a rebuttal against "but I'm so much more productive in $dynamically_typed_language". I've also seen it in discussions about Scala, Haskell, TypeScript, etc. Intuitively it makes a lot of sense, and it jives with my subjective feelings (especially for longer-lived projects), but I'm not sure if there have been any studies to back up that claim.
- maxfurman 6y agoIs there a good post out there explaining "const generics"? I'm very curious about this phrase and not sure what it means.
- steveklabnik 6y agohttps://rust-lang.github.io/rfcs/2000-const-generics.html https://rust-lang.github.io/rfcs/2000-const-generics.html is the design document, it may or may not be a good resource depending on your knowledge of Rust. A classic example of them being used in Rust is to be generic over arrays, like what the blog post talks about. Arrays encode their length as part of the type; [T; N] is the type of an array of Ts that’s N elements long. In other words: fn foo<T>(array: [T; ?]) { How do you define ? to work on any length? When const generics is implemented, you’d write fn foo<T, const N>(array: [T; N]) { and now you can call this function on arrays of varying lengths. There's a bit more to it than that, but that's the core of it. Does that help?
- maxfurman 6y agoSo in Rust you must specify the length of an array? How do you implement map, fold, etc., that work on an entire collection regardless of length? Is that a different API in Rust?
- steveklabnik 6y ago> So in Rust you must specify the length of an array? Correct. > How do you implement map, fold, etc., that work on an entire collection regardless of length? So, while arrays exist, there are also things like slices and vectors, which have a runtime length, rather than an array's compile-time length. So that's one bit of it. But the other part is that these are implemented on iterators, rather than on the type directly, so usually what happens is "turn that into an iterator, then do map/fold/filter/whatever on the iterator. It is easy to convert the compile-time length array to a run-time length iterator, so it ends up being a uniform interface.
- 6y ago
- kibwen 6y agoGreat to see that const generics has become mature enough to be exposed by the stdlib, even if it's not ready for full stabilization just yet. People wanting to use const generics themselves will want to follow this issue, which is about stabilizing a minimally-useful subset of const generics: https://github.com/rust-lang/rust/issues/74878 https://github.com/rust-lang/rust/issues/74878 . It seems to be coming along well: "Regarding the remaining steps: there are only a handful of issues I think are blocking min_const_generics at this stage (several of which already have open pull requests). We also want to add many more tests, which is something anyone can easily help with. If you want to tackle one of the issues, feel free to ask @lcnr or myself how to get started; I'm going to dedicate time to fixing whichever remain."
- dfranke 6y agoI hope we eventually get Presburger arithmetic support so that one could write fn concat<T,M,N>([T; M], [T; N]) -> [T; M+N]
- baq 6y agoand also proper units of measurement support while we're at it...
- coder543 6y agoI don't understand what you're asking for here. I did an experiment with units of measure years ago in Rust: https://github.com/coder543/metric https://github.com/coder543/metric To me, it felt ergonomic, and it was absolutely compile-time type safe to the extent you would expect. It worked just fine. I know of quite a few other libraries that do the same thing with their own unique approaches, so there are many flavors of this that all work on stable Rust. If you're asking for something like this to be built into the standard library... that's very unlikely to happen in the foreseeable future.
- baq 6y agoi'm actually asking for something like this to be implemented on a language level, but if the type system is ergonomic enough, then i'd be mostly fine. most numbers i deal with in my code have units somewhere. mistakes happen. i don't want to choose from multiple unique approaches, i need the ecosystem to standardize on one solution. see also the async task executor problem in other languages.
- mwcampbell 6y ago> Control Flow Guard on Windows I gather from the description that this is not enabled by default. Is that correct? If so, why isn't it enabled by default? It would seem to fit with Rust's focus on safety.
- tptacek 6y agoIt's a memory safe language, and CFI has overhead.
- mlindner 6y agoBecause it has no purpose in normal Rust code as it's already guaranteed to be safe. It's only purpose would be on {unsafe code, inline assembly} and is just a performance penalty otherwise.
- fulafel 6y agoThere's no formal verification that uses of unsafe in the standard library are correct and there are no bugs. (Of course goes for other libs too). So this justification doesn't really feel robust.
- mlindner 6y agoThere's no formal verification that the Windows OS syscalls are correct and there are no bugs either.
- rkangel 6y agoAre there any particular features from LLVM 11 that are interesting to Rust users?
- steveklabnik 6y agoOther than "it looks like maybe it made up some of the compile time loss from LLVM 10," I'm not aware of anything specific. In general, we update regularly to gain access to bug fixes and because upgrading regularly makes each upgrade easier, so we don't need something specific to trigger an update.
- 02020202 6y agoah, rust...the quasimodo of programming languages.
- zamalek 6y agoThis release seems like it focuses on ergonomics, which is fantastic. > Shorter backtraces This is a very welcome change! Having to find the "root" of a full stack trace can easily take 30 seconds, which really starts adding up.
- wzk86651 6y ago... and std channels still contain data races: cat src/main.rs fn main() { let (tx1, rx1) = std::sync::mpsc::sync_channel::<std::sync::mpsc::Receiver<_>>(0); let (tx2, rx2) = std::sync::mpsc::sync_channel::<std::sync::mpsc::Sender<_>>(0); std::thread::spawn(move || { for rx in rx1 { let _ = rx.recv_timeout(std::time::Duration::new(0, 0)); } }); std::thread::spawn(move || { for tx in rx2 { let _ = tx.clone(); } }); loop { let (tx, rx) = std::sync::mpsc::channel::<String>(); tx1.send(rx).unwrap(); tx2.send(tx).unwrap(); } } RUSTFLAGS=-Zsanitizer=thread cargo run -Z build-std --target x86_64-unknown-linux-gnu ================== WARNING: ThreadSanitizer: data race ... SUMMARY: ThreadSanitizer: data race in std::sync::mpsc::shared::Packet$LT$T$GT$::drop_port::hb1e2c47df4539855
- FullyFunctional 6y agoThis marks the first Rust release than can be directly installed with plain old rustup.sh on RISC-V Linux distributions (like Ubuntu, Fedora, and others). A very awesome milestone and my thanks to all who contributed. All the core tools I tested works 100% and almost all the crates work. A few, like libc and Nix, still needs explicit riscv64 support.
- fulafel 6y agoWhat does the complexity trajectory look like for Rust? In 10 years, is it going have many more language level features and interactions thereof?
- steveklabnik 6y agoMajor features have slowed down considerably. We'll see.