Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

cranelift-codegen: rename most uses of std to core and alloc (#12237)

SSD0889323abf3d
diff --git a/cranelift/codegen/meta/src/gen_inst.rs b/cranelift/codegen/meta/src/gen_inst.rs
index ab0db7c757..1b4612f108 100644
--- a/cranelift/codegen/meta/src/gen_inst.rs
+++ b/cranelift/codegen/meta/src/gen_inst.rs
@@ -312,7 +312,7 @@ fn gen_instruction_data_impl(formats: &[Rc<InstructionFormat>], fmt: &mut Format
(Some("args.as_slice(pool)"), "args.len(pool)")
} else if format.num_value_operands == 1 {
members.push("ref arg");
- (Some("std::slice::from_ref(arg)"), "1")
+ (Some("core::slice::from_ref(arg)"), "1")
} else if format.num_value_operands > 0 {
members.push("ref args");
(Some("args"), "args.len()")
@@ -324,7 +324,7 @@ fn gen_instruction_data_impl(formats: &[Rc<InstructionFormat>], fmt: &mut Format
0 => None,
1 => {
members.push("ref destination");
- Some(("std::slice::from_ref(destination)", "1"))
+ Some(("core::slice::from_ref(destination)", "1"))
}
_ => {
members.push("ref blocks");
diff --git a/cranelift/codegen/shared/src/lib.rs b/cranelift/codegen/shared/src/lib.rs
index 2a03a83234..8aa3026335 100644
--- a/cranelift/codegen/shared/src/lib.rs
+++ b/cranelift/codegen/shared/src/lib.rs
@@ -2,9 +2,10 @@
//! `cranelift-codegen-meta` libraries.
#![deny(missing_docs)]
+#![no_std]
pub mod constant_hash;
pub mod constants;
/// Version number of this crate.
-pub const VERSION: &str = env!("CARGO_PKG_VERSION");
+pub const VERSION: &str = core::env!("CARGO_PKG_VERSION");
diff --git a/cranelift/codegen/src/ctxhash.rs b/cranelift/codegen/src/ctxhash.rs
index 98931566aa..ea7de76600 100644
--- a/cranelift/codegen/src/ctxhash.rs
+++ b/cranelift/codegen/src/ctxhash.rs
@@ -4,8 +4,8 @@
//! node-internal data references some other storage (e.g., offsets into
//! an array or pool of shared data).
+use core::hash::{Hash, Hasher};
use hashbrown::hash_table::HashTable;
-use std::hash::{Hash, Hasher};
/// Trait that allows for equality comparison given some external
/// context.
@@ -92,7 +92,7 @@ impl<K, V> CtxHashMap<K, V> {
match self.raw.find_mut(hash as u64, |bucket| {
hash == bucket.hash && ctx.ctx_eq(&bucket.k, &k)
}) {
- Some(bucket) => Some(std::mem::replace(&mut bucket.v, v)),
+ Some(bucket) => Some(core::mem::replace(&mut bucket.v, v)),
None => {
let data = BucketData { hash, k, v };
self.raw
diff --git a/cranelift/codegen/src/data_value.rs b/cranelift/codegen/src/data_value.rs
index 4eeb8c117a..a2e69a724e 100644
--- a/cranelift/codegen/src/data_value.rs
+++ b/cranelift/codegen/src/data_value.rs
@@ -247,13 +247,13 @@ impl DataValue {
/// Write a [DataValue] to a memory location in native-endian byte order.
pub unsafe fn write_value_to(&self, p: *mut u128) {
let size = self.ty().bytes() as usize;
- self.write_to_slice_ne(unsafe { std::slice::from_raw_parts_mut(p as *mut u8, size) });
+ self.write_to_slice_ne(unsafe { core::slice::from_raw_parts_mut(p as *mut u8, size) });
}
/// Read a [DataValue] from a memory location using a given [Type] in native-endian byte order.
pub unsafe fn read_value_from(p: *const u128, ty: Type) -> Self {
DataValue::read_from_slice_ne(
- unsafe { std::slice::from_raw_parts(p as *const u8, ty.bytes() as usize) },
+ unsafe { core::slice::from_raw_parts(p as *const u8, ty.bytes() as usize) },
ty,
)
}
@@ -290,7 +290,7 @@ pub enum DataValueCastFailure {
// This is manually implementing Error and Display instead of using thiserror to reduce the amount
// of dependencies used by Cranelift.
-impl std::error::Error for DataValueCastFailure {}
+impl core::error::Error for DataValueCastFailure {}
impl Display for DataValueCastFailure {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
diff --git a/cranelift/codegen/src/dominator_tree.rs b/cranelift/codegen/src/dominator_tree.rs
index 10ab9c891e..23d099a425 100644
--- a/cranelift/codegen/src/dominator_tree.rs
+++ b/cranelift/codegen/src/dominator_tree.rs
@@ -94,7 +94,7 @@ impl SpanningTree {
}
}
-impl std::ops::Index<u32> for SpanningTree {
+impl core::ops::Index<u32> for SpanningTree {
type Output = SpanningTreeNode;
fn index(&self, idx: u32) -> &Self::Output {
@@ -102,7 +102,7 @@ impl std::ops::Index<u32> for SpanningTree {
}
}
-impl std::ops::IndexMut<u32> for SpanningTree {
+impl core::ops::IndexMut<u32> for SpanningTree {
fn index_mut(&mut self, idx: u32) -> &mut Self::Output {
&mut self.nodes[idx as usize]
}
@@ -439,7 +439,7 @@ impl DominatorTree {
}
let semi_candidate = self.eval(self.nodes[pred].pre_number, last_linked);
- semi = std::cmp::min(semi, semi_candidate);
+ semi = core::cmp::min(semi, semi_candidate);
}
let w_node = &mut self.stree[w];
diff --git a/cranelift/codegen/src/egraph.rs b/cranelift/codegen/src/egraph.rs
index 9993f7941f..46fdaf3698 100644
--- a/cranelift/codegen/src/egraph.rs
+++ b/cranelift/codegen/src/egraph.rs
@@ -660,7 +660,7 @@ where
let old_vals = ctx.func.dfg.inst_results(inst);
let new_vals = if let Some(val) = new_val.as_ref() {
- std::slice::from_ref(val)
+ core::slice::from_ref(val)
} else {
ctx.func.dfg.inst_results(new_inst)
};
@@ -1075,7 +1075,7 @@ impl<'a> CtxEq<(Type, InstructionData), (Type, InstructionData)> for GVNContext<
impl<'a> CtxHash<(Type, InstructionData)> for GVNContext<'a> {
fn ctx_hash<H: Hasher>(&self, state: &mut H, (ty, inst): &(Type, InstructionData)) {
- std::hash::Hash::hash(&ty, state);
+ core::hash::Hash::hash(&ty, state);
inst.hash(state, self.value_lists);
}
}
diff --git a/cranelift/codegen/src/egraph/cost.rs b/cranelift/codegen/src/egraph/cost.rs
index 1ff56fcd61..062196964c 100644
--- a/cranelift/codegen/src/egraph/cost.rs
+++ b/cranelift/codegen/src/egraph/cost.rs
@@ -48,7 +48,7 @@ impl core::fmt::Debug for Cost {
impl Ord for Cost {
#[inline]
- fn cmp(&self, other: &Self) -> std::cmp::Ordering {
+ fn cmp(&self, other: &Self) -> core::cmp::Ordering {
// We make sure that the high bits are the op cost and the low bits are
// the depth. This means that we can use normal integer comparison to
// order by op cost and then depth.
@@ -65,7 +65,7 @@ impl Ord for Cost {
impl PartialOrd for Cost {
#[inline]
- fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
+ fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
Some(self.cmp(other))
}
}
@@ -172,24 +172,24 @@ impl Cost {
}
}
-impl std::iter::Sum<Cost> for Cost {
+impl core::iter::Sum<Cost> for Cost {
fn sum<I: Iterator<Item = Cost>>(iter: I) -> Self {
iter.fold(Self::zero(), |a, b| a + b)
}
}
-impl std::default::Default for Cost {
+impl core::default::Default for Cost {
fn default() -> Cost {
Cost::zero()
}
}
-impl std::ops::Add<Cost> for Cost {
+impl core::ops::Add<Cost> for Cost {
type Output = Cost;
fn add(self, other: Cost) -> Cost {
let op_cost = self.op_cost().saturating_add(other.op_cost());
- let depth = std::cmp::max(self.depth(), other.depth());
+ let depth = core::cmp::max(self.depth(), other.depth());
Cost::new(op_cost, depth)
}
}
diff --git a/cranelift/codegen/src/egraph/elaborate.rs b/cranelift/codegen/src/egraph/elaborate.rs
index d9d156eb41..9328354b2d 100644
--- a/cranelift/codegen/src/egraph/elaborate.rs
+++ b/cranelift/codegen/src/egraph/elaborate.rs
@@ -82,7 +82,7 @@ impl PartialOrd for BestEntry {
impl Ord for BestEntry {
#[inline]
- fn cmp(&self, other: &Self) -> std::cmp::Ordering {
+ fn cmp(&self, other: &Self) -> core::cmp::Ordering {
self.0.cmp(&other.0).then_with(|| {
// Note that this comparison is reversed. When costs are equal,
// prefer the value with the bigger index. This is a heuristic that
@@ -321,9 +321,9 @@ impl<'a> Elaborator<'a> {
debug_assert!(!best[x].1.is_reserved_value());
debug_assert!(!best[y].1.is_reserved_value());
best[value] = if use_worst {
- std::cmp::max(best[x], best[y])
+ core::cmp::max(best[x], best[y])
} else {
- std::cmp::min(best[x], best[y])
+ core::cmp::min(best[x], best[y])
};
trace!(
" -> best of union({:?}, {:?}) = {:?}",
diff --git a/cranelift/codegen/src/incremental_cache.rs b/cranelift/codegen/src/incremental_cache.rs
index 9b9d935241..a597d18869 100644
--- a/cranelift/codegen/src/incremental_cache.rs
+++ b/cranelift/codegen/src/incremental_cache.rs
@@ -111,7 +111,7 @@ pub trait CacheKvStore {
#[derive(Clone, Hash, PartialEq, Eq)]
pub struct CacheKeyHash([u8; 32]);
-impl std::fmt::Display for CacheKeyHash {
+impl core::fmt::Display for CacheKeyHash {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "CacheKeyHash:{:?}", self.0)
}
diff --git a/cranelift/codegen/src/ir/condcodes.rs b/cranelift/codegen/src/ir/condcodes.rs
index e791649bb6..009f95bf39 100644
--- a/cranelift/codegen/src/ir/condcodes.rs
+++ b/cranelift/codegen/src/ir/condcodes.rs
@@ -344,7 +344,7 @@ impl FromStr for FloatCC {
#[cfg(test)]
mod tests {
use super::*;
- use std::string::ToString;
+ use alloc::string::ToString;
#[test]
fn int_complement() {
diff --git a/cranelift/codegen/src/ir/constant.rs b/cranelift/codegen/src/ir/constant.rs
index a9ac61e06a..67310cd946 100644
--- a/cranelift/codegen/src/ir/constant.rs
+++ b/cranelift/codegen/src/ir/constant.rs
@@ -272,7 +272,7 @@ impl ConstantPool {
#[cfg(test)]
mod tests {
use super::*;
- use std::string::ToString;
+ use alloc::string::ToString;
#[test]
fn empty() {
diff --git a/cranelift/codegen/src/ir/extname.rs b/cranelift/codegen/src/ir/extname.rs
index f29d854b1a..d28ebcb4e7 100644
--- a/cranelift/codegen/src/ir/extname.rs
+++ b/cranelift/codegen/src/ir/extname.rs
@@ -99,7 +99,7 @@ pub struct TestcaseName(Box<[u8]>);
impl fmt::Display for TestcaseName {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_char('%')?;
- f.write_str(std::str::from_utf8(&self.0).unwrap())
+ f.write_str(core::str::from_utf8(&self.0).unwrap())
}
}
diff --git a/cranelift/codegen/src/ir/instructions.rs b/cranelift/codegen/src/ir/instructions.rs
index 2b94d9da1e..80c04e48e6 100644
--- a/cranelift/codegen/src/ir/instructions.rs
+++ b/cranelift/codegen/src/ir/instructions.rs
@@ -429,7 +429,7 @@ impl InstructionData {
exception_tables: &'a ir::ExceptionTables,
) -> &'a [BlockCall] {
match self {
- Self::Jump { destination, .. } => std::slice::from_ref(destination),
+ Self::Jump { destination, .. } => core::slice::from_ref(destination),
Self::Brif { blocks, .. } => blocks.as_slice(),
Self::BranchTable { table, .. } => jump_tables.get(*table).unwrap().all_branches(),
Self::TryCall { exception, .. } | Self::TryCallIndirect { exception, .. } => {
@@ -451,7 +451,7 @@ impl InstructionData {
exception_tables: &'a mut ir::ExceptionTables,
) -> &'a mut [BlockCall] {
match self {
- Self::Jump { destination, .. } => std::slice::from_mut(destination),
+ Self::Jump { destination, .. } => core::slice::from_mut(destination),
Self::Brif { blocks, .. } => blocks.as_mut_slice(),
Self::BranchTable { table, .. } => {
jump_tables.get_mut(*table).unwrap().all_branches_mut()
@@ -1162,7 +1162,7 @@ mod tests {
fn inst_data_size() {
// The size of `InstructionData` is performance sensitive, so make sure
// we don't regress it unintentionally.
- assert_eq!(std::mem::size_of::<InstructionData>(), 16);
+ assert_eq!(core::mem::size_of::<InstructionData>(), 16);
}
#[test]
diff --git a/cranelift/codegen/src/ir/jumptable.rs b/cranelift/codegen/src/ir/jumptable.rs
index 5a26ef4e47..5bdad87d94 100644
--- a/cranelift/codegen/src/ir/jumptable.rs
+++ b/cranelift/codegen/src/ir/jumptable.rs
@@ -31,7 +31,7 @@ impl JumpTableData {
/// Create a new jump table with the provided blocks.
pub fn new(def: BlockCall, table: &[BlockCall]) -> Self {
Self {
- table: std::iter::once(def).chain(table.iter().copied()).collect(),
+ table: core::iter::once(def).chain(table.iter().copied()).collect(),
}
}
@@ -114,8 +114,8 @@ mod tests {
use crate::entity::EntityRef;
use crate::ir::instructions::ValueListPool;
use crate::ir::{Block, BlockArg, BlockCall, Value};
+ use alloc::string::ToString;
use alloc::vec::Vec;
- use std::string::ToString;
#[test]
fn empty() {
diff --git a/cranelift/codegen/src/ir/memtype.rs b/cranelift/codegen/src/ir/memtype.rs
index 4df26f1647..b7b0d7e2db 100644
--- a/cranelift/codegen/src/ir/memtype.rs
+++ b/cranelift/codegen/src/ir/memtype.rs
@@ -108,14 +108,14 @@ pub enum MemoryTypeData {
Empty,
}
-impl std::default::Default for MemoryTypeData {
+impl core::default::Default for MemoryTypeData {
fn default() -> Self {
Self::Empty
}
}
-impl std::fmt::Display for MemoryTypeData {
- fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+impl core::fmt::Display for MemoryTypeData {
+ fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
match self {
Self::Struct { size, fields } => {
write!(f, "struct {size} {{")?;
diff --git a/cranelift/codegen/src/ir/pcc.rs b/cranelift/codegen/src/ir/pcc.rs
index 4fb88fd02e..8b9a3cc6bb 100644
--- a/cranelift/codegen/src/ir/pcc.rs
+++ b/cranelift/codegen/src/ir/pcc.rs
@@ -77,14 +77,14 @@ use crate::ir::types::*;
use crate::isa::TargetIsa;
use crate::machinst::{BlockIndex, LowerBackend, VCode};
use crate::trace;
+use core::fmt;
use regalloc2::Function as _;
-use std::fmt;
#[cfg(feature = "enable-serde")]
use serde_derive::{Deserialize, Serialize};
/// The result of checking proof-carrying-code facts.
-pub type PccResult<T> = std::result::Result<T, PccError>;
+pub type PccResult<T> = core::result::Result<T, PccError>;
/// An error or inconsistency discovered when checking proof-carrying
/// code.
@@ -332,7 +332,7 @@ impl Expr {
} else {
Expr {
base: BaseExpr::min(&lhs.base, &rhs.base),
- offset: std::cmp::min(lhs.offset, rhs.offset),
+ offset: core::cmp::min(lhs.offset, rhs.offset),
}
}
}
@@ -347,7 +347,7 @@ impl Expr {
} else {
Expr {
base: BaseExpr::max(&lhs.base, &rhs.base),
- offset: std::cmp::max(lhs.offset, rhs.offset),
+ offset: core::cmp::max(lhs.offset, rhs.offset),
}
}
}
@@ -651,8 +651,8 @@ impl Fact {
},
) if bw_lhs == bw_rhs && max_lhs >= min_rhs && max_rhs >= min_lhs => Fact::Range {
bit_width: *bw_lhs,
- min: std::cmp::max(*min_lhs, *min_rhs),
- max: std::cmp::min(*max_lhs, *max_rhs),
+ min: core::cmp::max(*min_lhs, *min_rhs),
+ max: core::cmp::min(*max_lhs, *max_rhs),
},
(
@@ -693,8 +693,8 @@ impl Fact {
{
Fact::Mem {
ty: *ty_lhs,
- min_offset: std::cmp::max(*min_offset_lhs, *min_offset_rhs),
- max_offset: std::cmp::min(*max_offset_lhs, *max_offset_rhs),
+ min_offset: core::cmp::max(*min_offset_lhs, *min_offset_rhs),
+ max_offset: core::cmp::min(*max_offset_lhs, *max_offset_rhs),
nullable: *nullable_lhs && *nullable_rhs,
}
}
@@ -910,7 +910,7 @@ impl<'a> FactContext<'a> {
) if bw_lhs == bw_rhs && add_width >= *bw_lhs => {
let computed_min = min_lhs.checked_add(*min_rhs)?;
let computed_max = max_lhs.checked_add(*max_rhs)?;
- let computed_max = std::cmp::min(max_value_for_width(add_width), computed_max);
+ let computed_max = core::cmp::min(max_value_for_width(add_width), computed_max);
Some(Fact::Range {
bit_width: *bw_lhs,
min: computed_min,
diff --git a/cranelift/codegen/src/isa/aarch64/abi.rs b/cranelift/codegen/src/isa/aarch64/abi.rs
index 20f8476a60..8f1afce63a 100644
--- a/cranelift/codegen/src/isa/aarch64/abi.rs
+++ b/cranelift/codegen/src/isa/aarch64/abi.rs
@@ -12,11 +12,11 @@ use crate::isa::unwind::UnwindInst;
use crate::isa::winch;
use crate::machinst::*;
use crate::settings;
+use alloc::borrow::ToOwned;
use alloc::boxed::Box;
use alloc::vec::Vec;
use regalloc2::{MachineEnv, PReg, PRegSet};
use smallvec::{SmallVec, smallvec};
-use std::borrow::ToOwned;
use std::sync::OnceLock;
// We use a generic implementation that factors out AArch64 and x64 ABI commonalities, because
@@ -348,7 +348,7 @@ impl ABIMachineSpec for AArch64MachineDeps {
} else {
// Every arg takes a minimum slot of 8 bytes. (16-byte stack
// alignment happens separately after all args.)
- std::cmp::max(size, 8)
+ core::cmp::max(size, 8)
};
if !is_winch_return {
diff --git a/cranelift/codegen/src/isa/aarch64/inst/imms.rs b/cranelift/codegen/src/isa/aarch64/inst/imms.rs
index e408f26985..fcd67deed5 100644
--- a/cranelift/codegen/src/isa/aarch64/inst/imms.rs
+++ b/cranelift/codegen/src/isa/aarch64/inst/imms.rs
@@ -4,7 +4,7 @@ use crate::ir::types::*;
use crate::isa::aarch64::inst::{OperandSize, ScalarSize};
use crate::machinst::PrettyPrint;
-use std::string::String;
+use alloc::string::String;
/// An immediate that represents the NZCV flags.
#[derive(Clone, Copy, Debug)]
diff --git a/cranelift/codegen/src/isa/aarch64/inst/mod.rs b/cranelift/codegen/src/isa/aarch64/inst/mod.rs
index cc5ff8eb3a..90ba2ef0c7 100644
--- a/cranelift/codegen/src/isa/aarch64/inst/mod.rs
+++ b/cranelift/codegen/src/isa/aarch64/inst/mod.rs
@@ -9,11 +9,11 @@ use crate::{CodegenError, CodegenResult, settings};
use crate::machinst::{PrettyPrint, Reg, RegClass, Writable};
+use alloc::string::{String, ToString};
use alloc::vec::Vec;
+use core::fmt::Write;
use core::slice;
use smallvec::{SmallVec, smallvec};
-use std::fmt::Write;
-use std::string::{String, ToString};
pub(crate) mod regs;
pub(crate) use self::regs::*;
@@ -3109,6 +3109,6 @@ mod tests {
} else {
32
};
- assert_eq!(expected, std::mem::size_of::<Inst>());
+ assert_eq!(expected, core::mem::size_of::<Inst>());
}
}
diff --git a/cranelift/codegen/src/isa/aarch64/inst/regs.rs b/cranelift/codegen/src/isa/aarch64/inst/regs.rs
index f5a6eb526d..7db69df4eb 100644
--- a/cranelift/codegen/src/isa/aarch64/inst/regs.rs
+++ b/cranelift/codegen/src/isa/aarch64/inst/regs.rs
@@ -8,7 +8,7 @@ use crate::machinst::{Reg, RegClass, Writable};
use regalloc2::PReg;
use regalloc2::VReg;
-use std::string::{String, ToString};
+use alloc::string::{String, ToString};
//=============================================================================
// Registers, the Universe thereof, and printing
diff --git a/cranelift/codegen/src/isa/aarch64/lower/isle.rs b/cranelift/codegen/src/isa/aarch64/lower/isle.rs
index b372ace5cb..3e82af2a9c 100644
--- a/cranelift/codegen/src/isa/aarch64/lower/isle.rs
+++ b/cranelift/codegen/src/isa/aarch64/lower/isle.rs
@@ -31,10 +31,10 @@ use crate::{
abi::ArgPair, ty_bits,
},
};
+use alloc::boxed::Box;
+use alloc::vec::Vec;
use core::u32;
use regalloc2::PReg;
-use std::boxed::Box;
-use std::vec::Vec;
type BoxCallInfo = Box<CallInfo<ExternalName>>;
type BoxCallIndInfo = Box<CallInfo<Reg>>;
@@ -237,7 +237,7 @@ impl Context for IsleContext<'_, '_, MInst, AArch64Backend> {
fn lshl_from_u64(&mut self, ty: Type, n: u64) -> Option<ShiftOpAndAmt> {
let shiftimm = ShiftOpShiftImm::maybe_from_shift(n)?;
let shiftee_bits = ty_bits(ty);
- if shiftee_bits <= std::u8::MAX as usize {
+ if shiftee_bits <= core::u8::MAX as usize {
let shiftimm = shiftimm.mask(shiftee_bits as u8);
Some(ShiftOpAndAmt::new(ShiftOp::LSL, shiftimm))
} else {
@@ -248,7 +248,7 @@ impl Context for IsleContext<'_, '_, MInst, AArch64Backend> {
fn ashr_from_u64(&mut self, ty: Type, n: u64) -> Option<ShiftOpAndAmt> {
let shiftimm = ShiftOpShiftImm::maybe_from_shift(n)?;
let shiftee_bits = ty_bits(ty);
- if shiftee_bits <= std::u8::MAX as usize {
+ if shiftee_bits <= core::u8::MAX as usize {
let shiftimm = shiftimm.mask(shiftee_bits as u8);
Some(ShiftOpAndAmt::new(ShiftOp::ASR, shiftimm))
} else {
diff --git a/cranelift/codegen/src/isa/aarch64/mod.rs b/cranelift/codegen/src/isa/aarch64/mod.rs
index 892911edd8..2f80ad9fa2 100644
--- a/cranelift/codegen/src/isa/aarch64/mod.rs
+++ b/cranelift/codegen/src/isa/aarch64/mod.rs
@@ -12,10 +12,10 @@ use crate::machinst::{
};
use crate::result::CodegenResult;
use crate::settings as shared_settings;
+use alloc::string::String;
use alloc::{boxed::Box, vec::Vec};
use core::fmt;
use cranelift_control::ControlPlane;
-use std::string::String;
use target_lexicon::{Aarch64Architecture, Architecture, OperatingSystem, Triple};
// New backend:
diff --git a/cranelift/codegen/src/isa/mod.rs b/cranelift/codegen/src/isa/mod.rs
index 8728c299c1..2bc2033983 100644
--- a/cranelift/codegen/src/isa/mod.rs
+++ b/cranelift/codegen/src/isa/mod.rs
@@ -23,7 +23,7 @@
//! # #[macro_use] extern crate target_lexicon;
//! use cranelift_codegen::isa;
//! use cranelift_codegen::settings::{self, Configurable};
-//! use std::str::FromStr;
+//! use core::str::FromStr;
//! use target_lexicon::Triple;
//!
//! let shared_builder = settings::builder();
@@ -55,11 +55,11 @@ use crate::settings;
use crate::settings::Configurable;
use crate::settings::SetResult;
use crate::{Reg, flowgraph};
+use alloc::string::String;
use alloc::{boxed::Box, sync::Arc, vec::Vec};
use core::fmt;
use core::fmt::{Debug, Formatter};
use cranelift_control::ControlPlane;
-use std::string::String;
use target_lexicon::{Architecture, PointerWidth, Triple, triple};
// This module is made public here for benchmarking purposes. No guarantees are
@@ -146,7 +146,7 @@ pub enum LookupError {
// This is manually implementing Error and Display instead of using thiserror to reduce the amount
// of dependencies used by Cranelift.
-impl std::error::Error for LookupError {}
+impl core::error::Error for LookupError {}
impl fmt::Display for LookupError {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
diff --git a/cranelift/codegen/src/isa/pulley_shared/abi.rs b/cranelift/codegen/src/isa/pulley_shared/abi.rs
index 3529408fb5..de32099a14 100644
--- a/cranelift/codegen/src/isa/pulley_shared/abi.rs
+++ b/cranelift/codegen/src/isa/pulley_shared/abi.rs
@@ -9,12 +9,12 @@ use crate::{
machinst::*,
settings,
};
+use alloc::borrow::ToOwned;
use alloc::vec::Vec;
use core::marker::PhantomData;
use cranelift_bitset::ScalarBitSet;
use regalloc2::{MachineEnv, PReg, PRegSet};
use smallvec::{SmallVec, smallvec};
-use std::borrow::ToOwned;
use std::sync::OnceLock;
/// Support for the Pulley ABI from the callee side (within a function body).
@@ -130,7 +130,7 @@ where
// Compute size and 16-byte stack alignment happens
// separately after all args.
let size = reg_ty.bits() / 8;
- let size = std::cmp::max(size, 8);
+ let size = core::cmp::max(size, 8);
// Align.
debug_assert!(size.is_power_of_two());
diff --git a/cranelift/codegen/src/isa/pulley_shared/inst/args.rs b/cranelift/codegen/src/isa/pulley_shared/inst/args.rs
index 6ddd6a09dc..e97e3303ef 100644
--- a/cranelift/codegen/src/isa/pulley_shared/inst/args.rs
+++ b/cranelift/codegen/src/isa/pulley_shared/inst/args.rs
@@ -3,9 +3,9 @@
use super::*;
use crate::ir::ExternalName;
use crate::machinst::abi::StackAMode;
+use core::fmt;
use pulley_interpreter::encode;
use pulley_interpreter::regs::Reg as _;
-use std::fmt;
/// A macro for defining a newtype of `Reg` that enforces some invariant about
/// the wrapped `Reg` (such as that it is of a particular register class).
@@ -61,7 +61,7 @@ macro_rules! newtype_of_reg {
// NB: We cannot implement `DerefMut` because that would let people do
// nasty stuff like `*my_xreg.deref_mut() = some_freg`, breaking the
// invariants that `XReg` provides.
- impl std::ops::Deref for $newtype_reg {
+ impl core::ops::Deref for $newtype_reg {
type Target = Reg;
fn deref(&self) -> &Reg {
diff --git a/cranelift/codegen/src/isa/pulley_shared/inst/mod.rs b/cranelift/codegen/src/isa/pulley_shared/inst/mod.rs
index 9bf27e8b8a..d76705a7fb 100644
--- a/cranelift/codegen/src/isa/pulley_shared/inst/mod.rs
+++ b/cranelift/codegen/src/isa/pulley_shared/inst/mod.rs
@@ -611,7 +611,7 @@ const TRAP_OPCODE: &'static [u8] = &[
#[test]
fn test_trap_encoding() {
- let mut dst = std::vec::Vec::new();
+ let mut dst = alloc::vec::Vec::new();
pulley_interpreter::encode::trap(&mut dst);
assert_eq!(dst, TRAP_OPCODE);
}
diff --git a/cranelift/codegen/src/isa/pulley_shared/mod.rs b/cranelift/codegen/src/isa/pulley_shared/mod.rs
index c3f16efa2b..0b781e467a 100644
--- a/cranelift/codegen/src/isa/pulley_shared/mod.rs
+++ b/cranelift/codegen/src/isa/pulley_shared/mod.rs
@@ -17,11 +17,11 @@ use crate::{
settings::{self as shared_settings, Flags},
};
use alloc::boxed::Box;
+use alloc::string::String;
use alloc::vec::Vec;
use core::fmt::Debug;
use core::marker::PhantomData;
use cranelift_control::ControlPlane;
-use std::string::String;
use target_lexicon::{Architecture, Triple};
pub use settings::Flags as PulleyFlags;
diff --git a/cranelift/codegen/src/isa/riscv64/abi.rs b/cranelift/codegen/src/isa/riscv64/abi.rs
index 1292552192..f53eee9a53 100644
--- a/cranelift/codegen/src/isa/riscv64/abi.rs
+++ b/cranelift/codegen/src/isa/riscv64/abi.rs
@@ -19,8 +19,8 @@ use alloc::boxed::Box;
use alloc::vec::Vec;
use regalloc2::{MachineEnv, PReg, PRegSet};
+use alloc::borrow::ToOwned;
use smallvec::{SmallVec, smallvec};
-use std::borrow::ToOwned;
use std::sync::OnceLock;
/// Support for the Riscv64 ABI from the callee side (within a function body).
@@ -59,7 +59,7 @@ impl RiscvFlags {
// Due to a limitation in regalloc2, we can't support types
// larger than 1024 bytes. So limit that here.
- return std::cmp::min(size, 1024);
+ return core::cmp::min(size, 1024);
}
return 0;
@@ -165,7 +165,7 @@ impl ABIMachineSpec for Riscv64MachineDeps {
// Compute size and 16-byte stack alignment happens
// separately after all args.
let size = reg_ty.bits() / 8;
- let size = std::cmp::max(size, 8);
+ let size = core::cmp::max(size, 8);
// Align.
debug_assert!(size.is_power_of_two());
next_stack = align_to(next_stack, size);
diff --git a/cranelift/codegen/src/isa/riscv64/inst/args.rs b/cranelift/codegen/src/isa/riscv64/inst/args.rs
index a4cca65429..918a4854b3 100644
--- a/cranelift/codegen/src/isa/riscv64/inst/args.rs
+++ b/cranelift/codegen/src/isa/riscv64/inst/args.rs
@@ -8,7 +8,7 @@ use crate::isa::riscv64::lower::isle::generated_code::{
};
use crate::machinst::isle::WritableReg;
-use std::fmt::Result;
+use core::fmt::Result;
/// A macro for defining a newtype of `Reg` that enforces some invariant about
/// the wrapped `Reg` (such as that it is of a particular register class).
@@ -53,7 +53,7 @@ macro_rules! newtype_of_reg {
// NB: We cannot implement `DerefMut` because that would let people do
// nasty stuff like `*my_xreg.deref_mut() = some_freg`, breaking the
// invariants that `XReg` provides.
- impl std::ops::Deref for $newtype_reg {
+ impl core::ops::Deref for $newtype_reg {
type Target = Reg;
fn deref(&self) -> &Reg {
@@ -651,7 +651,7 @@ impl Display for FpuOPWidth {
impl TryFrom<Type> for FpuOPWidth {
type Error = &'static str;
- fn try_from(value: Type) -> std::result::Result<Self, Self::Error> {
+ fn try_from(value: Type) -> core::result::Result<Self, Self::Error> {
match value {
F16 => Ok(FpuOPWidth::H),
F32 => Ok(FpuOPWidth::S),
diff --git a/cranelift/codegen/src/isa/riscv64/inst/emit_tests.rs b/cranelift/codegen/src/isa/riscv64/inst/emit_tests.rs
index 9ad30a98d0..3b0cf59b63 100644
--- a/cranelift/codegen/src/isa/riscv64/inst/emit_tests.rs
+++ b/cranelift/codegen/src/isa/riscv64/inst/emit_tests.rs
@@ -1,6 +1,6 @@
use crate::isa::riscv64::inst::*;
use crate::isa::riscv64::lower::isle::generated_code::FpuOPWidth;
-use std::borrow::Cow;
+use alloc::borrow::Cow;
fn fa7() -> Reg {
f_reg(17)
diff --git a/cranelift/codegen/src/isa/riscv64/inst/imms.rs b/cranelift/codegen/src/isa/riscv64/inst/imms.rs
index 1b9621231a..92a8ceb60b 100644
--- a/cranelift/codegen/src/isa/riscv64/inst/imms.rs
+++ b/cranelift/codegen/src/isa/riscv64/inst/imms.rs
@@ -2,7 +2,7 @@
// Some variants are never constructed, but we still want them as options in the future.
use super::Inst;
-use std::fmt::{Debug, Display, Formatter, Result};
+use core::fmt::{Debug, Display, Formatter, Result};
#[derive(Copy, Clone, Debug, Default)]
pub struct Imm12 {
diff --git a/cranelift/codegen/src/isa/riscv64/inst/mod.rs b/cranelift/codegen/src/isa/riscv64/inst/mod.rs
index 2521e8d358..9349d64cd0 100644
--- a/cranelift/codegen/src/isa/riscv64/inst/mod.rs
+++ b/cranelift/codegen/src/isa/riscv64/inst/mod.rs
@@ -12,12 +12,12 @@ use crate::{CodegenError, CodegenResult, settings};
pub use crate::ir::condcodes::FloatCC;
+use alloc::boxed::Box;
+use alloc::string::{String, ToString};
use alloc::vec::Vec;
+use core::fmt::Write;
use regalloc2::RegClass;
use smallvec::{SmallVec, smallvec};
-use std::boxed::Box;
-use std::fmt::Write;
-use std::string::{String, ToString};
pub mod regs;
pub use self::regs::*;
@@ -38,7 +38,7 @@ use crate::isa::riscv64::abi::Riscv64MachineDeps;
#[cfg(test)]
mod emit_tests;
-use std::fmt::{Display, Formatter};
+use core::fmt::{Display, Formatter};
pub(crate) type VecU8 = Vec<u8>;
@@ -85,7 +85,7 @@ impl CondBrTarget {
}
impl Display for CondBrTarget {
- fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+ fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
match self {
CondBrTarget::Label(l) => write!(f, "{}", l.to_string()),
CondBrTarget::Fallthrough => write!(f, "0"),
diff --git a/cranelift/codegen/src/isa/riscv64/lower/isle.rs b/cranelift/codegen/src/isa/riscv64/lower/isle.rs
index 87bf480f2f..a2a7d0c196 100644
--- a/cranelift/codegen/src/isa/riscv64/lower/isle.rs
+++ b/cranelift/codegen/src/isa/riscv64/lower/isle.rs
@@ -21,9 +21,9 @@ use crate::{
isa::riscv64::inst::*,
machinst::{ArgPair, CallArgList, CallRetList, InstOutput},
};
+use alloc::boxed::Box;
+use alloc::vec::Vec;
use regalloc2::PReg;
-use std::boxed::Box;
-use std::vec::Vec;
use wasmtime_math::{f32_cvt_to_int_bounds, f64_cvt_to_int_bounds};
type BoxCallInfo = Box<CallInfo<ExternalName>>;
diff --git a/cranelift/codegen/src/isa/riscv64/mod.rs b/cranelift/codegen/src/isa/riscv64/mod.rs
index 873b698510..ca0a1a13e2 100644
--- a/cranelift/codegen/src/isa/riscv64/mod.rs
+++ b/cranelift/codegen/src/isa/riscv64/mod.rs
@@ -13,10 +13,10 @@ use crate::machinst::{
use crate::result::CodegenResult;
use crate::settings::{self as shared_settings, Flags};
use crate::{CodegenError, ir};
+use alloc::string::String;
use alloc::{boxed::Box, vec::Vec};
use core::fmt;
use cranelift_control::ControlPlane;
-use std::string::String;
use target_lexicon::{Architecture, Triple};
mod abi;
pub(crate) mod inst;
diff --git a/cranelift/codegen/src/isa/s390x/abi.rs b/cranelift/codegen/src/isa/s390x/abi.rs
index 7b8ad6da16..738e037047 100644
--- a/cranelift/codegen/src/isa/s390x/abi.rs
+++ b/cranelift/codegen/src/isa/s390x/abi.rs
@@ -144,10 +144,10 @@ use crate::isa::s390x::{inst::*, settings as s390x_settings};
use crate::isa::unwind::UnwindInst;
use crate::machinst::*;
use crate::settings;
+use alloc::borrow::ToOwned;
use alloc::vec::Vec;
use regalloc2::{MachineEnv, PRegSet};
use smallvec::{SmallVec, smallvec};
-use std::borrow::ToOwned;
use std::sync::OnceLock;
// We use a generic implementation that factors out ABI commonalities.
@@ -399,11 +399,11 @@ impl ABIMachineSpec for S390xMachineDeps {
// Compute size. Every argument or return value takes a slot of
// at least 8 bytes.
let size = (ty_bits(param.value_type) / 8) as u32;
- let slot_size = std::cmp::max(size, 8);
+ let slot_size = core::cmp::max(size, 8);
// Align the stack slot.
debug_assert!(slot_size.is_power_of_two());
- let slot_align = std::cmp::min(slot_size, 8);
+ let slot_align = core::cmp::min(slot_size, 8);
next_stack = align_to(next_stack, slot_align);
// If the type is actually of smaller size (and the argument
diff --git a/cranelift/codegen/src/isa/s390x/inst/imms.rs b/cranelift/codegen/src/isa/s390x/inst/imms.rs
index 8ceebbcdac..9559f34ac7 100644
--- a/cranelift/codegen/src/isa/s390x/inst/imms.rs
+++ b/cranelift/codegen/src/isa/s390x/inst/imms.rs
@@ -1,7 +1,7 @@
//! S390x ISA definitions: immediate constants.
use crate::machinst::PrettyPrint;
-use std::string::String;
+use alloc::string::String;
/// An unsigned 12-bit immediate.
#[derive(Clone, Copy, Debug)]
diff --git a/cranelift/codegen/src/isa/s390x/inst/mod.rs b/cranelift/codegen/src/isa/s390x/inst/mod.rs
index 1e9c0aeb72..762f6c58d2 100644
--- a/cranelift/codegen/src/isa/s390x/inst/mod.rs
+++ b/cranelift/codegen/src/isa/s390x/inst/mod.rs
@@ -7,10 +7,10 @@ use crate::isa::{CallConv, FunctionAlignment};
use crate::machinst::*;
use crate::{CodegenError, CodegenResult, settings};
use alloc::boxed::Box;
+use alloc::string::{String, ToString};
use alloc::vec::Vec;
+use core::fmt::Write;
use smallvec::SmallVec;
-use std::fmt::Write;
-use std::string::{String, ToString};
pub mod regs;
pub use self::regs::*;
pub mod imms;
@@ -55,7 +55,7 @@ pub struct ReturnCallInfo<T> {
fn inst_size_test() {
// This test will help with unintentionally growing the size
// of the Inst enum.
- assert_eq!(32, std::mem::size_of::<Inst>());
+ assert_eq!(32, core::mem::size_of::<Inst>());
}
/// A register pair. Enum so it can be destructured in ISLE.
diff --git a/cranelift/codegen/src/isa/s390x/lower/isle.rs b/cranelift/codegen/src/isa/s390x/lower/isle.rs
index b4bbbc7ec9..561fabd956 100644
--- a/cranelift/codegen/src/isa/s390x/lower/isle.rs
+++ b/cranelift/codegen/src/isa/s390x/lower/isle.rs
@@ -23,10 +23,10 @@ use crate::{
ArgPair, CallArgList, CallRetList, InstOutput, MachInst, VCodeConstant, VCodeConstantData,
},
};
+use alloc::boxed::Box;
+use alloc::vec::Vec;
+use core::cell::Cell;
use regalloc2::PReg;
-use std::boxed::Box;
-use std::cell::Cell;
-use std::vec::Vec;
type BoxCallInfo = Box<CallInfo<CallInstDest>>;
type BoxReturnCallInfo = Box<ReturnCallInfo<CallInstDest>>;
@@ -631,7 +631,7 @@ impl generated_code::Context for IsleContext<'_, '_, MInst, S390xBackend> {
#[inline]
fn fcvt_to_sint_lb32(&mut self, size: u8) -> u64 {
let lb = (-2.0_f32).powi((size - 1).into());
- std::cmp::max(lb.to_bits() + 1, (lb - 1.0).to_bits()) as u64
+ core::cmp::max(lb.to_bits() + 1, (lb - 1.0).to_bits()) as u64
}
#[inline]
@@ -642,7 +642,7 @@ impl generated_code::Context for IsleContext<'_, '_, MInst, S390xBackend> {
#[inline]
fn fcvt_to_sint_lb64(&mut self, size: u8) -> u64 {
let lb = (-2.0_f64).powi((size - 1).into());
- std::cmp::max(lb.to_bits() + 1, (lb - 1.0).to_bits())
+ core::cmp::max(lb.to_bits() + 1, (lb - 1.0).to_bits())
}
#[inline]
diff --git a/cranelift/codegen/src/isa/s390x/mod.rs b/cranelift/codegen/src/isa/s390x/mod.rs
index 8768b4eebf..6bc4048415 100644
--- a/cranelift/codegen/src/isa/s390x/mod.rs
+++ b/cranelift/codegen/src/isa/s390x/mod.rs
@@ -12,10 +12,10 @@ use crate::machinst::{
};
use crate::result::CodegenResult;
use crate::settings as shared_settings;
+use alloc::string::String;
use alloc::{boxed::Box, vec::Vec};
use core::fmt;
use cranelift_control::ControlPlane;
-use std::string::String;
use target_lexicon::{Architecture, Triple};
// New backend:
diff --git a/cranelift/codegen/src/isa/unwind/systemv.rs b/cranelift/codegen/src/isa/unwind/systemv.rs
index d85694e878..5989e0b2a1 100644
--- a/cranelift/codegen/src/isa/unwind/systemv.rs
+++ b/cranelift/codegen/src/isa/unwind/systemv.rs
@@ -23,10 +23,10 @@ pub enum RegisterMappingError {
// This is manually implementing Error and Display instead of using thiserror to reduce the amount
// of dependencies used by Cranelift.
-impl std::error::Error for RegisterMappingError {}
+impl core::error::Error for RegisterMappingError {}
-impl std::fmt::Display for RegisterMappingError {
- fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+impl core::fmt::Display for RegisterMappingError {
+ fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
match self {
RegisterMappingError::MissingBank => write!(f, "unable to find bank for register info"),
RegisterMappingError::UnsupportedArchitecture => write!(
diff --git a/cranelift/codegen/src/isa/winch.rs b/cranelift/codegen/src/isa/winch.rs
index c37ddd373e..df8fdce352 100644
--- a/cranelift/codegen/src/isa/winch.rs
+++ b/cranelift/codegen/src/isa/winch.rs
@@ -8,7 +8,7 @@ pub(super) fn reverse_stack(mut args: ArgsAccumulator, next_stack: u32, uses_ext
for slot in slots.iter_mut() {
if let ABIArgSlot::Stack { offset, ty, .. } = slot {
let size = if uses_extension {
- i64::from(std::cmp::max(ty.bytes(), 8))
+ i64::from(core::cmp::max(ty.bytes(), 8))
} else {
i64::from(ty.bytes())
};
diff --git a/cranelift/codegen/src/isa/x64/abi.rs b/cranelift/codegen/src/isa/x64/abi.rs
index 8189751064..b3a8dfed44 100644
--- a/cranelift/codegen/src/isa/x64/abi.rs
+++ b/cranelift/codegen/src/isa/x64/abi.rs
@@ -9,13 +9,13 @@ use crate::isa::{CallConv, unwind::UnwindInst, x64::inst::*, x64::settings as x6
use crate::machinst::abi::*;
use crate::machinst::*;
use crate::settings;
+use alloc::borrow::ToOwned;
use alloc::boxed::Box;
use alloc::vec::Vec;
use args::*;
use cranelift_assembler_x64 as asm;
use regalloc2::{MachineEnv, PReg, PRegSet};
use smallvec::{SmallVec, smallvec};
-use std::borrow::ToOwned;
use std::sync::OnceLock;
/// Support for the x64 ABI from the callee side (within a function body).
@@ -358,7 +358,7 @@ impl ABIMachineSpec for X64ABIMachineSpec {
{
size
} else {
- let size = std::cmp::max(size, 8);
+ let size = core::cmp::max(size, 8);
// Align.
debug_assert!(size.is_power_of_two());
diff --git a/cranelift/codegen/src/isa/x64/inst/args.rs b/cranelift/codegen/src/isa/x64/inst/args.rs
index c34983643e..233299966a 100644
--- a/cranelift/codegen/src/isa/x64/inst/args.rs
+++ b/cranelift/codegen/src/isa/x64/inst/args.rs
@@ -7,8 +7,8 @@ use crate::ir::types::*;
use crate::isa::x64::inst::Inst;
use crate::isa::x64::inst::regs::pretty_print_reg;
use crate::machinst::*;
-use std::fmt;
-use std::string::String;
+use alloc::string::String;
+use core::fmt;
/// An extension trait for converting `Writable{Xmm,Gpr}` to `Writable<Reg>`.
pub trait ToWritableReg {
@@ -87,7 +87,7 @@ macro_rules! newtype_of_reg {
// NB: We cannot implement `DerefMut` because that would let people do
// nasty stuff like `*my_gpr.deref_mut() = some_xmm_reg`, breaking the
// invariants that `Gpr` provides.
- impl std::ops::Deref for $newtype_reg {
+ impl core::ops::Deref for $newtype_reg {
type Target = Reg;
fn deref(&self) -> &Reg {
diff --git a/cranelift/codegen/src/isa/x64/inst/emit.rs b/cranelift/codegen/src/isa/x64/inst/emit.rs
index 406f9961f7..363f9194bd 100644
--- a/cranelift/codegen/src/isa/x64/inst/emit.rs
+++ b/cranelift/codegen/src/isa/x64/inst/emit.rs
@@ -735,7 +735,7 @@ pub(crate) fn emit(
// Emit jump table (table of 32-bit offsets).
sink.bind_label(start_of_jumptable, state.ctrl_plane_mut());
let jt_off = sink.cur_offset();
- for &target in targets.iter().chain(std::iter::once(default_target)) {
+ for &target in targets.iter().chain(core::iter::once(default_target)) {
let word_off = sink.cur_offset();
// off_into_table is an addend here embedded in the label to be later patched at
// the end of codegen. The offset is initially relative to this jump table entry;
diff --git a/cranelift/codegen/src/isa/x64/inst/external.rs b/cranelift/codegen/src/isa/x64/inst/external.rs
index 2394103a63..8d41f2e6d4 100644
--- a/cranelift/codegen/src/isa/x64/inst/external.rs
+++ b/cranelift/codegen/src/isa/x64/inst/external.rs
@@ -5,9 +5,9 @@ use super::{
SyntheticAmode, VCodeConstant, WritableGpr, WritableXmm, Xmm, args::FromWritableReg,
};
use crate::{Reg, Writable, ir::TrapCode};
+use alloc::string::String;
use cranelift_assembler_x64 as asm;
use regalloc2::{PReg, RegClass};
-use std::string::String;
/// Define the types of registers Cranelift will use.
#[derive(Clone, Debug)]
diff --git a/cranelift/codegen/src/isa/x64/inst/mod.rs b/cranelift/codegen/src/isa/x64/inst/mod.rs
index 298dc938b2..8bff031e3f 100644
--- a/cranelift/codegen/src/isa/x64/inst/mod.rs
+++ b/cranelift/codegen/src/isa/x64/inst/mod.rs
@@ -11,13 +11,13 @@ use crate::isa::{CallConv, FunctionAlignment};
use crate::{CodegenError, CodegenResult, settings};
use crate::{machinst::*, trace};
use alloc::boxed::Box;
+use alloc::string::{String, ToString};
use alloc::vec;
use alloc::vec::Vec;
+use core::fmt::{self, Write};
use core::slice;
use cranelift_assembler_x64 as asm;
use smallvec::{SmallVec, smallvec};
-use std::fmt::{self, Write};
-use std::string::{String, ToString};
pub mod args;
mod emit;
@@ -60,7 +60,7 @@ pub struct ReturnCallInfo<T> {
fn inst_size_test() {
// This test will help with unintentionally growing the size
// of the Inst enum.
- assert_eq!(48, std::mem::size_of::<Inst>());
+ assert_eq!(48, core::mem::size_of::<Inst>());
}
impl Inst {
@@ -1384,7 +1384,7 @@ impl MachInst for Inst {
}
fn gen_nop(preferred_size: usize) -> Inst {
- Inst::nop(std::cmp::min(preferred_size, 9) as u8)
+ Inst::nop(core::cmp::min(preferred_size, 9) as u8)
}
fn gen_nop_units() -> Vec<Vec<u8>> {
diff --git a/cranelift/codegen/src/isa/x64/inst/regs.rs b/cranelift/codegen/src/isa/x64/inst/regs.rs
index f4c0fc2abb..b1416e88df 100644
--- a/cranelift/codegen/src/isa/x64/inst/regs.rs
+++ b/cranelift/codegen/src/isa/x64/inst/regs.rs
@@ -6,10 +6,10 @@
//! Note also that we make use of pinned VRegs to refer to PRegs.
use crate::machinst::Reg;
+use alloc::string::String;
use alloc::string::ToString;
use cranelift_assembler_x64::{gpr, xmm};
use regalloc2::{PReg, RegClass, VReg};
-use std::string::String;
// Constructors for Regs.
diff --git a/cranelift/codegen/src/isa/x64/lower.rs b/cranelift/codegen/src/isa/x64/lower.rs
index 522a155ff1..a000f8ece1 100644
--- a/cranelift/codegen/src/isa/x64/lower.rs
+++ b/cranelift/codegen/src/isa/x64/lower.rs
@@ -16,7 +16,7 @@ use crate::machinst::lower::*;
use crate::machinst::*;
use crate::result::CodegenResult;
use crate::settings::Flags;
-use std::boxed::Box;
+use alloc::boxed::Box;
use target_lexicon::Triple;
/// Identifier for a particular input of an instruction.
diff --git a/cranelift/codegen/src/isa/x64/lower/isle.rs b/cranelift/codegen/src/isa/x64/lower/isle.rs
index 073284605e..57bfa06ee7 100644
--- a/cranelift/codegen/src/isa/x64/lower/isle.rs
+++ b/cranelift/codegen/src/isa/x64/lower/isle.rs
@@ -22,10 +22,10 @@ use crate::machinst::{
ArgPair, CallArgList, CallInfo, CallRetList, InstOutput, MachInst, VCodeConstant,
VCodeConstantData,
};
+use alloc::boxed::Box;
use alloc::vec::Vec;
use cranelift_assembler_x64 as asm;
use regalloc2::PReg;
-use std::boxed::Box;
/// Type representing out-of-line data for calls. This type optional because the
/// call instruction is also used by Winch to emit calls, but the
diff --git a/cranelift/codegen/src/isa/x64/mod.rs b/cranelift/codegen/src/isa/x64/mod.rs
index 0edaf5ccb7..37a3865043 100644
--- a/cranelift/codegen/src/isa/x64/mod.rs
+++ b/cranelift/codegen/src/isa/x64/mod.rs
@@ -16,10 +16,10 @@ use crate::machinst::{
use crate::result::{CodegenError, CodegenResult};
use crate::settings::{self as shared_settings, Flags};
use crate::{Final, MachBufferFinalized};
+use alloc::string::String;
use alloc::{borrow::ToOwned, boxed::Box, vec::Vec};
use core::fmt;
use cranelift_control::ControlPlane;
-use std::string::String;
use target_lexicon::Triple;
mod abi;
diff --git a/cranelift/codegen/src/isle_prelude.rs b/cranelift/codegen/src/isle_prelude.rs
index 6a9a57db40..a2b58b1543 100644
--- a/cranelift/codegen/src/isle_prelude.rs
+++ b/cranelift/codegen/src/isle_prelude.rs
@@ -130,7 +130,7 @@ macro_rules! isle_common_prelude_methods {
#[inline]
fn i64_sextend_u64(&mut self, ty: Type, x: u64) -> i64 {
- let shift_amt = std::cmp::max(0, 64 - ty.bits());
+ let shift_amt = core::cmp::max(0, 64 - ty.bits());
((x as i64) << shift_amt) >> shift_amt
}
@@ -167,7 +167,7 @@ macro_rules! isle_common_prelude_methods {
#[inline]
fn ty_bits(&mut self, ty: Type) -> u8 {
- use std::convert::TryInto;
+ use core::convert::TryInto;
ty.bits().try_into().unwrap()
}
diff --git a/cranelift/codegen/src/legalizer/globalvalue.rs b/cranelift/codegen/src/legalizer/globalvalue.rs
index d829302fbd..45444d1619 100644
--- a/cranelift/codegen/src/legalizer/globalvalue.rs
+++ b/cranelift/codegen/src/legalizer/globalvalue.rs
@@ -50,7 +50,7 @@ fn const_vector_scale(
assert!(ty.bytes() <= 16);
// Use a minimum of 128-bits for the base type.
- let base_bytes = std::cmp::max(ty.bytes(), 16);
+ let base_bytes = core::cmp::max(ty.bytes(), 16);
let scale = (isa.dynamic_vector_bytes(ty) / base_bytes) as i64;
assert!(scale > 0);
let pos = FuncCursor::new(func).at_inst(inst);
diff --git a/cranelift/codegen/src/loop_analysis.rs b/cranelift/codegen/src/loop_analysis.rs
index b9ac3a7c6a..5d88c519af 100644
--- a/cranelift/codegen/src/loop_analysis.rs
+++ b/cranelift/codegen/src/loop_analysis.rs
@@ -62,13 +62,13 @@ impl LoopLevel {
/// A clamped loop level from a larger-width (usize) depth.
pub fn clamped(level: usize) -> Self {
Self(
- u8::try_from(std::cmp::min(level, (Self::INVALID as usize) - 1))
+ u8::try_from(core::cmp::min(level, (Self::INVALID as usize) - 1))
.expect("Clamped value must always convert"),
)
}
}
-impl std::default::Default for LoopLevel {
+impl core::default::Default for LoopLevel {
fn default() -> Self {
LoopLevel::invalid()
}
diff --git a/cranelift/codegen/src/machinst/abi.rs b/cranelift/codegen/src/machinst/abi.rs
index e8949062f4..60ea23445e 100644
--- a/cranelift/codegen/src/machinst/abi.rs
+++ b/cranelift/codegen/src/machinst/abi.rs
@@ -99,6 +99,7 @@
//! ABI. See each platform's `abi.rs` implementation for details.
use crate::CodegenError;
+use crate::HashMap;
use crate::entity::SecondaryMap;
use crate::ir::{ArgumentExtension, ArgumentPurpose, ExceptionTag, Signature};
use crate::ir::{StackSlotKey, types::*};
@@ -107,11 +108,10 @@ use crate::settings::ProbestackStrategy;
use crate::{ir, isa};
use crate::{machinst::*, trace};
use alloc::boxed::Box;
+use core::marker::PhantomData;
use regalloc2::{MachineEnv, PReg, PRegSet};
use rustc_hash::FxHashMap;
use smallvec::smallvec;
-use std::collections::HashMap;
-use std::marker::PhantomData;
/// A small vector of instructions (with some reasonable size); appropriate for
/// a small fixed sequence implementing one operation.
@@ -1022,7 +1022,7 @@ impl SigSet {
// NB: we do _not_ implement `IndexMut` because these signatures are
// deduplicated and shared!
-impl std::ops::Index<Sig> for SigSet {
+impl core::ops::Index<Sig> for SigSet {
type Output = SigData;
fn index(&self, sig: Sig) -> &Self::Output {
@@ -1244,7 +1244,7 @@ impl<M: ABIMachineSpec> Callee<M> {
// We always at least machine-word-align slots, but also
// satisfy the user's requested alignment.
debug_assert!(data.align_shift < 32);
- let align = std::cmp::max(M::word_bytes(), 1u32 << data.align_shift);
+ let align = core::cmp::max(M::word_bytes(), 1u32 << data.align_shift);
let mask = align - 1;
let start_offset = checked_round_up(unaligned_start_offset, mask)
.ok_or(CodegenError::ImplLimitExceeded)?;
@@ -2183,7 +2183,7 @@ impl<M: ABIMachineSpec> Callee<M> {
// establishes live-ranges for in-register arguments and
// constrains them at the start of the function to the
// locations defined by the ABI.
- Some(M::gen_args(std::mem::take(&mut self.reg_args)))
+ Some(M::gen_args(core::mem::take(&mut self.reg_args)))
} else {
None
}
@@ -2612,6 +2612,6 @@ mod tests {
fn sig_data_size() {
// The size of `SigData` is performance sensitive, so make sure
// we don't regress it unintentionally.
- assert_eq!(std::mem::size_of::<SigData>(), 24);
+ assert_eq!(core::mem::size_of::<SigData>(), 24);
}
}
diff --git a/cranelift/codegen/src/machinst/blockorder.rs b/cranelift/codegen/src/machinst/blockorder.rs
index e41f1fa4f1..9e48e2c4d6 100644
--- a/cranelift/codegen/src/machinst/blockorder.rs
+++ b/cranelift/codegen/src/machinst/blockorder.rs
@@ -78,7 +78,7 @@ pub struct BlockLoweringOrder {
lowered_succ_indices: Vec<BlockIndex>,
/// Ranges in `lowered_succ_indices` giving the successor lists for each lowered
/// block. Indexed by lowering-order index (`BlockIndex`).
- lowered_succ_ranges: Vec<(Option<Inst>, std::ops::Range<usize>)>,
+ lowered_succ_ranges: Vec<(Option<Inst>, core::ops::Range<usize>)>,
/// BlockIndex for each original Block.
blockindex_by_block: SecondaryMap<Block, BlockIndex>,
/// Cold blocks. These blocks are not reordered in the
diff --git a/cranelift/codegen/src/machinst/buffer.rs b/cranelift/codegen/src/machinst/buffer.rs
index f386e2af50..abd5396178 100644
--- a/cranelift/codegen/src/machinst/buffer.rs
+++ b/cranelift/codegen/src/machinst/buffer.rs
@@ -180,15 +180,15 @@ use crate::machinst::{
use crate::trace;
use crate::{MachInstEmitState, ir};
use crate::{VCodeConstantData, timing};
+use alloc::collections::BinaryHeap;
+use alloc::string::String;
+use alloc::vec::Vec;
+use core::cmp::Ordering;
+use core::mem;
use core::ops::Range;
use cranelift_control::ControlPlane;
use cranelift_entity::{PrimaryMap, SecondaryMap, entity_impl};
use smallvec::SmallVec;
-use std::cmp::Ordering;
-use std::collections::BinaryHeap;
-use std::mem;
-use std::string::String;
-use std::vec::Vec;
#[cfg(feature = "enable-serde")]
use serde::{Deserialize, Serialize};
@@ -1820,7 +1820,7 @@ impl<T: CompilePhase> MachBufferFinalized<T> {
/// Return the code in this mach buffer as a hex string for testing purposes.
pub fn stringify_code_bytes(&self) -> String {
// This is pretty lame, but whatever ..
- use std::fmt::Write;
+ use core::fmt::Write;
let mut s = String::with_capacity(self.data.len() * 2);
for b in &self.data {
write!(&mut s, "{b:02X}").unwrap();
diff --git a/cranelift/codegen/src/machinst/helpers.rs b/cranelift/codegen/src/machinst/helpers.rs
index 411af0cdc7..01f397c8c6 100644
--- a/cranelift/codegen/src/machinst/helpers.rs
+++ b/cranelift/codegen/src/machinst/helpers.rs
@@ -1,7 +1,7 @@
//! Miscellaneous helpers for machine backends.
use crate::ir::Type;
-use std::ops::{Add, BitAnd, Not, Sub};
+use core::ops::{Add, BitAnd, Not, Sub};
/// Returns the size (in bits) of a given type.
pub fn ty_bits(ty: Type) -> usize {
diff --git a/cranelift/codegen/src/machinst/isle.rs b/cranelift/codegen/src/machinst/isle.rs
index ee8b29ceaf..f73ede5b25 100644
--- a/cranelift/codegen/src/machinst/isle.rs
+++ b/cranelift/codegen/src/machinst/isle.rs
@@ -218,7 +218,7 @@ macro_rules! isle_lower_prelude_methods {
_ => return None,
};
let ty = self.lower_ctx.output_ty(inst, 0);
- let shift_amt = std::cmp::max(0, 64 - self.ty_bits(ty));
+ let shift_amt = core::cmp::max(0, 64 - self.ty_bits(ty));
Some((constant << shift_amt) >> shift_amt)
}
@@ -760,7 +760,7 @@ macro_rules! isle_lower_prelude_methods {
&mut self,
targets: &MachLabelSlice,
) -> Option<(MachLabel, BoxVecMachLabel)> {
- use std::boxed::Box;
+ use alloc::boxed::Box;
if targets.is_empty() {
return None;
}
diff --git a/cranelift/codegen/src/machinst/lower.rs b/cranelift/codegen/src/machinst/lower.rs
index e94d261860..4c55b018c8 100644
--- a/cranelift/codegen/src/machinst/lower.rs
+++ b/cranelift/codegen/src/machinst/lower.rs
@@ -23,10 +23,10 @@ use crate::machinst::{
use crate::settings::Flags;
use crate::{CodegenError, CodegenResult, trace};
use alloc::vec::Vec;
+use core::fmt::Debug;
use cranelift_control::ControlPlane;
use rustc_hash::{FxHashMap, FxHashSet};
use smallvec::{SmallVec, smallvec};
-use std::fmt::Debug;
use super::{VCodeBuildDirection, VRegAllocator};
diff --git a/cranelift/codegen/src/machinst/mod.rs b/cranelift/codegen/src/machinst/mod.rs
index f534ddb87a..c327803d5f 100644
--- a/cranelift/codegen/src/machinst/mod.rs
+++ b/cranelift/codegen/src/machinst/mod.rs
@@ -53,13 +53,13 @@ use crate::result::CodegenResult;
use crate::settings;
use crate::settings::Flags;
use crate::value_label::ValueLabelsRanges;
+use alloc::string::String;
use alloc::vec::Vec;
use core::fmt::Debug;
use cranelift_control::ControlPlane;
use cranelift_entity::PrimaryMap;
use regalloc2::VReg;
use smallvec::{SmallVec, smallvec};
-use std::string::String;
#[cfg(feature = "enable-serde")]
use serde_derive::{Deserialize, Serialize};
@@ -444,7 +444,7 @@ impl<T: CompilePhase> CompiledCodeBase<T> {
params: Option<&crate::ir::function::FunctionParameters>,
cs: &capstone::Capstone,
) -> Result<String, anyhow::Error> {
- use std::fmt::Write;
+ use core::fmt::Write;
let mut buf = String::new();
diff --git a/cranelift/codegen/src/machinst/reg.rs b/cranelift/codegen/src/machinst/reg.rs
index f60afcf7d0..dd28ee05f4 100644
--- a/cranelift/codegen/src/machinst/reg.rs
+++ b/cranelift/codegen/src/machinst/reg.rs
@@ -111,8 +111,8 @@ impl Reg {
}
}
-impl std::fmt::Debug for Reg {
- fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+impl core::fmt::Debug for Reg {
+ fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
if VReg::from(self.0) == VReg::invalid() {
write!(f, "<invalid>")
} else if let Some(spillslot) = self.to_spillslot() {
@@ -153,8 +153,8 @@ impl RealReg {
}
}
-impl std::fmt::Debug for RealReg {
- fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+impl core::fmt::Debug for RealReg {
+ fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
Reg::from(*self).fmt(f)
}
}
@@ -179,8 +179,8 @@ impl VirtualReg {
}
}
-impl std::fmt::Debug for VirtualReg {
- fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+impl core::fmt::Debug for VirtualReg {
+ fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
Reg::from(*self).fmt(f)
}
}
@@ -243,20 +243,20 @@ impl<R: cranelift_assembler_x64::AsReg> cranelift_assembler_x64::AsReg for Writa
// Conversions between regalloc2 types (VReg, PReg) and our types
// (VirtualReg, RealReg, Reg).
-impl std::convert::From<regalloc2::VReg> for Reg {
+impl core::convert::From<regalloc2::VReg> for Reg {
fn from(vreg: regalloc2::VReg) -> Reg {
Reg(vreg.bits() as u32)
}
}
-impl std::convert::From<regalloc2::VReg> for VirtualReg {
+impl core::convert::From<regalloc2::VReg> for VirtualReg {
fn from(vreg: regalloc2::VReg) -> VirtualReg {
debug_assert!(pinned_vreg_to_preg(vreg).is_none());
VirtualReg(vreg)
}
}
-impl std::convert::From<Reg> for regalloc2::VReg {
+impl core::convert::From<Reg> for regalloc2::VReg {
/// Extract the underlying `regalloc2::VReg`. Note that physical
/// registers also map to particular (special) VRegs, so this
/// method can be used either on virtual or physical `Reg`s.
@@ -264,19 +264,19 @@ impl std::convert::From<Reg> for regalloc2::VReg {
reg.0.into()
}
}
-impl std::convert::From<&Reg> for regalloc2::VReg {
+impl core::convert::From<&Reg> for regalloc2::VReg {
fn from(reg: &Reg) -> regalloc2::VReg {
reg.0.into()
}
}
-impl std::convert::From<VirtualReg> for regalloc2::VReg {
+impl core::convert::From<VirtualReg> for regalloc2::VReg {
fn from(reg: VirtualReg) -> regalloc2::VReg {
reg.0
}
}
-impl std::convert::From<RealReg> for regalloc2::VReg {
+impl core::convert::From<RealReg> for regalloc2::VReg {
fn from(reg: RealReg) -> regalloc2::VReg {
// This representation is redundant: the class is implied in the vreg
// index as well as being in the vreg class field.
@@ -284,31 +284,31 @@ impl std::convert::From<RealReg> for regalloc2::VReg {
}
}
-impl std::convert::From<RealReg> for regalloc2::PReg {
+impl core::convert::From<RealReg> for regalloc2::PReg {
fn from(reg: RealReg) -> regalloc2::PReg {
reg.0
}
}
-impl std::convert::From<regalloc2::PReg> for RealReg {
+impl core::convert::From<regalloc2::PReg> for RealReg {
fn from(preg: regalloc2::PReg) -> RealReg {
RealReg(preg)
}
}
-impl std::convert::From<regalloc2::PReg> for Reg {
+impl core::convert::From<regalloc2::PReg> for Reg {
fn from(preg: regalloc2::PReg) -> Reg {
RealReg(preg).into()
}
}
-impl std::convert::From<RealReg> for Reg {
+impl core::convert::From<RealReg> for Reg {
fn from(reg: RealReg) -> Reg {
Reg(VReg::from(reg).bits() as u32)
}
}
-impl std::convert::From<VirtualReg> for Reg {
+impl core::convert::From<VirtualReg> for Reg {
fn from(reg: VirtualReg) -> Reg {
Reg(reg.0.bits() as u32)
}
@@ -317,7 +317,7 @@ impl std::convert::From<VirtualReg> for Reg {
/// A spill slot.
pub type SpillSlot = regalloc2::SpillSlot;
-impl std::convert::From<regalloc2::SpillSlot> for Reg {
+impl core::convert::From<regalloc2::SpillSlot> for Reg {
fn from(spillslot: regalloc2::SpillSlot) -> Reg {
Reg(REG_SPILLSLOT_BIT | spillslot.index() as u32)
}
diff --git a/cranelift/codegen/src/machinst/valueregs.rs b/cranelift/codegen/src/machinst/valueregs.rs
index 53eacea5d0..8a684d868f 100644
--- a/cranelift/codegen/src/machinst/valueregs.rs
+++ b/cranelift/codegen/src/machinst/valueregs.rs
@@ -4,7 +4,7 @@
use regalloc2::{PReg, VReg};
use super::{RealReg, Reg, VirtualReg, Writable};
-use std::fmt::Debug;
+use core::fmt::Debug;
const VALUE_REGS_PARTS: usize = 2;
diff --git a/cranelift/codegen/src/machinst/vcode.rs b/cranelift/codegen/src/machinst/vcode.rs
index 9bb44e43d5..596d720e4e 100644
--- a/cranelift/codegen/src/machinst/vcode.rs
+++ b/cranelift/codegen/src/machinst/vcode.rs
@@ -31,13 +31,13 @@ use regalloc2::{
};
use rustc_hash::FxHashMap;
+use crate::HashMap;
+use crate::hash_map::Entry;
use core::cmp::Ordering;
use core::fmt::{self, Write};
use core::mem::take;
use core::ops::Range;
use cranelift_entity::{Keys, entity_impl};
-use std::collections::HashMap;
-use std::collections::hash_map::Entry;
/// Index referring to an instruction in VCode.
pub type InsnIndex = regalloc2::Inst;
@@ -808,7 +808,7 @@ impl<I: VCodeInst> VCode<I> {
let mut cur_srcloc = None;
let mut last_offset = None;
let mut inst_offsets = vec![];
- let mut state = I::State::new(&self.abi, std::mem::take(ctrl_plane));
+ let mut state = I::State::new(&self.abi, core::mem::take(ctrl_plane));
let mut disasm = String::new();
@@ -1552,7 +1552,7 @@ impl<I: VCodeInst> VCode<I> {
}
}
-impl<I: VCodeInst> std::ops::Index<InsnIndex> for VCode<I> {
+impl<I: VCodeInst> core::ops::Index<InsnIndex> for VCode<I> {
type Output = I;
fn index(&self, idx: InsnIndex) -> &Self::Output {
&self.insts[idx.index()]
@@ -2040,7 +2040,7 @@ impl VCodeConstantData {
#[cfg(test)]
mod test {
use super::*;
- use std::mem::size_of;
+ use core::mem::size_of;
#[test]
fn size_of_constant_structs() {
diff --git a/cranelift/codegen/src/opts.rs b/cranelift/codegen/src/opts.rs
index b7a05cf4fe..fc360913b1 100644
--- a/cranelift/codegen/src/opts.rs
+++ b/cranelift/codegen/src/opts.rs
@@ -15,9 +15,9 @@ pub use crate::ir::{
use crate::isle_common_prelude_methods;
use crate::machinst::isle::*;
use crate::trace;
+use core::marker::PhantomData;
use cranelift_entity::packed_option::ReservedValue;
use smallvec::{SmallVec, smallvec};
-use std::marker::PhantomData;
pub type Unit = ();
pub type ValueArray2 = [Value; 2];
diff --git a/cranelift/codegen/src/remove_constant_phis.rs b/cranelift/codegen/src/remove_constant_phis.rs
index ccaa3973f8..ae9f3ad6ed 100644
--- a/cranelift/codegen/src/remove_constant_phis.rs
+++ b/cranelift/codegen/src/remove_constant_phis.rs
@@ -227,7 +227,7 @@ pub fn do_remove_constant_phis(func: &mut Function, domtree: &mut DominatorTree)
// info. The solver will iterate over the summaries, rather than having
// to inspect each instruction in each block.
let bump =
- Bump::with_capacity(domtree.cfg_postorder().len() * 4 * std::mem::size_of::<Value>());
+ Bump::with_capacity(domtree.cfg_postorder().len() * 4 * core::mem::size_of::<Value>());
let mut summaries =
SecondaryMap::<Block, BlockSummary>::with_capacity(domtree.cfg_postorder().len());
diff --git a/cranelift/codegen/src/result.rs b/cranelift/codegen/src/result.rs
index 5e4a490073..c62572cd99 100644
--- a/cranelift/codegen/src/result.rs
+++ b/cranelift/codegen/src/result.rs
@@ -4,7 +4,7 @@ use regalloc2::checker::CheckerErrors;
use crate::ir::pcc::PccError;
use crate::{ir::Function, verifier::VerifierErrors};
-use std::string::String;
+use alloc::string::String;
/// A compilation error.
///
@@ -52,8 +52,8 @@ pub type CodegenResult<T> = Result<T, CodegenError>;
// This is manually implementing Error and Display instead of using thiserror to reduce the amount
// of dependencies used by Cranelift.
-impl std::error::Error for CodegenError {
- fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
+impl core::error::Error for CodegenError {
+ fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
CodegenError::Verifier(source) => Some(source),
CodegenError::ImplLimitExceeded { .. }
@@ -67,8 +67,8 @@ impl std::error::Error for CodegenError {
}
}
-impl std::fmt::Display for CodegenError {
- fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+impl core::fmt::Display for CodegenError {
+ fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
match self {
CodegenError::Verifier(_) => write!(f, "Verifier errors"),
CodegenError::ImplLimitExceeded => write!(f, "Implementation limit exceeded"),
diff --git a/cranelift/codegen/src/settings.rs b/cranelift/codegen/src/settings.rs
index af8cbd5140..158ba139bd 100644
--- a/cranelift/codegen/src/settings.rs
+++ b/cranelift/codegen/src/settings.rs
@@ -290,7 +290,7 @@ pub enum SetError {
BadValue(String),
}
-impl std::error::Error for SetError {}
+impl core::error::Error for SetError {}
impl fmt::Display for SetError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
diff --git a/cranelift/codegen/src/take_and_replace.rs b/cranelift/codegen/src/take_and_replace.rs
index 78b8c71e82..584d9239d0 100644
--- a/cranelift/codegen/src/take_and_replace.rs
+++ b/cranelift/codegen/src/take_and_replace.rs
@@ -64,7 +64,7 @@ where
U: Default,
{
fn drop(&mut self) {
- *(self.proj)(self.container) = std::mem::take(&mut self.value);
+ *(self.proj)(self.container) = core::mem::take(&mut self.value);
}
}
@@ -76,7 +76,7 @@ where
/// Create a new `TakeAndReplace` that temporarily takes out
/// `proj(container)`.
pub fn new(mut container: &'a mut T, proj: F) -> Self {
- let value = std::mem::take(proj(&mut container));
+ let value = core::mem::take(proj(&mut container));
TakeAndReplace {
container,
value,
diff --git a/cranelift/codegen/src/timing.rs b/cranelift/codegen/src/timing.rs
index a61dd21f79..a06c6001ef 100644
--- a/cranelift/codegen/src/timing.rs
+++ b/cranelift/codegen/src/timing.rs
@@ -118,12 +118,12 @@ pub use enabled::*;
#[cfg(feature = "timing")]
mod enabled {
use super::{DESCRIPTIONS, DefaultProfiler, NUM_PASSES, Pass, Profiler};
- use std::any::Any;
- use std::boxed::Box;
- use std::cell::{Cell, RefCell};
- use std::fmt;
- use std::mem;
- use std::time::Duration;
+ use alloc::boxed::Box;
+ use core::any::Any;
+ use core::cell::{Cell, RefCell};
+ use core::fmt;
+ use core::mem;
+ use core::time::Duration;
use std::time::Instant;
// Information about passes in a single thread.
@@ -135,7 +135,7 @@ mod enabled {
///
/// Returns the old profiler.
pub fn set_thread_profiler(new_profiler: Box<dyn Profiler>) -> Box<dyn Profiler> {
- PROFILER.with(|profiler| std::mem::replace(&mut *profiler.borrow_mut(), new_profiler))
+ PROFILER.with(|profiler| core::mem::replace(&mut *profiler.borrow_mut(), new_profiler))
}
/// Start timing `pass` as a child of the currently running pass, if any.
diff --git a/cranelift/codegen/src/verifier/mod.rs b/cranelift/codegen/src/verifier/mod.rs
index 8406820d6a..c57846c59c 100644
--- a/cranelift/codegen/src/verifier/mod.rs
+++ b/cranelift/codegen/src/verifier/mod.rs
@@ -99,7 +99,7 @@ pub struct VerifierError {
// This is manually implementing Error and Display instead of using thiserror to reduce the amount
// of dependencies used by Cranelift.
-impl std::error::Error for VerifierError {}
+impl core::error::Error for VerifierError {}
impl Display for VerifierError {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
@@ -178,7 +178,7 @@ pub struct VerifierErrors(pub Vec<VerifierError>);
// This is manually implementing Error and Display instead of using thiserror to reduce the amount
// of dependencies used by Cranelift.
-impl std::error::Error for VerifierErrors {}
+impl core::error::Error for VerifierErrors {}
impl VerifierErrors {
/// Return a new `VerifierErrors` struct.