Earlier quoted context omitted.
Of course you can call drop() manually, but almost nobody does or even think about it because that's not the way you program in a language with RAII. Don't get me wrong. I do think that rust and c++ RAII is much more convenient and safe than the C or Zig way. (I'd even prefer if you could annotate given struct in rust so the compiler could drop them as soon as it's no longer used, but that s not that simple)
I definitely wish that Non-Lexical Lifetimes would eagerly drop anything that doesn't implement Drop. It would probably be a breaking change to automatically call an explicit Drop implementation anywhere other than the end of the current scope, so I think that would have to be left as-is. String doesn't implement Drop, so it could easily be dropped eagerly within the scope as soon as it won't be referenced again. Suc…
Zig self hosted compiler is now capable of building itself
201–210 of 285 posts
Re: Zig self hosted compiler is now capable of building itself
#202Earlier quoted context omitted.
Thanks :) The new Zig implementation is certainly more well designed than the C++ implementation, for several reasons: * It's the second implementation of the language * It did not have to survive as much evolution and language churn * I leveled up as a programmer over the last 7 years * The Zig language safety and debugging features make it possible to do things I would never dream of attempting in C++ for fear of f…
> * a Digital Audio Workstation ORLY? Maybe you can put together a better, faster team (like Presonus managed to do for Studio One), but most current DAWs have been in existence for 20 years or more. Catching up with that is a challenge, and if you don't catch up then it's an interesting toy or half-a-DAW. So why? ps. obviously I am biased.
Re: Zig self hosted compiler is now capable of building itself
#203Earlier quoted context omitted.
The perspective of someone who is learning Rust (but not professionally) during the last few months. : - The borrow checker is one of the easier parts of Rust to grok, it's just as you say, not that complicated in the end. - Traits are more annoying to understand and find in source code when they can get added from anywhere, and suddenly you code gets extra functionality, or it's missing the right one unless you impo…
`rust-analyzer` lets you find the trait/impl that provides a method, if you don't have it in your IDE you should get it.
Re: Zig self hosted compiler is now capable of building itself
#204Earlier quoted context omitted.
> because automatic deallocations lead to hard-to-predict lifetimes (excess memory usage, and bugs for resource handles that are destructed at hard to predict moments). I don't really feel this is the case in Rust.
But it is. If you have a String on the stack, it's memory is only reclaimed at the end of the scope, while it often could be free'd before. This is especially bad in async code around await point since it means the memory need to be kept alive more than needed.
I’m assuming by string you mean a stack allocated array of char and not a std::string.
Re: Zig self hosted compiler is now capable of building itself
#205Earlier quoted context omitted.
If the union is untagged, how can it be determined (at runtime) that you've accessed the wrong field?
The compiler adds a tag in debug modes, but not in release modes.
Re: Zig self hosted compiler is now capable of building itself
#206Earlier quoted context omitted.
The lifetime of the memory a smart pointer manages is very predictable. It will have the same lifetime as the smart pointer itself (this is ignoring moves).
I think what he's saying is there is a way to carelessly use smart pointers in rust. pub enum List { Empty, Elem(i32, Box ), } instead of : pub struct List { head: Link, } enum Link { Empty, Some(Box ), } struct Node { elem: i32, next: Link, }
Re: Zig self hosted compiler is now capable of building itself
#207Earlier quoted context omitted.
> * a Digital Audio Workstation Woah. A little bit ago I went to write a little tool that mucked with the FL Studio FLP format. It was easy enough to guess out the bits that I cared about, so I pretty much just did that using a couple quick projects with specific things in them. However, I did check to see if anyone else had mucked around with the FLP format, and couldn’t help but notice your name. Was pretty surpris…
> It took me so much effort to feel like I could understand FFTs enough to actually implement them.) Do you understand how little DSP is involved in writing a DAW? It has almost nothing to do with DSP and everything to do with application architecture, data management, threading and more.
That said, Rust seemed pretty promising for writing the audio engine of a DAW due to the memory ownership model. It was relatively easy to come up with a way to architect a very basic lock-free audio thread and feel sure that it was at least memory correct. I have no idea how a real DAW avoids certain pitfalls in the audio thread; lock-free isn’t too hard, but avoiding allocations in all circumstances seems tricky.
Re: Zig self hosted compiler is now capable of building itself
#208Earlier quoted context omitted.
But it is. If you have a String on the stack, it's memory is only reclaimed at the end of the scope, while it often could be free'd before. This is especially bad in async code around await point since it means the memory need to be kept alive more than needed.
Stacks are a fixed size. Unless you are running out of stack space there is no point in “freeing” memory from the stack. Where in the stack the stack pointer points has no bearing on stack size for any OS I’m aware of. I’m assuming by string you mean a stack allocated array of char and not a std::string.
Re: Zig self hosted compiler is now capable of building itself
#209Earlier quoted context omitted.
> * a Digital Audio Workstation Woah. A little bit ago I went to write a little tool that mucked with the FL Studio FLP format. It was easy enough to guess out the bits that I cared about, so I pretty much just did that using a couple quick projects with specific things in them. However, I did check to see if anyone else had mucked around with the FLP format, and couldn’t help but notice your name. Was pretty surpris…
It's a fun exercise to implement FFT and other DSP algorithms, but for real-world software please stick to true and tested libraries like FFTW or FFTPACK instead of your own naïve implementation.
Re: Zig self hosted compiler is now capable of building itself
#210Earlier quoted context omitted.
I definitely wish that Non-Lexical Lifetimes would eagerly drop anything that doesn't implement Drop. It would probably be a breaking change to automatically call an explicit Drop implementation anywhere other than the end of the current scope, so I think that would have to be left as-is. String doesn't implement Drop, so it could easily be dropped eagerly within the scope as soon as it won't be referenced again. Suc…
100%. I would actually go further and say every value should be dropped immediately after its last use, including temporaries in the middle of statements, whether or not it implements Drop. Reuse the same rules that NLL uses. Breaking change yes, so do it next edition. It would lower memory usage in general and solve so many little pain points, not least of which is holding strings across await points.
fn foo(xx : &Mutex) {
let lock = xx.lock();
let ptr = &mut *lock as *mut String;
unsafe { use_from_c(ptr) }
}
You get the idea: you don't want the lock or the string to be dropped before the unsafe code, even if the actual string is no longer used. That's the breaking change. It's hard to detect automatically, so hard to justify even in an edition.