Rustfmt
This commit is contained in:
parent
89702b9917
commit
95539518ec
24
src/base.rs
24
src/base.rs
@ -18,9 +18,8 @@ pub fn trans_mono_item<'a, 'tcx: 'a>(
|
|||||||
) {
|
) {
|
||||||
match mono_item {
|
match mono_item {
|
||||||
MonoItem::Fn(inst) => {
|
MonoItem::Fn(inst) => {
|
||||||
let _inst_guard = PrintOnPanic(|| {
|
let _inst_guard =
|
||||||
format!("{:?} {}", inst, tcx.symbol_name(inst).as_str())
|
PrintOnPanic(|| format!("{:?} {}", inst, tcx.symbol_name(inst).as_str()));
|
||||||
});
|
|
||||||
let _mir_guard = PrintOnPanic(|| {
|
let _mir_guard = PrintOnPanic(|| {
|
||||||
match inst.def {
|
match inst.def {
|
||||||
InstanceDef::Item(_)
|
InstanceDef::Item(_)
|
||||||
@ -377,8 +376,9 @@ fn trans_stmt<'a, 'tcx: 'a>(
|
|||||||
if *variant_index != dataful_variant {
|
if *variant_index != dataful_variant {
|
||||||
let niche = place.place_field(fx, mir::Field::new(0));
|
let niche = place.place_field(fx, mir::Field::new(0));
|
||||||
//let niche_llty = niche.layout.immediate_llvm_type(bx.cx);
|
//let niche_llty = niche.layout.immediate_llvm_type(bx.cx);
|
||||||
let niche_value = ((variant_index.as_u32() - niche_variants.start().as_u32()) as u128)
|
let niche_value =
|
||||||
.wrapping_add(niche_start);
|
((variant_index.as_u32() - niche_variants.start().as_u32()) as u128)
|
||||||
|
.wrapping_add(niche_start);
|
||||||
// FIXME(eddyb) Check the actual primitive type here.
|
// FIXME(eddyb) Check the actual primitive type here.
|
||||||
let niche_llval = if niche_value == 0 {
|
let niche_llval = if niche_value == 0 {
|
||||||
CValue::const_val(fx, niche.layout().ty, 0)
|
CValue::const_val(fx, niche.layout().ty, 0)
|
||||||
@ -606,7 +606,10 @@ fn trans_stmt<'a, 'tcx: 'a>(
|
|||||||
let usize_type = fx.clif_type(fx.tcx.types.usize).unwrap();
|
let usize_type = fx.clif_type(fx.tcx.types.usize).unwrap();
|
||||||
let layout = fx.layout_of(content_ty);
|
let layout = fx.layout_of(content_ty);
|
||||||
let llsize = fx.bcx.ins().iconst(usize_type, layout.size.bytes() as i64);
|
let llsize = fx.bcx.ins().iconst(usize_type, layout.size.bytes() as i64);
|
||||||
let llalign = fx.bcx.ins().iconst(usize_type, layout.align.abi.bytes() as i64);
|
let llalign = fx
|
||||||
|
.bcx
|
||||||
|
.ins()
|
||||||
|
.iconst(usize_type, layout.align.abi.bytes() as i64);
|
||||||
let box_layout = fx.layout_of(fx.tcx.mk_box(content_ty));
|
let box_layout = fx.layout_of(fx.tcx.mk_box(content_ty));
|
||||||
|
|
||||||
// Allocate space:
|
// Allocate space:
|
||||||
@ -688,9 +691,12 @@ pub fn trans_get_discriminant<'a, 'tcx: 'a>(
|
|||||||
}
|
}
|
||||||
match layout.variants {
|
match layout.variants {
|
||||||
layout::Variants::Single { index } => {
|
layout::Variants::Single { index } => {
|
||||||
let discr_val = layout.ty.ty_adt_def().map_or(index.as_u32() as u128, |def| {
|
let discr_val = layout
|
||||||
def.discriminant_for_variant(fx.tcx, index).val
|
.ty
|
||||||
});
|
.ty_adt_def()
|
||||||
|
.map_or(index.as_u32() as u128, |def| {
|
||||||
|
def.discriminant_for_variant(fx.tcx, index).val
|
||||||
|
});
|
||||||
return CValue::const_val(fx, dest_layout.ty, discr_val as u64 as i64);
|
return CValue::const_val(fx, dest_layout.ty, discr_val as u64 as i64);
|
||||||
}
|
}
|
||||||
layout::Variants::Tagged { .. } | layout::Variants::NicheFilling { .. } => {}
|
layout::Variants::Tagged { .. } | layout::Variants::NicheFilling { .. } => {}
|
||||||
|
@ -389,15 +389,18 @@ impl<'a, 'tcx: 'a> CPlace<'tcx> {
|
|||||||
// &'a T -> &'b T is allowed
|
// &'a T -> &'b T is allowed
|
||||||
}
|
}
|
||||||
(ty::FnPtr(_), ty::FnPtr(_)) => {
|
(ty::FnPtr(_), ty::FnPtr(_)) => {
|
||||||
let from_sig = fx.tcx.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &from_ty.fn_sig(fx.tcx));
|
let from_sig = fx.tcx.normalize_erasing_late_bound_regions(
|
||||||
let to_sig = fx.tcx.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &to_ty.fn_sig(fx.tcx));
|
ParamEnv::reveal_all(),
|
||||||
|
&from_ty.fn_sig(fx.tcx),
|
||||||
|
);
|
||||||
|
let to_sig = fx.tcx.normalize_erasing_late_bound_regions(
|
||||||
|
ParamEnv::reveal_all(),
|
||||||
|
&to_ty.fn_sig(fx.tcx),
|
||||||
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
from_sig,
|
from_sig, to_sig,
|
||||||
to_sig,
|
|
||||||
"Can't write fn ptr with incompatible sig {:?} to place with sig {:?}\n\n{:#?}",
|
"Can't write fn ptr with incompatible sig {:?} to place with sig {:?}\n\n{:#?}",
|
||||||
from_sig,
|
from_sig, to_sig, fx,
|
||||||
to_sig,
|
|
||||||
fx,
|
|
||||||
);
|
);
|
||||||
// fn(&T) -> for<'l> fn(&'l T) is allowed
|
// fn(&T) -> for<'l> fn(&'l T) is allowed
|
||||||
}
|
}
|
||||||
@ -577,7 +580,11 @@ impl<'a, 'tcx: 'a> CPlace<'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn downcast_variant(self, fx: &FunctionCx<'a, 'tcx, impl Backend>, variant: VariantIdx) -> Self {
|
pub fn downcast_variant(
|
||||||
|
self,
|
||||||
|
fx: &FunctionCx<'a, 'tcx, impl Backend>,
|
||||||
|
variant: VariantIdx,
|
||||||
|
) -> Self {
|
||||||
let layout = self.layout().for_variant(fx, variant);
|
let layout = self.layout().for_variant(fx, variant);
|
||||||
self.unchecked_cast_to(layout)
|
self.unchecked_cast_to(layout)
|
||||||
}
|
}
|
||||||
|
@ -133,13 +133,23 @@ fn trans_const_place<'a, 'tcx: 'a>(
|
|||||||
ty::ParamEnv::reveal_all(),
|
ty::ParamEnv::reveal_all(),
|
||||||
TransPlaceInterpreter,
|
TransPlaceInterpreter,
|
||||||
);
|
);
|
||||||
ecx.push_stack_frame(fx.instance, DUMMY_SP, fx.mir, None, StackPopCleanup::None { cleanup: false }).unwrap();
|
ecx.push_stack_frame(
|
||||||
let op = ecx.eval_operand(&Operand::Constant(Box::new(Constant {
|
fx.instance,
|
||||||
span: DUMMY_SP,
|
DUMMY_SP,
|
||||||
ty: const_.ty,
|
fx.mir,
|
||||||
user_ty: None,
|
None,
|
||||||
literal: const_,
|
StackPopCleanup::None { cleanup: false },
|
||||||
})), None)?;
|
)
|
||||||
|
.unwrap();
|
||||||
|
let op = ecx.eval_operand(
|
||||||
|
&Operand::Constant(Box::new(Constant {
|
||||||
|
span: DUMMY_SP,
|
||||||
|
ty: const_.ty,
|
||||||
|
user_ty: None,
|
||||||
|
literal: const_,
|
||||||
|
})),
|
||||||
|
None,
|
||||||
|
)?;
|
||||||
let ptr = ecx.allocate(op.layout, MemoryKind::Stack)?;
|
let ptr = ecx.allocate(op.layout, MemoryKind::Stack)?;
|
||||||
ecx.copy_op(op, ptr.into())?;
|
ecx.copy_op(op, ptr.into())?;
|
||||||
let alloc = ecx.memory().get(ptr.to_ptr()?.alloc_id)?;
|
let alloc = ecx.memory().get(ptr.to_ptr()?.alloc_id)?;
|
||||||
|
30
src/lib.rs
30
src/lib.rs
@ -1,22 +1,17 @@
|
|||||||
#![feature(
|
#![feature(rustc_private, macro_at_most_once_rep, never_type, decl_macro)]
|
||||||
rustc_private,
|
|
||||||
macro_at_most_once_rep,
|
|
||||||
never_type,
|
|
||||||
decl_macro,
|
|
||||||
)]
|
|
||||||
#![allow(intra_doc_link_resolution_failure)]
|
#![allow(intra_doc_link_resolution_failure)]
|
||||||
|
|
||||||
extern crate syntax;
|
extern crate log;
|
||||||
extern crate rustc;
|
extern crate rustc;
|
||||||
extern crate rustc_allocator;
|
extern crate rustc_allocator;
|
||||||
extern crate rustc_codegen_ssa;
|
extern crate rustc_codegen_ssa;
|
||||||
extern crate rustc_codegen_utils;
|
extern crate rustc_codegen_utils;
|
||||||
|
extern crate rustc_data_structures;
|
||||||
|
extern crate rustc_fs_util;
|
||||||
extern crate rustc_incremental;
|
extern crate rustc_incremental;
|
||||||
extern crate rustc_mir;
|
extern crate rustc_mir;
|
||||||
extern crate rustc_target;
|
extern crate rustc_target;
|
||||||
extern crate rustc_data_structures;
|
extern crate syntax;
|
||||||
extern crate rustc_fs_util;
|
|
||||||
extern crate log;
|
|
||||||
|
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
@ -29,10 +24,10 @@ use rustc::session::{
|
|||||||
CompileIncomplete,
|
CompileIncomplete,
|
||||||
};
|
};
|
||||||
use rustc::ty::query::Providers;
|
use rustc::ty::query::Providers;
|
||||||
|
use rustc_codegen_ssa::back::linker::LinkerInfo;
|
||||||
|
use rustc_codegen_ssa::CrateInfo;
|
||||||
use rustc_codegen_utils::codegen_backend::CodegenBackend;
|
use rustc_codegen_utils::codegen_backend::CodegenBackend;
|
||||||
use rustc_codegen_utils::link::out_filename;
|
use rustc_codegen_utils::link::out_filename;
|
||||||
use rustc_codegen_ssa::CrateInfo;
|
|
||||||
use rustc_codegen_ssa::back::linker::LinkerInfo;
|
|
||||||
|
|
||||||
use cranelift::codegen::settings;
|
use cranelift::codegen::settings;
|
||||||
use cranelift_faerie::*;
|
use cranelift_faerie::*;
|
||||||
@ -83,8 +78,8 @@ mod prelude {
|
|||||||
};
|
};
|
||||||
pub use rustc_mir::monomorphize::{collector, MonoItem};
|
pub use rustc_mir::monomorphize::{collector, MonoItem};
|
||||||
|
|
||||||
pub use rustc_codegen_ssa::{CodegenResults, CompiledModule, ModuleKind};
|
|
||||||
pub use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
|
pub use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
|
||||||
|
pub use rustc_codegen_ssa::{CodegenResults, CompiledModule, ModuleKind};
|
||||||
|
|
||||||
pub use cranelift::codegen::ir::{
|
pub use cranelift::codegen::ir::{
|
||||||
condcodes::IntCC, function::Function, ExternalName, FuncRef, Inst, StackSlot,
|
condcodes::IntCC, function::Function, ExternalName, FuncRef, Inst, StackSlot,
|
||||||
@ -183,13 +178,14 @@ impl CodegenBackend for CraneliftCodegenBackend {
|
|||||||
match tcx.sess.opts.optimize {
|
match tcx.sess.opts.optimize {
|
||||||
OptLevel::No => {
|
OptLevel::No => {
|
||||||
flags_builder.set("opt_level", "fastest").unwrap();
|
flags_builder.set("opt_level", "fastest").unwrap();
|
||||||
},
|
}
|
||||||
OptLevel::Less | OptLevel::Default => {},
|
OptLevel::Less | OptLevel::Default => {}
|
||||||
OptLevel::Aggressive => {
|
OptLevel::Aggressive => {
|
||||||
flags_builder.set("opt_level", "best").unwrap();
|
flags_builder.set("opt_level", "best").unwrap();
|
||||||
},
|
}
|
||||||
OptLevel::Size | OptLevel::SizeMin => {
|
OptLevel::Size | OptLevel::SizeMin => {
|
||||||
tcx.sess.warn("Optimizing for size is not supported. Just ignoring the request");
|
tcx.sess
|
||||||
|
.warn("Optimizing for size is not supported. Just ignoring the request");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
16
src/link.rs
16
src/link.rs
@ -9,8 +9,8 @@ use rustc::session::config::{self, CrateType, DebugInfo, RUST_CGU_EXT};
|
|||||||
use rustc::session::search_paths::PathKind;
|
use rustc::session::search_paths::PathKind;
|
||||||
use rustc::session::Session;
|
use rustc::session::Session;
|
||||||
use rustc_codegen_ssa::back::command::Command;
|
use rustc_codegen_ssa::back::command::Command;
|
||||||
use rustc_codegen_ssa::back::linker::*;
|
|
||||||
use rustc_codegen_ssa::back::link::*;
|
use rustc_codegen_ssa::back::link::*;
|
||||||
|
use rustc_codegen_ssa::back::linker::*;
|
||||||
use rustc_fs_util::fix_windows_verbatim_for_gcc;
|
use rustc_fs_util::fix_windows_verbatim_for_gcc;
|
||||||
use rustc_target::spec::{LinkerFlavor, PanicStrategy, RelroLevel};
|
use rustc_target::spec::{LinkerFlavor, PanicStrategy, RelroLevel};
|
||||||
|
|
||||||
@ -27,11 +27,15 @@ pub(crate) fn link_rlib(sess: &Session, res: &CodegenResults, output_name: PathB
|
|||||||
if let Some(ref object_path) = module.object {
|
if let Some(ref object_path) = module.object {
|
||||||
let object = File::open(object_path).expect("Someone deleted our object file");
|
let object = File::open(object_path).expect("Someone deleted our object file");
|
||||||
let object_len = object.metadata().unwrap().len();
|
let object_len = object.metadata().unwrap().len();
|
||||||
builder.append(
|
builder
|
||||||
&ar::Header::new((module.name.to_string() + RUST_CGU_EXT).into_bytes(), object_len),
|
.append(
|
||||||
object,
|
&ar::Header::new(
|
||||||
)
|
(module.name.to_string() + RUST_CGU_EXT).into_bytes(),
|
||||||
.unwrap();
|
object_len,
|
||||||
|
),
|
||||||
|
object,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use cranelift::prelude::*;
|
use cranelift::prelude::*;
|
||||||
|
|
||||||
use cranelift::codegen::ir::TrapCode;
|
use cranelift::codegen::ir::TrapCode;
|
||||||
|
|
||||||
/// Trap code: user0
|
/// Trap code: user0
|
||||||
|
@ -21,16 +21,20 @@ pub macro unimpl($($tt:tt)*) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn try_unimpl(tcx: TyCtxt, log: &mut Option<File>, f: impl FnOnce()) {
|
pub fn try_unimpl(tcx: TyCtxt, log: &mut Option<File>, f: impl FnOnce()) {
|
||||||
let res = ::std::panic::catch_unwind(::std::panic::AssertUnwindSafe(|| {
|
let res = ::std::panic::catch_unwind(::std::panic::AssertUnwindSafe(|| f()));
|
||||||
f()
|
|
||||||
}));
|
|
||||||
|
|
||||||
if let Err(err) = res {
|
if let Err(err) = res {
|
||||||
SPAN_STACK.with(|span_stack| {
|
SPAN_STACK.with(|span_stack| {
|
||||||
match err.downcast::<NonFatal>() {
|
match err.downcast::<NonFatal>() {
|
||||||
Ok(non_fatal) => {
|
Ok(non_fatal) => {
|
||||||
if cfg!(debug_assertions) {
|
if cfg!(debug_assertions) {
|
||||||
writeln!(log.as_mut().unwrap(), "{} at {:?}", &non_fatal.0, span_stack.borrow()).unwrap();
|
writeln!(
|
||||||
|
log.as_mut().unwrap(),
|
||||||
|
"{} at {:?}",
|
||||||
|
&non_fatal.0,
|
||||||
|
span_stack.borrow()
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
tcx.sess.err(&non_fatal.0)
|
tcx.sess.err(&non_fatal.0)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user