Skip to content

Commit

Permalink
Update to Rust 2018 edition (bytecodealliance#632)
Browse files Browse the repository at this point in the history
* initial cargo fix run

* Upgrade cranelift-entity crate

* Upgrade bforest crate

* Upgrade the codegen crate

* Upgrade the faerie crate

* Upgrade the filetests crate

* Upgrade the codegen-meta crate

* Upgrade the frontend crate

* Upgrade the cranelift-module crate

* Upgrade the cranelift-native crate

* Upgrade the cranelift-preopt crate

* Upgrade the cranelift-reader crate

* Upgrade the cranelift-serde crate

* Upgrade the cranelift-simplejit crate

* Upgrade the cranelift or cranelift-umbrella crate

* Upgrade the cranelift-wasm crate

* Upgrade cranelift-tools crate

* Use new import style on remaining files

* run format-all.sh

* run test-all.sh, update Readme and travis ci configuration
fixed an AssertionError also

* Remove deprecated functions
  • Loading branch information
mominul authored and sunfishcode committed Dec 26, 2018
1 parent e3db942 commit effe6c0
Show file tree
Hide file tree
Showing 217 changed files with 963 additions and 1,021 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ language: rust
rust:
# The oldest version we currently support. See
# CONTRIBUTING.md#rustc-version-support for details.
- 1.30.1
- 1.31.1
- beta
- nightly
matrix:
Expand Down
1 change: 1 addition & 0 deletions cranelift/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ license = "Apache-2.0 WITH LLVM-exception"
documentation = "https://cranelift.readthedocs.io/"
repository = "https://github.com/CraneStation/cranelift"
publish = false
edition = "2018"

[[bin]]
name = "clif-util"
Expand Down
2 changes: 1 addition & 1 deletion cranelift/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ into executable machine code.
[![Travis Status](https://travis-ci.org/CraneStation/cranelift.svg?branch=master)](https://travis-ci.org/CraneStation/cranelift)
[![Appveyor Status](https://ci.appveyor.com/api/projects/status/oub7wrrb59utuv8x?svg=true)](https://ci.appveyor.com/project/CraneStation/cranelift)
[![Gitter chat](https://badges.gitter.im/CraneStation/CraneStation.svg)](https://gitter.im/CraneStation/Lobby)
![Minimum rustc 1.30](https://img.shields.io/badge/rustc-1.30+-green.svg)
![Minimum rustc 1.31](https://img.shields.io/badge/rustc-1.31+-green.svg)

For more information, see [the
documentation](https://cranelift.readthedocs.io/en/latest/?badge=latest).
Expand Down
4 changes: 2 additions & 2 deletions cranelift/src/cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
//! Read a sequence of Cranelift IR files and print them again to stdout. This has the effect of
//! normalizing formatting and removing comments.

use crate::utils::read_to_string;
use crate::CommandResult;
use cranelift_reader::parse_functions;
use utils::read_to_string;
use CommandResult;

pub fn run(files: &[String]) -> CommandResult {
for (i, f) in files.into_iter().enumerate() {
Expand Down
17 changes: 1 addition & 16 deletions cranelift/src/clif-util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,13 @@
)
)]

extern crate file_per_thread_logger;
#[macro_use]
extern crate cfg_if;
#[cfg(feature = "disas")]
extern crate capstone;
extern crate clap;
extern crate cranelift_codegen;
#[cfg(feature = "wasm")]
extern crate cranelift_entity;
extern crate cranelift_filetests;
extern crate cranelift_reader;
extern crate pretty_env_logger;
use cfg_if::cfg_if;

cfg_if! {
if #[cfg(feature = "wasm")] {
extern crate cranelift_wasm;
extern crate term;
extern crate wabt;
mod wasm;
}
}
extern crate target_lexicon;

use clap::{App, Arg, SubCommand};
use cranelift_codegen::dbg::LOG_FILENAME_PREFIX;
Expand Down
3 changes: 2 additions & 1 deletion cranelift/src/compile.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! CLI tool to read Cranelift IR files and compile them into native code.

use crate::utils::{parse_sets_and_triple, read_to_string};
use cfg_if::cfg_if;
use cranelift_codegen::isa::TargetIsa;
use cranelift_codegen::print_errors::pretty_error;
use cranelift_codegen::settings::FlagsOrIsa;
Expand All @@ -9,7 +11,6 @@ use cranelift_codegen::{binemit, ir};
use cranelift_reader::parse_test;
use std::path::Path;
use std::path::PathBuf;
use utils::{parse_sets_and_triple, read_to_string};

struct PrintRelocs {
flag_print: bool,
Expand Down
4 changes: 2 additions & 2 deletions cranelift/src/print_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
//! Read a series of Cranelift IR files and print their control flow graphs
//! in graphviz format.

use crate::utils::read_to_string;
use crate::CommandResult;
use cranelift_codegen::cfg_printer::CFGPrinter;
use cranelift_reader::parse_functions;
use utils::read_to_string;
use CommandResult;

pub fn run(files: &[String]) -> CommandResult {
for (i, f) in files.into_iter().enumerate() {
Expand Down
2 changes: 1 addition & 1 deletion cranelift/src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use cranelift_wasm::{
use std::path::Path;
use std::path::PathBuf;
use term;
use utils::{parse_sets_and_triple, read_to_end};
use crate::utils::{parse_sets_and_triple, read_to_end};
use wabt::wat2wasm;

macro_rules! vprintln {
Expand Down
2 changes: 0 additions & 2 deletions cranelift/tests/filetests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate cranelift_filetests;

#[test]
fn filetests() {
// Run all the filetests in the following directories.
Expand Down
1 change: 1 addition & 0 deletions lib/bforest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ repository = "https://github.com/CraneStation/cranelift"
categories = ["no-std"]
readme = "README.md"
keywords = ["btree", "forest", "set", "map"]
edition = "2018"

[dependencies]
cranelift-entity = { path = "../entity", version = "0.26.0", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions lib/bforest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ mod std {

#[macro_use]
extern crate cranelift_entity as entity;
use entity::packed_option;
use crate::entity::packed_option;

use std::borrow::BorrowMut;
use std::cmp::Ordering;
Expand Down Expand Up @@ -157,7 +157,7 @@ fn slice_shift<T: Copy>(s: &mut [T], n: usize) {
#[cfg(test)]
mod tests {
use super::*;
use entity::EntityRef;
use crate::entity::EntityRef;

/// An opaque reference to an extended basic block in a function.
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
Expand Down
2 changes: 1 addition & 1 deletion lib/bforest/src/map.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Forest of maps.

use super::{Comparator, Forest, Node, NodeData, NodePool, Path, INNER_SIZE};
use packed_option::PackedOption;
use crate::packed_option::PackedOption;
#[cfg(test)]
use std::fmt;
use std::marker::PhantomData;
Expand Down
4 changes: 2 additions & 2 deletions lib/bforest/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#[cfg(test)]
use super::Comparator;
use super::{Forest, Node, NodeData};
use entity::PrimaryMap;
use crate::entity::PrimaryMap;
#[cfg(test)]
use std::fmt;
use std::ops::{Index, IndexMut};
Expand Down Expand Up @@ -83,7 +83,7 @@ impl<F: Forest> NodePool<F> {
NodeData<F>: fmt::Display,
F::Key: fmt::Display,
{
use entity::SparseSet;
use crate::entity::SparseSet;
use std::borrow::Borrow;
use std::cmp::Ordering;
use std::vec::Vec;
Expand Down
2 changes: 1 addition & 1 deletion lib/bforest/src/set.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Forest of sets.

use super::{Comparator, Forest, Node, NodeData, NodePool, Path, SetValue, INNER_SIZE};
use packed_option::PackedOption;
use crate::packed_option::PackedOption;
#[cfg(test)]
use std::fmt;
use std::marker::PhantomData;
Expand Down
1 change: 1 addition & 0 deletions lib/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ categories = ["no-std"]
readme = "README.md"
keywords = ["compile", "compiler", "jit"]
build = "build.rs"
edition = "2018"

[dependencies]
cranelift-entity = { path = "../entity", version = "0.26.0", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions lib/codegen/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
// The build script expects to be run from the directory where this build.rs file lives. The
// current directory is used to find the sources.

extern crate cranelift_codegen_meta as meta;
use cranelift_codegen_meta as meta;

use meta::isa::Isa;
use crate::meta::isa::Isa;
use std::env;
use std::process;
use std::time::Instant;
Expand Down
3 changes: 2 additions & 1 deletion lib/codegen/meta-python/cdsl/predicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ def rust_predicate(self, prec):
"""
# Prepend `field` to the predicate function arguments.
args = (self.field.rust_name(),) + tuple(map(str, self.args))
return '::predicates::{}({})'.format(self.function, ', '.join(args))
return 'crate::predicates::{}({})'\
.format(self.function, ', '.join(args))


class IsEqual(FieldPredicate):
Expand Down
2 changes: 1 addition & 1 deletion lib/codegen/meta-python/cdsl/xform.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ def rust_name(self):
# table referring to it.
return self.name
else:
return '::legalizer::{}'.format(self.name)
return 'crate::legalizer::{}'.format(self.name)

def legalize(self, src, dst):
# type: (Union[Def, Apply], Rtl) -> None
Expand Down
16 changes: 9 additions & 7 deletions lib/codegen/meta-python/gen_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def emit_instp(instp, fmt, has_func=False):
fields = ', '.join(sorted(fnames))

with fmt.indented(
'if let ir::InstructionData::{} {{ {}, .. }} = *inst {{'
'if let crate::ir::InstructionData::{} {{ {}, .. }} = *inst {{'
.format(iform.name, fields), '}'):
if has_type_check:
# We could implement this if we need to.
Expand All @@ -132,7 +132,8 @@ def emit_inst_predicates(instps, fmt):
for instp, number in instps.items():
name = 'inst_predicate_{}'.format(number)
with fmt.indented(
'fn {}(func: &ir::Function, inst: &ir::InstructionData)'
'fn {}(func: &crate::ir::Function, '
'inst: &crate::ir::InstructionData)'
'-> bool {{'.format(name), '}'):
emit_instp(instp, fmt, has_func=True)

Expand Down Expand Up @@ -168,7 +169,7 @@ def emit_recipe_predicates(isa, fmt):

# Generate the predicate function.
with fmt.indented(
'fn {}({}: ::settings::PredicateView, '
'fn {}({}: crate::settings::PredicateView, '
'{}: &ir::InstructionData) -> bool {{'
.format(
name,
Expand Down Expand Up @@ -657,7 +658,8 @@ def emit_level2_hashtables(level2_hashtables, offt, level2_doc, fmt):
if entry:
fmt.line(
'Level2Entry ' +
'{{ opcode: Some(ir::Opcode::{}), offset: {:#08x} }},'
'{{ opcode: Some(crate::ir::Opcode::{}), '
'offset: {:#08x} }},'
.format(entry.inst.camel_name, entry.offset))
else:
fmt.line(
Expand All @@ -682,15 +684,15 @@ def hash_func(level2):
# Empty hash table entry. Include the default legalization action.
if not level2:
fmt.format(
'Level1Entry {{ ty: ir::types::INVALID, log2len: !0, '
'offset: 0, legalize: {} }},',
'Level1Entry {{ ty: crate::ir::types::INVALID, '
'log2len: !0, offset: 0, legalize: {} }},',
level1.legalize_code)
continue

if level2.ty is not None:
tyname = level2.ty.rust_name()
else:
tyname = 'ir::types::INVALID'
tyname = 'crate::ir::types::INVALID'

lcode = cpumode.isa.legalize_code(level2.legalize)

Expand Down
2 changes: 1 addition & 1 deletion lib/codegen/meta-python/gen_instr.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ def gen_inst_builder(inst, fmt):
# The controlling type variable will be inferred from the input values if
# possible. Otherwise, it is the first method argument.
if inst.is_polymorphic and not inst.use_typevar_operand:
args.append('{}: ir::Type'.format(inst.ctrl_typevar.name))
args.append('{}: crate::ir::Type'.format(inst.ctrl_typevar.name))

tmpl_types = list() # type: List[str]
into_args = list() # type: List[str]
Expand Down
28 changes: 15 additions & 13 deletions lib/codegen/meta-python/gen_legalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,21 @@ def build_derived_expr(tv):

base_exp = build_derived_expr(tv.base)
if (tv.derived_func == TypeVar.LANEOF):
return "{}.map(|t: ir::Type| t.lane_type())".format(base_exp)
return "{}.map(|t: crate::ir::Type| t.lane_type())"\
.format(base_exp)
elif (tv.derived_func == TypeVar.ASBOOL):
return "{}.map(|t: ir::Type| t.as_bool())".format(base_exp)
return "{}.map(|t: crate::ir::Type| t.as_bool())".format(base_exp)
elif (tv.derived_func == TypeVar.HALFWIDTH):
return "{}.and_then(|t: ir::Type| t.half_width())".format(base_exp)
return "{}.and_then(|t: crate::ir::Type| t.half_width())"\
.format(base_exp)
elif (tv.derived_func == TypeVar.DOUBLEWIDTH):
return "{}.and_then(|t: ir::Type| t.double_width())"\
return "{}.and_then(|t: crate::ir::Type| t.double_width())"\
.format(base_exp)
elif (tv.derived_func == TypeVar.HALFVECTOR):
return "{}.and_then(|t: ir::Type| t.half_vector())"\
return "{}.and_then(|t: crate::ir::Type| t.half_vector())"\
.format(base_exp)
elif (tv.derived_func == TypeVar.DOUBLEVECTOR):
return "{}.and_then(|t: ir::Type| t.by(2))".format(base_exp)
return "{}.and_then(|t: crate::ir::Type| t.by(2))".format(base_exp)
else:
assert False, "Unknown derived function {}".format(tv.derived_func)

Expand Down Expand Up @@ -174,7 +176,7 @@ def unwrap_inst(iref, node, fmt):
arg_names = tuple(
arg.name if isinstance(arg, Var) else '_' for arg in expr.args)
with fmt.indented(
'let ({}, predicate) = if let ir::InstructionData::{} {{'
'let ({}, predicate) = if let crate::ir::InstructionData::{} {{'
.format(', '.join(map(str, arg_names)), iform.name), '};'):
# Fields are encoded directly.
for f in iform.imm_fields:
Expand Down Expand Up @@ -359,13 +361,13 @@ def gen_xform_group(xgrp, fmt, type_sets):
fmt.doc_comment("Legalize `inst`.")
fmt.line('#[allow(unused_variables,unused_assignments,non_snake_case)]')
with fmt.indented('pub fn {}('.format(xgrp.name)):
fmt.line('inst: ir::Inst,')
fmt.line('func: &mut ir::Function,')
fmt.line('cfg: &mut ::flowgraph::ControlFlowGraph,')
fmt.line('isa: &::isa::TargetIsa,')
fmt.line('inst: crate::ir::Inst,')
fmt.line('func: &mut crate::ir::Function,')
fmt.line('cfg: &mut crate::flowgraph::ControlFlowGraph,')
fmt.line('isa: &crate::isa::TargetIsa,')
with fmt.indented(') -> bool {', '}'):
fmt.line('use ir::InstBuilder;')
fmt.line('use cursor::{Cursor, FuncCursor};')
fmt.line('use crate::ir::InstBuilder;')
fmt.line('use crate::cursor::{Cursor, FuncCursor};')
fmt.line('let mut pos = FuncCursor::new(func).at_inst(inst);')
fmt.line('pos.use_srcloc(inst);')

Expand Down
6 changes: 3 additions & 3 deletions lib/codegen/meta-python/gen_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ def gen_getters(sgrp, fmt):
with fmt.indented('impl Flags {', '}'):
fmt.doc_comment('Get a view of the boolean predicates.')
with fmt.indented(
'pub fn predicate_view(&self) -> ::settings::PredicateView {',
'}'):
'pub fn predicate_view(&self) -> '
'crate::settings::PredicateView {', '}'):
fmt.format(
'::settings::PredicateView::new(&self.bytes[{}..])',
'crate::settings::PredicateView::new(&self.bytes[{}..])',
sgrp.boolean_offset)
if sgrp.settings:
fmt.doc_comment('Dynamic numbered predicate getter.')
Expand Down
8 changes: 4 additions & 4 deletions lib/codegen/meta-python/isa/x86/recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1934,7 +1934,7 @@ def valid_scale(iform):
PUT_OP(bits, rex2(in_reg0, in_reg1), sink);
modrm_rr(in_reg0, in_reg1, sink);
// `setCC` instruction, no REX.
use ir::condcodes::IntCC::*;
use crate::ir::condcodes::IntCC::*;
let setcc = match cond {
Equal => 0x94,
NotEqual => 0x95,
Expand Down Expand Up @@ -1962,7 +1962,7 @@ def valid_scale(iform):
let imm: i64 = imm.into();
sink.put1(imm as u8);
// `setCC` instruction, no REX.
use ir::condcodes::IntCC::*;
use crate::ir::condcodes::IntCC::*;
let setcc = match cond {
Equal => 0x94,
NotEqual => 0x95,
Expand Down Expand Up @@ -1990,7 +1990,7 @@ def valid_scale(iform):
let imm: i64 = imm.into();
sink.put4(imm as u32);
// `setCC` instruction, no REX.
use ir::condcodes::IntCC::*;
use crate::ir::condcodes::IntCC::*;
let setcc = match cond {
Equal => 0x94,
NotEqual => 0x95,
Expand Down Expand Up @@ -2030,7 +2030,7 @@ def valid_scale(iform):
PUT_OP(bits, rex2(in_reg1, in_reg0), sink);
modrm_rr(in_reg1, in_reg0, sink);
// `setCC` instruction, no REX.
use ir::condcodes::FloatCC::*;
use crate::ir::condcodes::FloatCC::*;
let setcc = match cond {
Ordered => 0x9b, // EQ|LT|GT => setnp (P=0)
Unordered => 0x9a, // UN => setp (P=1)
Expand Down
4 changes: 2 additions & 2 deletions lib/codegen/meta-python/test_gen_legalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ def test_vselect_imm(self):
self.v5 << vselect(self.v1, self.v3, self.v4),
)
x = XForm(r, r)
tv2_exp = 'Some({}).map(|t: ir::Type| t.as_bool())'\
tv2_exp = 'Some({}).map(|t: crate::ir::Type| t.as_bool())'\
.format(self.v2.get_typevar().name)
tv3_exp = 'Some({}).map(|t: ir::Type| t.as_bool())'\
tv3_exp = 'Some({}).map(|t: crate::ir::Type| t.as_bool())'\
.format(self.v3.get_typevar().name)

self.check_yo_check(
Expand Down
Loading

0 comments on commit effe6c0

Please sign in to comment.