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
Hey there, using abi_stable I've noticed significant size requirements for performing layout checks. It appears to stem from indirection caused by accessing type IDs and layouts within TypeLayout and SharedVars through ctors. This leads to explosion of tiny functions bloating the binary/library size. If I am not mistaken, this was done due to self-referential structures and it being impossible for the compiler to deal with.
The trick here is to have 2 type IDs, one that evaluates IDs within its type, and the other "shallow" one that skips the contents of the type. This way everything is evaluated until the last type, however, this still does not solve the self-referential cycles. The latter is solved by providing special implementations for all 4 types of indirection available in rust (mut/const references and pointers) that use only the shallow type ID. This works, because T: StableAbi implies &T: StableAbi. The example works with generating unique Type IDs, however, I think it would similarly be able to be extended over to TypeLayouts as well. Finally, it may even be possible to reduce a lot of type checking into a single stable hash value.
The question is, would the implementation of this be in your interest? I believe this would lead to positive impact to all abi_stable users and am willing to implement it, however, it would be great to do it in cooperation, as I do not want to miss out on key details regarding prefix types, reflection, etc.
The text was updated successfully, but these errors were encountered:
Hey there, using abi_stable I've noticed significant size requirements for performing layout checks. It appears to stem from indirection caused by accessing type IDs and layouts within
TypeLayout
andSharedVars
through ctors. This leads to explosion of tiny functions bloating the binary/library size. If I am not mistaken, this was done due to self-referential structures and it being impossible for the compiler to deal with.I tinkered a little bit, trying to see if one could come up with a way to support self-referential structures while staying completely in compile-time, and here is a little PoC:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1e622b3aea8aa4437a25cae2646de820
The trick here is to have 2 type IDs, one that evaluates IDs within its type, and the other "shallow" one that skips the contents of the type. This way everything is evaluated until the last type, however, this still does not solve the self-referential cycles. The latter is solved by providing special implementations for all 4 types of indirection available in rust (mut/const references and pointers) that use only the shallow type ID. This works, because
T: StableAbi
implies&T: StableAbi
. The example works with generating unique Type IDs, however, I think it would similarly be able to be extended over toTypeLayout
s as well. Finally, it may even be possible to reduce a lot of type checking into a single stable hash value.The question is, would the implementation of this be in your interest? I believe this would lead to positive impact to all abi_stable users and am willing to implement it, however, it would be great to do it in cooperation, as I do not want to miss out on key details regarding prefix types, reflection, etc.
The text was updated successfully, but these errors were encountered: