Skip to content

Commit 0889323

Browse files
authored
cranelift-codegen: rename most uses of std to core and alloc (#12237)
* rename most std uses to core and alloc * cargo fmt
1 parent b5272a5 commit 0889323

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+180
-179
lines changed

cranelift/codegen/meta/src/gen_inst.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ fn gen_instruction_data_impl(formats: &[Rc<InstructionFormat>], fmt: &mut Format
312312
(Some("args.as_slice(pool)"), "args.len(pool)")
313313
} else if format.num_value_operands == 1 {
314314
members.push("ref arg");
315-
(Some("std::slice::from_ref(arg)"), "1")
315+
(Some("core::slice::from_ref(arg)"), "1")
316316
} else if format.num_value_operands > 0 {
317317
members.push("ref args");
318318
(Some("args"), "args.len()")
@@ -324,7 +324,7 @@ fn gen_instruction_data_impl(formats: &[Rc<InstructionFormat>], fmt: &mut Format
324324
0 => None,
325325
1 => {
326326
members.push("ref destination");
327-
Some(("std::slice::from_ref(destination)", "1"))
327+
Some(("core::slice::from_ref(destination)", "1"))
328328
}
329329
_ => {
330330
members.push("ref blocks");

cranelift/codegen/shared/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
//! `cranelift-codegen-meta` libraries.
33
44
#![deny(missing_docs)]
5+
#![no_std]
56

67
pub mod constant_hash;
78
pub mod constants;
89

910
/// Version number of this crate.
10-
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
11+
pub const VERSION: &str = core::env!("CARGO_PKG_VERSION");

cranelift/codegen/src/ctxhash.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
//! node-internal data references some other storage (e.g., offsets into
55
//! an array or pool of shared data).
66
7+
use core::hash::{Hash, Hasher};
78
use hashbrown::hash_table::HashTable;
8-
use std::hash::{Hash, Hasher};
99

1010
/// Trait that allows for equality comparison given some external
1111
/// context.
@@ -92,7 +92,7 @@ impl<K, V> CtxHashMap<K, V> {
9292
match self.raw.find_mut(hash as u64, |bucket| {
9393
hash == bucket.hash && ctx.ctx_eq(&bucket.k, &k)
9494
}) {
95-
Some(bucket) => Some(std::mem::replace(&mut bucket.v, v)),
95+
Some(bucket) => Some(core::mem::replace(&mut bucket.v, v)),
9696
None => {
9797
let data = BucketData { hash, k, v };
9898
self.raw

cranelift/codegen/src/data_value.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,13 @@ impl DataValue {
247247
/// Write a [DataValue] to a memory location in native-endian byte order.
248248
pub unsafe fn write_value_to(&self, p: *mut u128) {
249249
let size = self.ty().bytes() as usize;
250-
self.write_to_slice_ne(unsafe { std::slice::from_raw_parts_mut(p as *mut u8, size) });
250+
self.write_to_slice_ne(unsafe { core::slice::from_raw_parts_mut(p as *mut u8, size) });
251251
}
252252

253253
/// Read a [DataValue] from a memory location using a given [Type] in native-endian byte order.
254254
pub unsafe fn read_value_from(p: *const u128, ty: Type) -> Self {
255255
DataValue::read_from_slice_ne(
256-
unsafe { std::slice::from_raw_parts(p as *const u8, ty.bytes() as usize) },
256+
unsafe { core::slice::from_raw_parts(p as *const u8, ty.bytes() as usize) },
257257
ty,
258258
)
259259
}
@@ -290,7 +290,7 @@ pub enum DataValueCastFailure {
290290

291291
// This is manually implementing Error and Display instead of using thiserror to reduce the amount
292292
// of dependencies used by Cranelift.
293-
impl std::error::Error for DataValueCastFailure {}
293+
impl core::error::Error for DataValueCastFailure {}
294294

295295
impl Display for DataValueCastFailure {
296296
fn fmt(&self, f: &mut Formatter) -> fmt::Result {

cranelift/codegen/src/dominator_tree.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ impl SpanningTree {
9494
}
9595
}
9696

97-
impl std::ops::Index<u32> for SpanningTree {
97+
impl core::ops::Index<u32> for SpanningTree {
9898
type Output = SpanningTreeNode;
9999

100100
fn index(&self, idx: u32) -> &Self::Output {
101101
&self.nodes[idx as usize]
102102
}
103103
}
104104

105-
impl std::ops::IndexMut<u32> for SpanningTree {
105+
impl core::ops::IndexMut<u32> for SpanningTree {
106106
fn index_mut(&mut self, idx: u32) -> &mut Self::Output {
107107
&mut self.nodes[idx as usize]
108108
}
@@ -439,7 +439,7 @@ impl DominatorTree {
439439
}
440440

441441
let semi_candidate = self.eval(self.nodes[pred].pre_number, last_linked);
442-
semi = std::cmp::min(semi, semi_candidate);
442+
semi = core::cmp::min(semi, semi_candidate);
443443
}
444444

445445
let w_node = &mut self.stree[w];

cranelift/codegen/src/egraph.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ where
660660

661661
let old_vals = ctx.func.dfg.inst_results(inst);
662662
let new_vals = if let Some(val) = new_val.as_ref() {
663-
std::slice::from_ref(val)
663+
core::slice::from_ref(val)
664664
} else {
665665
ctx.func.dfg.inst_results(new_inst)
666666
};
@@ -1075,7 +1075,7 @@ impl<'a> CtxEq<(Type, InstructionData), (Type, InstructionData)> for GVNContext<
10751075

10761076
impl<'a> CtxHash<(Type, InstructionData)> for GVNContext<'a> {
10771077
fn ctx_hash<H: Hasher>(&self, state: &mut H, (ty, inst): &(Type, InstructionData)) {
1078-
std::hash::Hash::hash(&ty, state);
1078+
core::hash::Hash::hash(&ty, state);
10791079
inst.hash(state, self.value_lists);
10801080
}
10811081
}

cranelift/codegen/src/egraph/cost.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl core::fmt::Debug for Cost {
4848

4949
impl Ord for Cost {
5050
#[inline]
51-
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
51+
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
5252
// We make sure that the high bits are the op cost and the low bits are
5353
// the depth. This means that we can use normal integer comparison to
5454
// order by op cost and then depth.
@@ -65,7 +65,7 @@ impl Ord for Cost {
6565

6666
impl PartialOrd for Cost {
6767
#[inline]
68-
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
68+
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
6969
Some(self.cmp(other))
7070
}
7171
}
@@ -172,24 +172,24 @@ impl Cost {
172172
}
173173
}
174174

175-
impl std::iter::Sum<Cost> for Cost {
175+
impl core::iter::Sum<Cost> for Cost {
176176
fn sum<I: Iterator<Item = Cost>>(iter: I) -> Self {
177177
iter.fold(Self::zero(), |a, b| a + b)
178178
}
179179
}
180180

181-
impl std::default::Default for Cost {
181+
impl core::default::Default for Cost {
182182
fn default() -> Cost {
183183
Cost::zero()
184184
}
185185
}
186186

187-
impl std::ops::Add<Cost> for Cost {
187+
impl core::ops::Add<Cost> for Cost {
188188
type Output = Cost;
189189

190190
fn add(self, other: Cost) -> Cost {
191191
let op_cost = self.op_cost().saturating_add(other.op_cost());
192-
let depth = std::cmp::max(self.depth(), other.depth());
192+
let depth = core::cmp::max(self.depth(), other.depth());
193193
Cost::new(op_cost, depth)
194194
}
195195
}

cranelift/codegen/src/egraph/elaborate.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl PartialOrd for BestEntry {
8282

8383
impl Ord for BestEntry {
8484
#[inline]
85-
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
85+
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
8686
self.0.cmp(&other.0).then_with(|| {
8787
// Note that this comparison is reversed. When costs are equal,
8888
// prefer the value with the bigger index. This is a heuristic that
@@ -321,9 +321,9 @@ impl<'a> Elaborator<'a> {
321321
debug_assert!(!best[x].1.is_reserved_value());
322322
debug_assert!(!best[y].1.is_reserved_value());
323323
best[value] = if use_worst {
324-
std::cmp::max(best[x], best[y])
324+
core::cmp::max(best[x], best[y])
325325
} else {
326-
std::cmp::min(best[x], best[y])
326+
core::cmp::min(best[x], best[y])
327327
};
328328
trace!(
329329
" -> best of union({:?}, {:?}) = {:?}",

cranelift/codegen/src/incremental_cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pub trait CacheKvStore {
111111
#[derive(Clone, Hash, PartialEq, Eq)]
112112
pub struct CacheKeyHash([u8; 32]);
113113

114-
impl std::fmt::Display for CacheKeyHash {
114+
impl core::fmt::Display for CacheKeyHash {
115115
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
116116
write!(f, "CacheKeyHash:{:?}", self.0)
117117
}

cranelift/codegen/src/ir/condcodes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ impl FromStr for FloatCC {
344344
#[cfg(test)]
345345
mod tests {
346346
use super::*;
347-
use std::string::ToString;
347+
use alloc::string::ToString;
348348

349349
#[test]
350350
fn int_complement() {

0 commit comments

Comments
 (0)