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

Fold the allocator back into the mnemos repo #54

Merged
merged 26 commits into from
Jun 4, 2023
Merged

Conversation

jamesmunns
Copy link
Contributor

This undoes a decision from about a year ago to move the allocator into its own crate.

Merged as an "unrelated history", meaning all history is retained.

This should NOT be a squash merge.

jamesmunns and others added 23 commits June 26, 2022 22:51
This branch adds `fmt::Debug`, `fmt::Display`, and `fmt::Pointer` impls
to `HeapArc`, `HeapArray`, and `HeapFixedVec`, as appropriate. The
`Display` and `Debug` impls forward to the inner types, and require
`T: fmt::Debug` or `T: fmt::Display`; on the other hand, the
`fmt::Pointer` impls are always present regardless of `T` and display
the address of the heap allocation.

I wanted the `fmt::Pointer` impls specifically for #4, so
that the bbqueue traces could include the address of the shared buffer,
but they didn't exist at the time, so I thought they would be nice to
add.
Add `fmt` trait impls for heap containers
This commit fixes some implementations of `Send` and `Sync` for the
`HeapFoo` container types that were either wrong or missing. In
particular:

- No heap container types currently implement `Sync`. This is
  unfortunate when trying to spawn Tokio tasks in `melpomene`, since
  tasks must be `Send + Sync` to be spawned. I've added `Sync` impls for
  all the heap types.
- The `Send` implementations for `HeapBox`, `HeapArray`, and
  `HeapFixedVec` do not require that `T: Send`. This is incorrect;
  sending a `HeapBox<T>` where `T: !Send` is functionally equivalent to
  sending a `T`. Note that (for ereference) `alloc::boxed::Box`'s `Send`
  impl [requires `T: Send`][1].
- The `Send` and `Sync` impls for `HeapArc<T>` both require
  `T: Send + Sync`, since sending an `Arc<T>` across threads is morally
  equivalent to sending an `&T`. Again, these are the same bounds as the
  `Send` and `Sync` [impls for `alloc::sync::Arc`][2].

[1]:
    https://doc.rust-lang.org/stable/alloc/boxed/struct.Box.html#impl-Send

[2]:
    https://doc.rust-lang.org/stable/alloc/sync/struct.Arc.html#impl-Send
containers: fix missing and wrong `Send` + `Sync` impls
This branch adds new APIs for lower-level manual memory management.
The `Heap::allocate_raw` method takes a user-provided `Layout` and
allocates an unsized, untyped allocation for that layout. The `unsafe`
free function `deallocate_raw` deallocates a pointer and `Layout` pair
that were allocated by `allocate_raw`. Together, these (unsafe) APIs
allow the implementation of user-defined types which manually manage a
dynamically-sized allocation, which was not previously possible with
`mnemos-alloc`.

Closes #4

Note that unlike the proposed interface in #4, this does *not* allow a
`HeapBox` to own a `!Sized` type. I'd like to figure that out
eventually, but it's somewhat orthogonal to the central concern of "how
do I allocate a raw `Layout`?

Co-authored-by: James Munns <james@onevariable.com>
* Correct alignment of unsized items
* Address review comments
This branch updates the `cordyceps` and `maitake` dependencies to
hawkw/mycelium@5e46e35.
@netlify
Copy link

netlify bot commented Jun 4, 2023

Deploy Preview for merry-scone-cc7a60 ready!

Name Link
🔨 Latest commit 376d41e
🔍 Latest deploy log https://app.netlify.com/sites/merry-scone-cc7a60/deploys/647bebfb80ba4300081146dc
😎 Deploy Preview https://deploy-preview-54--merry-scone-cc7a60.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Copy link
Contributor

@hawkw hawkw left a comment

Choose a reason for hiding this comment

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

let's goooooo

@hawkw
Copy link
Contributor

hawkw commented Jun 4, 2023

i love how the first commit in this history is "Export from mnemos super repo"

@jamesmunns jamesmunns merged commit 04d4a80 into main Jun 4, 2023
@jamesmunns jamesmunns deleted the james/monorepo-alloc branch June 4, 2023 01:45
jamesmunns added a commit that referenced this pull request Jun 4, 2023
Monorepo the `forth3` project.

Keeps forth3 and f3repl, forthboy's parts now live in https://github.com/tosc-rs/teletype/.

Same deal as #54.
@jamesmunns jamesmunns added the area: kernel Related to the cross-platform kernel label Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: kernel Related to the cross-platform kernel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants