From 25c8b89e5b1aa2aa45686c4906bb5988d26b9d0a Mon Sep 17 00:00:00 2001 From: tjjfvi Date: Mon, 27 May 2024 16:36:05 -0400 Subject: [PATCH] actually no_std --- .github/workflows/checks.yml | 2 ++ Cargo.lock | 7 ++----- Cargo.toml | 5 ++++- ast/Cargo.toml | 6 +++--- ast/src/ast.rs | 1 + host/Cargo.toml | 4 ++-- runtime/Cargo.toml | 4 ++-- runtime/src/runtime.rs | 1 + transform/Cargo.toml | 5 ++--- transform/src/transform.rs | 12 ++++++++++-- util/Cargo.toml | 6 +++++- util/src/lib.rs | 2 ++ util/src/maybe_grow.rs | 6 ++++++ 13 files changed, 42 insertions(+), 19 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 2717b200..8bdad5b6 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -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 diff --git a/Cargo.lock b/Cargo.lock index f2335691..b1daa4d7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5,8 +5,7 @@ version = 3 [[package]] name = "TSPL" version = "0.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52dfd6238b1461b99635b26585a85b4e7b9c786cc0481b3c540ae5f590b6dfb6" +source = "git+https://github.com/tjjfvi/TSPL?branch=no_std#35e172d6369794c6a81c9cd1bb249277e66e79c6" dependencies = [ "highlight_error", ] @@ -266,8 +265,7 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "highlight_error" version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "809e18805660d7b6b2e2b9f316a5099521b5998d5cba4dda11b5157a21aaef03" +source = "git+https://github.com/tjjfvi/rust_highlight_error/?branch=no_std#e4136b3dd5a80699ecbab8fe708433da21ff1be1" [[package]] name = "hvm64" @@ -320,7 +318,6 @@ dependencies = [ "hvm64-runtime", "hvm64-util", "ordered-float", - "thiserror", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index c25e4188..ffeb91ab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" } @@ -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" } diff --git a/ast/Cargo.toml b/ast/Cargo.toml index b2894996..4a6d9a3f 100644 --- a/ast/Cargo.toml +++ b/ast/Cargo.toml @@ -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] diff --git a/ast/src/ast.rs b/ast/src/ast.rs index 33d2f942..2dee343d 100644 --- a/ast/src/ast.rs +++ b/ast/src/ast.rs @@ -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"); diff --git a/host/Cargo.toml b/host/Cargo.toml index 3a5b2901..e337a6d5 100644 --- a/host/Cargo.toml +++ b/host/Cargo.toml @@ -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 diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index d05a9e7d..c8cc6661 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -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] diff --git a/runtime/src/runtime.rs b/runtime/src/runtime.rs index 7b35dcf7..9a14ee34 100644 --- a/runtime/src/runtime.rs +++ b/runtime/src/runtime.rs @@ -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"); diff --git a/transform/Cargo.toml b/transform/Cargo.toml index 3ccccf36..1024942e 100644 --- a/transform/Cargo.toml +++ b/transform/Cargo.toml @@ -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 diff --git a/transform/src/transform.rs b/transform/src/transform.rs index 4ef6f811..b6bfcc4f 100644 --- a/transform/src/transform.rs +++ b/transform/src/transform.rs @@ -2,6 +2,8 @@ include!("../../prelude.rs"); +use crate::prelude::*; + use hvm64_ast::Book; pub mod eta_reduce; @@ -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>; } diff --git a/util/Cargo.toml b/util/Cargo.toml index 304adf21..b2cfbf56 100644 --- a/util/Cargo.toml +++ b/util/Cargo.toml @@ -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 diff --git a/util/src/lib.rs b/util/src/lib.rs index be7b857e..d080f897 100644 --- a/util/src/lib.rs +++ b/util/src/lib.rs @@ -1,3 +1,5 @@ +#![cfg_attr(not(feature = "std"), no_std)] + include!("../../prelude.rs"); pub mod ops; diff --git a/util/src/maybe_grow.rs b/util/src/maybe_grow.rs index 11c04cf8..2025d57b 100644 --- a/util/src/maybe_grow.rs +++ b/util/src/maybe_grow.rs @@ -1,4 +1,10 @@ /// Guard against stack overflows in recursive functions. +#[cfg(feature = "std")] pub fn maybe_grow(f: impl FnOnce() -> R) -> R { stacker::maybe_grow(1024 * 32, 1024 * 1024, f) } + +#[cfg(not(feature = "std"))] +pub fn maybe_grow(f: impl FnOnce() -> R) -> R { + f() +}