Skip to content

alloc: allow containers to use custom allocators#77

Merged
pawelrutkaq merged 1 commit intoeclipse-score:mainfrom
qorix-group:arkjedrz_allocator-changes
Mar 26, 2026
Merged

alloc: allow containers to use custom allocators#77
pawelrutkaq merged 1 commit intoeclipse-score:mainfrom
qorix-group:arkjedrz_allocator-changes

Conversation

@arkjedrz
Copy link
Copy Markdown
Contributor

@arkjedrz arkjedrz commented Mar 23, 2026

Reworked abstraction to allow usage of custom allocator implementations.

Notes for Reviewer

Pre-Review Checklist for the PR Author

  • PR title is short, expressive and meaningful
  • Commits are properly organized
  • Relevant issues are linked in the References section
  • Tests are conducted
  • Unit tests are added

Checklist for the PR Reviewer

  • Commits are properly organized and messages are according to the guideline
  • Unit tests have been written for new behavior
  • Public API is documented
  • PR title describes the changes

Post-review Checklist for the PR Author

  • All open points are addressed and tracked via issues

References

Closes #81

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 23, 2026

License Check Results

🚀 The license check job ran with the Bazel command:

bazel run --lockfile_mode=error //:license-check

Status: ⚠️ Needs Review

Click to expand output
[License Check Output]
Extracting Bazel installation...
Starting local Bazel server (8.4.2) and connecting to it...
INFO: Invocation ID: 578de106-3853-4bd4-ab5f-098085396f7b
Computing main repo mapping: 
Computing main repo mapping: 
WARNING: For repository 'rules_python', the root module requires module version rules_python@1.4.1, but got rules_python@1.8.3 in the resolved dependency graph. Please update the version in your MODULE.bazel or set --check_direct_dependencies=off
WARNING: For repository 'bazel_skylib', the root module requires module version bazel_skylib@1.7.1, but got bazel_skylib@1.8.2 in the resolved dependency graph. Please update the version in your MODULE.bazel or set --check_direct_dependencies=off
WARNING: For repository 'rules_rust', the root module requires module version rules_rust@0.61.0, but got rules_rust@0.67.0 in the resolved dependency graph. Please update the version in your MODULE.bazel or set --check_direct_dependencies=off
WARNING: For repository 'rules_cc', the root module requires module version rules_cc@0.1.1, but got rules_cc@0.2.14 in the resolved dependency graph. Please update the version in your MODULE.bazel or set --check_direct_dependencies=off
WARNING: For repository 'buildifier_prebuilt', the root module requires module version buildifier_prebuilt@7.3.1, but got buildifier_prebuilt@8.2.0.2 in the resolved dependency graph. Please update the version in your MODULE.bazel or set --check_direct_dependencies=off
Loading: 
Loading: 0 packages loaded
Loading: 0 packages loaded
Loading: 0 packages loaded
    currently loading: 
Loading: 0 packages loaded
    currently loading: 
Analyzing: target //:license-check (1 packages loaded, 0 targets configured)
Analyzing: target //:license-check (1 packages loaded, 0 targets configured)

Analyzing: target //:license-check (30 packages loaded, 9 targets configured)

Analyzing: target //:license-check (87 packages loaded, 9 targets configured)

Analyzing: target //:license-check (143 packages loaded, 1088 targets configured)

Analyzing: target //:license-check (143 packages loaded, 1088 targets configured)

Analyzing: target //:license-check (153 packages loaded, 2723 targets configured)

Analyzing: target //:license-check (157 packages loaded, 3177 targets configured)

Analyzing: target //:license-check (165 packages loaded, 3236 targets configured)

Analyzing: target //:license-check (165 packages loaded, 3236 targets configured)

Analyzing: target //:license-check (166 packages loaded, 3236 targets configured)

Analyzing: target //:license-check (168 packages loaded, 5125 targets configured)

Analyzing: target //:license-check (168 packages loaded, 5125 targets configured)

Analyzing: target //:license-check (168 packages loaded, 5125 targets configured)

Analyzing: target //:license-check (168 packages loaded, 5125 targets configured)

Analyzing: target //:license-check (168 packages loaded, 5125 targets configured)

Analyzing: target //:license-check (168 packages loaded, 5125 targets configured)

Analyzing: target //:license-check (175 packages loaded, 5459 targets configured)
[1 / 1] no actions running
Analyzing: target //:license-check (197 packages loaded, 5552 targets configured)
[13 / 17] JavaToolchainCompileClasses external/rules_java+/toolchains/platformclasspath_classes; 0s disk-cache, processwrapper-sandbox ... (2 actions, 1 running)
INFO: From Generating Dash formatted dependency file ...:
INFO: Successfully converted 5 packages from Cargo.lock to bazel-out/k8-fastbuild/bin/formatted.txt
Analyzing: target //:license-check (197 packages loaded, 5552 targets configured)
[15 / 17] JavaToolchainCompileBootClasspath external/rules_java+/toolchains/platformclasspath.jar; 0s disk-cache, processwrapper-sandbox
Analyzing: target //:license-check (197 packages loaded, 5552 targets configured)
[17 / 17] no actions running
INFO: Analyzed target //:license-check (198 packages loaded, 9886 targets configured).
INFO: Found 1 target...
Target //:license.check.license_check up-to-date:
  bazel-bin/license.check.license_check
  bazel-bin/license.check.license_check.jar
