Skip to content

feat: new allocator features - #656

Open
alejandro-vaz wants to merge 11 commits into
servo:v2from
alejandro-vaz:new-allocators
Open

alejandro-vaz wants to merge 11 commits into
servo:v2from
alejandro-vaz:new-allocators

Conversation

@alejandro-vaz

@alejandro-vaz alejandro-vaz commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

this PR revamps the allocator features

feature hierarchy

  1. no features = custom allocator implemented
  2. allocator-api = requires nightly, uses the API
  3. allocator-api2 = pulls the API from crates.io

the allocator-api2 implies allocator-api, to make sure no weird case of both together when they should be disjoint exists

exported types

each of the three modes internally exports three types: Global, Vec and Box

which are then used in the rest of the API

that means that all conversions only happen to and from those types, not others

this is relevant to #649, though allocator-handling is a bit fucked up in the base case, so I'm not sure if it'd be easy to handle it there. and it unblocks #644

closes #655

closes #631

note: there is a regression in from_elem because I couldn't use the vec macro anymore without doing macro wizardry, so it now uses iterators again

@alejandro-vaz
alejandro-vaz requested a review from jdm September 21, 2026 21:07
@alejandro-vaz alejandro-vaz self-assigned this Sep 21, 2026
@alejandro-vaz

Copy link
Copy Markdown
Collaborator Author

well I think it makes more sense to invert the dependency dependencies of the two allocator ones and have the allocator-api2 as the default

@alejandro-vaz
alejandro-vaz marked this pull request as draft September 21, 2026 21:09
@alejandro-vaz

Copy link
Copy Markdown
Collaborator Author

ah no, can't do that because the nightly one then will randomly download allocator-api2 which is pointless

@alejandro-vaz
alejandro-vaz marked this pull request as ready for review September 21, 2026 21:11
@alejandro-vaz

Copy link
Copy Markdown
Collaborator Author

I've disabled one fuzzing operation because it magically failed to compile

we have to remake fuzzing anyway so I'm not worried, see #657

@alejandro-vaz

Copy link
Copy Markdown
Collaborator Author

I will fix the fuzzing stuff once #658 lands

@bolshoytoster

Copy link
Copy Markdown
Contributor

note: there is a regression in from_elem because I couldn't use the vec macro anymore without doing macro wizardry, so it now uses iterators again

I've been able to get it to work by just exporting the macro from the allocator/ modules. Although I have to add #[rustfmt::skip] to stop it from merging

pub use alloc::{
    vec::Vec,
    vec
};

into

pub use alloc::{
    vec::{
        self,
        Vec
    }
};

@alejandro-vaz

Copy link
Copy Markdown
Collaborator Author

yeah that's exactly what I didn't want to do

do we have any other alternative??

maybe

#[rustfmt::skip]
pub use alloc::vec;

@bolshoytoster

Copy link
Copy Markdown
Contributor

Yeah I think that should work too.

@bolshoytoster

Copy link
Copy Markdown
Contributor

Does this PR mean you can only From/Into the Vec exposed by allocator?

Given that the default would be allocator-api2::vec::Vec, would it be nice to at least make sure SmallVec<T, N, Global> from/into alloc::vec::Vec<T, Global> are supported?

@alejandro-vaz

alejandro-vaz commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator Author

that's a good point

maybe by default we should disable all features and that's it honestly

very few people use custom allocators yet anyway

it'd also make CI simpler

@pedrodesu

Copy link
Copy Markdown
Contributor

I've disabled one fuzzing operation because it magically failed to compile

we have to remake fuzzing anyway so I'm not worried, see #657

What did it complain about?

@alejandro-vaz

Copy link
Copy Markdown
Collaborator Author

actually I think it'll work now

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.

remove may_dangle feature description from ./README.md allow v2 to always compile in MSRV with no features enabled

3 participants