You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
These are some of my old notes on how to implement KnownLayout. They're no longer relevant, but I'm writing them down for posterity.
Replace KnownLayout::LAYOUT with associated types which represent:
Base size
Alignment
Trailing slice element type
When deriving KnownLayout for Foo { a: A, b: B, c: C }, synthesize the following type:
FooSynthesized {
a: A,
b: B,
c_sized: C::Base, // For T: Sized, T::Base = T, so for Foo: Sized, FooSynthesized has the same layout as Foo
_align: [C::TrailingSliceElement; 0]
}
For T: Sized, T::Base = T and T::TrailingSliceElement = (). Note that () has alignment 1, which means that, for Foo: Sized, Foo: Synthesized has the same layout as Foo (c_sized is just C, and _align adds no padding after c_sized).
We still need:
Some way to distinguish between sized and unsized types (since you can have an unsized type whose trailing slice element is ())
Is there any way to teach the type system that T: Sized is special? We don’t have a blanket impl to avoid impl conflicts. What are the advantages of being able to teach this to type system? At the time of writing, I'm not remembering why that was important, but maybe it has to do with this?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
These are some of my old notes on how to implement
KnownLayout
. They're no longer relevant, but I'm writing them down for posterity.Replace
KnownLayout::LAYOUT
with associated types which represent:When deriving KnownLayout for
Foo { a: A, b: B, c: C }
, synthesize the following type:For
T: Sized
,T::Base = T
andT::TrailingSliceElement = ()
. Note that()
has alignment 1, which means that, forFoo: Sized
,Foo: Synthesized
has the same layout asFoo
(c_sized
is justC
, and_align
adds no padding afterc_sized
).We still need:
()
)T: Sized
is special? We don’t have a blanket impl to avoid impl conflicts. What are the advantages of being able to teach this to type system? At the time of writing, I'm not remembering why that was important, but maybe it has to do with this?Beta Was this translation helpful? Give feedback.
All reactions