-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dynamic alignment support #2
Comments
I designed in constant alignment to make the runtime offset calculations cheaper. In theory we could extend this with support for dynamic alignment, together with an option to say "this type's alignment is actually known statically; no need to calculate it dynamically". I haven't thought through all the implications of this. Can you pad alignment up to a predefined max alignment? E.g. universally forcing alignment of 16 bytes is fairly common in some systems. |
Thanks for getting back to me so quickly!
That makes sense---how difficult do you think adding this dynamic alignment would be?
This would probably work for most objective-c programs, but the runtime spec allows consumers to specify arbitrary (power of 2) alignments when adding instance variables to classes. |
In principle it's doable. We'd remove That gets us to a point where the trait system at least allows you to do what you'd like. However, the types produced by the
In fact, I can't immediately see how to map your usecase to the |
I'm actually not using the #[repr(C)]
pub struct Repr<T> {
/// Pointer to this object's class.
is_a: Receiver,
data: T,
} This is supposed to help me model the objective-c Then I fill the #[define_varlen]
pub struct ObjectData {
#[controls_layout]
pub(crate) ivar_bytes: usize,
#[varlen_array]
pub(crate) ivars: [u8; *ivar_bytes],
} . I'm simplifying by assuming the dispatch table is just instance variables and not methods or the like. The when we create an instance of the class, we have access to a |
Thanks! So if I'm understanding this correctly, if you wanted dynamic alignment support, you'd probably do something like this:
Am I getting that right? (The generics issue with |
Yeah that's exactly right! It'd be extra nice if I could just stick a Regarding |
Is there anything I can do to help realize this in varlen? I'm not super comfortable developing macros but willing to learn. |
Thanks for the offer! I'll give some advice at the end of this comment for how you can try out what I described above. However, I should say that I still have some reservations about whether this alignment support is a good fit for (a) your problem and (b) the varlen library. Regarding (b), my reservation is that varlen is aimed at the use case of storing variable-length arrays inline in objects in support of better (faster and smaller) memory layouts than Vec<> would offer. The alignment support currently built into varlen is sufficient for that, because we're using arrays of known types. In contrast, alignment support only seems to show up when we have unknown (dynamic) typing, as in your scenario. I suspect that when doing dynamic typing of this form, there are many additional concerns that the varlen library doesn't handle: for example, safely transmuting from the (static) child type to the (dynamic) parent type; or doing method dispatch for known methods of the child type; etc. I didn't intend for varlen to solve all of those concerns, and I suspect that just solving this alignment issue for that use case doesn't provide enough of a help to be worth it in that case. Regarding (a), from the description you've given I suspect you must already need a substantial amount of code to (1) calculate the layout for instance variables and (2) read/write instance variables and bytecast/transmute between u8 arrays and the true types of your instance variables. I don't think varlen will provide assistance with those concerns, and I suspect you will need to end up writing Perhaps I'm wrong in understanding what value Guidance on trying this out in
|
Hello.
I am trying to implement an objective-c runtime in rust. I'm currently working on building dispatch tables. The runtime's api allows dynamic creation of classes (and thus the dynamic addition of instance variables and methods to the class), causing the dispatch tables to have variable length, hence my interest in this crate.
One issue, however, is that in addition to the dispatch tables having variable length, they can also have variable alignment, depending on what types of instance variables have been added to the class the object is an instance of. Unfortunately, the
VarLen
trait requires a constant alignment.Is there a way around this for me?
The text was updated successfully, but these errors were encountered: