Skip to content

chore(redux): prefer core/alloc over std#2208

Open
0xDevNinja wants to merge 2 commits into
o1-labs:developfrom
0xDevNinja:fix/1260-redux-prefer-core
Open

chore(redux): prefer core/alloc over std#2208
0xDevNinja wants to merge 2 commits into
o1-labs:developfrom
0xDevNinja:fix/1260-redux-prefer-core

Conversation

@0xDevNinja
Copy link
Copy Markdown

Description

First incremental step toward #1260. Scope is the reusable libs/redux crate only — swap std::X for core::X / alloc::X wherever an equivalent exists, and add extern crate alloc; at the crate root.

Changes (8 files, +20/-17):

  • lib.rs — add extern crate alloc;
  • dispatcher.rsstd::collections::VecDequealloc::collections::VecDeque; std::marker::PhantomDatacore::marker::PhantomData
  • callback.rsstd::borrow::Cowalloc::borrow::Cow; std::any::{Any,type_name}core::any::{Any,type_name} (incl. inside the public _callback! macro body)
  • timestamp.rs, action/action_id.rs, action/action_with_meta.rs, action/action_meta.rsstd::time::Durationcore::time::Duration; impl std::ops::Addimpl core::ops::Add (3 impls)
  • instant.rsstd::{cell::RefCell, cmp, ops, time::Duration}core::{...}; std::fmt::{Debug,Formatter,Result}core::fmt::{...}

Left on std:: (no core/alloc equivalent):

  • std::sync::OnceLock in store.rs — needs platform sync primitives
  • std::time::Instant, std::time::SystemTime — not in core; existing wasm-timer shim already covers cfg(target_arch = "wasm32")
  • thread_local! macro in instant.rs — std-only macro

No behaviour change.

Related Issue(s)

Refs #1260.

Intentionally not a Closes#1260 spans the whole workspace. This PR lands the leaf library first to validate the direction; further crates (crates/core, crates/p2p, crates/node, crates/ledger, …) follow in separate PRs.

Type of Change

  • Refactoring (no functional changes)

Testing

Local, branched off fresh upstream/develop:

cargo check -p redux
cargo clippy -p redux --all-targets --no-deps -- --deny=warnings
cargo test -p redux
cargo check --workspace
cargo fmt --all --check
make check-trailing-whitespace

All green. cargo check --workspace produces only pre-existing warnings in crates/node and crates/p2p unrelated to this diff.

Changelog Entry

Changelog Summary: Changed the redux library to prefer core:: and alloc:: paths over std:: where possible (refs #1260).

Move imports in the `redux` library off `std::` where `core::` or
`alloc::` provide the same item. Adds `extern crate alloc;` to make
`alloc::collections::VecDeque` and `alloc::borrow::Cow` reachable.

Kept on `std::` because no `core`/`alloc` equivalent exists:
- `std::sync::OnceLock` (needs platform sync primitives)
- `std::time::Instant`, `std::time::SystemTime`
- `thread_local!` macro

No behaviour change. `cargo check`, `cargo clippy --deny=warnings`,
`cargo test -p redux`, and `cargo check --workspace` are all green.

Refs o1-labs#1260.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant