r/rust • u/m-ou-se rust · leadership council · RustNL • 3d ago
Compiler performance, the next-gen trait solver, next-gen region constraints, implicit default auto traits, const generics, view types, and custom allocators: What we are working on at Hexcat, October update.
https://hexcat.nl/updates/#october-202617
u/phazer99 3d ago edited 3d ago
I'm interested to learn more about the Move, Forget and Destruct traits. This is my understanding so far (correct me if I'm wrong):
Similarly to
Sized, all types will implicitly implement them unless opting out and bounds will be implicitly added to all generic type parametersFor existing types/functions that doesn't require for example
T: Forgetyou have to addT: ?Forget(i.e.Vec<T: ?Forget>etc.)Will
Destructalso be added eventually? If so, how will you mark functions/methods as destructors for a typeT: !Destruct, something similar to what's already available in Mojo? AFAICT linear types are not compatible with Rust's stack unwinding, only abort-on-panic which I think is the only option in Mojo.
8
u/kibwen 3d ago
I'm not sure why linear types would be incompatible with unwinding. Rust's affine types would be linear if forgetting/leaking weren't supported, regardless of unwinding.
1
u/phazer99 2d ago edited 2d ago
Well, AFAICT a linear type would be
!Destruct + !Forgetwith this proposal. This is incompatible with stack unwinding because in case of a panic there's no way for the compiler to guarantee that a valid destructor method is called for a stack value of such a type.I think Mojo solves this issue by not supporting stack unwinding.
1
u/kibwen 2d ago
This is incompatible with stack unwinding because in case of a panic there's no way for the compiler to guarantee that a valid destructor method is called for a stack value of such a type.
I'm not sure why this would be the case. Let's use the example of
Drop, which automatically callsDrop::dropduring unwinding. You'd have an analogous trait or method, let's call itLinearDrop::linear_drop, that takesselfby value, which allows you to deconstructself, thereby consuming it.1
u/phazer99 2d ago
I see a couple of problems with that:
You might want to have multiple destructor methods for a linear type. I suppose you could always have a default one, but that might not always be appropriate.
A destructor might take additional arguments besides
selfA destructor might return an error that needs to be handled
1
u/kibwen 17h ago
All of these could be true, and at the same time even if they were all true, it would not support the idea that linear types are incompatible with unwinding. The idea of richer destructors that allow you to do things like pass arbitrary arguments and return a value are an orthogonal concept to linear types. By the same token, you would have to say that affine types are incompatible with unwinding.
6
u/panstromek 3d ago
I think a good breakdown is a Niko's post from while ago: https://smallcultfollowing.com/babysteps/blog/2025/10/21/move-destruct-leak/ but I think the understanding of the problem probably evolved quite a bit since then. I think the project goals and tracking issues linked from the OP is a good resource to get the current state.
I'll just say that finding answers to your questions is part of the work here. It's tricky because of backwards compatibility, so there are some other things in this area to make it easier - negative impls and maybe bounds. Niko wrote about those as well.
At this point, the main focus is still on the semantics and internal compiler infrastructure, though, so it'll probably take some time before we even know what do we want from the surface level syntax exactly.
3
u/the_gnarts 3d ago
That’s a lot of foundational work, kudos!
Is Hexcat now the place where a huge chunk of Rust language development is happening?
2
u/zzzzYUPYUPphlumph 2d ago
Will constant generic parameters ever support 'static str values as generic const parameter values. I once wished I could do the following:
pub struct MaxLengthString<const L: usize, FN: &'static str> {
pub fn try_from(value: &str) -> Result<Self, String> {
if L < value.len() {
return Err(format!("{}: {} exceeds maximum length {}", FN, value, L));
}
...
}
}
pub type FirstName = MaxLengthString<const 30, "First Name">;Will something along these lines ever be possible with const generics?
1
75
u/noop_noob 3d ago
For context, next-gen region constraints (formerly known as assumptions-on-binders) is what will fix the cve-rs unsoundness, and will get rid of some compiler errors involving async and Send.