Skip to content
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

Refactor and export AssumeInit trait from rten-tensor and use it downstream #598

Merged
merged 2 commits into from
Feb 15, 2025

Conversation

robertknight
Copy link
Owner

Refactor and export the internal AssumeInit trait from rten-tensor and use it to replace several [MaybeUninit<T>] -> [T] casts downstream in the rten crate. This makes it more obvious what those casts are doing and what the safety requirements are.

Move the `AssumeInit` trait used in lazy initialization of collections into its
own submodule, expand the documentation and export it for use in downstream
crates.

In the process the implementation for `Vec<MaybeUninit<T>>` was reworked to be
more sound. The previous transmute assumed that `Vec<MaybeUninit<T>>` and
`Vec<T>` have the same representation. I believe that is true in practice but
not guaranteed. The new implementation de-constructs and then re-constructs the
`Vec` in way that I believe should be sound.
This is both more succinct than using a transmute and also more explicit /
obvious about what the cast is doing and what the safety requirements are.
@robertknight robertknight merged commit 024c1e9 into main Feb 15, 2025
2 checks passed
@robertknight robertknight deleted the assume-init-refactor branch February 15, 2025 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant