From 7375088c3ec10c9f12298a011d2eec69aed7a633 Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Mon, 15 Jan 2018 14:05:38 -0500 Subject: [PATCH 01/27] Most of the way to no_std support --- lib/cretonne/Cargo.toml | 8 +++++ lib/cretonne/src/abi.rs | 1 + lib/cretonne/src/dbg.rs | 18 ++++++++++ lib/cretonne/src/dominator_tree.rs | 1 + lib/cretonne/src/entity/list.rs | 1 + lib/cretonne/src/entity/map.rs | 1 + lib/cretonne/src/entity/primary.rs | 1 + lib/cretonne/src/entity/set.rs | 1 + lib/cretonne/src/entity/sparse.rs | 1 + lib/cretonne/src/ir/extfunc.rs | 1 + lib/cretonne/src/ir/instructions.rs | 1 + lib/cretonne/src/ir/jumptable.rs | 1 + lib/cretonne/src/ir/stackslot.rs | 1 + lib/cretonne/src/isa/arm32/mod.rs | 2 ++ lib/cretonne/src/isa/arm64/mod.rs | 2 ++ lib/cretonne/src/isa/intel/mod.rs | 1 + lib/cretonne/src/isa/mod.rs | 2 ++ lib/cretonne/src/isa/riscv/mod.rs | 2 ++ lib/cretonne/src/legalizer/boundary.rs | 1 + lib/cretonne/src/legalizer/libcall.rs | 2 +- lib/cretonne/src/legalizer/split.rs | 1 + lib/cretonne/src/lib.rs | 34 ++++++++++++++++++- lib/cretonne/src/licm.rs | 1 + lib/cretonne/src/loop_analysis.rs | 1 + lib/cretonne/src/regalloc/coalescing.rs | 3 ++ lib/cretonne/src/regalloc/diversion.rs | 1 + .../src/regalloc/live_value_tracker.rs | 1 + lib/cretonne/src/regalloc/liveness.rs | 1 + lib/cretonne/src/regalloc/reload.rs | 1 + lib/cretonne/src/regalloc/solver.rs | 1 + lib/cretonne/src/regalloc/spilling.rs | 1 + lib/cretonne/src/settings.rs | 1 + lib/cretonne/src/simple_gvn.rs | 3 ++ lib/cretonne/src/timing.rs | 25 ++++++++++++-- lib/cretonne/src/topo_order.rs | 3 ++ lib/cretonne/src/verifier/mod.rs | 2 ++ lib/cretonne/src/write.rs | 1 + lib/frontend/Cargo.toml | 3 ++ lib/frontend/src/lib.rs | 12 +++++++ lib/frontend/src/ssa.rs | 1 + lib/native/Cargo.toml | 3 ++ lib/native/src/lib.rs | 2 +- 42 files changed, 146 insertions(+), 5 deletions(-) diff --git a/lib/cretonne/Cargo.toml b/lib/cretonne/Cargo.toml index 88ae712c07..91dc6ccdac 100644 --- a/lib/cretonne/Cargo.toml +++ b/lib/cretonne/Cargo.toml @@ -17,3 +17,11 @@ name = "cretonne" # Please don't add any unless they are essential to the task of creating binary # machine code. Integration tests that need external dependencies can be # accomodated in `tests`. +[dependencies.hashmap_core] +version = "0.1.1" +optional = true + +[features] +# Currently, the only feature is the `no_std` feature. +# Enabling this disables use of `stdlib`. +no_std = ["hashmap_core"] \ No newline at end of file diff --git a/lib/cretonne/src/abi.rs b/lib/cretonne/src/abi.rs index 5c121824aa..45840d63db 100644 --- a/lib/cretonne/src/abi.rs +++ b/lib/cretonne/src/abi.rs @@ -5,6 +5,7 @@ use ir::{ArgumentLoc, AbiParam, ArgumentExtension, Type}; use std::cmp::Ordering; +use std::vec::Vec; /// Legalization action to perform on a single argument or return value when converting a /// signature. diff --git a/lib/cretonne/src/dbg.rs b/lib/cretonne/src/dbg.rs index 5acadd2098..cb8dd07118 100644 --- a/lib/cretonne/src/dbg.rs +++ b/lib/cretonne/src/dbg.rs @@ -10,12 +10,17 @@ /// thread doing the logging. use std::cell::RefCell; +#[cfg(not(feature = "no_std"))] use std::env; +#[cfg(not(feature = "no_std"))] use std::ffi::OsStr; use std::fmt; +#[cfg(not(feature = "no_std"))] use std::fs::File; +#[cfg(not(feature = "no_std"))] use std::io::{self, Write}; use std::sync::atomic; +#[cfg(not(feature = "no_std"))] use std::thread; static STATE: atomic::AtomicIsize = atomic::ATOMIC_ISIZE_INIT; @@ -26,6 +31,7 @@ static STATE: atomic::AtomicIsize = atomic::ATOMIC_ISIZE_INIT; /// other than `0`. /// /// This inline function turns into a constant `false` when debug assertions are disabled. +#[cfg(not(feature = "no_std"))] #[inline] pub fn enabled() -> bool { if cfg!(debug_assertions) { @@ -38,7 +44,15 @@ pub fn enabled() -> bool { } } +/// Does nothing +#[cfg(feature = "no_std")] +#[inline] +pub fn enabled() -> bool { + false +} + /// Initialize `STATE` from the environment variable. +#[cfg(not(feature = "no_std"))] fn initialize() -> bool { let enable = match env::var_os("CRETONNE_DBG") { Some(s) => s != OsStr::new("0"), @@ -54,6 +68,7 @@ fn initialize() -> bool { enable } +#[cfg(not(feature = "no_std"))] thread_local! { static WRITER : RefCell> = RefCell::new(open_file()); } @@ -61,6 +76,7 @@ thread_local! { /// Write a line with the given format arguments. /// /// This is for use by the `dbg!` macro. +#[cfg(not(feature = "no_std"))] pub fn writeln_with_format_args(args: fmt::Arguments) -> io::Result<()> { WRITER.with(|rc| { let mut w = rc.borrow_mut(); @@ -70,6 +86,7 @@ pub fn writeln_with_format_args(args: fmt::Arguments) -> io::Result<()> { } /// Open the tracing file for the current thread. +#[cfg(not(feature = "no_std"))] fn open_file() -> io::BufWriter { let curthread = thread::current(); let tmpstr; @@ -97,6 +114,7 @@ macro_rules! dbg { if $crate::dbg::enabled() { // Drop the error result so we don't get compiler errors for ignoring it. // What are you going to do, log the error? + #[cfg(not(feature = "no_std"))] $crate::dbg::writeln_with_format_args(format_args!($($arg)+)).ok(); } } diff --git a/lib/cretonne/src/dominator_tree.rs b/lib/cretonne/src/dominator_tree.rs index f7b7273681..a7625f840e 100644 --- a/lib/cretonne/src/dominator_tree.rs +++ b/lib/cretonne/src/dominator_tree.rs @@ -10,6 +10,7 @@ use std::mem; use timing; use std::cmp::Ordering; +use std::vec::Vec; // RPO numbers are not first assigned in a contiguous way but as multiples of STRIDE, to leave // room for modifications of the dominator tree. diff --git a/lib/cretonne/src/entity/list.rs b/lib/cretonne/src/entity/list.rs index c9bb5b1a69..58c91d9287 100644 --- a/lib/cretonne/src/entity/list.rs +++ b/lib/cretonne/src/entity/list.rs @@ -3,6 +3,7 @@ use entity::EntityRef; use std::hash::{Hash, Hasher}; use std::marker::PhantomData; use std::mem; +use std::vec::Vec; /// A small list of entity references allocated from a pool. /// diff --git a/lib/cretonne/src/entity/map.rs b/lib/cretonne/src/entity/map.rs index 9622f93485..f251c2f831 100644 --- a/lib/cretonne/src/entity/map.rs +++ b/lib/cretonne/src/entity/map.rs @@ -3,6 +3,7 @@ use entity::{EntityRef, Keys}; use std::marker::PhantomData; use std::ops::{Index, IndexMut}; +use std::vec::Vec; /// A mapping `K -> V` for densely indexed entity references. /// diff --git a/lib/cretonne/src/entity/primary.rs b/lib/cretonne/src/entity/primary.rs index 137320f3e5..c06b818355 100644 --- a/lib/cretonne/src/entity/primary.rs +++ b/lib/cretonne/src/entity/primary.rs @@ -2,6 +2,7 @@ use entity::{EntityRef, Keys}; use std::marker::PhantomData; use std::ops::{Index, IndexMut}; +use std::vec::Vec; /// A primary mapping `K -> V` allocating dense entity references. /// diff --git a/lib/cretonne/src/entity/set.rs b/lib/cretonne/src/entity/set.rs index 82dc1384ee..e4acf47723 100644 --- a/lib/cretonne/src/entity/set.rs +++ b/lib/cretonne/src/entity/set.rs @@ -2,6 +2,7 @@ use entity::{EntityRef, Keys}; use std::marker::PhantomData; +use std::vec::Vec; /// A set of `K` for densely indexed entity references. /// diff --git a/lib/cretonne/src/entity/sparse.rs b/lib/cretonne/src/entity/sparse.rs index dacbf66031..a4836cb9d5 100644 --- a/lib/cretonne/src/entity/sparse.rs +++ b/lib/cretonne/src/entity/sparse.rs @@ -11,6 +11,7 @@ use entity::{EntityRef, EntityMap}; use std::mem; use std::slice; use std::u32; +use std::vec::Vec; /// Trait for extracting keys from values stored in a `SparseMap`. /// diff --git a/lib/cretonne/src/ir/extfunc.rs b/lib/cretonne/src/ir/extfunc.rs index b3c3a274e7..0aa87fa60e 100644 --- a/lib/cretonne/src/ir/extfunc.rs +++ b/lib/cretonne/src/ir/extfunc.rs @@ -10,6 +10,7 @@ use isa::{RegInfo, RegUnit}; use std::cmp; use std::fmt; use std::str::FromStr; +use std::vec::Vec; /// Function signature. /// diff --git a/lib/cretonne/src/ir/instructions.rs b/lib/cretonne/src/ir/instructions.rs index af570f7ad5..1340c14055 100644 --- a/lib/cretonne/src/ir/instructions.rs +++ b/lib/cretonne/src/ir/instructions.rs @@ -9,6 +9,7 @@ use std::fmt::{self, Display, Formatter}; use std::str::FromStr; use std::ops::{Deref, DerefMut}; +use std::vec::Vec; use ir; use ir::{Value, Type, Ebb, JumpTable, SigRef, FuncRef, StackSlot, MemFlags}; diff --git a/lib/cretonne/src/ir/jumptable.rs b/lib/cretonne/src/ir/jumptable.rs index 2d09aab4da..4f6e117b64 100644 --- a/lib/cretonne/src/ir/jumptable.rs +++ b/lib/cretonne/src/ir/jumptable.rs @@ -8,6 +8,7 @@ use ir::entities::Ebb; use std::iter; use std::slice; use std::fmt::{self, Display, Formatter}; +use std::vec::Vec; /// Contents of a jump table. /// diff --git a/lib/cretonne/src/ir/stackslot.rs b/lib/cretonne/src/ir/stackslot.rs index 4a0804787b..744bd06ac3 100644 --- a/lib/cretonne/src/ir/stackslot.rs +++ b/lib/cretonne/src/ir/stackslot.rs @@ -10,6 +10,7 @@ use std::cmp; use std::fmt; use std::ops::{Index, IndexMut}; use std::str::FromStr; +use std::vec::Vec; /// The size of an object on the stack, or the size of a stack frame. /// diff --git a/lib/cretonne/src/isa/arm32/mod.rs b/lib/cretonne/src/isa/arm32/mod.rs index c3f295d4fb..50ef3ea7db 100644 --- a/lib/cretonne/src/isa/arm32/mod.rs +++ b/lib/cretonne/src/isa/arm32/mod.rs @@ -15,6 +15,8 @@ use ir; use regalloc; use std::fmt; +use std::boxed::Box; + #[allow(dead_code)] struct Isa { shared_flags: shared_settings::Flags, diff --git a/lib/cretonne/src/isa/arm64/mod.rs b/lib/cretonne/src/isa/arm64/mod.rs index d0644ae2f6..b69e044bf4 100644 --- a/lib/cretonne/src/isa/arm64/mod.rs +++ b/lib/cretonne/src/isa/arm64/mod.rs @@ -15,6 +15,8 @@ use ir; use regalloc; use std::fmt; +use std::boxed::Box; + #[allow(dead_code)] struct Isa { shared_flags: shared_settings::Flags, diff --git a/lib/cretonne/src/isa/intel/mod.rs b/lib/cretonne/src/isa/intel/mod.rs index 3f02890a82..e4841558e4 100644 --- a/lib/cretonne/src/isa/intel/mod.rs +++ b/lib/cretonne/src/isa/intel/mod.rs @@ -17,6 +17,7 @@ use result; use timing; use std::fmt; +use std::boxed::Box; #[allow(dead_code)] struct Isa { diff --git a/lib/cretonne/src/isa/mod.rs b/lib/cretonne/src/isa/mod.rs index 38164e5167..cedfdaa301 100644 --- a/lib/cretonne/src/isa/mod.rs +++ b/lib/cretonne/src/isa/mod.rs @@ -55,6 +55,8 @@ use timing; use isa::enc_tables::Encodings; use std::fmt; +use std::boxed::Box; + #[cfg(build_riscv)] mod riscv; diff --git a/lib/cretonne/src/isa/riscv/mod.rs b/lib/cretonne/src/isa/riscv/mod.rs index 2fd0d5cdb9..1993ecb9d6 100644 --- a/lib/cretonne/src/isa/riscv/mod.rs +++ b/lib/cretonne/src/isa/riscv/mod.rs @@ -15,6 +15,8 @@ use ir; use regalloc; use std::fmt; +use std::boxed::Box; + #[allow(dead_code)] struct Isa { shared_flags: shared_settings::Flags, diff --git a/lib/cretonne/src/legalizer/boundary.rs b/lib/cretonne/src/legalizer/boundary.rs index ea81c1ff95..5d9dd71dc0 100644 --- a/lib/cretonne/src/legalizer/boundary.rs +++ b/lib/cretonne/src/legalizer/boundary.rs @@ -25,6 +25,7 @@ use ir::{Function, DataFlowGraph, Inst, InstBuilder, Ebb, Type, Value, Signature use ir::instructions::CallInfo; use isa::TargetIsa; use legalizer::split::{isplit, vsplit}; +use std::vec::Vec; /// Legalize all the function signatures in `func`. /// diff --git a/lib/cretonne/src/legalizer/libcall.rs b/lib/cretonne/src/legalizer/libcall.rs index 156a05b813..cdf6a763a4 100644 --- a/lib/cretonne/src/legalizer/libcall.rs +++ b/lib/cretonne/src/legalizer/libcall.rs @@ -15,7 +15,7 @@ pub fn expand_as_libcall(inst: ir::Inst, func: &mut ir::Function) -> bool { let funcref = find_funcref(libcall, func).unwrap_or_else(|| make_funcref(libcall, inst, func)); // Now we convert `inst` to a call. First save the arguments. - let mut args = Vec::new(); + let mut args = vec![]; args.extend_from_slice(func.dfg.inst_args(inst)); // The replace builder will preserve the instruction result values. func.dfg.replace(inst).call(funcref, &args); diff --git a/lib/cretonne/src/legalizer/split.rs b/lib/cretonne/src/legalizer/split.rs index 0c73e7c2d4..76ad05a2bc 100644 --- a/lib/cretonne/src/legalizer/split.rs +++ b/lib/cretonne/src/legalizer/split.rs @@ -68,6 +68,7 @@ use cursor::{Cursor, CursorPosition, FuncCursor}; use flowgraph::ControlFlowGraph; use ir::{self, Ebb, Inst, Value, Type, Opcode, ValueDef, InstructionData, InstBuilder}; use std::iter; +use std::vec::Vec; /// Split `value` into two values using the `isplit` semantics. Do this by reusing existing values /// if possible. diff --git a/lib/cretonne/src/lib.rs b/lib/cretonne/src/lib.rs index b4c386477c..2bed9df4fb 100644 --- a/lib/cretonne/src/lib.rs +++ b/lib/cretonne/src/lib.rs @@ -1,7 +1,17 @@ //! Cretonne code generation library. - +#![cfg_attr(feature = "no_std", no_std)] #![deny(missing_docs)] +// Turns on alloc feature if no_std +#![cfg_attr(feature = "no_std", feature(alloc))] + +// Include the `hashmap_core` crate if no_std +#[cfg(feature = "no_std")] +extern crate hashmap_core; +#[cfg(feature = "no_std")] +#[macro_use] +extern crate alloc; + pub use context::Context; pub use legalizer::legalize_function; pub use verifier::verify_function; @@ -46,3 +56,25 @@ mod stack_layout; mod topo_order; mod unreachable_code; mod write; + +/// This replaces `std` in builds with no_std. +#[cfg(feature = "no_std")] +mod std { + pub use core::*; + #[macro_use] + pub use alloc::{boxed, vec, string}; + pub mod prelude { + pub use core::prelude as v1; + } + pub mod collections { + pub use hashmap_core::{HashMap, HashSet}; + pub use hashmap_core::map as hash_map; + pub use alloc::BTreeSet; + } + pub mod error { + pub trait Error { + fn description(&self) -> &str; + fn cause(&self) -> Option<&Error> { None } + } + } +} \ No newline at end of file diff --git a/lib/cretonne/src/licm.rs b/lib/cretonne/src/licm.rs index 1eb035d9bf..e767fc838b 100644 --- a/lib/cretonne/src/licm.rs +++ b/lib/cretonne/src/licm.rs @@ -8,6 +8,7 @@ use dominator_tree::DominatorTree; use entity::{EntityList, ListPool}; use loop_analysis::{Loop, LoopAnalysis}; use timing; +use std::vec::Vec; /// Performs the LICM pass by detecting loops within the CFG and moving /// loop-invariant instructions out of them. diff --git a/lib/cretonne/src/loop_analysis.rs b/lib/cretonne/src/loop_analysis.rs index f6dee54d71..dfd5cf135a 100644 --- a/lib/cretonne/src/loop_analysis.rs +++ b/lib/cretonne/src/loop_analysis.rs @@ -8,6 +8,7 @@ use flowgraph::ControlFlowGraph; use ir::{Function, Ebb, Layout}; use packed_option::PackedOption; use timing; +use std::vec::Vec; /// A opaque reference to a code loop. #[derive(Copy, Clone, PartialEq, Eq, Hash)] diff --git a/lib/cretonne/src/regalloc/coalescing.rs b/lib/cretonne/src/regalloc/coalescing.rs index 416783b6c0..225aa8e9d8 100644 --- a/lib/cretonne/src/regalloc/coalescing.rs +++ b/lib/cretonne/src/regalloc/coalescing.rs @@ -18,6 +18,9 @@ use std::cmp; use std::iter; use std::fmt; use std::slice; +use std::iter::Peekable; +use std::mem; +use std::vec::Vec; use isa::{TargetIsa, EncInfo}; use timing; diff --git a/lib/cretonne/src/regalloc/diversion.rs b/lib/cretonne/src/regalloc/diversion.rs index 588ad040a5..16eb0e9b50 100644 --- a/lib/cretonne/src/regalloc/diversion.rs +++ b/lib/cretonne/src/regalloc/diversion.rs @@ -11,6 +11,7 @@ use ir::{Value, ValueLoc, ValueLocations, StackSlot}; use ir::{InstructionData, Opcode}; use isa::{RegUnit, RegInfo}; use std::fmt; +use std::vec::Vec; /// A diversion of a value from its original location to a new register or stack location. /// diff --git a/lib/cretonne/src/regalloc/live_value_tracker.rs b/lib/cretonne/src/regalloc/live_value_tracker.rs index d0810a5cf7..de300ced0e 100644 --- a/lib/cretonne/src/regalloc/live_value_tracker.rs +++ b/lib/cretonne/src/regalloc/live_value_tracker.rs @@ -13,6 +13,7 @@ use regalloc::affinity::Affinity; use regalloc::liveness::Liveness; use regalloc::liverange::LiveRange; use std::collections::HashMap; +use std::vec::Vec; type ValueList = EntityList; diff --git a/lib/cretonne/src/regalloc/liveness.rs b/lib/cretonne/src/regalloc/liveness.rs index 2778f47f63..83b63366a5 100644 --- a/lib/cretonne/src/regalloc/liveness.rs +++ b/lib/cretonne/src/regalloc/liveness.rs @@ -184,6 +184,7 @@ use regalloc::affinity::Affinity; use regalloc::liverange::{LiveRange, LiveRangeForest, LiveRangeContext}; use std::mem; use std::ops::Index; +use std::vec::Vec; use timing; /// A set of live ranges, indexed by value number. diff --git a/lib/cretonne/src/regalloc/reload.rs b/lib/cretonne/src/regalloc/reload.rs index 2cb37d7d6a..10b803c831 100644 --- a/lib/cretonne/src/regalloc/reload.rs +++ b/lib/cretonne/src/regalloc/reload.rs @@ -21,6 +21,7 @@ use regalloc::live_value_tracker::{LiveValue, LiveValueTracker}; use regalloc::liveness::Liveness; use timing; use topo_order::TopoOrder; +use std::vec::Vec; /// Reusable data structures for the reload pass. pub struct Reload { diff --git a/lib/cretonne/src/regalloc/solver.rs b/lib/cretonne/src/regalloc/solver.rs index a3b732799c..c2f8017c3a 100644 --- a/lib/cretonne/src/regalloc/solver.rs +++ b/lib/cretonne/src/regalloc/solver.rs @@ -108,6 +108,7 @@ use std::fmt; use std::mem; use super::AllocatableSet; use std::u16; +use std::vec::Vec; /// A variable in the constraint problem. /// diff --git a/lib/cretonne/src/regalloc/spilling.rs b/lib/cretonne/src/regalloc/spilling.rs index 84ef76fdff..5f6677d650 100644 --- a/lib/cretonne/src/regalloc/spilling.rs +++ b/lib/cretonne/src/regalloc/spilling.rs @@ -26,6 +26,7 @@ use regalloc::liveness::Liveness; use regalloc::pressure::Pressure; use regalloc::virtregs::VirtRegs; use std::fmt; +use std::vec::Vec; use timing; use topo_order::TopoOrder; diff --git a/lib/cretonne/src/settings.rs b/lib/cretonne/src/settings.rs index 36a48e04b4..a7da8d6f17 100644 --- a/lib/cretonne/src/settings.rs +++ b/lib/cretonne/src/settings.rs @@ -24,6 +24,7 @@ use constant_hash::{probe, simple_hash}; use isa::TargetIsa; use std::fmt; use std::result; +use std::vec::Vec; /// A string-based configurator for settings groups. /// diff --git a/lib/cretonne/src/simple_gvn.rs b/lib/cretonne/src/simple_gvn.rs index 8642122593..e0350ad687 100644 --- a/lib/cretonne/src/simple_gvn.rs +++ b/lib/cretonne/src/simple_gvn.rs @@ -7,6 +7,9 @@ use ir::{InstructionData, Function, Inst, Opcode, Type}; use scoped_hash_map::ScopedHashMap; use timing; +#[cfg(feature = "no_std")] +use alloc::Vec; + /// Test whether the given opcode is unsafe to even consider for GVN. fn trivially_unsafe_for_gvn(opcode: Opcode) -> bool { opcode.is_call() || opcode.is_branch() || opcode.is_terminator() || diff --git a/lib/cretonne/src/timing.rs b/lib/cretonne/src/timing.rs index d120d43c32..90d15353e1 100644 --- a/lib/cretonne/src/timing.rs +++ b/lib/cretonne/src/timing.rs @@ -87,12 +87,12 @@ impl fmt::Display for Pass { } } - /// Implementation details. /// /// This whole module can be gated on a `cfg` feature to provide a dummy implementation for /// performance-sensitive builds or restricted environments. The dummy implementation must provide -/// `TimingToken` and `PassTimings` types and a `take_current` function. +/// `TimingToken` and `PassTimes` types and `take_current`, `add_to_current`, and `start_pass` functions. +#[cfg(not(feature = "no_std"))] mod details { use super::{Pass, NUM_PASSES, DESCRIPTIONS}; use std::cell::{Cell, RefCell}; @@ -214,6 +214,27 @@ mod details { } } +/// Dummy `debug` implementation +#[cfg(feature = "no_std")] +mod details { + use super::Pass; + /// Dummy `TimingToken` + pub struct TimingToken; + /// Dummy `PassTimes` + pub struct PassTimes; + /// Returns dummy `PassTimes` + pub fn take_current() -> PassTimes { + PassTimes + } + /// does nothing + pub fn add_to_current(_times: PassTimes) { } + + /// does nothing + pub(super) fn start_pass(_pass: Pass) -> TimingToken { + TimingToken + } +} + #[cfg(test)] mod test { use super::*; diff --git a/lib/cretonne/src/topo_order.rs b/lib/cretonne/src/topo_order.rs index cd783c928a..660179f1f9 100644 --- a/lib/cretonne/src/topo_order.rs +++ b/lib/cretonne/src/topo_order.rs @@ -4,6 +4,9 @@ use entity::SparseSet; use dominator_tree::DominatorTree; use ir::{Ebb, Layout}; +#[cfg(feature = "no_std")] +use alloc::Vec; + /// Present EBBs in a topological order such that all dominating EBBs are guaranteed to be visited /// before the current EBB. /// diff --git a/lib/cretonne/src/verifier/mod.rs b/lib/cretonne/src/verifier/mod.rs index a346573e67..c3bebc5ae6 100644 --- a/lib/cretonne/src/verifier/mod.rs +++ b/lib/cretonne/src/verifier/mod.rs @@ -73,6 +73,8 @@ use std::collections::BTreeSet; use std::error as std_error; use std::fmt::{self, Display, Formatter, Write}; use std::result; +use std::vec::Vec; +use std::string::String; use timing; pub use self::cssa::verify_cssa; diff --git a/lib/cretonne/src/write.rs b/lib/cretonne/src/write.rs index d9853d5768..4ca8ddaadb 100644 --- a/lib/cretonne/src/write.rs +++ b/lib/cretonne/src/write.rs @@ -9,6 +9,7 @@ use isa::{TargetIsa, RegInfo}; use std::fmt::{self, Result, Error, Write}; use std::result; use packed_option::ReservedValue; +use std::string::String; /// Write `func` to `w` as equivalent text. /// Use `isa` to emit ISA-dependent annotations. diff --git a/lib/frontend/Cargo.toml b/lib/frontend/Cargo.toml index eea524ef1c..32c65e4ded 100644 --- a/lib/frontend/Cargo.toml +++ b/lib/frontend/Cargo.toml @@ -13,3 +13,6 @@ name = "cton_frontend" [dependencies] cretonne = { path = "../cretonne", version = "0.1.0" } + +[features] +no_std = ["cretonne/no_std"] diff --git a/lib/frontend/src/lib.rs b/lib/frontend/src/lib.rs index 9db5a4a34b..37a3504bf5 100644 --- a/lib/frontend/src/lib.rs +++ b/lib/frontend/src/lib.rs @@ -142,11 +142,23 @@ //! } //! ``` +#![cfg_attr(feature = "no_std", no_std)] #![deny(missing_docs)] +#![cfg_attr(feature = "no_std", feature(alloc))] + extern crate cretonne; +#[cfg(feature = "no_std")] +extern crate alloc; + pub use frontend::{ILBuilder, FunctionBuilder}; mod frontend; mod ssa; + +#[cfg(feature = "no_std")] +mod std { + pub use alloc::vec; + pub use core::*; +} \ No newline at end of file diff --git a/lib/frontend/src/ssa.rs b/lib/frontend/src/ssa.rs index 2b758ef18b..f99ff5e179 100644 --- a/lib/frontend/src/ssa.rs +++ b/lib/frontend/src/ssa.rs @@ -15,6 +15,7 @@ use std::u32; use cretonne::ir::types::{F32, F64}; use cretonne::ir::immediates::{Ieee32, Ieee64}; use std::mem; +use std::vec::Vec; /// Structure containing the data relevant the construction of SSA for a given function. /// diff --git a/lib/native/Cargo.toml b/lib/native/Cargo.toml index 13556b0eb0..57a2d0bc3c 100644 --- a/lib/native/Cargo.toml +++ b/lib/native/Cargo.toml @@ -15,3 +15,6 @@ cretonne = { path = "../cretonne", version = "0.1.0" } [target.'cfg(any(target_arch = "x86", target_arch = "x86_64"))'.dependencies] raw-cpuid = "3.0.0" + +[features] +no_std = ["cretonne/no_std"] diff --git a/lib/native/src/lib.rs b/lib/native/src/lib.rs index 6cdb39a15e..284366a65c 100644 --- a/lib/native/src/lib.rs +++ b/lib/native/src/lib.rs @@ -1,6 +1,6 @@ //! Performs autodetection of the host for the purposes of running //! Cretonne to generate code to run on the same machine. - +#![cfg_attr(feature = "no_std", no_std)] #![deny(missing_docs)] extern crate cretonne; From 299e8a9737259e6fd8052f3e520533f8fc3cd7f9 Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Mon, 15 Jan 2018 16:21:26 -0500 Subject: [PATCH 02/27] lib/cretonne works with no_std --- lib/cretonne/Cargo.toml | 5 ++++- lib/cretonne/src/dbg.rs | 1 + lib/cretonne/src/lib.rs | 7 +++---- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/cretonne/Cargo.toml b/lib/cretonne/Cargo.toml index 91dc6ccdac..0cf3fffd9b 100644 --- a/lib/cretonne/Cargo.toml +++ b/lib/cretonne/Cargo.toml @@ -20,8 +20,11 @@ name = "cretonne" [dependencies.hashmap_core] version = "0.1.1" optional = true +[dependencies.error_core] +version = "0.1.0" +optional = true [features] # Currently, the only feature is the `no_std` feature. # Enabling this disables use of `stdlib`. -no_std = ["hashmap_core"] \ No newline at end of file +no_std = ["hashmap_core", "error_core"] \ No newline at end of file diff --git a/lib/cretonne/src/dbg.rs b/lib/cretonne/src/dbg.rs index cb8dd07118..7e5cd2777c 100644 --- a/lib/cretonne/src/dbg.rs +++ b/lib/cretonne/src/dbg.rs @@ -9,6 +9,7 @@ /// The output will appear in files named `cretonne.dbg.*`, where the suffix is named after the /// thread doing the logging. +#[cfg(not(feature = "no_std"))] use std::cell::RefCell; #[cfg(not(feature = "no_std"))] use std::env; diff --git a/lib/cretonne/src/lib.rs b/lib/cretonne/src/lib.rs index 2bed9df4fb..c448cc1d0f 100644 --- a/lib/cretonne/src/lib.rs +++ b/lib/cretonne/src/lib.rs @@ -9,6 +9,8 @@ #[cfg(feature = "no_std")] extern crate hashmap_core; #[cfg(feature = "no_std")] +extern crate error_core; +#[cfg(feature = "no_std")] #[macro_use] extern crate alloc; @@ -72,9 +74,6 @@ mod std { pub use alloc::BTreeSet; } pub mod error { - pub trait Error { - fn description(&self) -> &str; - fn cause(&self) -> Option<&Error> { None } - } + pub use error_core::Error; } } \ No newline at end of file From 66a150e67acded290bd7259ca7cc5113e428f5c0 Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Mon, 15 Jan 2018 16:21:42 -0500 Subject: [PATCH 03/27] lib/wasm works with no_std --- lib/wasm/Cargo.toml | 12 ++++++++++++ lib/wasm/src/code_translator.rs | 3 +++ lib/wasm/src/environ/dummy.rs | 4 ++++ lib/wasm/src/environ/spec.rs | 4 ++++ lib/wasm/src/lib.rs | 25 +++++++++++++++++++++++++ lib/wasm/src/module_translator.rs | 3 +++ lib/wasm/src/sections_translator.rs | 4 ++++ lib/wasm/src/state.rs | 3 +++ 8 files changed, 58 insertions(+) diff --git a/lib/wasm/Cargo.toml b/lib/wasm/Cargo.toml index 2bad5f8d2a..448166d568 100644 --- a/lib/wasm/Cargo.toml +++ b/lib/wasm/Cargo.toml @@ -15,5 +15,17 @@ wasmparser = "0.14.1" cretonne = { path = "../cretonne", version = "0.1.0" } cretonne-frontend = { path = "../frontend", version = "0.1.0" } +[dependencies.hashmap_core] +version = "0.1.1" +optional = true +[dependencies.error_core] +version = "0.1.0" +optional = true + [dev-dependencies] tempdir = "0.3.5" + +[features] +# Currently, the only feature is the `no_std` feature. +# Enabling this disables use of `stdlib`. +no_std = ["hashmap_core", "error_core", "cretonne/no_std", "cretonne-frontend/no_std"] \ No newline at end of file diff --git a/lib/wasm/src/code_translator.rs b/lib/wasm/src/code_translator.rs index 903b9cd9e1..ea33f311a9 100644 --- a/lib/wasm/src/code_translator.rs +++ b/lib/wasm/src/code_translator.rs @@ -34,6 +34,9 @@ use std::collections::{HashMap, hash_map}; use environ::{FuncEnvironment, GlobalValue}; use std::{i32, u32}; +// this is for no_std builds, but has no affect on regular builds +use std::vec::Vec; + /// Translates wasm operators into Cretonne IL instructions. Returns `true` if it inserted /// a return. pub fn translate_operator( diff --git a/lib/wasm/src/environ/dummy.rs b/lib/wasm/src/environ/dummy.rs index 5557d842f6..9238cbf665 100644 --- a/lib/wasm/src/environ/dummy.rs +++ b/lib/wasm/src/environ/dummy.rs @@ -11,6 +11,10 @@ use cretonne::settings; use wasmparser; use std::error::Error; +// this is for no_std builds, but has no affect on regular builds +use std::vec::Vec; +use std::string::String; + /// Compute a `ir::ExternalName` for a given wasm function index. fn get_func_name(func_index: FunctionIndex) -> ir::ExternalName { ir::ExternalName::user(0, func_index as u32) diff --git a/lib/wasm/src/environ/spec.rs b/lib/wasm/src/environ/spec.rs index 31e4782918..c8a8f54111 100644 --- a/lib/wasm/src/environ/spec.rs +++ b/lib/wasm/src/environ/spec.rs @@ -6,6 +6,10 @@ use cretonne::settings::Flags; use translation_utils::{SignatureIndex, FunctionIndex, TableIndex, GlobalIndex, MemoryIndex, Global, Table, Memory}; +// this is for no_std builds, but has no affect on regular builds +use std::vec::Vec; +use std::string::String; + /// The value of a WebAssembly global variable. #[derive(Clone, Copy)] pub enum GlobalValue { diff --git a/lib/wasm/src/lib.rs b/lib/wasm/src/lib.rs index b5b79049fe..dde500af97 100644 --- a/lib/wasm/src/lib.rs +++ b/lib/wasm/src/lib.rs @@ -9,8 +9,20 @@ //! //! The main function of this module is [`translate_module`](fn.translate_module.html). +#![cfg_attr(feature = "no_std", no_std)] #![deny(missing_docs)] +#![cfg_attr(feature = "no_std", feature(alloc))] + +#[cfg(feature = "no_std")] +#[macro_use] +extern crate alloc; + +#[cfg(feature = "no_std")] +extern crate hashmap_core; +#[cfg(feature = "no_std")] +extern crate error_core; + extern crate wasmparser; extern crate cton_frontend; #[macro_use(dbg)] @@ -29,3 +41,16 @@ pub use module_translator::translate_module; pub use environ::{FuncEnvironment, ModuleEnvironment, DummyEnvironment, GlobalValue}; pub use translation_utils::{FunctionIndex, GlobalIndex, TableIndex, MemoryIndex, SignatureIndex, Global, GlobalInit, Table, Memory}; + +#[cfg(feature = "no_std")] +mod std { + pub use alloc::vec; + pub use alloc::string; + pub use core::{u32, i32, str, cmp}; + pub mod collections { + pub use hashmap_core::{HashMap, map as hash_map}; + } + pub mod error { + pub use error_core::Error; + } +} \ No newline at end of file diff --git a/lib/wasm/src/module_translator.rs b/lib/wasm/src/module_translator.rs index d75f60a35e..2786f9094e 100644 --- a/lib/wasm/src/module_translator.rs +++ b/lib/wasm/src/module_translator.rs @@ -8,6 +8,9 @@ use sections_translator::{SectionParsingError, parse_function_signatures, parse_ parse_elements_section, parse_data_section}; use environ::ModuleEnvironment; +// this is for no_std builds, but has no affect on regular builds +use std::string::String; + /// Translate a sequence of bytes forming a valid Wasm binary into a list of valid Cretonne IL /// [`Function`](../cretonne/ir/function/struct.Function.html). /// Returns the functions and also the mappings for imported functions and signature between the diff --git a/lib/wasm/src/sections_translator.rs b/lib/wasm/src/sections_translator.rs index d02a4a7c2a..ff641a6889 100644 --- a/lib/wasm/src/sections_translator.rs +++ b/lib/wasm/src/sections_translator.rs @@ -17,6 +17,10 @@ use wasmparser; use std::str::from_utf8; use environ::ModuleEnvironment; +// this is for no_std builds, but has no affect on regular builds +use std::vec::Vec; +use std::string::String; + pub enum SectionParsingError { WrongSectionContent(String), } diff --git a/lib/wasm/src/state.rs b/lib/wasm/src/state.rs index f9f76d2934..625e39b4e9 100644 --- a/lib/wasm/src/state.rs +++ b/lib/wasm/src/state.rs @@ -8,6 +8,9 @@ use environ::{FuncEnvironment, GlobalValue}; use std::collections::HashMap; use translation_utils::{GlobalIndex, MemoryIndex, SignatureIndex, FunctionIndex}; +// this is for no_std builds, but has no affect on regular builds +use std::vec::Vec; + /// A control stack frame can be an `if`, a `block` or a `loop`, each one having the following /// fields: /// From 5c85c1ba4a1890fa0ec05b3355c85ffab8435fc9 Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Mon, 15 Jan 2018 17:02:28 -0500 Subject: [PATCH 04/27] Fixed formatting issues --- lib/cretonne/src/timing.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cretonne/src/timing.rs b/lib/cretonne/src/timing.rs index 90d15353e1..c05ee93004 100644 --- a/lib/cretonne/src/timing.rs +++ b/lib/cretonne/src/timing.rs @@ -91,7 +91,7 @@ impl fmt::Display for Pass { /// /// This whole module can be gated on a `cfg` feature to provide a dummy implementation for /// performance-sensitive builds or restricted environments. The dummy implementation must provide -/// `TimingToken` and `PassTimes` types and `take_current`, `add_to_current`, and `start_pass` functions. +/// `TimingToken` and `PassTimes` types and `take_current`, `add_to_current`, and `start_pass` funcs #[cfg(not(feature = "no_std"))] mod details { use super::{Pass, NUM_PASSES, DESCRIPTIONS}; @@ -227,7 +227,7 @@ mod details { PassTimes } /// does nothing - pub fn add_to_current(_times: PassTimes) { } + pub fn add_to_current(_times: PassTimes) {} /// does nothing pub(super) fn start_pass(_pass: Pass) -> TimingToken { From 2462a065add5e516794cd225e1bbd45e69d1c1e5 Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Mon, 15 Jan 2018 17:14:48 -0500 Subject: [PATCH 05/27] Fixed formatting issues --- lib/cretonne/src/dbg.rs | 1 - lib/cretonne/src/lib.rs | 2 +- lib/cretonne/src/simple_gvn.rs | 3 +-- lib/cretonne/src/topo_order.rs | 3 +-- lib/frontend/src/lib.rs | 2 +- lib/wasm/src/code_translator.rs | 1 - lib/wasm/src/environ/dummy.rs | 1 - lib/wasm/src/environ/spec.rs | 1 - lib/wasm/src/lib.rs | 2 +- lib/wasm/src/module_translator.rs | 1 - lib/wasm/src/sections_translator.rs | 1 - lib/wasm/src/state.rs | 1 - 12 files changed, 5 insertions(+), 14 deletions(-) diff --git a/lib/cretonne/src/dbg.rs b/lib/cretonne/src/dbg.rs index 7e5cd2777c..ace22b6c47 100644 --- a/lib/cretonne/src/dbg.rs +++ b/lib/cretonne/src/dbg.rs @@ -8,7 +8,6 @@ /// /// The output will appear in files named `cretonne.dbg.*`, where the suffix is named after the /// thread doing the logging. - #[cfg(not(feature = "no_std"))] use std::cell::RefCell; #[cfg(not(feature = "no_std"))] diff --git a/lib/cretonne/src/lib.rs b/lib/cretonne/src/lib.rs index c448cc1d0f..22914cc17b 100644 --- a/lib/cretonne/src/lib.rs +++ b/lib/cretonne/src/lib.rs @@ -76,4 +76,4 @@ mod std { pub mod error { pub use error_core::Error; } -} \ No newline at end of file +} diff --git a/lib/cretonne/src/simple_gvn.rs b/lib/cretonne/src/simple_gvn.rs index e0350ad687..8f09398c82 100644 --- a/lib/cretonne/src/simple_gvn.rs +++ b/lib/cretonne/src/simple_gvn.rs @@ -7,8 +7,7 @@ use ir::{InstructionData, Function, Inst, Opcode, Type}; use scoped_hash_map::ScopedHashMap; use timing; -#[cfg(feature = "no_std")] -use alloc::Vec; +use std::vec::Vec; /// Test whether the given opcode is unsafe to even consider for GVN. fn trivially_unsafe_for_gvn(opcode: Opcode) -> bool { diff --git a/lib/cretonne/src/topo_order.rs b/lib/cretonne/src/topo_order.rs index 660179f1f9..f2c57f8166 100644 --- a/lib/cretonne/src/topo_order.rs +++ b/lib/cretonne/src/topo_order.rs @@ -4,8 +4,7 @@ use entity::SparseSet; use dominator_tree::DominatorTree; use ir::{Ebb, Layout}; -#[cfg(feature = "no_std")] -use alloc::Vec; +use std::vec::Vec; /// Present EBBs in a topological order such that all dominating EBBs are guaranteed to be visited /// before the current EBB. diff --git a/lib/frontend/src/lib.rs b/lib/frontend/src/lib.rs index 37a3504bf5..84af6f976b 100644 --- a/lib/frontend/src/lib.rs +++ b/lib/frontend/src/lib.rs @@ -161,4 +161,4 @@ mod ssa; mod std { pub use alloc::vec; pub use core::*; -} \ No newline at end of file +} diff --git a/lib/wasm/src/code_translator.rs b/lib/wasm/src/code_translator.rs index ea33f311a9..4a66bce463 100644 --- a/lib/wasm/src/code_translator.rs +++ b/lib/wasm/src/code_translator.rs @@ -34,7 +34,6 @@ use std::collections::{HashMap, hash_map}; use environ::{FuncEnvironment, GlobalValue}; use std::{i32, u32}; -// this is for no_std builds, but has no affect on regular builds use std::vec::Vec; /// Translates wasm operators into Cretonne IL instructions. Returns `true` if it inserted diff --git a/lib/wasm/src/environ/dummy.rs b/lib/wasm/src/environ/dummy.rs index 9238cbf665..d0dba2c817 100644 --- a/lib/wasm/src/environ/dummy.rs +++ b/lib/wasm/src/environ/dummy.rs @@ -11,7 +11,6 @@ use cretonne::settings; use wasmparser; use std::error::Error; -// this is for no_std builds, but has no affect on regular builds use std::vec::Vec; use std::string::String; diff --git a/lib/wasm/src/environ/spec.rs b/lib/wasm/src/environ/spec.rs index c8a8f54111..dfc2685f33 100644 --- a/lib/wasm/src/environ/spec.rs +++ b/lib/wasm/src/environ/spec.rs @@ -6,7 +6,6 @@ use cretonne::settings::Flags; use translation_utils::{SignatureIndex, FunctionIndex, TableIndex, GlobalIndex, MemoryIndex, Global, Table, Memory}; -// this is for no_std builds, but has no affect on regular builds use std::vec::Vec; use std::string::String; diff --git a/lib/wasm/src/lib.rs b/lib/wasm/src/lib.rs index dde500af97..9005e6cd42 100644 --- a/lib/wasm/src/lib.rs +++ b/lib/wasm/src/lib.rs @@ -53,4 +53,4 @@ mod std { pub mod error { pub use error_core::Error; } -} \ No newline at end of file +} diff --git a/lib/wasm/src/module_translator.rs b/lib/wasm/src/module_translator.rs index 2786f9094e..43a47b68af 100644 --- a/lib/wasm/src/module_translator.rs +++ b/lib/wasm/src/module_translator.rs @@ -8,7 +8,6 @@ use sections_translator::{SectionParsingError, parse_function_signatures, parse_ parse_elements_section, parse_data_section}; use environ::ModuleEnvironment; -// this is for no_std builds, but has no affect on regular builds use std::string::String; /// Translate a sequence of bytes forming a valid Wasm binary into a list of valid Cretonne IL diff --git a/lib/wasm/src/sections_translator.rs b/lib/wasm/src/sections_translator.rs index ff641a6889..a1e172aa7c 100644 --- a/lib/wasm/src/sections_translator.rs +++ b/lib/wasm/src/sections_translator.rs @@ -17,7 +17,6 @@ use wasmparser; use std::str::from_utf8; use environ::ModuleEnvironment; -// this is for no_std builds, but has no affect on regular builds use std::vec::Vec; use std::string::String; diff --git a/lib/wasm/src/state.rs b/lib/wasm/src/state.rs index 625e39b4e9..cb8aebb653 100644 --- a/lib/wasm/src/state.rs +++ b/lib/wasm/src/state.rs @@ -8,7 +8,6 @@ use environ::{FuncEnvironment, GlobalValue}; use std::collections::HashMap; use translation_utils::{GlobalIndex, MemoryIndex, SignatureIndex, FunctionIndex}; -// this is for no_std builds, but has no affect on regular builds use std::vec::Vec; /// A control stack frame can be an `if`, a `block` or a `loop`, each one having the following From 6bd6a80b785acda493087f8323b29c194e714d46 Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Mon, 15 Jan 2018 18:32:27 -0500 Subject: [PATCH 06/27] Updated top-level README.rst --- README.rst | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/README.rst b/README.rst index 05ddeb6b70..4672c092d4 100644 --- a/README.rst +++ b/README.rst @@ -57,6 +57,37 @@ You may need to install the *wat2wasm* tool from the `wabt WebAssembly tests. Tests requiring wat2wasm are ignored if the tool is not installed. +Building with `no_std` +---------------------- + +To build cretonne without libstd, enable the `no_std` feature on `lib/cretonne`, +`lib/frontend`, `lib/native`, and `lib/wasm`. + +For example, to build `cretonne`: + + cd lib/cretonne + cargo build --features no_std + +Or, when using `cretonne` as a dependency (in Cargo.toml): + + [dependency.cretonne] + path = "..." + features = ["no_std"] + +Currently, tests don't test the `no_std` feature. + +It's important to note that cretonne still needs liballoc to compile. +Thus, whatever environment is used must implement an allocator. + +Also, to allow the use of HashMaps in `no_std` mode, an external crate +called `hashmap_core` is pulled in (only in `no_std` builds). This +is mostly the same as `std::collections::HashMap`, except that it doesn't +have DOS protection. Just something to think about. + +Lastly, to support `std::error`, which isn't is `std` or `alloc` for +an inexplicable reason, the `error_core` crate is also used in `no_std` builds. +You might need it, as well, when interfacing with `CtonError`. + Building the documentation -------------------------- From 5590abcfd95671baa9109662fbae5606826de47d Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Mon, 15 Jan 2018 18:48:32 -0500 Subject: [PATCH 07/27] Expanded on `no_std` in README.rst --- README.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 4672c092d4..71d4b3902e 100644 --- a/README.rst +++ b/README.rst @@ -74,7 +74,11 @@ Or, when using `cretonne` as a dependency (in Cargo.toml): path = "..." features = ["no_std"] -Currently, tests don't test the `no_std` feature. +Currently, tests don't test the `no_std` feature: + +1. `cargo test --features no_std` won't compile. + +1. `./test_all.sh` doesn't test the `no_std` feature. It's important to note that cretonne still needs liballoc to compile. Thus, whatever environment is used must implement an allocator. From ddfa88c8ba909cf78d007c2d92b05ad59605a2e2 Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Mon, 15 Jan 2018 19:00:40 -0500 Subject: [PATCH 08/27] Removed extraneous newlines --- lib/cretonne/src/dominator_tree.rs | 1 - lib/cretonne/src/isa/arm32/mod.rs | 1 - lib/cretonne/src/isa/arm64/mod.rs | 1 - lib/cretonne/src/isa/intel/mod.rs | 1 - lib/cretonne/src/isa/mod.rs | 1 - lib/cretonne/src/isa/riscv/mod.rs | 1 - lib/cretonne/src/simple_gvn.rs | 1 - lib/cretonne/src/topo_order.rs | 1 - lib/wasm/src/code_translator.rs | 1 - lib/wasm/src/environ/dummy.rs | 1 - lib/wasm/src/environ/spec.rs | 1 - lib/wasm/src/sections_translator.rs | 1 - lib/wasm/src/state.rs | 1 - 13 files changed, 13 deletions(-) diff --git a/lib/cretonne/src/dominator_tree.rs b/lib/cretonne/src/dominator_tree.rs index a7625f840e..6617085834 100644 --- a/lib/cretonne/src/dominator_tree.rs +++ b/lib/cretonne/src/dominator_tree.rs @@ -8,7 +8,6 @@ use packed_option::PackedOption; use std::cmp; use std::mem; use timing; - use std::cmp::Ordering; use std::vec::Vec; diff --git a/lib/cretonne/src/isa/arm32/mod.rs b/lib/cretonne/src/isa/arm32/mod.rs index 50ef3ea7db..02e0d5f1af 100644 --- a/lib/cretonne/src/isa/arm32/mod.rs +++ b/lib/cretonne/src/isa/arm32/mod.rs @@ -14,7 +14,6 @@ use isa::{TargetIsa, RegInfo, RegClass, EncInfo}; use ir; use regalloc; use std::fmt; - use std::boxed::Box; #[allow(dead_code)] diff --git a/lib/cretonne/src/isa/arm64/mod.rs b/lib/cretonne/src/isa/arm64/mod.rs index b69e044bf4..8239cb01e9 100644 --- a/lib/cretonne/src/isa/arm64/mod.rs +++ b/lib/cretonne/src/isa/arm64/mod.rs @@ -14,7 +14,6 @@ use isa::{TargetIsa, RegInfo, RegClass, EncInfo}; use ir; use regalloc; use std::fmt; - use std::boxed::Box; #[allow(dead_code)] diff --git a/lib/cretonne/src/isa/intel/mod.rs b/lib/cretonne/src/isa/intel/mod.rs index e4841558e4..578dac2d16 100644 --- a/lib/cretonne/src/isa/intel/mod.rs +++ b/lib/cretonne/src/isa/intel/mod.rs @@ -16,7 +16,6 @@ use regalloc; use result; use timing; use std::fmt; - use std::boxed::Box; #[allow(dead_code)] diff --git a/lib/cretonne/src/isa/mod.rs b/lib/cretonne/src/isa/mod.rs index cedfdaa301..7e10f12620 100644 --- a/lib/cretonne/src/isa/mod.rs +++ b/lib/cretonne/src/isa/mod.rs @@ -54,7 +54,6 @@ use result; use timing; use isa::enc_tables::Encodings; use std::fmt; - use std::boxed::Box; #[cfg(build_riscv)] diff --git a/lib/cretonne/src/isa/riscv/mod.rs b/lib/cretonne/src/isa/riscv/mod.rs index 1993ecb9d6..8efae74af7 100644 --- a/lib/cretonne/src/isa/riscv/mod.rs +++ b/lib/cretonne/src/isa/riscv/mod.rs @@ -14,7 +14,6 @@ use isa::{TargetIsa, RegInfo, RegClass, EncInfo}; use ir; use regalloc; use std::fmt; - use std::boxed::Box; #[allow(dead_code)] diff --git a/lib/cretonne/src/simple_gvn.rs b/lib/cretonne/src/simple_gvn.rs index 8f09398c82..dd0fb3b1aa 100644 --- a/lib/cretonne/src/simple_gvn.rs +++ b/lib/cretonne/src/simple_gvn.rs @@ -6,7 +6,6 @@ use dominator_tree::DominatorTree; use ir::{InstructionData, Function, Inst, Opcode, Type}; use scoped_hash_map::ScopedHashMap; use timing; - use std::vec::Vec; /// Test whether the given opcode is unsafe to even consider for GVN. diff --git a/lib/cretonne/src/topo_order.rs b/lib/cretonne/src/topo_order.rs index f2c57f8166..373ab69e0d 100644 --- a/lib/cretonne/src/topo_order.rs +++ b/lib/cretonne/src/topo_order.rs @@ -3,7 +3,6 @@ use entity::SparseSet; use dominator_tree::DominatorTree; use ir::{Ebb, Layout}; - use std::vec::Vec; /// Present EBBs in a topological order such that all dominating EBBs are guaranteed to be visited diff --git a/lib/wasm/src/code_translator.rs b/lib/wasm/src/code_translator.rs index 4a66bce463..c62e1fe76a 100644 --- a/lib/wasm/src/code_translator.rs +++ b/lib/wasm/src/code_translator.rs @@ -33,7 +33,6 @@ use state::{TranslationState, ControlStackFrame}; use std::collections::{HashMap, hash_map}; use environ::{FuncEnvironment, GlobalValue}; use std::{i32, u32}; - use std::vec::Vec; /// Translates wasm operators into Cretonne IL instructions. Returns `true` if it inserted diff --git a/lib/wasm/src/environ/dummy.rs b/lib/wasm/src/environ/dummy.rs index d0dba2c817..de941f3b9a 100644 --- a/lib/wasm/src/environ/dummy.rs +++ b/lib/wasm/src/environ/dummy.rs @@ -10,7 +10,6 @@ use cretonne::cursor::FuncCursor; use cretonne::settings; use wasmparser; use std::error::Error; - use std::vec::Vec; use std::string::String; diff --git a/lib/wasm/src/environ/spec.rs b/lib/wasm/src/environ/spec.rs index dfc2685f33..7872bdb0ea 100644 --- a/lib/wasm/src/environ/spec.rs +++ b/lib/wasm/src/environ/spec.rs @@ -5,7 +5,6 @@ use cretonne::cursor::FuncCursor; use cretonne::settings::Flags; use translation_utils::{SignatureIndex, FunctionIndex, TableIndex, GlobalIndex, MemoryIndex, Global, Table, Memory}; - use std::vec::Vec; use std::string::String; diff --git a/lib/wasm/src/sections_translator.rs b/lib/wasm/src/sections_translator.rs index a1e172aa7c..a12a92e100 100644 --- a/lib/wasm/src/sections_translator.rs +++ b/lib/wasm/src/sections_translator.rs @@ -16,7 +16,6 @@ use wasmparser::{Parser, ParserState, FuncType, ImportSectionEntryType, External use wasmparser; use std::str::from_utf8; use environ::ModuleEnvironment; - use std::vec::Vec; use std::string::String; diff --git a/lib/wasm/src/state.rs b/lib/wasm/src/state.rs index cb8aebb653..40de47d7c6 100644 --- a/lib/wasm/src/state.rs +++ b/lib/wasm/src/state.rs @@ -7,7 +7,6 @@ use cretonne::ir::{self, Ebb, Inst, Value}; use environ::{FuncEnvironment, GlobalValue}; use std::collections::HashMap; use translation_utils::{GlobalIndex, MemoryIndex, SignatureIndex, FunctionIndex}; - use std::vec::Vec; /// A control stack frame can be an `if`, a `block` or a `loop`, each one having the following From 4cdbf2f56e134a52cd6be3fceff8d283547cbcdb Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Mon, 15 Jan 2018 19:11:52 -0500 Subject: [PATCH 09/27] Removed unused prelude --- lib/cretonne/src/lib.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/cretonne/src/lib.rs b/lib/cretonne/src/lib.rs index 22914cc17b..8302095998 100644 --- a/lib/cretonne/src/lib.rs +++ b/lib/cretonne/src/lib.rs @@ -65,9 +65,6 @@ mod std { pub use core::*; #[macro_use] pub use alloc::{boxed, vec, string}; - pub mod prelude { - pub use core::prelude as v1; - } pub mod collections { pub use hashmap_core::{HashMap, HashSet}; pub use hashmap_core::map as hash_map; From 48229f02e3b9712f10f128bfc548dbf22b6e90a7 Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Mon, 15 Jan 2018 19:12:06 -0500 Subject: [PATCH 10/27] Fixed typo in README.rst --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 71d4b3902e..8c685ac1ae 100644 --- a/README.rst +++ b/README.rst @@ -78,7 +78,7 @@ Currently, tests don't test the `no_std` feature: 1. `cargo test --features no_std` won't compile. -1. `./test_all.sh` doesn't test the `no_std` feature. +1. `./test-all.sh` doesn't test the `no_std` feature. It's important to note that cretonne still needs liballoc to compile. Thus, whatever environment is used must implement an allocator. From d8c8e4af3d4c5d74c5d7dd463a1d678f046c78d0 Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Mon, 15 Jan 2018 20:50:19 -0500 Subject: [PATCH 11/27] 2 is after 1 --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 8c685ac1ae..e9c9b568d9 100644 --- a/README.rst +++ b/README.rst @@ -78,7 +78,7 @@ Currently, tests don't test the `no_std` feature: 1. `cargo test --features no_std` won't compile. -1. `./test-all.sh` doesn't test the `no_std` feature. +2. `./test-all.sh` doesn't test the `no_std` feature. It's important to note that cretonne still needs liballoc to compile. Thus, whatever environment is used must implement an allocator. From 023f8d798013db09c7df804f21ca0b644b4a5481 Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Thu, 18 Jan 2018 21:42:58 -0500 Subject: [PATCH 12/27] Fixed missing vec --- lib/cretonne/src/regalloc/virtregs.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/cretonne/src/regalloc/virtregs.rs b/lib/cretonne/src/regalloc/virtregs.rs index 5116e8f02a..df2dbca78e 100644 --- a/lib/cretonne/src/regalloc/virtregs.rs +++ b/lib/cretonne/src/regalloc/virtregs.rs @@ -21,6 +21,7 @@ use packed_option::PackedOption; use ref_slice::ref_slice; use std::cmp::Ordering; use std::fmt; +use std::vec::Vec; /// A virtual register reference. #[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] From 61db54c44705488188340e97a0d3f8e785d6e767 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 18 Jan 2018 22:05:51 -0800 Subject: [PATCH 13/27] Add support for running tests in `no_std` mode. --- README.rst | 10 ++++--- cranelift/test-no_std.sh | 28 ++++++++++++++++++++ lib/cretonne/src/bforest/map.rs | 7 +++-- lib/cretonne/src/bforest/node.rs | 1 + lib/cretonne/src/bforest/pool.rs | 1 + lib/cretonne/src/bforest/set.rs | 4 ++- lib/cretonne/src/dbg.rs | 2 ++ lib/cretonne/src/flowgraph.rs | 1 + lib/cretonne/src/ir/condcodes.rs | 1 + lib/cretonne/src/ir/dfg.rs | 1 + lib/cretonne/src/ir/entities.rs | 1 + lib/cretonne/src/ir/extfunc.rs | 1 + lib/cretonne/src/ir/extname.rs | 1 + lib/cretonne/src/ir/immediates.rs | 1 + lib/cretonne/src/ir/instructions.rs | 1 + lib/cretonne/src/ir/jumptable.rs | 2 ++ lib/cretonne/src/ir/layout.rs | 1 + lib/cretonne/src/ir/libcall.rs | 1 + lib/cretonne/src/ir/progpoint.rs | 1 + lib/cretonne/src/ir/sourceloc.rs | 1 + lib/cretonne/src/ir/stackslot.rs | 1 + lib/cretonne/src/ir/trapcode.rs | 1 + lib/cretonne/src/ir/types.rs | 1 + lib/cretonne/src/isa/arm32/registers.rs | 1 + lib/cretonne/src/isa/arm64/registers.rs | 1 + lib/cretonne/src/isa/intel/registers.rs | 1 + lib/cretonne/src/isa/riscv/mod.rs | 1 + lib/cretonne/src/isa/riscv/registers.rs | 1 + lib/cretonne/src/isa/riscv/settings.rs | 1 + lib/cretonne/src/iterators.rs | 2 ++ lib/cretonne/src/lib.rs | 1 - lib/cretonne/src/loop_analysis.rs | 1 + lib/cretonne/src/partition_slice.rs | 1 + lib/cretonne/src/regalloc/allocatable_set.rs | 1 + lib/cretonne/src/regalloc/coalescing.rs | 2 -- lib/cretonne/src/regalloc/liverange.rs | 1 + lib/cretonne/src/regalloc/pressure.rs | 1 + lib/cretonne/src/regalloc/solver.rs | 1 + lib/cretonne/src/settings.rs | 1 + lib/cretonne/src/timing.rs | 1 + lib/cretonne/src/verifier/mod.rs | 3 +++ lib/cretonne/src/write.rs | 1 + lib/frontend/src/ssa.rs | 21 ++++++++++++--- 43 files changed, 101 insertions(+), 13 deletions(-) create mode 100755 cranelift/test-no_std.sh diff --git a/README.rst b/README.rst index e9c9b568d9..690472578b 100644 --- a/README.rst +++ b/README.rst @@ -74,11 +74,13 @@ Or, when using `cretonne` as a dependency (in Cargo.toml): path = "..." features = ["no_std"] -Currently, tests don't test the `no_std` feature: +`no_std` is currently "best effort". We won't try to break it, and we'll +accept patches fixing problems, however we don't expect all developers to +build and test with `no_std` when submitting patches. Accordingly, the +`./test-all.sh` script does not test `no_std`. -1. `cargo test --features no_std` won't compile. - -2. `./test-all.sh` doesn't test the `no_std` feature. +There is a separate `./test-no_std.sh` script that tests the `no_std` +feature in packages which support it. It's important to note that cretonne still needs liballoc to compile. Thus, whatever environment is used must implement an allocator. diff --git a/cranelift/test-no_std.sh b/cranelift/test-no_std.sh new file mode 100755 index 0000000000..c9d3fe38f7 --- /dev/null +++ b/cranelift/test-no_std.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# This is the test script for testing the no_std configuration of +# packages which support it. + +# Exit immediately on errors. +set -e + +# Repository top-level directory. +cd $(dirname "$0") +topdir=$(pwd) + +function banner() { + echo "====== $@ ======" +} + +# Test those packages which have no_std support. +LIBS="cretonne frontend wasm native" +cd "$topdir" +for LIB in $LIBS +do + banner "Rust unit tests in $LIB" + cd "lib/$LIB" + cargo test --features no_std + cd "$topdir" +done + +banner "OK" diff --git a/lib/cretonne/src/bforest/map.rs b/lib/cretonne/src/bforest/map.rs index 5aa19bceda..073f27529b 100644 --- a/lib/cretonne/src/bforest/map.rs +++ b/lib/cretonne/src/bforest/map.rs @@ -222,7 +222,8 @@ where } /// Get a text version of the path to `key`. - fn tpath(&self, key: K, forest: &MapForest, comp: &C) -> String { + fn tpath(&self, key: K, forest: &MapForest, comp: &C) -> ::std::string::String { + use std::string::ToString; match self.root.expand() { None => "map(empty)".to_string(), Some(root) => { @@ -415,7 +416,8 @@ where } /// Get a text version of the path to the current position. - fn tpath(&self) -> String { + fn tpath(&self) -> ::std::string::String { + use std::string::ToString; self.path.to_string() } } @@ -423,6 +425,7 @@ where #[cfg(test)] mod test { use std::mem; + use std::vec::Vec; use super::*; use super::super::NodeData; diff --git a/lib/cretonne/src/bforest/node.rs b/lib/cretonne/src/bforest/node.rs index 53a96f9b14..779554f0c8 100644 --- a/lib/cretonne/src/bforest/node.rs +++ b/lib/cretonne/src/bforest/node.rs @@ -580,6 +580,7 @@ where #[cfg(test)] mod test { use std::mem; + use std::string::ToString; use super::*; // Forest impl for a set implementation. diff --git a/lib/cretonne/src/bforest/pool.rs b/lib/cretonne/src/bforest/pool.rs index 37801ee4ab..18c455fdd1 100644 --- a/lib/cretonne/src/bforest/pool.rs +++ b/lib/cretonne/src/bforest/pool.rs @@ -78,6 +78,7 @@ impl NodePool { { use std::borrow::Borrow; use std::cmp::Ordering; + use std::vec::Vec; use super::Comparator; use entity::SparseSet; diff --git a/lib/cretonne/src/bforest/set.rs b/lib/cretonne/src/bforest/set.rs index 6992265773..22f5122c7c 100644 --- a/lib/cretonne/src/bforest/set.rs +++ b/lib/cretonne/src/bforest/set.rs @@ -314,7 +314,8 @@ where } /// Get a text version of the path to the current position. - fn tpath(&self) -> String { + fn tpath(&self) -> ::std::string::String { + use std::string::ToString; self.path.to_string() } } @@ -351,6 +352,7 @@ where #[cfg(test)] mod test { use std::mem; + use std::vec::Vec; use super::*; use super::super::NodeData; diff --git a/lib/cretonne/src/dbg.rs b/lib/cretonne/src/dbg.rs index ace22b6c47..8f949f00e1 100644 --- a/lib/cretonne/src/dbg.rs +++ b/lib/cretonne/src/dbg.rs @@ -19,10 +19,12 @@ use std::fmt; use std::fs::File; #[cfg(not(feature = "no_std"))] use std::io::{self, Write}; +#[cfg(not(feature = "no_std"))] use std::sync::atomic; #[cfg(not(feature = "no_std"))] use std::thread; +#[cfg(not(feature = "no_std"))] static STATE: atomic::AtomicIsize = atomic::ATOMIC_ISIZE_INIT; /// Is debug tracing enabled? diff --git a/lib/cretonne/src/flowgraph.rs b/lib/cretonne/src/flowgraph.rs index d1e45312ac..9c0fa09f26 100644 --- a/lib/cretonne/src/flowgraph.rs +++ b/lib/cretonne/src/flowgraph.rs @@ -204,6 +204,7 @@ mod tests { use super::*; use cursor::{Cursor, FuncCursor}; use ir::{Function, InstBuilder, types}; + use std::vec::Vec; #[test] fn empty() { diff --git a/lib/cretonne/src/ir/condcodes.rs b/lib/cretonne/src/ir/condcodes.rs index 4bbf82cb6f..11c438b10a 100644 --- a/lib/cretonne/src/ir/condcodes.rs +++ b/lib/cretonne/src/ir/condcodes.rs @@ -266,6 +266,7 @@ impl FromStr for FloatCC { #[cfg(test)] mod tests { use super::*; + use std::string::ToString; static INT_ALL: [IntCC; 10] = [ IntCC::Equal, diff --git a/lib/cretonne/src/ir/dfg.rs b/lib/cretonne/src/ir/dfg.rs index 023d8751b6..2f1cc8763b 100644 --- a/lib/cretonne/src/ir/dfg.rs +++ b/lib/cretonne/src/ir/dfg.rs @@ -944,6 +944,7 @@ mod tests { use cursor::{Cursor, FuncCursor}; use ir::types; use ir::{Function, Opcode, InstructionData, TrapCode}; + use std::string::ToString; #[test] fn make_inst() { diff --git a/lib/cretonne/src/ir/entities.rs b/lib/cretonne/src/ir/entities.rs index a9e6705d98..1a4e772be4 100644 --- a/lib/cretonne/src/ir/entities.rs +++ b/lib/cretonne/src/ir/entities.rs @@ -262,6 +262,7 @@ impl From for AnyEntity { mod tests { use super::*; use std::u32; + use std::string::ToString; #[test] fn value_with_number() { diff --git a/lib/cretonne/src/ir/extfunc.rs b/lib/cretonne/src/ir/extfunc.rs index 0aa87fa60e..f8fe767970 100644 --- a/lib/cretonne/src/ir/extfunc.rs +++ b/lib/cretonne/src/ir/extfunc.rs @@ -379,6 +379,7 @@ impl FromStr for CallConv { mod tests { use super::*; use ir::types::{I32, F32, B8}; + use std::string::ToString; #[test] fn argument_type() { diff --git a/lib/cretonne/src/ir/extname.rs b/lib/cretonne/src/ir/extname.rs index f58f8d24ec..b7bcc7d94f 100644 --- a/lib/cretonne/src/ir/extname.rs +++ b/lib/cretonne/src/ir/extname.rs @@ -122,6 +122,7 @@ impl FromStr for ExternalName { mod tests { use super::ExternalName; use ir::LibCall; + use std::string::ToString; #[test] fn display_testcase() { diff --git a/lib/cretonne/src/ir/immediates.rs b/lib/cretonne/src/ir/immediates.rs index 69607754a2..0dca3144cb 100644 --- a/lib/cretonne/src/ir/immediates.rs +++ b/lib/cretonne/src/ir/immediates.rs @@ -630,6 +630,7 @@ mod tests { use std::{f32, f64}; use std::str::FromStr; use std::fmt::Display; + use std::string::ToString; #[test] fn format_imm64() { diff --git a/lib/cretonne/src/ir/instructions.rs b/lib/cretonne/src/ir/instructions.rs index 1340c14055..22800ac634 100644 --- a/lib/cretonne/src/ir/instructions.rs +++ b/lib/cretonne/src/ir/instructions.rs @@ -724,6 +724,7 @@ pub enum ResolvedConstraint { #[cfg(test)] mod tests { use super::*; + use std::string::ToString; #[test] fn opcodes() { diff --git a/lib/cretonne/src/ir/jumptable.rs b/lib/cretonne/src/ir/jumptable.rs index 4f6e117b64..1c7bf79157 100644 --- a/lib/cretonne/src/ir/jumptable.rs +++ b/lib/cretonne/src/ir/jumptable.rs @@ -142,6 +142,8 @@ mod tests { use super::JumpTableData; use ir::Ebb; use entity::EntityRef; + use std::vec::Vec; + use std::string::ToString; #[test] fn empty() { diff --git a/lib/cretonne/src/ir/layout.rs b/lib/cretonne/src/ir/layout.rs index e18ffd7a33..1fc1c048fb 100644 --- a/lib/cretonne/src/ir/layout.rs +++ b/lib/cretonne/src/ir/layout.rs @@ -743,6 +743,7 @@ mod tests { use entity::EntityRef; use ir::{Ebb, Inst, ProgramOrder, SourceLoc}; use std::cmp::Ordering; + use std::vec::Vec; struct LayoutCursor<'f> { /// Borrowed function layout. Public so it can be re-borrowed from this cursor. diff --git a/lib/cretonne/src/ir/libcall.rs b/lib/cretonne/src/ir/libcall.rs index e8c848f71d..85133611be 100644 --- a/lib/cretonne/src/ir/libcall.rs +++ b/lib/cretonne/src/ir/libcall.rs @@ -100,6 +100,7 @@ impl LibCall { #[cfg(test)] mod test { use super::*; + use std::string::ToString; #[test] fn display() { diff --git a/lib/cretonne/src/ir/progpoint.rs b/lib/cretonne/src/ir/progpoint.rs index 480160ea96..72a00602ee 100644 --- a/lib/cretonne/src/ir/progpoint.rs +++ b/lib/cretonne/src/ir/progpoint.rs @@ -148,6 +148,7 @@ mod tests { use super::*; use entity::EntityRef; use ir::{Inst, Ebb}; + use std::string::ToString; #[test] fn convert() { diff --git a/lib/cretonne/src/ir/sourceloc.rs b/lib/cretonne/src/ir/sourceloc.rs index ffcf0db943..36e5247488 100644 --- a/lib/cretonne/src/ir/sourceloc.rs +++ b/lib/cretonne/src/ir/sourceloc.rs @@ -51,6 +51,7 @@ impl fmt::Display for SourceLoc { #[cfg(test)] mod tests { use ir::SourceLoc; + use std::string::ToString; #[test] fn display() { diff --git a/lib/cretonne/src/ir/stackslot.rs b/lib/cretonne/src/ir/stackslot.rs index 744bd06ac3..7baadde636 100644 --- a/lib/cretonne/src/ir/stackslot.rs +++ b/lib/cretonne/src/ir/stackslot.rs @@ -320,6 +320,7 @@ mod tests { use ir::Function; use ir::types; use super::*; + use std::string::ToString; #[test] fn stack_slot() { diff --git a/lib/cretonne/src/ir/trapcode.rs b/lib/cretonne/src/ir/trapcode.rs index 2374c206f3..1487a63aad 100644 --- a/lib/cretonne/src/ir/trapcode.rs +++ b/lib/cretonne/src/ir/trapcode.rs @@ -83,6 +83,7 @@ impl FromStr for TrapCode { #[cfg(test)] mod tests { use super::*; + use std::string::ToString; // Everything but user-defined codes. const CODES: [TrapCode; 8] = [ diff --git a/lib/cretonne/src/ir/types.rs b/lib/cretonne/src/ir/types.rs index f8774250ec..07cf97aefa 100644 --- a/lib/cretonne/src/ir/types.rs +++ b/lib/cretonne/src/ir/types.rs @@ -324,6 +324,7 @@ impl Default for Type { #[cfg(test)] mod tests { use super::*; + use std::string::ToString; #[test] fn basic_scalars() { diff --git a/lib/cretonne/src/isa/arm32/registers.rs b/lib/cretonne/src/isa/arm32/registers.rs index 7c6ac406e1..e2c4813bdd 100644 --- a/lib/cretonne/src/isa/arm32/registers.rs +++ b/lib/cretonne/src/isa/arm32/registers.rs @@ -8,6 +8,7 @@ include!(concat!(env!("OUT_DIR"), "/registers-arm32.rs")); mod tests { use super::{INFO, GPR, S, D}; use isa::RegUnit; + use std::string::{String, ToString}; #[test] fn unit_encodings() { diff --git a/lib/cretonne/src/isa/arm64/registers.rs b/lib/cretonne/src/isa/arm64/registers.rs index 62311aaebe..2c1d85e091 100644 --- a/lib/cretonne/src/isa/arm64/registers.rs +++ b/lib/cretonne/src/isa/arm64/registers.rs @@ -8,6 +8,7 @@ include!(concat!(env!("OUT_DIR"), "/registers-arm64.rs")); mod tests { use super::INFO; use isa::RegUnit; + use std::string::{String, ToString}; #[test] fn unit_encodings() { diff --git a/lib/cretonne/src/isa/intel/registers.rs b/lib/cretonne/src/isa/intel/registers.rs index c2b96f77d3..c972c10a13 100644 --- a/lib/cretonne/src/isa/intel/registers.rs +++ b/lib/cretonne/src/isa/intel/registers.rs @@ -8,6 +8,7 @@ include!(concat!(env!("OUT_DIR"), "/registers-intel.rs")); mod tests { use super::*; use isa::RegUnit; + use std::string::{String, ToString}; #[test] fn unit_encodings() { diff --git a/lib/cretonne/src/isa/riscv/mod.rs b/lib/cretonne/src/isa/riscv/mod.rs index 8efae74af7..6fc976686b 100644 --- a/lib/cretonne/src/isa/riscv/mod.rs +++ b/lib/cretonne/src/isa/riscv/mod.rs @@ -117,6 +117,7 @@ mod tests { use isa; use ir::{DataFlowGraph, InstructionData, Opcode}; use ir::{types, immediates}; + use std::string::{String, ToString}; fn encstr(isa: &isa::TargetIsa, enc: Result) -> String { match enc { diff --git a/lib/cretonne/src/isa/riscv/registers.rs b/lib/cretonne/src/isa/riscv/registers.rs index 3cce8c4988..e2073899b6 100644 --- a/lib/cretonne/src/isa/riscv/registers.rs +++ b/lib/cretonne/src/isa/riscv/registers.rs @@ -8,6 +8,7 @@ include!(concat!(env!("OUT_DIR"), "/registers-riscv.rs")); mod tests { use super::{INFO, GPR, FPR}; use isa::RegUnit; + use std::string::{String, ToString}; #[test] fn unit_encodings() { diff --git a/lib/cretonne/src/isa/riscv/settings.rs b/lib/cretonne/src/isa/riscv/settings.rs index 8cb376e5da..7b609acf20 100644 --- a/lib/cretonne/src/isa/riscv/settings.rs +++ b/lib/cretonne/src/isa/riscv/settings.rs @@ -12,6 +12,7 @@ include!(concat!(env!("OUT_DIR"), "/settings-riscv.rs")); mod tests { use super::{builder, Flags}; use settings::{self, Configurable}; + use std::string::ToString; #[test] fn display_default() { diff --git a/lib/cretonne/src/iterators.rs b/lib/cretonne/src/iterators.rs index 08866717e8..0524343028 100644 --- a/lib/cretonne/src/iterators.rs +++ b/lib/cretonne/src/iterators.rs @@ -48,6 +48,8 @@ where #[cfg(test)] mod tests { + use std::vec::Vec; + #[test] fn adjpairs() { use super::IteratorExtras; diff --git a/lib/cretonne/src/lib.rs b/lib/cretonne/src/lib.rs index 8302095998..95868a6933 100644 --- a/lib/cretonne/src/lib.rs +++ b/lib/cretonne/src/lib.rs @@ -63,7 +63,6 @@ mod write; #[cfg(feature = "no_std")] mod std { pub use core::*; - #[macro_use] pub use alloc::{boxed, vec, string}; pub mod collections { pub use hashmap_core::{HashMap, HashSet}; diff --git a/lib/cretonne/src/loop_analysis.rs b/lib/cretonne/src/loop_analysis.rs index dfd5cf135a..431496b6e4 100644 --- a/lib/cretonne/src/loop_analysis.rs +++ b/lib/cretonne/src/loop_analysis.rs @@ -231,6 +231,7 @@ mod test { use loop_analysis::{Loop, LoopAnalysis}; use flowgraph::ControlFlowGraph; use dominator_tree::DominatorTree; + use std::vec::Vec; #[test] fn nested_loops_detection() { diff --git a/lib/cretonne/src/partition_slice.rs b/lib/cretonne/src/partition_slice.rs index 6f106e5bfc..7a94a9fe0d 100644 --- a/lib/cretonne/src/partition_slice.rs +++ b/lib/cretonne/src/partition_slice.rs @@ -33,6 +33,7 @@ where #[cfg(test)] mod tests { use super::partition_slice; + use std::vec::Vec; fn check(x: &[u32], want: &[u32]) { assert_eq!(x.len(), want.len()); diff --git a/lib/cretonne/src/regalloc/allocatable_set.rs b/lib/cretonne/src/regalloc/allocatable_set.rs index cc72066b5d..e0abf76d37 100644 --- a/lib/cretonne/src/regalloc/allocatable_set.rs +++ b/lib/cretonne/src/regalloc/allocatable_set.rs @@ -221,6 +221,7 @@ impl fmt::Display for AllocatableSet { mod tests { use super::*; use isa::registers::{RegClass, RegClassData}; + use std::vec::Vec; // Register classes for testing. const GPR: RegClass = &RegClassData { diff --git a/lib/cretonne/src/regalloc/coalescing.rs b/lib/cretonne/src/regalloc/coalescing.rs index 225aa8e9d8..5933170e33 100644 --- a/lib/cretonne/src/regalloc/coalescing.rs +++ b/lib/cretonne/src/regalloc/coalescing.rs @@ -18,8 +18,6 @@ use std::cmp; use std::iter; use std::fmt; use std::slice; -use std::iter::Peekable; -use std::mem; use std::vec::Vec; use isa::{TargetIsa, EncInfo}; use timing; diff --git a/lib/cretonne/src/regalloc/liverange.rs b/lib/cretonne/src/regalloc/liverange.rs index 7d7d6a8775..93d5b0c244 100644 --- a/lib/cretonne/src/regalloc/liverange.rs +++ b/lib/cretonne/src/regalloc/liverange.rs @@ -463,6 +463,7 @@ mod tests { use entity::EntityRef; use ir::{ProgramOrder, ExpandedProgramPoint}; use std::cmp::Ordering; + use std::vec::Vec; // Dummy program order which simply compares indexes. // It is assumed that EBBs have indexes that are multiples of 10, and instructions have indexes diff --git a/lib/cretonne/src/regalloc/pressure.rs b/lib/cretonne/src/regalloc/pressure.rs index c71037efdd..67e0e99b70 100644 --- a/lib/cretonne/src/regalloc/pressure.rs +++ b/lib/cretonne/src/regalloc/pressure.rs @@ -273,6 +273,7 @@ mod tests { use regalloc::AllocatableSet; use std::borrow::Borrow; use super::Pressure; + use std::boxed::Box; // Make an arm32 `TargetIsa`, if possible. fn arm32() -> Option> { diff --git a/lib/cretonne/src/regalloc/solver.rs b/lib/cretonne/src/regalloc/solver.rs index c2f8017c3a..db5efcab06 100644 --- a/lib/cretonne/src/regalloc/solver.rs +++ b/lib/cretonne/src/regalloc/solver.rs @@ -1163,6 +1163,7 @@ mod tests { use isa::{TargetIsa, RegClass, RegUnit, RegInfo}; use regalloc::AllocatableSet; use super::{Solver, Move}; + use std::boxed::Box; // Make an arm32 `TargetIsa`, if possible. fn arm32() -> Option> { diff --git a/lib/cretonne/src/settings.rs b/lib/cretonne/src/settings.rs index a7da8d6f17..b6ef9eae30 100644 --- a/lib/cretonne/src/settings.rs +++ b/lib/cretonne/src/settings.rs @@ -348,6 +348,7 @@ mod tests { use super::{builder, Flags}; use super::Error::*; use super::Configurable; + use std::string::ToString; #[test] fn display_default() { diff --git a/lib/cretonne/src/timing.rs b/lib/cretonne/src/timing.rs index c05ee93004..15496ed9ce 100644 --- a/lib/cretonne/src/timing.rs +++ b/lib/cretonne/src/timing.rs @@ -238,6 +238,7 @@ mod details { #[cfg(test)] mod test { use super::*; + use std::string::ToString; #[test] fn display() { diff --git a/lib/cretonne/src/verifier/mod.rs b/lib/cretonne/src/verifier/mod.rs index c3bebc5ae6..117de2f38b 100644 --- a/lib/cretonne/src/verifier/mod.rs +++ b/lib/cretonne/src/verifier/mod.rs @@ -1132,7 +1132,10 @@ mod tests { Ok(_) => { panic!("Expected an error!") }, Err(Error { message, .. } ) => { if !message.contains($msg) { + #[cfg(not(feature = "no_std"))] panic!(format!("'{}' did not contain the substring '{}'", message, $msg)); + #[cfg(feature = "no_std")] + panic!("error message did not contain the expected substring"); } } } diff --git a/lib/cretonne/src/write.rs b/lib/cretonne/src/write.rs index 4ca8ddaadb..ff60033af2 100644 --- a/lib/cretonne/src/write.rs +++ b/lib/cretonne/src/write.rs @@ -467,6 +467,7 @@ impl<'a> fmt::Display for DisplayValues<'a> { mod tests { use ir::{Function, ExternalName, StackSlotData, StackSlotKind}; use ir::types; + use std::string::ToString; #[test] fn basic() { diff --git a/lib/frontend/src/ssa.rs b/lib/frontend/src/ssa.rs index f99ff5e179..fc2ebcca08 100644 --- a/lib/frontend/src/ssa.rs +++ b/lib/frontend/src/ssa.rs @@ -1039,7 +1039,12 @@ mod tests { let flags = settings::Flags::new(&settings::builder()); match verify_function(&func, &flags) { Ok(()) => {} - Err(err) => panic!(err.message), + Err(err) => { + #[cfg(not(feature = "no_std"))] + panic!(err.message); + #[cfg(feature = "no_std")] + panic!("function failed to verify"); + } } } @@ -1213,7 +1218,12 @@ mod tests { let flags = settings::Flags::new(&settings::builder()); match verify_function(&func, &flags) { Ok(()) => {} - Err(err) => panic!(err.message), + Err(err) => { + #[cfg(not(feature = "no_std"))] + panic!(err.message); + #[cfg(feature = "no_std")] + panic!("function failed to verify"); + } } } @@ -1259,7 +1269,12 @@ mod tests { let flags = settings::Flags::new(&settings::builder()); match verify_function(&func, &flags) { Ok(()) => {} - Err(err) => panic!(err.message), + Err(err) => { + #[cfg(not(feature = "no_std"))] + panic!(err.message); + #[cfg(feature = "no_std")] + panic!("function failed to verify"); + } } } } From e37f45667fc37c0813def2359acd2a54cc6744f6 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 13 Feb 2018 17:48:04 -0800 Subject: [PATCH 14/27] Add an explicit `std` feature so that features are purely additive. --- README.rst | 10 ++++++---- cranelift/test-no_std.sh | 1 + lib/cretonne/Cargo.toml | 11 ++++++++--- lib/cretonne/src/lib.rs | 8 ++++---- lib/frontend/Cargo.toml | 4 +++- lib/frontend/src/lib.rs | 8 ++++---- lib/native/Cargo.toml | 4 +++- lib/native/src/lib.rs | 3 ++- lib/wasm/Cargo.toml | 11 ++++++----- lib/wasm/src/lib.rs | 8 ++++---- 10 files changed, 41 insertions(+), 27 deletions(-) diff --git a/README.rst b/README.rst index 690472578b..caa24342d9 100644 --- a/README.rst +++ b/README.rst @@ -60,18 +60,20 @@ installed. Building with `no_std` ---------------------- -To build cretonne without libstd, enable the `no_std` feature on `lib/cretonne`, -`lib/frontend`, `lib/native`, and `lib/wasm`. +To build cretonne without libstd, disable the `std` feature on `lib/cretonne`, +`lib/frontend`, `lib/native`, and `lib/wasm`, which is otherwise enabled by +default, and enable the `no_std` feature. For example, to build `cretonne`: cd lib/cretonne - cargo build --features no_std + cargo build --no-default-features --features no_std Or, when using `cretonne` as a dependency (in Cargo.toml): [dependency.cretonne] - path = "..." + ... + default-features = false features = ["no_std"] `no_std` is currently "best effort". We won't try to break it, and we'll diff --git a/cranelift/test-no_std.sh b/cranelift/test-no_std.sh index c9d3fe38f7..d3edbb921f 100755 --- a/cranelift/test-no_std.sh +++ b/cranelift/test-no_std.sh @@ -21,6 +21,7 @@ for LIB in $LIBS do banner "Rust unit tests in $LIB" cd "lib/$LIB" + cargo test --no-default-features --features no_std cargo test --features no_std cd "$topdir" done diff --git a/lib/cretonne/Cargo.toml b/lib/cretonne/Cargo.toml index 0cf3fffd9b..c1c666fa77 100644 --- a/lib/cretonne/Cargo.toml +++ b/lib/cretonne/Cargo.toml @@ -17,14 +17,19 @@ name = "cretonne" # Please don't add any unless they are essential to the task of creating binary # machine code. Integration tests that need external dependencies can be # accomodated in `tests`. + [dependencies.hashmap_core] version = "0.1.1" optional = true + [dependencies.error_core] version = "0.1.0" optional = true [features] -# Currently, the only feature is the `no_std` feature. -# Enabling this disables use of `stdlib`. -no_std = ["hashmap_core", "error_core"] \ No newline at end of file +# The "std" feature enables use of libstd. The "no_std" feature enables use +# of some minimal std-like replacement libraries. At least one of these two +# features to be enabled. +default = ["std"] +std = [] +no_std = ["hashmap_core", "error_core"] diff --git a/lib/cretonne/src/lib.rs b/lib/cretonne/src/lib.rs index 95868a6933..0952969bb1 100644 --- a/lib/cretonne/src/lib.rs +++ b/lib/cretonne/src/lib.rs @@ -1,16 +1,16 @@ //! Cretonne code generation library. -#![cfg_attr(feature = "no_std", no_std)] #![deny(missing_docs)] // Turns on alloc feature if no_std -#![cfg_attr(feature = "no_std", feature(alloc))] +#![cfg_attr(not(feature = "std"), no_std)] +#![cfg_attr(not(feature = "std"), feature(alloc))] // Include the `hashmap_core` crate if no_std #[cfg(feature = "no_std")] extern crate hashmap_core; #[cfg(feature = "no_std")] extern crate error_core; -#[cfg(feature = "no_std")] +#[cfg(not(feature = "std"))] #[macro_use] extern crate alloc; @@ -60,7 +60,7 @@ mod unreachable_code; mod write; /// This replaces `std` in builds with no_std. -#[cfg(feature = "no_std")] +#[cfg(not(feature = "std"))] mod std { pub use core::*; pub use alloc::{boxed, vec, string}; diff --git a/lib/frontend/Cargo.toml b/lib/frontend/Cargo.toml index 32c65e4ded..bccc84f6bc 100644 --- a/lib/frontend/Cargo.toml +++ b/lib/frontend/Cargo.toml @@ -12,7 +12,9 @@ readme = "README.md" name = "cton_frontend" [dependencies] -cretonne = { path = "../cretonne", version = "0.1.0" } +cretonne = { path = "../cretonne", version = "0.1.0", default-features = false } [features] +default = ["std"] +std = ["cretonne/std"] no_std = ["cretonne/no_std"] diff --git a/lib/frontend/src/lib.rs b/lib/frontend/src/lib.rs index 84af6f976b..52765b5a20 100644 --- a/lib/frontend/src/lib.rs +++ b/lib/frontend/src/lib.rs @@ -142,14 +142,14 @@ //! } //! ``` -#![cfg_attr(feature = "no_std", no_std)] #![deny(missing_docs)] -#![cfg_attr(feature = "no_std", feature(alloc))] +#![cfg_attr(not(feature = "std"), no_std)] +#![cfg_attr(not(feature = "std"), feature(alloc))] extern crate cretonne; -#[cfg(feature = "no_std")] +#[cfg(not(feature = "std"))] extern crate alloc; pub use frontend::{ILBuilder, FunctionBuilder}; @@ -157,7 +157,7 @@ pub use frontend::{ILBuilder, FunctionBuilder}; mod frontend; mod ssa; -#[cfg(feature = "no_std")] +#[cfg(not(feature = "std"))] mod std { pub use alloc::vec; pub use core::*; diff --git a/lib/native/Cargo.toml b/lib/native/Cargo.toml index 57a2d0bc3c..32417e8718 100644 --- a/lib/native/Cargo.toml +++ b/lib/native/Cargo.toml @@ -11,10 +11,12 @@ readme = "README.md" name = "cton_native" [dependencies] -cretonne = { path = "../cretonne", version = "0.1.0" } +cretonne = { path = "../cretonne", version = "0.1.0", default-features = false } [target.'cfg(any(target_arch = "x86", target_arch = "x86_64"))'.dependencies] raw-cpuid = "3.0.0" [features] +default = ["std"] +std = ["cretonne/std"] no_std = ["cretonne/no_std"] diff --git a/lib/native/src/lib.rs b/lib/native/src/lib.rs index 284366a65c..514e6df314 100644 --- a/lib/native/src/lib.rs +++ b/lib/native/src/lib.rs @@ -1,8 +1,9 @@ //! Performs autodetection of the host for the purposes of running //! Cretonne to generate code to run on the same machine. -#![cfg_attr(feature = "no_std", no_std)] #![deny(missing_docs)] +#![cfg_attr(not(feature = "std"), no_std)] + extern crate cretonne; #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] diff --git a/lib/wasm/Cargo.toml b/lib/wasm/Cargo.toml index 448166d568..3bd2b36aa8 100644 --- a/lib/wasm/Cargo.toml +++ b/lib/wasm/Cargo.toml @@ -12,12 +12,13 @@ name = "cton_wasm" [dependencies] wasmparser = "0.14.1" -cretonne = { path = "../cretonne", version = "0.1.0" } -cretonne-frontend = { path = "../frontend", version = "0.1.0" } +cretonne = { path = "../cretonne", version = "0.1.0", default_features = false } +cretonne-frontend = { path = "../frontend", version = "0.1.0", default_features = false } [dependencies.hashmap_core] version = "0.1.1" optional = true + [dependencies.error_core] version = "0.1.0" optional = true @@ -26,6 +27,6 @@ optional = true tempdir = "0.3.5" [features] -# Currently, the only feature is the `no_std` feature. -# Enabling this disables use of `stdlib`. -no_std = ["hashmap_core", "error_core", "cretonne/no_std", "cretonne-frontend/no_std"] \ No newline at end of file +default = ["std"] +std = ["cretonne/std", "cretonne-frontend/std"] +no_std = ["hashmap_core", "error_core", "cretonne/no_std", "cretonne-frontend/no_std"] diff --git a/lib/wasm/src/lib.rs b/lib/wasm/src/lib.rs index 9005e6cd42..76e69887d9 100644 --- a/lib/wasm/src/lib.rs +++ b/lib/wasm/src/lib.rs @@ -9,12 +9,12 @@ //! //! The main function of this module is [`translate_module`](fn.translate_module.html). -#![cfg_attr(feature = "no_std", no_std)] #![deny(missing_docs)] -#![cfg_attr(feature = "no_std", feature(alloc))] +#![cfg_attr(not(feature = "std"), no_std)] +#![cfg_attr(not(feature = "std"), feature(alloc))] -#[cfg(feature = "no_std")] +#[cfg(not(feature = "std"))] #[macro_use] extern crate alloc; @@ -42,7 +42,7 @@ pub use environ::{FuncEnvironment, ModuleEnvironment, DummyEnvironment, GlobalVa pub use translation_utils::{FunctionIndex, GlobalIndex, TableIndex, MemoryIndex, SignatureIndex, Global, GlobalInit, Table, Memory}; -#[cfg(feature = "no_std")] +#[cfg(not(feature = "std"))] mod std { pub use alloc::vec; pub use alloc::string; From 6c9cf2bacfafd9b90e828616e8cc9f8c343fcc50 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 15 Feb 2018 23:14:33 -0800 Subject: [PATCH 15/27] Switch from error_core to failure. --- README.rst | 4 --- lib/cretonne/Cargo.toml | 8 +++--- lib/cretonne/src/lib.rs | 8 +++--- lib/cretonne/src/result.rs | 43 +++++++------------------------- lib/cretonne/src/verifier/mod.rs | 9 +------ lib/filecheck/Cargo.toml | 2 ++ lib/filecheck/src/error.rs | 41 ++++++++---------------------- lib/filecheck/src/lib.rs | 3 +++ lib/wasm/Cargo.toml | 6 +---- lib/wasm/src/environ/dummy.rs | 3 +-- lib/wasm/src/lib.rs | 5 ---- 11 files changed, 33 insertions(+), 99 deletions(-) diff --git a/README.rst b/README.rst index caa24342d9..621217f888 100644 --- a/README.rst +++ b/README.rst @@ -92,10 +92,6 @@ called `hashmap_core` is pulled in (only in `no_std` builds). This is mostly the same as `std::collections::HashMap`, except that it doesn't have DOS protection. Just something to think about. -Lastly, to support `std::error`, which isn't is `std` or `alloc` for -an inexplicable reason, the `error_core` crate is also used in `no_std` builds. -You might need it, as well, when interfacing with `CtonError`. - Building the documentation -------------------------- diff --git a/lib/cretonne/Cargo.toml b/lib/cretonne/Cargo.toml index c1c666fa77..09d3a7dd7b 100644 --- a/lib/cretonne/Cargo.toml +++ b/lib/cretonne/Cargo.toml @@ -17,19 +17,17 @@ name = "cretonne" # Please don't add any unless they are essential to the task of creating binary # machine code. Integration tests that need external dependencies can be # accomodated in `tests`. +failure = { version = "0.1.1", default-features = false, features = ["derive"] } +failure_derive = { version = "0.1.1", default-features = false } [dependencies.hashmap_core] version = "0.1.1" optional = true -[dependencies.error_core] -version = "0.1.0" -optional = true - [features] # The "std" feature enables use of libstd. The "no_std" feature enables use # of some minimal std-like replacement libraries. At least one of these two # features to be enabled. default = ["std"] std = [] -no_std = ["hashmap_core", "error_core"] +no_std = ["hashmap_core"] diff --git a/lib/cretonne/src/lib.rs b/lib/cretonne/src/lib.rs index 0952969bb1..ddb391852d 100644 --- a/lib/cretonne/src/lib.rs +++ b/lib/cretonne/src/lib.rs @@ -8,11 +8,12 @@ // Include the `hashmap_core` crate if no_std #[cfg(feature = "no_std")] extern crate hashmap_core; -#[cfg(feature = "no_std")] -extern crate error_core; #[cfg(not(feature = "std"))] #[macro_use] extern crate alloc; +extern crate failure; +#[macro_use] +extern crate failure_derive; pub use context::Context; pub use legalizer::legalize_function; @@ -69,7 +70,4 @@ mod std { pub use hashmap_core::map as hash_map; pub use alloc::BTreeSet; } - pub mod error { - pub use error_core::Error; - } } diff --git a/lib/cretonne/src/result.rs b/lib/cretonne/src/result.rs index 387eaa9a2a..2b89c774d3 100644 --- a/lib/cretonne/src/result.rs +++ b/lib/cretonne/src/result.rs @@ -1,25 +1,28 @@ //! Result and error types representing the outcome of compiling a function. use verifier; -use std::error::Error as StdError; -use std::fmt; /// A compilation error. /// /// When Cretonne fails to compile a function, it will return one of these error codes. -#[derive(Debug, PartialEq, Eq)] +#[derive(Fail, Debug, PartialEq, Eq)] pub enum CtonError { /// The input is invalid. /// /// This error code is used by a WebAssembly translator when it encounters invalid WebAssembly /// code. This should never happen for validated WebAssembly code. + #[fail(display = "Invalid input code")] InvalidInput, /// An IL verifier error. /// /// This always represents a bug, either in the code that generated IL for Cretonne, or a bug /// in Cretonne itself. - Verifier(verifier::Error), + #[fail(display = "Verifier error: {}", _0)] + Verifier( + #[cause] + verifier::Error + ), /// An implementation limit was exceeded. /// @@ -27,48 +30,20 @@ pub enum CtonError { /// limits][limits] that cause compilation to fail when they are exceeded. /// /// [limits]: http://cretonne.readthedocs.io/en/latest/langref.html#implementation-limits + #[fail(display = "Implementation limit exceeded")] ImplLimitExceeded, /// The code size for the function is too large. /// /// Different target ISAs may impose a limit on the size of a compiled function. If that limit /// is exceeded, compilation fails. + #[fail(display = "Code for function is too large")] CodeTooLarge, } /// A Cretonne compilation result. pub type CtonResult = Result<(), CtonError>; -impl fmt::Display for CtonError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match *self { - CtonError::Verifier(ref e) => write!(f, "Verifier error: {}", e), - CtonError::InvalidInput | - CtonError::ImplLimitExceeded | - CtonError::CodeTooLarge => f.write_str(self.description()), - } - } -} - -impl StdError for CtonError { - fn description(&self) -> &str { - match *self { - CtonError::InvalidInput => "Invalid input code", - CtonError::Verifier(ref e) => &e.message, - CtonError::ImplLimitExceeded => "Implementation limit exceeded", - CtonError::CodeTooLarge => "Code for function is too large", - } - } - fn cause(&self) -> Option<&StdError> { - match *self { - CtonError::Verifier(ref e) => Some(e), - CtonError::InvalidInput | - CtonError::ImplLimitExceeded | - CtonError::CodeTooLarge => None, - } - } -} - impl From for CtonError { fn from(e: verifier::Error) -> CtonError { CtonError::Verifier(e) diff --git a/lib/cretonne/src/verifier/mod.rs b/lib/cretonne/src/verifier/mod.rs index 117de2f38b..821bc3d623 100644 --- a/lib/cretonne/src/verifier/mod.rs +++ b/lib/cretonne/src/verifier/mod.rs @@ -70,7 +70,6 @@ use self::flags::verify_flags; use settings::{Flags, FlagsOrIsa}; use std::cmp::Ordering; use std::collections::BTreeSet; -use std::error as std_error; use std::fmt::{self, Display, Formatter, Write}; use std::result; use std::vec::Vec; @@ -104,7 +103,7 @@ mod liveness; mod locations; /// A verifier error. -#[derive(Debug, PartialEq, Eq)] +#[derive(Fail, Debug, PartialEq, Eq)] pub struct Error { /// The entity causing the verifier error. pub location: AnyEntity, @@ -118,12 +117,6 @@ impl Display for Error { } } -impl std_error::Error for Error { - fn description(&self) -> &str { - &self.message - } -} - /// Verifier result. pub type Result = result::Result<(), Error>; diff --git a/lib/filecheck/Cargo.toml b/lib/filecheck/Cargo.toml index aec22b0f51..b29eaa5c53 100644 --- a/lib/filecheck/Cargo.toml +++ b/lib/filecheck/Cargo.toml @@ -12,3 +12,5 @@ name = "filecheck" [dependencies] regex = "0.2.6" +failure = "0.1.1" +failure_derive = "0.1.1" diff --git a/lib/filecheck/src/error.rs b/lib/filecheck/src/error.rs index 5580cc4c3c..af9657cdcc 100644 --- a/lib/filecheck/src/error.rs +++ b/lib/filecheck/src/error.rs @@ -1,21 +1,21 @@ use std::result; use std::convert::From; -use std::error::Error as StdError; -use std::fmt; use regex; /// A result from the filecheck library. pub type Result = result::Result; /// A filecheck error. -#[derive(Debug)] +#[derive(Fail, Debug)] pub enum Error { /// A syntax error in a check line. + #[fail(display = "{}", _0)] Syntax(String), /// A check refers to an undefined variable. /// /// The pattern contains `$foo` where the `foo` variable has not yet been defined. /// Use `$$` to match a literal dollar sign. + #[fail(display = "{}", _0)] UndefVariable(String), /// A pattern contains a back-reference to a variable that was defined in the same pattern. /// @@ -26,40 +26,19 @@ pub enum Error { /// check: Hello $(world=[^ ]*) /// sameln: $world /// ``` + #[fail(display = "{}", _0)] Backref(String), /// A pattern contains multiple definitions of the same variable. + #[fail(display = "{}", _0)] DuplicateDef(String), /// An error in a regular expression. /// /// Use `cause()` to get the underlying `Regex` library error. - Regex(regex::Error), -} - -impl StdError for Error { - fn description(&self) -> &str { - use Error::*; - match *self { - Syntax(ref s) | - UndefVariable(ref s) | - Backref(ref s) | - DuplicateDef(ref s) => s, - Regex(ref err) => err.description(), - } - } - - fn cause(&self) -> Option<&StdError> { - use Error::*; - match *self { - Regex(ref err) => Some(err), - _ => None, - } - } -} - -impl fmt::Display for Error { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - write!(fmt, "{}", self.description()) - } + #[fail(display = "{}", _0)] + Regex( + #[cause] + regex::Error + ), } impl From for Error { diff --git a/lib/filecheck/src/lib.rs b/lib/filecheck/src/lib.rs index a189acebdb..b29377f9ac 100644 --- a/lib/filecheck/src/lib.rs +++ b/lib/filecheck/src/lib.rs @@ -243,6 +243,9 @@ pub use variable::{VariableMap, Value, NO_VARIABLES}; pub use checker::{Checker, CheckerBuilder}; extern crate regex; +extern crate failure; +#[macro_use] +extern crate failure_derive; mod error; mod variable; diff --git a/lib/wasm/Cargo.toml b/lib/wasm/Cargo.toml index 3bd2b36aa8..7954ebc209 100644 --- a/lib/wasm/Cargo.toml +++ b/lib/wasm/Cargo.toml @@ -19,14 +19,10 @@ cretonne-frontend = { path = "../frontend", version = "0.1.0", default_features version = "0.1.1" optional = true -[dependencies.error_core] -version = "0.1.0" -optional = true - [dev-dependencies] tempdir = "0.3.5" [features] default = ["std"] std = ["cretonne/std", "cretonne-frontend/std"] -no_std = ["hashmap_core", "error_core", "cretonne/no_std", "cretonne-frontend/no_std"] +no_std = ["hashmap_core", "cretonne/no_std", "cretonne-frontend/no_std"] diff --git a/lib/wasm/src/environ/dummy.rs b/lib/wasm/src/environ/dummy.rs index de941f3b9a..102e83ef79 100644 --- a/lib/wasm/src/environ/dummy.rs +++ b/lib/wasm/src/environ/dummy.rs @@ -9,7 +9,6 @@ use cretonne::ir::types::*; use cretonne::cursor::FuncCursor; use cretonne::settings; use wasmparser; -use std::error::Error; use std::vec::Vec; use std::string::String; @@ -387,7 +386,7 @@ impl<'data> ModuleEnvironment<'data> for DummyEnvironment { let reader = wasmparser::BinaryReader::new(body_bytes); self.trans .translate_from_reader(reader, &mut func, &mut func_environ) - .map_err(|e| String::from(e.description()))?; + .map_err(|e| format!("{}", e))?; func }; self.func_bytecode_sizes.push(body_bytes.len()); diff --git a/lib/wasm/src/lib.rs b/lib/wasm/src/lib.rs index 76e69887d9..ae5c99e05e 100644 --- a/lib/wasm/src/lib.rs +++ b/lib/wasm/src/lib.rs @@ -20,8 +20,6 @@ extern crate alloc; #[cfg(feature = "no_std")] extern crate hashmap_core; -#[cfg(feature = "no_std")] -extern crate error_core; extern crate wasmparser; extern crate cton_frontend; @@ -50,7 +48,4 @@ mod std { pub mod collections { pub use hashmap_core::{HashMap, map as hash_map}; } - pub mod error { - pub use error_core::Error; - } } From 5ffdc5174238fab5ed3c596105ab9b4345342f72 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 27 Feb 2018 12:41:43 -0800 Subject: [PATCH 16/27] Fix formatting of no_std instructions in README.rst. --- README.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.rst b/README.rst index 621217f888..0186bc57f8 100644 --- a/README.rst +++ b/README.rst @@ -66,11 +66,15 @@ default, and enable the `no_std` feature. For example, to build `cretonne`: +.. code-block:: sh + cd lib/cretonne cargo build --no-default-features --features no_std Or, when using `cretonne` as a dependency (in Cargo.toml): +.. code-block:: + [dependency.cretonne] ... default-features = false From 1a671cf82f6144856b257a193ba6605f06872c15 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 12 Mar 2018 14:06:15 -0700 Subject: [PATCH 17/27] Remove uses of `println!` in tests. In this case, it's a little nicer to just use more assertions, which will print their line number indicating how far the test got, when they fail. And this allows the tests to be run in no_std configurations. --- lib/cretonne/src/divconst_magic_numbers.rs | 23 ++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/cretonne/src/divconst_magic_numbers.rs b/lib/cretonne/src/divconst_magic_numbers.rs index b046e22411..f189e23d1a 100644 --- a/lib/cretonne/src/divconst_magic_numbers.rs +++ b/lib/cretonne/src/divconst_magic_numbers.rs @@ -480,56 +480,63 @@ mod tests { // don't panic with integer wraparounds, especially at boundary // cases for their arguments. The actual results are thrown away. let mut total: u64 = 0; - println!("Testing UP magicU32"); + // Testing UP magicU32 for x in 2..(200 * 1000u32) { let m = magicU32(x); total = total ^ (m.mulBy as u64); total = total + (m.shiftBy as u64); total = total - (if m.doAdd { 123 } else { 456 }); } - println!("Testing DOWN magicU32"); + assert_eq!(total, 1747815691); + // Testing DOWN magicU32 for x in 0..(200 * 1000u32) { let m = magicU32(0xFFFF_FFFFu32 - x); total = total ^ (m.mulBy as u64); total = total + (m.shiftBy as u64); total = total - (if m.doAdd { 123 } else { 456 }); } + assert_eq!(total, 2210292772); - println!("Testing UP magicU64"); + // Testing UP magicU64 for x in 2..(200 * 1000u64) { let m = magicU64(x); total = total ^ m.mulBy; total = total + (m.shiftBy as u64); total = total - (if m.doAdd { 123 } else { 456 }); } - println!("Testing DOWN magicU64"); + assert_eq!(total, 7430004084791260605); + // Testing DOWN magicU64 for x in 0..(200 * 1000u64) { let m = magicU64(0xFFFF_FFFF_FFFF_FFFFu64 - x); total = total ^ m.mulBy; total = total + (m.shiftBy as u64); total = total - (if m.doAdd { 123 } else { 456 }); } + assert_eq!(total, 7547519887519825919); - println!("Testing UP magicS32"); + // Testing UP magicS32 for x in 0..(200 * 1000i32) { let m = magicS32(-0x8000_0000i32 + x); total = total ^ (m.mulBy as u64); total = total + (m.shiftBy as u64); } - println!("Testing DOWN magicS32"); + assert_eq!(total, 10899224186731671235); + // Testing DOWN magicS32 for x in 0..(200 * 1000i32) { let m = magicS32(0x7FFF_FFFFi32 - x); total = total ^ (m.mulBy as u64); total = total + (m.shiftBy as u64); } + assert_eq!(total, 7547519887517897369); - println!("Testing UP magicS64"); + // Testing UP magicS64 for x in 0..(200 * 1000i64) { let m = magicS64(-0x8000_0000_0000_0000i64 + x); total = total ^ (m.mulBy as u64); total = total + (m.shiftBy as u64); } - println!("Testing DOWN magicS64"); + assert_eq!(total, 8029756891368555163); + // Testing DOWN magicS64 for x in 0..(200 * 1000i64) { let m = magicS64(0x7FFF_FFFF_FFFF_FFFFi64 - x); total = total ^ (m.mulBy as u64); From aaf0def241e40b44badedf97b113be49bb00df9e Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 12 Mar 2018 14:09:34 -0700 Subject: [PATCH 18/27] Add lint overrides for unused `extern crate hashmap_core`. This allows these files to build with both the `no_std` and `std` features enabled at the same time. --- lib/cretonne/src/lib.rs | 1 + lib/wasm/src/lib.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/cretonne/src/lib.rs b/lib/cretonne/src/lib.rs index 9656f6d1e1..29643d552f 100644 --- a/lib/cretonne/src/lib.rs +++ b/lib/cretonne/src/lib.rs @@ -9,6 +9,7 @@ #![cfg_attr(not(feature = "std"), feature(alloc))] // Include the `hashmap_core` crate if no_std +#[allow(unused_extern_crates)] #[cfg(feature = "no_std")] extern crate hashmap_core; #[cfg(not(feature = "std"))] diff --git a/lib/wasm/src/lib.rs b/lib/wasm/src/lib.rs index 4dc802d50f..a6492b5d66 100644 --- a/lib/wasm/src/lib.rs +++ b/lib/wasm/src/lib.rs @@ -20,6 +20,7 @@ #[macro_use] extern crate alloc; +#[allow(unused_extern_crates)] #[cfg(feature = "no_std")] extern crate hashmap_core; From fc7b0a7e510606a16ed5c8da3f6be3d85902683d Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 22 Mar 2018 13:43:06 -0700 Subject: [PATCH 19/27] Rename the `no_std` feature to `core`. See https://github.com/yurydelendik/wasmparser.rs/pull/49#issuecomment-375436225 for more details. --- README.rst | 22 +++++++++++----------- cranelift/test-no_std.sh | 4 ++-- lib/cretonne/Cargo.toml | 4 ++-- lib/cretonne/src/dbg.rs | 30 +++++++++++++++--------------- lib/cretonne/src/lib.rs | 8 ++++---- lib/cretonne/src/timing.rs | 4 ++-- lib/cretonne/src/verifier/mod.rs | 4 ++-- lib/frontend/Cargo.toml | 2 +- lib/frontend/src/ssa.rs | 12 ++++++------ lib/native/Cargo.toml | 2 +- lib/wasm/Cargo.toml | 2 +- lib/wasm/src/lib.rs | 2 +- 12 files changed, 48 insertions(+), 48 deletions(-) diff --git a/README.rst b/README.rst index 51ee362d10..8368aed68f 100644 --- a/README.rst +++ b/README.rst @@ -62,14 +62,14 @@ Building with `no_std` To build cretonne without libstd, disable the `std` feature on `lib/cretonne`, `lib/frontend`, `lib/native`, and `lib/wasm`, which is otherwise enabled by -default, and enable the `no_std` feature. +default, and enable the `core` feature. For example, to build `cretonne`: .. code-block:: sh cd lib/cretonne - cargo build --no-default-features --features no_std + cargo build --no-default-features --features core Or, when using `cretonne` as a dependency (in Cargo.toml): @@ -78,23 +78,23 @@ Or, when using `cretonne` as a dependency (in Cargo.toml): [dependency.cretonne] ... default-features = false - features = ["no_std"] + features = ["core"] -`no_std` is currently "best effort". We won't try to break it, and we'll -accept patches fixing problems, however we don't expect all developers to -build and test with `no_std` when submitting patches. Accordingly, the +`no_std` support is currently "best effort". We won't try to break it, and +we'll accept patches fixing problems, however we don't expect all developers to +build and test `no_std` when submitting patches. Accordingly, the `./test-all.sh` script does not test `no_std`. There is a separate `./test-no_std.sh` script that tests the `no_std` -feature in packages which support it. +support in packages which support it. It's important to note that cretonne still needs liballoc to compile. Thus, whatever environment is used must implement an allocator. -Also, to allow the use of HashMaps in `no_std` mode, an external crate -called `hashmap_core` is pulled in (only in `no_std` builds). This -is mostly the same as `std::collections::HashMap`, except that it doesn't -have DOS protection. Just something to think about. +Also, to allow the use of HashMaps with `no_std`, an external crate called +`hashmap_core` is pulled in (via the `core` feature). This is mostly the same +as `std::collections::HashMap`, except that it doesn't have DOS protection. +Just something to think about. Building the documentation -------------------------- diff --git a/cranelift/test-no_std.sh b/cranelift/test-no_std.sh index d3edbb921f..c2857ff756 100755 --- a/cranelift/test-no_std.sh +++ b/cranelift/test-no_std.sh @@ -21,8 +21,8 @@ for LIB in $LIBS do banner "Rust unit tests in $LIB" cd "lib/$LIB" - cargo test --no-default-features --features no_std - cargo test --features no_std + cargo test --no-default-features --features core + cargo test --features core cd "$topdir" done diff --git a/lib/cretonne/Cargo.toml b/lib/cretonne/Cargo.toml index 89340e0a1a..01b7e2ab70 100644 --- a/lib/cretonne/Cargo.toml +++ b/lib/cretonne/Cargo.toml @@ -26,9 +26,9 @@ version = "0.1.1" optional = true [features] -# The "std" feature enables use of libstd. The "no_std" feature enables use +# The "std" feature enables use of libstd. The "core" feature enables use # of some minimal std-like replacement libraries. At least one of these two # features to be enabled. default = ["std"] std = [] -no_std = ["hashmap_core"] +core = ["hashmap_core"] diff --git a/lib/cretonne/src/dbg.rs b/lib/cretonne/src/dbg.rs index 8f949f00e1..6c51bd23e5 100644 --- a/lib/cretonne/src/dbg.rs +++ b/lib/cretonne/src/dbg.rs @@ -8,23 +8,23 @@ /// /// The output will appear in files named `cretonne.dbg.*`, where the suffix is named after the /// thread doing the logging. -#[cfg(not(feature = "no_std"))] +#[cfg(feature = "std")] use std::cell::RefCell; -#[cfg(not(feature = "no_std"))] +#[cfg(feature = "std")] use std::env; -#[cfg(not(feature = "no_std"))] +#[cfg(feature = "std")] use std::ffi::OsStr; use std::fmt; -#[cfg(not(feature = "no_std"))] +#[cfg(feature = "std")] use std::fs::File; -#[cfg(not(feature = "no_std"))] +#[cfg(feature = "std")] use std::io::{self, Write}; -#[cfg(not(feature = "no_std"))] +#[cfg(feature = "std")] use std::sync::atomic; -#[cfg(not(feature = "no_std"))] +#[cfg(feature = "std")] use std::thread; -#[cfg(not(feature = "no_std"))] +#[cfg(feature = "std")] static STATE: atomic::AtomicIsize = atomic::ATOMIC_ISIZE_INIT; /// Is debug tracing enabled? @@ -33,7 +33,7 @@ static STATE: atomic::AtomicIsize = atomic::ATOMIC_ISIZE_INIT; /// other than `0`. /// /// This inline function turns into a constant `false` when debug assertions are disabled. -#[cfg(not(feature = "no_std"))] +#[cfg(feature = "std")] #[inline] pub fn enabled() -> bool { if cfg!(debug_assertions) { @@ -47,14 +47,14 @@ pub fn enabled() -> bool { } /// Does nothing -#[cfg(feature = "no_std")] +#[cfg(not(feature = "std"))] #[inline] pub fn enabled() -> bool { false } /// Initialize `STATE` from the environment variable. -#[cfg(not(feature = "no_std"))] +#[cfg(feature = "std")] fn initialize() -> bool { let enable = match env::var_os("CRETONNE_DBG") { Some(s) => s != OsStr::new("0"), @@ -70,7 +70,7 @@ fn initialize() -> bool { enable } -#[cfg(not(feature = "no_std"))] +#[cfg(feature = "std")] thread_local! { static WRITER : RefCell> = RefCell::new(open_file()); } @@ -78,7 +78,7 @@ thread_local! { /// Write a line with the given format arguments. /// /// This is for use by the `dbg!` macro. -#[cfg(not(feature = "no_std"))] +#[cfg(feature = "std")] pub fn writeln_with_format_args(args: fmt::Arguments) -> io::Result<()> { WRITER.with(|rc| { let mut w = rc.borrow_mut(); @@ -88,7 +88,7 @@ pub fn writeln_with_format_args(args: fmt::Arguments) -> io::Result<()> { } /// Open the tracing file for the current thread. -#[cfg(not(feature = "no_std"))] +#[cfg(feature = "std")] fn open_file() -> io::BufWriter { let curthread = thread::current(); let tmpstr; @@ -116,7 +116,7 @@ macro_rules! dbg { if $crate::dbg::enabled() { // Drop the error result so we don't get compiler errors for ignoring it. // What are you going to do, log the error? - #[cfg(not(feature = "no_std"))] + #[cfg(feature = "std")] $crate::dbg::writeln_with_format_args(format_args!($($arg)+)).ok(); } } diff --git a/lib/cretonne/src/lib.rs b/lib/cretonne/src/lib.rs index 29643d552f..8511951b50 100644 --- a/lib/cretonne/src/lib.rs +++ b/lib/cretonne/src/lib.rs @@ -4,13 +4,13 @@ trivial_numeric_casts, unused_extern_crates)] -// Turns on alloc feature if no_std +// Turns on no_std and alloc features if std is not available. #![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(not(feature = "std"), feature(alloc))] -// Include the `hashmap_core` crate if no_std +// Include the `hashmap_core` crate if std is not available. #[allow(unused_extern_crates)] -#[cfg(feature = "no_std")] +#[cfg(not(feature = "std"))] extern crate hashmap_core; #[cfg(not(feature = "std"))] #[macro_use] @@ -66,7 +66,7 @@ mod topo_order; mod unreachable_code; mod write; -/// This replaces `std` in builds with no_std. +/// This replaces `std` in builds with `core`. #[cfg(not(feature = "std"))] mod std { pub use core::*; diff --git a/lib/cretonne/src/timing.rs b/lib/cretonne/src/timing.rs index a70ed5fb21..bbe2fce07c 100644 --- a/lib/cretonne/src/timing.rs +++ b/lib/cretonne/src/timing.rs @@ -93,7 +93,7 @@ impl fmt::Display for Pass { /// This whole module can be gated on a `cfg` feature to provide a dummy implementation for /// performance-sensitive builds or restricted environments. The dummy implementation must provide /// `TimingToken` and `PassTimes` types and `take_current`, `add_to_current`, and `start_pass` funcs -#[cfg(not(feature = "no_std"))] +#[cfg(feature = "std")] mod details { use super::{Pass, NUM_PASSES, DESCRIPTIONS}; use std::cell::{Cell, RefCell}; @@ -216,7 +216,7 @@ mod details { } /// Dummy `debug` implementation -#[cfg(feature = "no_std")] +#[cfg(not(feature = "std"))] mod details { use super::Pass; /// Dummy `TimingToken` diff --git a/lib/cretonne/src/verifier/mod.rs b/lib/cretonne/src/verifier/mod.rs index d8c2cb6dc3..b2ad18c8e8 100644 --- a/lib/cretonne/src/verifier/mod.rs +++ b/lib/cretonne/src/verifier/mod.rs @@ -1125,9 +1125,9 @@ mod tests { Ok(_) => { panic!("Expected an error!") }, Err(Error { message, .. } ) => { if !message.contains($msg) { - #[cfg(not(feature = "no_std"))] + #[cfg(feature = "std")] panic!(format!("'{}' did not contain the substring '{}'", message, $msg)); - #[cfg(feature = "no_std")] + #[cfg(not(feature = "std"))] panic!("error message did not contain the expected substring"); } } diff --git a/lib/frontend/Cargo.toml b/lib/frontend/Cargo.toml index cdbabdda79..75822af7ce 100644 --- a/lib/frontend/Cargo.toml +++ b/lib/frontend/Cargo.toml @@ -17,4 +17,4 @@ cretonne = { path = "../cretonne", version = "0.3.4", default-features = false } [features] default = ["std"] std = ["cretonne/std"] -no_std = ["cretonne/no_std"] +core = ["cretonne/core"] diff --git a/lib/frontend/src/ssa.rs b/lib/frontend/src/ssa.rs index cf44371983..37e4fd8751 100644 --- a/lib/frontend/src/ssa.rs +++ b/lib/frontend/src/ssa.rs @@ -1026,9 +1026,9 @@ mod tests { match verify_function(&func, &flags) { Ok(()) => {} Err(err) => { - #[cfg(not(feature = "no_std"))] + #[cfg(feature = "std")] panic!(err.message); - #[cfg(feature = "no_std")] + #[cfg(not(feature = "std"))] panic!("function failed to verify"); } } @@ -1205,9 +1205,9 @@ mod tests { match verify_function(&func, &flags) { Ok(()) => {} Err(err) => { - #[cfg(not(feature = "no_std"))] + #[cfg(feature = "std")] panic!(err.message); - #[cfg(feature = "no_std")] + #[cfg(not(feature = "std"))] panic!("function failed to verify"); } } @@ -1256,9 +1256,9 @@ mod tests { match verify_function(&func, &flags) { Ok(()) => {} Err(err) => { - #[cfg(not(feature = "no_std"))] + #[cfg(feature = "std")] panic!(err.message); - #[cfg(feature = "no_std")] + #[cfg(not(feature = "std"))] panic!("function failed to verify"); } } diff --git a/lib/native/Cargo.toml b/lib/native/Cargo.toml index e89b0f02fe..817f12c73d 100644 --- a/lib/native/Cargo.toml +++ b/lib/native/Cargo.toml @@ -19,4 +19,4 @@ raw-cpuid = "3.0.0" [features] default = ["std"] std = ["cretonne/std"] -no_std = ["cretonne/no_std"] +core = ["cretonne/core"] diff --git a/lib/wasm/Cargo.toml b/lib/wasm/Cargo.toml index 3f35ee5c96..27177521ee 100644 --- a/lib/wasm/Cargo.toml +++ b/lib/wasm/Cargo.toml @@ -26,4 +26,4 @@ tempdir = "0.3.5" [features] default = ["std"] std = ["cretonne/std", "cretonne-frontend/std"] -no_std = ["hashmap_core", "cretonne/no_std", "cretonne-frontend/no_std"] +core = ["hashmap_core", "cretonne/core", "cretonne-frontend/core"] diff --git a/lib/wasm/src/lib.rs b/lib/wasm/src/lib.rs index a6492b5d66..d791a14846 100644 --- a/lib/wasm/src/lib.rs +++ b/lib/wasm/src/lib.rs @@ -21,7 +21,7 @@ extern crate alloc; #[allow(unused_extern_crates)] -#[cfg(feature = "no_std")] +#[cfg(not(feature = "std"))] extern crate hashmap_core; extern crate wasmparser; From fdf34e9d3eb85050bcfe42fc010f36485c0a3818 Mon Sep 17 00:00:00 2001 From: morenzg Date: Tue, 17 Apr 2018 21:07:22 -0400 Subject: [PATCH 20/27] Fix up nostd dependencies --- lib/codegen/Cargo.toml | 2 +- lib/wasm/Cargo.toml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/codegen/Cargo.toml b/lib/codegen/Cargo.toml index 63a1566007..d362e0ee4e 100644 --- a/lib/codegen/Cargo.toml +++ b/lib/codegen/Cargo.toml @@ -11,7 +11,7 @@ keywords = ["compile", "compiler", "jit"] build = "build.rs" [dependencies] -cretonne-entity = { path = "../entity", version = "0.5.0" } +cretonne-entity = { path = "../entity", version = "0.5.0", default-features = false } # It is a goal of the cretonne-codegen crate to have minimal external dependencies. # Please don't add any unless they are essential to the task of creating binary # machine code. Integration tests that need external dependencies can be diff --git a/lib/wasm/Cargo.toml b/lib/wasm/Cargo.toml index dd053698f0..ddf76afaf5 100644 --- a/lib/wasm/Cargo.toml +++ b/lib/wasm/Cargo.toml @@ -9,7 +9,7 @@ readme = "README.md" keywords = ["webassembly", "wasm"] [dependencies] -wasmparser = "0.15.1" +wasmparser = { git = "https://github.com/yurydelendik/wasmparser.rs", default_features = false } cretonne-codegen = { path = "../codegen", version = "0.5.0", default_features = false } cretonne-frontend = { path = "../frontend", version = "0.5.0", default_features = false } @@ -22,8 +22,8 @@ tempdir = "0.3.5" [features] default = ["std"] -std = ["cretonne-codegen/std", "cretonne-frontend/std"] -core = ["hashmap_core", "cretonne-codegen/core", "cretonne-frontend/core"] +std = ["cretonne-codegen/std", "cretonne-frontend/std", "wasmparser/std"] +core = ["hashmap_core", "cretonne-codegen/core", "cretonne-frontend/core", "wasmparser/core"] [badges] maintenance = { status = "experimental" } From c791a4f8b18c0190907d39dd9593f7454ebf5911 Mon Sep 17 00:00:00 2001 From: morenzg Date: Wed, 18 Apr 2018 12:46:55 -0400 Subject: [PATCH 21/27] Update to wasmparser 0.16.0 --- lib/wasm/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/wasm/Cargo.toml b/lib/wasm/Cargo.toml index ddf76afaf5..b2ec94fa34 100644 --- a/lib/wasm/Cargo.toml +++ b/lib/wasm/Cargo.toml @@ -9,7 +9,7 @@ readme = "README.md" keywords = ["webassembly", "wasm"] [dependencies] -wasmparser = { git = "https://github.com/yurydelendik/wasmparser.rs", default_features = false } +wasmparser = { version = "0.16.0", default_features = false } cretonne-codegen = { path = "../codegen", version = "0.5.0", default_features = false } cretonne-frontend = { path = "../frontend", version = "0.5.0", default_features = false } From 830ee60d28faeef4830e03d85d519a7600151b16 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 18 Apr 2018 17:39:43 -0700 Subject: [PATCH 22/27] Add no_std support in module, simplejit, and umbrella. --- README.rst | 29 +++++++++++++++++++---------- cranelift/test-no_std.sh | 7 ++++++- lib/codegen/Cargo.toml | 6 +++--- lib/codegen/src/context.rs | 1 + lib/module/Cargo.toml | 13 +++++++++++-- lib/simplejit/Cargo.toml | 13 +++++++++---- lib/umbrella/Cargo.toml | 9 +++++++-- 7 files changed, 56 insertions(+), 22 deletions(-) diff --git a/README.rst b/README.rst index 28f2250ace..1e519f2117 100644 --- a/README.rst +++ b/README.rst @@ -35,9 +35,9 @@ the System V AMD64 ABI calling convention used on many platforms, but does not yet support the Windows x64 calling convention. The performance of code produced by Cretonne is not yet impressive, though we have plans to fix that. -The core codegen crates have minimal dependencies, and do not require any host -floating-point support. Support for `no_std` mode in the core codegen crates is -`in development `_. +The core codegen crates have minimal dependencies, support +`no_std <#building-with-no-std>` mode, and do not require any host +floating-point support. Cretonne does not yet perform mitigations for Spectre or related security issues, though it may do so in the future. It does not currently make any @@ -93,22 +93,31 @@ installed. Building with `no_std` ---------------------- -To build cretonne without libstd, disable the `std` feature on `lib/cretonne`, -`lib/frontend`, `lib/native`, and `lib/wasm`, which is otherwise enabled by -default, and enable the `core` feature. +The following crates support `no_std`: + - `cretonne-entity` + - `cretonne-codegen` + - `cretonne-frontend` + - `cretonne-native` + - `cretonne-wasm` + - `cretonne-module` + - `cretonne-simplejit` + - `cretonne` -For example, to build `cretonne`: +To use `no_std` mode, disable the `std` feature and enable the `core` feature. +This currently requires nightly rust. + +For example, to build `cretonne-codegen`: .. code-block:: sh - cd lib/cretonne + cd lib/codegen cargo build --no-default-features --features core -Or, when using `cretonne` as a dependency (in Cargo.toml): +Or, when using `cretonne-codegen` as a dependency (in Cargo.toml): .. code-block:: - [dependency.cretonne] + [dependency.cretonne-codegen] ... default-features = false features = ["core"] diff --git a/cranelift/test-no_std.sh b/cranelift/test-no_std.sh index 800c712402..66a629eb57 100755 --- a/cranelift/test-no_std.sh +++ b/cranelift/test-no_std.sh @@ -15,14 +15,19 @@ function banner() { } # Test those packages which have no_std support. -LIBS="codegen frontend wasm native" +LIBS="codegen frontend wasm native module simplejit umbrella" cd "$topdir" for LIB in $LIBS do banner "Rust unit tests in $LIB" cd "lib/$LIB" + + # Test with just "core" enabled. cargo test --no-default-features --features core + + # Test with "core" and "std" enabled at the same time. cargo test --features core + cd "$topdir" done diff --git a/lib/codegen/Cargo.toml b/lib/codegen/Cargo.toml index 2a7854f6c1..0c5a1104ba 100644 --- a/lib/codegen/Cargo.toml +++ b/lib/codegen/Cargo.toml @@ -12,12 +12,12 @@ build = "build.rs" [dependencies] cretonne-entity = { path = "../entity", version = "0.5.1", default-features = false } +failure = { version = "0.1.1", default-features = false, features = ["derive"] } +failure_derive = { version = "0.1.1", default-features = false } # It is a goal of the cretonne-codegen crate to have minimal external dependencies. # Please don't add any unless they are essential to the task of creating binary # machine code. Integration tests that need external dependencies can be # accomodated in `tests`. -failure = { version = "0.1.1", default-features = false, features = ["derive"] } -failure_derive = { version = "0.1.1", default-features = false } [dependencies.hashmap_core] version = "0.1.1" @@ -28,7 +28,7 @@ optional = true # of some minimal std-like replacement libraries. At least one of these two # features to be enabled. default = ["std"] -std = [] +std = ["cretonne-entity/std"] core = ["hashmap_core"] [badges] diff --git a/lib/codegen/src/context.rs b/lib/codegen/src/context.rs index 95e78ff128..71b873b653 100644 --- a/lib/codegen/src/context.rs +++ b/lib/codegen/src/context.rs @@ -23,6 +23,7 @@ use preopt::do_preopt; use regalloc; use result::{CtonError, CtonResult}; use settings::{FlagsOrIsa, OptLevel}; +use std::vec::Vec; use simple_gvn::do_simple_gvn; use timing; use unreachable_code::eliminate_unreachable_code; diff --git a/lib/module/Cargo.toml b/lib/module/Cargo.toml index 42dc6ee916..f9d5728109 100644 --- a/lib/module/Cargo.toml +++ b/lib/module/Cargo.toml @@ -9,8 +9,17 @@ license = "Apache-2.0" readme = "README.md" [dependencies] -cretonne-codegen = { path = "../codegen", version = "0.5.1" } -cretonne-entity = { path = "../entity", version = "0.5.1" } +cretonne-codegen = { path = "../codegen", version = "0.5.1", default-features = false } +cretonne-entity = { path = "../entity", version = "0.5.1", default-features = false } + +[dependencies.hashmap_core] +version = "0.1.1" +optional = true + +[features] +default = ["std"] +std = ["cretonne-codegen/std", "cretonne-entity/std"] +core = ["hashmap_core", "cretonne-codegen/core"] [badges] maintenance = { status = "experimental" } diff --git a/lib/simplejit/Cargo.toml b/lib/simplejit/Cargo.toml index 0fdc16da32..7d5fbb4d23 100644 --- a/lib/simplejit/Cargo.toml +++ b/lib/simplejit/Cargo.toml @@ -9,13 +9,18 @@ license = "Apache-2.0" readme = "README.md" [dependencies] -cretonne-codegen = { path = "../codegen", version = "0.5.1" } -cretonne-module = { path = "../module", version = "0.5.1" } -cretonne-native = { path = "../native", version = "0.5.1" } +cretonne-codegen = { path = "../codegen", version = "0.5.1", default-features = false } +cretonne-module = { path = "../module", version = "0.5.1", default-features = false } +cretonne-native = { path = "../native", version = "0.5.1", default-features = false } region = "0.2.0" -libc = "0.2.40" +libc = { version = "0.2.40", default-features = false } errno = "0.2.3" +[features] +default = ["std"] +std = ["libc/use_std", "cretonne-codegen/std", "cretonne-module/std", "cretonne-native/std"] +core = ["cretonne-codegen/core", "cretonne-module/core", "cretonne-native/core"] + [badges] maintenance = { status = "experimental" } travis-ci = { repository = "Cretonne/cretonne" } diff --git a/lib/umbrella/Cargo.toml b/lib/umbrella/Cargo.toml index f7bdc002cd..6895955244 100644 --- a/lib/umbrella/Cargo.toml +++ b/lib/umbrella/Cargo.toml @@ -10,8 +10,13 @@ readme = "README.md" keywords = ["compile", "compiler", "jit"] [dependencies] -cretonne-codegen = { path = "../codegen", version = "0.5.1" } -cretonne-frontend = { path = "../frontend", version = "0.5.1" } +cretonne-codegen = { path = "../codegen", version = "0.5.1", default-features = false } +cretonne-frontend = { path = "../frontend", version = "0.5.1", default-features = false } + +[features] +default = ["std"] +std = ["cretonne-codegen/std", "cretonne-frontend/std"] +core = ["cretonne-codegen/core", "cretonne-frontend/core"] [badges] maintenance = { status = "experimental" } From d72706c47845701d181491392466f3cd3a3fe197 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 19 Apr 2018 13:14:12 -0700 Subject: [PATCH 23/27] Use `use` declarations rather than '::std::...' names. This is what most of the rest of the codebase does, so this patch just tidies up a few additional places. --- lib/codegen/src/bforest/map.rs | 16 ++++++++++------ lib/codegen/src/bforest/pool.rs | 6 ++++-- lib/codegen/src/bforest/set.rs | 8 ++++++-- lib/codegen/src/dbg.rs | 1 - lib/codegen/src/ir/extname.rs | 3 ++- lib/codegen/src/legalizer/libcall.rs | 3 ++- 6 files changed, 24 insertions(+), 13 deletions(-) diff --git a/lib/codegen/src/bforest/map.rs b/lib/codegen/src/bforest/map.rs index b6a62ef419..7cfa824a43 100644 --- a/lib/codegen/src/bforest/map.rs +++ b/lib/codegen/src/bforest/map.rs @@ -3,6 +3,10 @@ use super::{Comparator, Forest, Node, NodeData, NodePool, Path, INNER_SIZE}; use packed_option::PackedOption; use std::marker::PhantomData; +#[cfg(test)] +use std::fmt; +#[cfg(test)] +use std::string::String; /// Tag type defining forest types for a map. struct MapTypes(PhantomData<(K, V, C)>); @@ -207,14 +211,14 @@ where #[cfg(test)] impl Map where - K: Copy + ::std::fmt::Display, + K: Copy + fmt::Display, V: Copy, C: Comparator, { /// Verify consistency. fn verify(&self, forest: &MapForest, comp: &C) where - NodeData>: ::std::fmt::Display, + NodeData>: fmt::Display, { if let Some(root) = self.root.expand() { forest.nodes.verify_tree(root, comp); @@ -222,7 +226,7 @@ where } /// Get a text version of the path to `key`. - fn tpath(&self, key: K, forest: &MapForest, comp: &C) -> ::std::string::String { + fn tpath(&self, key: K, forest: &MapForest, comp: &C) -> String { use std::string::ToString; match self.root.expand() { None => "map(empty)".to_string(), @@ -406,8 +410,8 @@ where #[cfg(test)] impl<'a, K, V, C> MapCursor<'a, K, V, C> where - K: Copy + ::std::fmt::Display, - V: Copy + ::std::fmt::Display, + K: Copy + fmt::Display, + V: Copy + fmt::Display, C: Comparator, { fn verify(&self) { @@ -416,7 +420,7 @@ where } /// Get a text version of the path to the current position. - fn tpath(&self) -> ::std::string::String { + fn tpath(&self) -> String { use std::string::ToString; self.path.to_string() } diff --git a/lib/codegen/src/bforest/pool.rs b/lib/codegen/src/bforest/pool.rs index eed9402c84..d543991312 100644 --- a/lib/codegen/src/bforest/pool.rs +++ b/lib/codegen/src/bforest/pool.rs @@ -3,6 +3,8 @@ use super::{Forest, Node, NodeData}; use entity::PrimaryMap; use std::ops::{Index, IndexMut}; +#[cfg(test)] +use std::fmt; /// A pool of nodes, including a free list. pub(super) struct NodePool { @@ -74,8 +76,8 @@ impl NodePool { /// Verify the consistency of the tree rooted at `node`. pub fn verify_tree(&self, node: Node, comp: &F::Comparator) where - NodeData: ::std::fmt::Display, - F::Key: ::std::fmt::Display, + NodeData: fmt::Display, + F::Key: fmt::Display, { use super::Comparator; use entity::SparseSet; diff --git a/lib/codegen/src/bforest/set.rs b/lib/codegen/src/bforest/set.rs index 3c479dd876..667cd133e2 100644 --- a/lib/codegen/src/bforest/set.rs +++ b/lib/codegen/src/bforest/set.rs @@ -3,6 +3,10 @@ use super::{Comparator, Forest, Node, NodeData, NodePool, Path, SetValue, INNER_SIZE}; use packed_option::PackedOption; use std::marker::PhantomData; +#[cfg(test)] +use std::fmt; +#[cfg(test)] +use std::string::String; /// Tag type defining forest types for a set. struct SetTypes(PhantomData<(K, C)>); @@ -305,7 +309,7 @@ where #[cfg(test)] impl<'a, K, C> SetCursor<'a, K, C> where - K: Copy + ::std::fmt::Display, + K: Copy + fmt::Display, C: Comparator, { fn verify(&self) { @@ -314,7 +318,7 @@ where } /// Get a text version of the path to the current position. - fn tpath(&self) -> ::std::string::String { + fn tpath(&self) -> String { use std::string::ToString; self.path.to_string() } diff --git a/lib/codegen/src/dbg.rs b/lib/codegen/src/dbg.rs index 6c51bd23e5..a514dd7a05 100644 --- a/lib/codegen/src/dbg.rs +++ b/lib/codegen/src/dbg.rs @@ -116,7 +116,6 @@ macro_rules! dbg { if $crate::dbg::enabled() { // Drop the error result so we don't get compiler errors for ignoring it. // What are you going to do, log the error? - #[cfg(feature = "std")] $crate::dbg::writeln_with_format_args(format_args!($($arg)+)).ok(); } } diff --git a/lib/codegen/src/ir/extname.rs b/lib/codegen/src/ir/extname.rs index dcb3666703..ed723be6fe 100644 --- a/lib/codegen/src/ir/extname.rs +++ b/lib/codegen/src/ir/extname.rs @@ -121,6 +121,7 @@ mod tests { use super::ExternalName; use ir::LibCall; use std::string::ToString; + use std::u32; #[test] fn display_testcase() { @@ -143,7 +144,7 @@ mod tests { assert_eq!(ExternalName::user(0, 0).to_string(), "u0:0"); assert_eq!(ExternalName::user(1, 1).to_string(), "u1:1"); assert_eq!( - ExternalName::user(::std::u32::MAX, ::std::u32::MAX).to_string(), + ExternalName::user(u32::MAX, u32::MAX).to_string(), "u4294967295:4294967295" ); } diff --git a/lib/codegen/src/legalizer/libcall.rs b/lib/codegen/src/legalizer/libcall.rs index 8f69cba18d..17f9174706 100644 --- a/lib/codegen/src/legalizer/libcall.rs +++ b/lib/codegen/src/legalizer/libcall.rs @@ -2,6 +2,7 @@ use ir; use ir::InstBuilder; +use std::vec::Vec; /// Try to expand `inst` as a library call, returning true is successful. pub fn expand_as_libcall(inst: ir::Inst, func: &mut ir::Function) -> bool { @@ -15,7 +16,7 @@ pub fn expand_as_libcall(inst: ir::Inst, func: &mut ir::Function) -> bool { let funcref = find_funcref(libcall, func).unwrap_or_else(|| make_funcref(libcall, inst, func)); // Now we convert `inst` to a call. First save the arguments. - let mut args = vec![]; + let mut args = Vec::new(); args.extend_from_slice(func.dfg.inst_args(inst)); // The replace builder will preserve the instruction result values. func.dfg.replace(inst).call(funcref, &args); From 73c19bbf6da2d5009e93e17b04d16bec2fd4ecc8 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 19 Apr 2018 13:18:21 -0700 Subject: [PATCH 24/27] Fix the `dbg!` macro for `no_std` mode. Check for the `std` feature outside the macro body rather than inside, so that we get the `std` feature in `cretonne-codegen`, rather than in whatever crate the macro is being expanded in. --- lib/codegen/src/dbg.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/codegen/src/dbg.rs b/lib/codegen/src/dbg.rs index a514dd7a05..8dd47f625d 100644 --- a/lib/codegen/src/dbg.rs +++ b/lib/codegen/src/dbg.rs @@ -110,6 +110,7 @@ fn open_file() -> io::BufWriter { /// Write a line to the debug trace file if tracing is enabled. /// /// Arguments are the same as for `printf!`. +#[cfg(feature = "std")] #[macro_export] macro_rules! dbg { ($($arg:tt)+) => { @@ -121,6 +122,13 @@ macro_rules! dbg { } } +/// `dbg!` isn't supported in `no_std` mode, so expand it into nothing. +#[cfg(not(feature = "std"))] +#[macro_export] +macro_rules! dbg { + ($($arg:tt)+) => {} +} + /// Helper for printing lists. pub struct DisplayList<'a, T>(pub &'a [T]) where From 33e266eeeb149d0d06413af609fe824b27c3cf2b Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 20 Apr 2018 11:04:13 -0700 Subject: [PATCH 25/27] Fix missing word. --- lib/codegen/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/codegen/Cargo.toml b/lib/codegen/Cargo.toml index 0c5a1104ba..8304c50ca4 100644 --- a/lib/codegen/Cargo.toml +++ b/lib/codegen/Cargo.toml @@ -26,7 +26,7 @@ optional = true [features] # The "std" feature enables use of libstd. The "core" feature enables use # of some minimal std-like replacement libraries. At least one of these two -# features to be enabled. +# features need to be enabled. default = ["std"] std = ["cretonne-entity/std"] core = ["hashmap_core"] From 9249080ce8b5d3ed72a34bae584f888602aabcdc Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 20 Apr 2018 11:06:25 -0700 Subject: [PATCH 26/27] Fix URL syntax. --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 1e519f2117..59316dff13 100644 --- a/README.rst +++ b/README.rst @@ -36,7 +36,7 @@ yet support the Windows x64 calling convention. The performance of code produced by Cretonne is not yet impressive, though we have plans to fix that. The core codegen crates have minimal dependencies, support -`no_std <#building-with-no-std>` mode, and do not require any host +`no_std <#building-with-no-std>`_ mode, and do not require any host floating-point support. Cretonne does not yet perform mitigations for Spectre or related security From 653c11d580dcacd930f3657c80c9f626170abdef Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 20 Apr 2018 11:11:38 -0700 Subject: [PATCH 27/27] Use "set -euo pipefail" in test-no_std.sh. This makes it consistent with other shell scripts in the repo. --- cranelift/test-no_std.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cranelift/test-no_std.sh b/cranelift/test-no_std.sh index 66a629eb57..7d372f3558 100755 --- a/cranelift/test-no_std.sh +++ b/cranelift/test-no_std.sh @@ -1,11 +1,9 @@ #!/bin/bash +set -euo pipefail # This is the test script for testing the no_std configuration of # packages which support it. -# Exit immediately on errors. -set -e - # Repository top-level directory. cd $(dirname "$0") topdir=$(pwd)