[17 / 17] no actions running
INFO: Elapsed time: 32.515s, Critical Path: 3.44s
INFO: 17 processes: 12 internal, 4 processwrapper-sandbox, 1 worker.
INFO: Build completed successfully, 17 total actions
INFO: Running command line: bazel-bin/license.check.license_check ./formatted.txt <args omitted>
usage: org.eclipse.dash.licenses.cli.Main [-batch <int>] [-cd <url>]
       [-confidence <int>] [-ef <url>] [-excludeSources <sources>] [-help] [-lic
       <url>] [-project <shortname>] [-repo <url>] [-review] [-summary <file>]
       [-timeout <seconds>] [-token <token>]

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the container/storage abstraction to support custom allocator implementations, and wires the containers crate to use the elementary allocator interfaces.

Changes:

  • Reworks Storage usage so generic containers are constructed with a concrete storage instance (instead of Storage::new/try_new on the trait).
  • Adds allocator-parameterization to heap-backed storage and fixed-capacity containers via BasicAllocator (defaulting to GlobalAllocator).
  • Reshapes elementary’s public surface by re-exporting allocator types at the crate root and updating GlobalAllocator to the new BasicAllocator signatures.

Reviewed changes

Copilot reviewed 18 out of 19 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/sync/arc_in.rs Updates imports to the new elementary re-exports.
src/elementary/lib.rs Makes modules private and re-exports BasicAllocator, GlobalAllocator, etc.
src/elementary/global_allocator.rs Updates GlobalAllocator to new BasicAllocator API + derives Default.
src/elementary/allocator_traits.rs Changes BasicAllocator bounds/signatures (notably adds Default).
src/containers/storage/mod.rs Removes constructor methods from Storage; adds test-only TestVec storage impl.
src/containers/storage/inline.rs Updates inline storage construction (new() + Default).
src/containers/storage/heap.rs Introduces allocator-generic heap storage and *_in constructors.
src/containers/inline/vec.rs Adjusts to construct GenericVec with Inline storage instance.
src/containers/inline/string.rs Adjusts to construct GenericString with Inline storage instance.
src/containers/inline/queue.rs Adjusts to construct GenericQueue with Inline storage instance.
src/containers/generic/vec.rs GenericVec::new now takes storage; tests use TestVec.
src/containers/generic/string.rs GenericString::new now takes storage; tests use TestVec.
src/containers/generic/queue.rs GenericQueue::new now takes storage; tests use TestVec.
src/containers/fixed_capacity/vec.rs Adds allocator generic parameter + new_in/try_new_in.
src/containers/fixed_capacity/string.rs Adds allocator generic parameter + new_in/try_new_in.
src/containers/fixed_capacity/queue.rs Adds allocator generic parameter + new_in.
src/containers/Cargo.toml Adds dependency on elementary.
src/containers/BUILD Adds Bazel dep on //src/elementary.
Cargo.lock Records containers -> elementary dependency.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@arkjedrz arkjedrz force-pushed the arkjedrz_allocator-changes branch from 8319dec to 658f82e Compare March 23, 2026 11:37
@arkjedrz arkjedrz requested a deployment to workflow-approval March 23, 2026 11:37 — with GitHub Actions Waiting
@arkjedrz arkjedrz requested a deployment to workflow-approval March 23, 2026 11:37 — with GitHub Actions Waiting
Reworked abstraction to allow usage of custom allocator implementations.
@arkjedrz arkjedrz force-pushed the arkjedrz_allocator-changes branch from 658f82e to 4680977 Compare March 24, 2026 14:26
@arkjedrz arkjedrz temporarily deployed to workflow-approval March 24, 2026 14:26 — with GitHub Actions Inactive
@arkjedrz arkjedrz temporarily deployed to workflow-approval March 24, 2026 14:26 — with GitHub Actions Inactive
pub trait BasicAllocator {
/// Allocates a block of memory as described by `layout`.
fn allocate(&self, layout: core::alloc::Layout) -> Result<NonNull<[u8]>, AllocationError>;
fn allocate(&self, layout: Layout) -> Result<NonNull<u8>, AllocationError>;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why change ? At the end we allocate the array of u8 always.

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.

Because this prevents usage of NonNull::dangling due to the size for values of type [u8] cannot be known at compilation time.

}

impl<T: fmt::Debug> fmt::Debug for FixedCapacityVec<T> {
impl<T: fmt::Debug, A: BasicAllocator> fmt::Debug for FixedCapacityVecIn<'_, T, A> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe we shal ladd ScoreDebug too.

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.

To be done in scope of #82

@pawelrutkaq pawelrutkaq marked this pull request as ready for review March 26, 2026 09:11
@arkjedrz arkjedrz requested a review from pawelrutkaq March 26, 2026 10:46
@github-project-automation github-project-automation bot moved this from In Progress to On Hold in BAS - Baselibs FT Mar 26, 2026
@pawelrutkaq pawelrutkaq merged commit 17b3140 into eclipse-score:main Mar 26, 2026
14 checks passed
@github-project-automation github-project-automation bot moved this from On Hold to Done in BAS - Baselibs FT Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Improvement: Allow custom allocators in containers

3 participants