[Pre-RFC] BTF relocations
vad:
RalfJung:
FWIW this will be very non-trivial because Rust has generics. Today one can write a generic function that takes an arbitrary
T(implicitly:T: Sized) and then obtain its size as a compile-time constant. This is not something we can break. That's why people are saying that the Sized hierarchy work is a prerequisite for supporting this kind of a type.I'm fine with making support for BTF relocations depend on the
Sizedhierarchy work if there is strong opposition to introducing#[repr(btf)]types that don't work with generics.
It may not be as hard of a blocker as that makes it sound.
First, you may be able to start with an unstable implementation even if the Sized hierarchy is a blocker for stabilization. This is the case for scalable vectors, which already have a prototype implementation in the compiler despite the Sized hierarchy not yet having one.
Second, you may be able to come up with a subset of the feature that doesn't depend on the Sized hierarchy at all. This should be easier for BTF types than for scalable vector types. The prototype of scalable vector types is pretty hacky: the compiler treats these types as Sized (despite the lack of a compile-time constant size), with the intent to downgrade to runtime-sized once that becomes a thing. This is because scalable vectors need to be passed by value and treated as Copy, which isn't supported for !Sized types. For BTF types, though, passing by value is not that essential, so you could probably start by making them !Sized, with the intent to upgrade to runtime-sized once that becomes a thing. This would be backwards-compatible and wouldn't break any existing generic code, so maybe it would even be stabilizable? (but I'm only speculating on that.)
The innovation would be having a type be !Sized but still allowing struct field access on it. You still need to work out the proper operational semantics for that, but that seems reasonably orthogonal to the Sized hierarchy.
Unfortunately, this would probably only work for structs. For arrays, Rust array types ([T]) require the element to be Sized, so it probably makes sense to wait for the Sized hierarchy before trying to relax that.
Discussion in the ATmosphere