Update no_std support for Rust 2018 Edition.

With Rust 2018 Edition, the `mod std` trick to alias `core` names to
`std` no longer works, so switch to just having the code use `core`
explicitly.

So instead, switch to just using `core::*` for things that in core.
This is more consistent with other Rust no_std code. And it allows
us to enable `no_std` mode unconditionally in the crates that support
it, which makes testing a little easier.

There actually three cases:

 - For things in std and also in core, like `cmp`: Just use them via
   `core::*`.

 - For things in std and also in alloc, like `Vec`: Import alloc as std, as
   use them from std. This allows them to work on both stable (which
   doesn't provide alloc, but we don't support no_std mode anyway) and
   nightly.

 - For HashMap and similar which are not in core or alloc, import them in
   the top-level lib.rs files from either std or the third-party hashmap_core
   crate, and then have the code use super::hashmap_core.

Also, no_std support continues to be "best effort" at this time and not
something most people need to be testing.
This commit is contained in:
Dan Gohman
2019-01-07 11:04:58 -08:00
parent 50a045363c
commit aeb9161e2c
118 changed files with 322 additions and 355 deletions

View File

@@ -59,7 +59,7 @@ pub trait InstInserterBase<'f>: Sized {
fn insert_built_inst(self, inst: Inst, ctrl_typevar: Type) -> &'f mut DataFlowGraph;
}
use std::marker::PhantomData;
use core::marker::PhantomData;
/// Builder that inserts an instruction at the current position.
///

View File

