re-allocating" storage for a local could allow faster code
▲ 27 r/ProgrammingLanguages+1 crossposts

re-allocating" storage for a local could allow faster code

Rust already knows when a value has been moved, so I think it would make sense for the compiler to also be able to treat the storage behind that local as reusable.

For example:
´´´
let x = big_value();
let y = x; // x is moved

// x can no longer be used here anyway

x = another_value();
´´´

Right now, Rust can be more restrictive than necessary about keeping the same storage associated with `x`.

Issue #61849 proposes allowing the old storage to effectively die after the move. If `x` is initialized again later, the compiler wouldn't necessarily have to put the new value back in the exact same stack slot.

That could give the compiler more freedom to:

- reuse stack space earlier
- reduce stack usage in some functions
- shorten lifetimes of stack allocations
- potentially unlock further optimizations

What I like about the idea is that it matches how moves already feel in Rust: once a value is moved, that value is gone. It seems natural that its storage shouldn't have to remain special either.

There are obviously details around raw pointers and observable addresses that would need proper language semantics, so it isn't just a simple compiler optimization.

But the general rule seems very appealing:

If Rust says the old value no longer exists,
the compiler should be free to stop preserving its storage.

The issue has been open since 2019, and I think it would be interesting to revisit whether this could give modern rustc more optimization freedom. If you agree please react on the GitHub issue with ❤️ or 👍 to show support by the community

Edit:link to the modern version

I am creating a compiler

I am creating a compiler for my own programming language, I have been suffering a lot but I am improving slowly, it has been alot of Google and asking ChatGPT for small exemples, trying to recreate but for what I want, realizing it doesnt really work trying to fix etc.

It has been an interesting experience, im currently at the type checker

reddit.com
u/Negative_Effort_2642 — 2 months ago
▲ 3 r/theprimeagen+1 crossposts

Programmers are cool

I emailed both Bjarne Stroustrup and fabrice bellard with questions and both answered, bjarne reply was smaller and more concise but it’s pretty cool both had the time to answer.

reddit.com
u/Negative_Effort_2642 — 3 months ago
▲ 7 r/learnrust+2 crossposts

File archive tool

rust-file is a small Rust archive tool. Given a directory, it merges all files into one archive, compresses it, encrypts it, and can later restore the original files

github.com
u/Negative_Effort_2642 — 2 months ago
▲ 24 r/VibeCodeCamp+1 crossposts

What would u code if you knew how to code?

Let’s supposed that tomorrow instead of waking up with your prompting skills you woke up actually knowing how to code in a low level language, what would u do ?

reddit.com
u/Negative_Effort_2642 — 3 months ago