3 ms·
> There’s no malloc/free Calling into libc isn't a problem, see http://doc.rust-lang.org/libc/x86_64-unknown-linux-gnu/libc/fn.malloc.html http://doc.rust-lang
by kibwen 10y ago
> There’s no malloc/free
Calling into libc isn't a problem, see http://doc.rust-lang.org/libc/x86_64-unknown-linux-gnu/libc/fn.malloc.html http://doc.rust-lang.org/libc/x86_64-unknown-linux-gnu/libc/... (and in the future, http://doc.rust-lang.org/alloc/heap/index.html http://doc.rust-lang.org/alloc/heap/index.html will be stabilized).
> placement new is still unstable
That's a fair criticism, the onus is on us to get these features finalized and polished. :) Placement new is certainly going to be a high priority once MIR and specialization are wrapped up.
> Is it good the compiler prevents me
> from doing that at all
But it's not preventing you from doing anything, it's just telling you that it can't automatically prove that a use of references is safe. This is precisely what raw pointers are intended for: Rust isn't about entirely eliminating potential unsafety, it's about encapsulating it behind an "I know better than the compiler" interface that can be feasibly hand-audited.
> workarounds, that will cost me time to
> implement, will be ugly, and/or will
> sacrifice runtime performance
I still don't quite understand this criticism. If you were so inclined, you could forgo references altogether and code Rust as though it were C, with nothing but raw pointers, and it shouldn't take any more time to write than C, be no more ugly (syntactic differences aside), and have no difference in runtime performance.
- Const-me 10y ago> you could forgo references altogether and code Rust as though it were C, with nothing but raw pointers, and it shouldn't take any more time to write than C Disagree. In C++ we have sophisticated debuggers, we have standard C library, STL with its containers, algorithms and lots more, boost and other third-party libraries. When coding typical Rust, we have descent-quality standard library, also big set of third-party libraries. When coding Rust as though it were C, we have almost nothing, because the rust’s standard library doesn’t expose unsafe API. Unsafe Rust only takes same time to write as C++ if you’re coding something trivial, like a “Programming 101” homework. For anything even remotely useful, debugger and libraries make huge difference. A single bounds checking feature (C++ has that with STL containers in debug builds, controlled by _GLIBCXX_DEBUG or _ITERATOR_DEBUG_LEVEL) can sometimes save hours.
- kibwen 10y ago> In C++ we have sophisticated debuggers What features do you look for in a sophisticated debugger? There's upstream support for Rust in GDB (https://np.reddit.com/r/rust/comments/4merw3/gdb_now_supports_debugging_programs_written_in/ https://np.reddit.com/r/rust/comments/4merw3/gdb_now_support...), I've seen people do reverse debugging with rr (http://huonw.github.io/blog/2015/10/rreverse-debugging/ http://huonw.github.io/blog/2015/10/rreverse-debugging/) as well as Valgrind, and the compiler knows how to emit debuginfo, and so should work with any tool that can read DWARF (like LLDB). Mozilla is investing even more into dedicated IDE support this year and the next. > the rust’s standard library doesn’t expose unsafe API What unsafe APIs would you like to see? Using Vec as an example, I see a function for constructing a Vec out of raw data (http://doc.rust-lang.org/std/vec/struct.Vec.html#method.from_raw_parts http://doc.rust-lang.org/std/vec/struct.Vec.html#method.from...), a function for mucking around with the private length field (http://doc.rust-lang.org/std/vec/struct.Vec.html#method.set_len http://doc.rust-lang.org/std/vec/struct.Vec.html#method.set_...), a function for receiving a raw pointer to the underlying buffer (http://doc.rust-lang.org/std/vec/struct.Vec.html#method.as_mut_ptr http://doc.rust-lang.org/std/vec/struct.Vec.html#method.as_m...)... we're far from opposed to adding low-level APIs for complete control over collections, all you need to do is ask for them and tell us why they'd be useful. :) > A single bounds checking feature I'm not sure what this is asking for. All Rust containers are bounds-checked by default.
- Const-me 10y ago> What unsafe APIs would you like to see? Well, here’s a simple example I’ve wrote above: “Some container that keeps some items + a linked list to track and evict the least recently used item from that container”. You know, LRU caches are everywhere. I remember in C++, I recently wrote something similar in three completely unrelated projects. Well, a linked list alone isn’t usually enough, but a linked list + unordered map that maps elements to list iterators do the job very well. To update the LRU order, I query the hashmap and get a list position, then I move that element to the list’s tail. And when I need to evict an element, I grab the list’s head and evict those. Note the following good things about this C++ solution: (1) All those operations (hashmap lookup, linked list reorder, linked list remove head) are O(1), i.e. I can have millions items in my cache, and still update my LRU order for practically no cost (a few pointer writes). (2) I didn’t wrote much code, only creatively combined what was already here in the C++ standard library. Now Rust. The safety means pointers to list nodes aren’t part of the list’s API. And without raw pointers, linked lists are nearly useless, because we can’t split or reorder them efficiently. If you’ll read the documentation for LinkedList<T>::split_off, you’ll find the complexity is O(n), while for most other languages, linked lists are famous for being able to do that for O(1). I’m not sure any efficient linked list API is possible within Rust memory management model, safe or unsafe.