Skip to content

feat: proper conversions - #791

Open
alejandro-vaz wants to merge 34 commits into
servo:v2from
alejandro-vaz:proper-conversions
Open

alejandro-vaz wants to merge 34 commits into
servo:v2from
alejandro-vaz:proper-conversions

Conversation

@alejandro-vaz

@alejandro-vaz alejandro-vaz commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

this remakes and generalizes conversions to comply fully with the allocator API and adds conversions to and from Cow

@alejandro-vaz alejandro-vaz self-assigned this Oct 22, 2026
@alejandro-vaz

Copy link
Copy Markdown
Collaborator Author

reminder: fix proptest and warnings above

@GauravPawar101

Copy link
Copy Markdown
Collaborator

Hey, shouldn't we break it into sub issues. As of now, I think it's too many breaking changes in a single PR

@alejandro-vaz

Copy link
Copy Markdown
Collaborator Author

honestly it all is intertwined so I'm not sure I can

to complete conversions I had to expand the Like trait in certain ways, and all else follows from that basically

I honestly prefer big scoped PRs over micro-ones because it retains my flow state better

@GauravPawar101

Copy link
Copy Markdown
Collaborator

No problem, let's just keep at it

@alejandro-vaz
alejandro-vaz requested a review from jdm October 24, 2026 12:11
@alejandro-vaz
alejandro-vaz marked this pull request as ready for review October 24, 2026 12:12

@jdm jdm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a really difficult PR to review. It's really big and it seems to mix functional changes with stylistic changes (like the try_from implementation, or renaming parameters/variables), so I had to read it really closely to figure out if anything was actually changing. Please find ways to keep those changes separate in the future.

Comment thread src/allocator/vec.rs Resolved
Comment thread src/allocator/vec.rs Outdated
Comment on lines +120 to +133
fn construct(
pointer: Option<NonNull<[MaybeUninit<Self::Item>]>>,
length: usize,
allocator: Self::Heap
) -> Self::Type {
if let Some(pointer) = pointer {
unsafe {
Self::Type::from_raw_parts_in(
pointer.as_ptr().cast(),
length,
pointer.len(),
allocator
)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am worried that this method is marked safe because the docs for https://doc.rust-lang.org/stable/std/vec/struct.Vec.html#method.from_raw_parts_in mention a bunch of reasons that's unsafe and those conditions do not appear to be checked anywhere.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is for internal use, but yes, it should be marked unsafe now that I think about it

I'll change it

Comment thread src/allocator/vec.rs Resolved
Comment thread src/conversions.rs Outdated
fn from(value: Cow<'_, [Item]>) -> Self {
match value {
Cow::Owned(mut vector) => unsafe {
Self::from_raw_parts(vector.as_mut_ptr(), vector.len(), vector.capacity())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this safe? from_raw_parts says it's for creating a smallvec from another smallvec, and that's not necessarily what is happening here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right, I've checked the invariants, we need #817 first

Comment thread src/conversions.rs Resolved
@alejandro-vaz
alejandro-vaz marked this pull request as draft October 28, 2026 17:10
@alejandro-vaz

Copy link
Copy Markdown
Collaborator Author

now awaiting #817

@alejandro-vaz
alejandro-vaz marked this pull request as ready for review October 30, 2026 17:22
@alejandro-vaz
alejandro-vaz requested a review from jdm October 30, 2026 17:22
@alejandro-vaz

Copy link
Copy Markdown
Collaborator Author

it now also adds the missing parts conversions. not the from ones, since those are unsafe, only the into ones

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.

3 participants