@@ -4,8 +4,8 @@
//! are different rules for comparing integers and floating point numbers, so they use different
//! condition codes.
use std::fmt::{self, Display, Formatter};
use std::str::FromStr;
use core::fmt::{self, Display, Formatter};
use core::str::FromStr;
/// Common traits of condition codes.
pub trait CondCode: Copy {

View File

@@ -10,11 +10,11 @@ use crate::ir::{Ebb, FuncRef, Inst, SigRef, Signature, Type, Value, ValueList, V
use crate::isa::TargetIsa;
use crate::packed_option::ReservedValue;
use crate::write::write_operands;
use std::fmt;
use std::iter;
use std::mem;
use std::ops::{Index, IndexMut};
use std::u16;
use core::fmt;
use core::iter;
use core::mem;
use core::ops::{Index, IndexMut};
use core::u16;
/// A data flow graph defines all instructions and extended basic blocks in a function as well as
/// the data flow dependencies between them. The DFG also tracks values which can be either

View File

@@ -20,8 +20,8 @@
//! format.
use crate::entity::entity_impl;
use std::fmt;
use std::u32;
use core::fmt;
use core::u32;
/// An opaque reference to an extended basic block in a function.
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
@@ -305,8 +305,8 @@ impl From<Table> for AnyEntity {
#[cfg(test)]
mod tests {
use super::*;
use core::u32;
use std::string::ToString;
use std::u32;
#[test]
fn value_with_number() {
@@ -320,7 +320,7 @@ mod tests {
#[test]
fn memory() {
use crate::packed_option::PackedOption;
use std::mem;
use core::mem;
// This is the whole point of `PackedOption`.
assert_eq!(
mem::size_of::<Value>(),

View File

@@ -7,8 +7,8 @@
use crate::ir::{ArgumentLoc, ExternalName, SigRef, Type};
use crate::isa::{CallConv, RegInfo, RegUnit};
use std::fmt;
use std::str::FromStr;
use core::fmt;
use core::str::FromStr;
use std::vec::Vec;
/// Function signature.

View File

@@ -5,9 +5,9 @@
//! Cranelift, which compiles functions independently.
use crate::ir::LibCall;
use std::cmp;
use std::fmt::{self, Write};
use std::str::FromStr;
use core::cmp;
use core::fmt::{self, Write};
use core::str::FromStr;
const TESTCASE_NAME_LENGTH: usize = 16;
@@ -120,8 +120,8 @@ impl FromStr for ExternalName {
mod tests {
use super::ExternalName;
use crate::ir::LibCall;
use core::u32;
use std::string::ToString;
use std::u32;
#[test]
fn display_testcase() {

View File

@@ -16,7 +16,7 @@ use crate::ir::{JumpTableOffsets, JumpTables};
use crate::isa::{CallConv, EncInfo, Encoding, Legalize, TargetIsa};
use crate::regalloc::RegDiversions;
use crate::write::write_function;
use std::fmt;
use core::fmt;
/// A function.
///

View File

@@ -3,7 +3,7 @@
use crate::ir::immediates::{Imm64, Offset32};
use crate::ir::{ExternalName, GlobalValue, Type};
use crate::isa::TargetIsa;
use std::fmt;
use core::fmt;
/// Information about a global value declaration.
#[derive(Clone)]

View File

@@ -2,7 +2,7 @@
use crate::ir::immediates::Uimm64;
use crate::ir::{GlobalValue, Type};
use std::fmt;
use core::fmt;
/// Information about a heap declaration.
#[derive(Clone)]

View File

@@ -4,10 +4,10 @@
//! Each type here should have a corresponding definition in the `cranelift.immediates` Python
//! module in the meta language.
use std::fmt::{self, Display, Formatter};
use std::mem;
use std::str::FromStr;
use std::{i32, u32};
use core::fmt::{self, Display, Formatter};
use core::mem;
use core::str::FromStr;
use core::{i32, u32};
/// 64-bit immediate signed integer operand.
///
@@ -729,10 +729,10 @@ impl FromStr for Ieee64 {
#[cfg(test)]
mod tests {
use super::*;
use std::fmt::Display;
use std::str::FromStr;
use core::fmt::Display;
use core::str::FromStr;
use core::{f32, f64};
use std::string::ToString;
use std::{f32, f64};
#[test]
fn format_imm64() {

View File

@@ -6,9 +6,9 @@
//! A large part of this module is auto-generated from the instruction descriptions in the meta
//! directory.
use std::fmt::{self, Display, Formatter};
use std::ops::{Deref, DerefMut};
use std::str::FromStr;
use core::fmt::{self, Display, Formatter};
use core::ops::{Deref, DerefMut};
use core::str::FromStr;
use std::vec::Vec;
use crate::ir;
@@ -561,7 +561,7 @@ mod tests {
#[test]
fn opcodes() {
use std::mem;
use core::mem;
let x = Opcode::Iadd;
let mut y = Opcode::Isub;
@@ -590,7 +590,7 @@ mod tests {
#[test]
fn instruction_data() {
use std::mem;
use core::mem;
// The size of the `InstructionData` enum is important for performance. It should not
// exceed 16 bytes. Use `Box<FooData>` out-of-line payloads for instruction formats that
// require more space than that. It would be fine with a data structure smaller than 16

View File

@@ -4,8 +4,8 @@
//! The actual table of destinations is stored in a `JumpTableData` struct defined in this module.
use crate::ir::entities::Ebb;
use std::fmt::{self, Display, Formatter};
use std::slice::{Iter, IterMut};
use core::fmt::{self, Display, Formatter};
use core::slice::{Iter, IterMut};
use std::vec::Vec;
/// Contents of a jump table.

View File

@@ -8,9 +8,9 @@ use crate::ir::progpoint::{ExpandedProgramPoint, ProgramOrder};
use crate::ir::{Ebb, Inst};
use crate::packed_option::PackedOption;
use crate::timing;
use core::cmp;
use core::iter::{IntoIterator, Iterator};
use log::debug;
use std::cmp;
use std::iter::{IntoIterator, Iterator};
/// The `Layout` struct determines the layout of EBBs and instructions in a function. It does not
/// contain definitions of instructions or EBBs, but depends on `Inst` and `Ebb` entity references
@@ -745,7 +745,7 @@ mod tests {
use crate::cursor::{Cursor, CursorPosition};
use crate::entity::EntityRef;
use crate::ir::{Ebb, Inst, ProgramOrder, SourceLoc};
use std::cmp::Ordering;
use core::cmp::Ordering;
use std::vec::Vec;
struct LayoutCursor<'f> {

View File

@@ -5,8 +5,8 @@ use crate::ir::{
Signature, Type,
};
use crate::isa::{CallConv, RegUnit, TargetIsa};
use std::fmt;
use std::str::FromStr;
use core::fmt;
use core::str::FromStr;
/// The name of a runtime library routine.
///

View File

@@ -1,6 +1,6 @@
//! Memory operation flags.
use std::fmt;
use core::fmt;
enum FlagBit {
Notrap,

View File

@@ -2,9 +2,9 @@
use crate::entity::EntityRef;
use crate::ir::{Ebb, Inst, ValueDef};
use std::cmp;
use std::fmt;
use std::u32;
use core::cmp;
use core::fmt;
use core::u32;
/// A `ProgramPoint` represents a position in a function where the live range of an SSA value can
/// begin or end. It can be either:

View File

@@ -3,7 +3,7 @@
//! Cranelift tracks the original source location of each instruction, and preserves the source
//! location when instructions are transformed.
use std::fmt;
use core::fmt;
/// A source location.
///

View File

@@ -6,11 +6,11 @@
use crate::entity::{Iter, IterMut, Keys, PrimaryMap};
use crate::ir::{StackSlot, Type};
use crate::packed_option::PackedOption;
use std::cmp;
use std::fmt;
use std::ops::{Index, IndexMut};
use std::slice;
use std::str::FromStr;
use core::cmp;
use core::fmt;
use core::ops::{Index, IndexMut};
use core::slice;
use core::str::FromStr;
use std::vec::Vec;
/// The size of an object on the stack, or the size of a stack frame.

View File

@@ -2,7 +2,7 @@
use crate::ir::immediates::Uimm64;
use crate::ir::{GlobalValue, Type};
use std::fmt;
use core::fmt;
/// Information about a table declaration.
#[derive(Clone)]

View File

@@ -1,7 +1,7 @@
//! Trap codes describing the reason for a trap.
use std::fmt::{self, Display, Formatter};
use std::str::FromStr;
use core::fmt::{self, Display, Formatter};
use core::str::FromStr;
/// A trap code describing the reason for a trap.
///

View File

@@ -1,7 +1,7 @@
//! Common types for the Cranelift code generator.
use std::default::Default;
use std::fmt::{self, Debug, Display, Formatter};
use core::default::Default;
use core::fmt::{self, Debug, Display, Formatter};
use target_lexicon::{PointerWidth, Triple};
/// The type of an SSA value.

View File

@@ -5,7 +5,7 @@
use crate::ir::StackSlot;
use crate::isa::{RegInfo, RegUnit};
use std::fmt;
use core::fmt;
/// Value location.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]