Skip to content

Commit

Permalink
actually no_std
Browse files Browse the repository at this point in the history
  • Loading branch information
tjjfvi committed May 27, 2024
1 parent 0350323 commit d311136
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
- run: RUSTFLAGS="-D warnings" cargo check --all-targets
- run: RUSTFLAGS="-D warnings" cargo check --all-targets --features trace
- run: RUSTFLAGS="-D warnings" cargo check --all-targets --no-default-features
- run: cargo install cargo-no-std-check
- run: cargo no-std-check --workspace --exclude hvm64 --no-default-features
clippy:
runs-on: ubuntu-latest
timeout-minutes: 10
Expand Down
7 changes: 2 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ debug = "full"
[dependencies]
clap = { version = "4.5.4", features = ["derive"] }
libloading = { version = "0.8.3", default-features = false }
ordered-float = { version = "4.2.0" }
ordered-float = { version = "4.2.0", default-features = false }
thiserror = "1.0.58"

hvm64-ast = { path = "./ast" }
Expand All @@ -52,3 +52,6 @@ serial_test = "3.0.0"
default = ["std"]
std = []
trace = ["hvm64-runtime/trace"]

[patch.crates-io]
highlight_error = { git = "https://github.com/tjjfvi/rust_highlight_error/", branch = "no_std" }
6 changes: 3 additions & 3 deletions ast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ path = "src/ast.rs"

[dependencies]
ordered-float = { version = "4.2.0", default-features = false }
TSPL = { version = "0.0.12", optional = true }
TSPL = { git = "https://github.com/tjjfvi/TSPL", branch = "no_std", optional = true }

hvm64-util = { path = "../util" }
hvm64-util = { path = "../util", default-features = false }

[features]
default = ["std", "parser"]
std = []
std = ["hvm64-util/std"]
parser = ["dep:TSPL"]

[lints]
Expand Down
1 change: 1 addition & 0 deletions ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
//! The AST is based on the [interaction calculus].
//!
//! [interaction calculus]: https://en.wikipedia.org/wiki/Interaction_nets#Interaction_calculus
#![cfg_attr(not(feature = "std"), no_std)]

include!("../../prelude.rs");

Expand Down
4 changes: 2 additions & 2 deletions host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ edition = "2021"
path = "src/host.rs"

[dependencies]
hvm64-util = { path = "../util" }
hvm64-util = { path = "../util", default-features = false }
hvm64-ast = { path = "../ast", default-features = false }
hvm64-runtime = { path = "../runtime", default-features = false }

[features]
default = ["std"]
std = ["hvm64-ast/std", "hvm64-runtime/std"]
std = ["hvm64-util/std", "hvm64-ast/std", "hvm64-runtime/std"]

[lints]
workspace = true
4 changes: 2 additions & 2 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ edition = "2021"
path = "src/runtime.rs"

[dependencies]
hvm64-util = { path = "../util" }
hvm64-util = { path = "../util", default-features = false }

[features]
default = ["std"]
std = []
std = ["hvm64-util/std"]
trace = ["std"]

[lints]
Expand Down
1 change: 1 addition & 0 deletions runtime/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
//! - active pairs are thus stored in a dedicated vector, `net.redexes`
#![feature(const_type_id, extern_types, inline_const, new_uninit)]
#![cfg_attr(feature = "trace", feature(const_type_name))]
#![cfg_attr(not(feature = "std"), no_std)]

include!("../../prelude.rs");

Expand Down
5 changes: 2 additions & 3 deletions transform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ path = "src/transform.rs"

[dependencies]
ordered-float = { version = "4.2.0", default-features = false }
thiserror = "1.0.58"

hvm64-util = { path = "../util" }
hvm64-util = { path = "../util", default-features = false }
hvm64-runtime = { path = "../runtime", default-features = false }
hvm64-ast = { path = "../ast", default-features = false }
hvm64-host = { path = "../host", default-features = false }

[features]
default = ["std"]
std = ["hvm64-runtime/std", "hvm64-ast/std", "hvm64-host/std"]
std = ["hvm64-util/std", "hvm64-runtime/std", "hvm64-ast/std", "hvm64-host/std"]

[lints]
workspace = true
12 changes: 10 additions & 2 deletions transform/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

include!("../../prelude.rs");

use crate::prelude::*;

use hvm64_ast::Book;

pub mod eta_reduce;
Expand All @@ -16,12 +18,18 @@ use prune::Prune;

#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
#[cfg_attr(feature = "std", derive(thiserror::Error))]
pub enum TransformError {
#[cfg_attr(feature = "std", error("infinite reference cycle in `@{0}`"))]
InfiniteRefCycle(String),
}

impl fmt::Display for TransformError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TransformError::InfiniteRefCycle(name) => write!(f, "infinite reference cycle in `@{name}`"),
}
}
}

pub trait Transform {
fn transform(&mut self, passes: TransformPasses, opts: &TransformOpts) -> Result<(), TransformError>;
}
Expand Down
6 changes: 5 additions & 1 deletion util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ version = "0.3.0"
edition = "2021"

[dependencies]
stacker = { version = "0.1.15" }
stacker = { version = "0.1.15", optional = true }

[features]
default = ["std"]
std = ["dep:stacker"]

[lints]
workspace = true
2 changes: 2 additions & 0 deletions util/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg_attr(not(feature = "std"), no_std)]

include!("../../prelude.rs");

pub mod ops;
Expand Down
6 changes: 6 additions & 0 deletions util/src/maybe_grow.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
/// Guard against stack overflows in recursive functions.
#[cfg(feature = "std")]
pub fn maybe_grow<R>(f: impl FnOnce() -> R) -> R {
stacker::maybe_grow(1024 * 32, 1024 * 1024, f)
}

#[cfg(not(feature = "std"))]
pub fn maybe_grow<R>(f: impl FnOnce() -> R) -> R {
f()
}

0 comments on commit d311136

Please sign in to comment.