Skip to content

feat: expand allocator support in specialization.rs (#710) - #759

Closed
Ankit-cs wants to merge 2 commits into
servo:v2from
Ankit-cs:fix/710-allocator-specialization
Closed

Ankit-cs wants to merge 2 commits into
servo:v2from
Ankit-cs:fix/710-allocator-specialization

Conversation

@Ankit-cs

@Ankit-cs Ankit-cs commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Description

This PR addresses the allocator expansion task for specialization.rs (#710).

The following specialization traits have been updated to be generic over Heap: Allocator rather than being hardcoded to the Global allocator:

  • SpecFromElem (for both Clone and Copy item implementations)
  • SpecFromSlice (for both Clone and Copy item implementations)

Note on SpecFromIterator:
As discussed in the main allocator tracking issue by @bolshoytoster and @alejandro-vaz, expanding FromIterator to custom allocators would awkwardly require A: Allocator + Default. To stay consistent with standard library patterns, SpecFromIterator was intentionally left untouched and remains bound to Global.

Related Issue

Fixes #710

@Ankit-cs

Ankit-cs commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

lookin for feedback for the above pr @alejandro-vaz

Comment thread benches/bench.rs Outdated
const SPILLED_SIZE: usize = 100;

trait Vector<T>: for<'a> From<&'a [T]> + Extend<T> + FromIterator<T> {
/// A trait defining common vector operations, implemented by vectors taking items from a slice of lifetime 'slice.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

remove the doc comment, we really aren't reading them at all

we will figure out in rc what doc comments we really need

Comment thread fuzz/fuzz_targets/main.rs Outdated
// Bounded `usize` between `0..=CAP`
impl<'a, const CAP: usize> Arbitrary<'a> for Bounded<usize, CAP> {
impl<'data, const CAP: usize> Arbitrary<'data> for Bounded<usize, CAP> {
/// Generates an arbitrary bounded usize value using the unstructured fuzzing data of lifetime 'data.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same

Comment thread fuzz/fuzz_targets/main.rs Outdated
where T: Arbitrary<'data>
{
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
/// Generates an arbitrary bounded vector by consuming items from the unstructured data stream of lifetime 'data.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

above

Comment thread tests/main.rs Outdated
fn splice_reserve_panic() {
struct CountDrop<'a>(&'a Cell<usize>);
/// A helper struct that increments a counter when dropped, bound to the cell's lifetime 'cell.
struct CountDrop<'cell>(&'cell Cell<usize>);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

change this to 'valid

Comment thread tests/main.rs Outdated
struct DropCounter<'cell>(&'cell Cell<i32>);

impl<'a> Drop for DropCounter<'a> {
impl<'cell> Drop for DropCounter<'cell> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

and this

Comment thread tests/main.rs Outdated
#[test]
fn splice_reserve_panic() {
struct CountDrop<'a>(&'a Cell<usize>);
/// A helper struct that increments a counter when dropped, bound to the cell's lifetime 'cell.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

no doc comment

Comment thread tests/main.rs Outdated
#[test]
fn into_iter_drop() {
struct DropCounter<'a>(&'a Cell<i32>);
/// A helper struct that increments a counter when dropped, bound to the cell's lifetime 'cell.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

neither

@alejandro-vaz

Copy link
Copy Markdown
Collaborator

also half of the checks fail

@Ankit-cs

Ankit-cs commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Ooh sorry for that I will to solve this fully by tomorrow morning and make sure every checks passes

@alejandro-vaz

Copy link
Copy Markdown
Collaborator

you there?? no pressure

@Ankit-cs

Copy link
Copy Markdown
Contributor Author

Yes sir I got a fever for 3 days

@alejandro-vaz

Copy link
Copy Markdown
Collaborator

hahahaha fair brother fair

@Ankit-cs

Copy link
Copy Markdown
Contributor Author

Hi @alejandro-vaz, I am here! I have addressed all your review comments:

Removed the doc comments on Vector, Arbitrary implementations, and test helper structs.
Renamed all remaining lifetimes ('slice, 'data, 'cell) to 'valid.
The changes have just been pushed to this branch. But i am unable to solve this checks any guidance for this ?

@Ankit-cs
Ankit-cs force-pushed the fix/710-allocator-specialization branch from ff5d79a to e18d381 Compare October 15, 2026 07:43
@alejandro-vaz

Copy link
Copy Markdown
Collaborator

conflicts to be solved now in the base allocator

@Ankit-cs

Copy link
Copy Markdown
Contributor Author

OK sir just 30 minutes I will solve this ci part

@Ankit-cs
Ankit-cs force-pushed the fix/710-allocator-specialization branch from e18d381 to 4f072ac Compare October 16, 2026 05:03
@Ankit-cs

Copy link
Copy Markdown
Contributor Author

thanks @alejandro-vaz the above suggestion work successfuly

@alejandro-vaz alejandro-vaz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm wondering if any of the implementations indeed needs allocator support on specialization at all

Comment thread src/lib.rs Outdated
Comment on lines 119 to 126
impl<Item, const INLINE: usize, Heap: Allocator + Default> Default
for SmallVec<Item, INLINE, Heap>
{
#[inline]
fn default() -> Self {
Self::new()
Self::new_in(Heap::default())
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this is wrong, no allocator support should be added here

default should always use the global allocator

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok sir

Comment thread src/lib.rs Outdated
/// a separate implementation block for easy access whenever specialization is
/// disabled.
impl<Item, const INLINE: usize> SmallVec<Item, INLINE, Global> {
impl<Item, const INLINE: usize, Heap: Allocator + Default> SmallVec<Item, INLINE, Heap> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same as above

Comment thread src/lib.rs Outdated
unsafe fn from_elem_fallback(elem: Item, n: usize) -> Self
where Item: Clone {
let mut result = Self::new();
let mut result = Self::new_in(Heap::default());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same

Comment thread src/lib.rs Outdated
unsafe fn from_slice_fallback(slice: &[Item]) -> Self
where Item: Clone {
let mut v = Self::new();
let mut v = Self::new_in(Heap::default());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same

Comment thread src/specialization.rs Outdated
}

impl<Item: Clone, const INLINE: usize> SpecFromElem<Item> for SmallVec<Item, INLINE, Global> {
impl<Item: Clone, const INLINE: usize, Heap: Allocator + Default> SpecFromElem<Item>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same as above

Comment thread src/specialization.rs Outdated
Comment on lines +35 to +37
impl<Item: Copy, const INLINE: usize, Heap: Allocator + Default> SpecFromElem<Item>
for SmallVec<Item, INLINE, Heap>
{

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same

Comment thread src/specialization.rs Outdated
{
unsafe fn spec_from_elem(elem: Item, n: usize) -> Self {
let mut result = Self::new();
let mut result = Self::new_in(Heap::default());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same

Comment thread src/specialization.rs Outdated
Comment on lines +305 to +307
impl<Item: Clone, const INLINE: usize, Heap: Allocator + Default> SpecFromSlice<Item>
for SmallVec<Item, INLINE, Heap>
{

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same as above

Comment thread src/specialization.rs Outdated
Comment on lines +314 to +316
impl<Item: Copy, const INLINE: usize, Heap: Allocator + Default> SpecFromSlice<Item>
for SmallVec<Item, INLINE, Heap>
{

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same

Comment thread src/specialization.rs Outdated
{
unsafe fn spec_from(slice: &[Item]) -> Self {
let mut v = Self::new();
let mut v = Self::new_in(Heap::default());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same

@Ankit-cs

Copy link
Copy Markdown
Contributor Author

Ok sir i will complete all the above feedback by the Eod

@Ankit-cs

Copy link
Copy Markdown
Contributor Author

Updated! Reverted Default, from_elem, and from_slice specializations back to SmallVec<Item, INLINE, Global>. Constructors without an allocator parameter shouldn't assume Heap: Allocator + Default. Pushed in commit 751df21.
Looking for feedback @alejandro-vaz

@alejandro-vaz

Copy link
Copy Markdown
Collaborator

well yeah... no files changed

specialization didn't need allocator support now I'm realizing

thanks @Ankit-cs for finding out

@Ankit-cs

Copy link
Copy Markdown
Contributor Author

OK @alejandro-vaz sir Finally it's completed

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.

allocator expansion for specialization.rs

2 participants