diff --git a/build_sysroot/alloc_system/lib.rs b/build_sysroot/alloc_system/lib.rs index 74b52a6497e..a942fa8d95e 100644 --- a/build_sysroot/alloc_system/lib.rs +++ b/build_sysroot/alloc_system/lib.rs @@ -23,7 +23,6 @@ feature(integer_atomics, stdsimd) )] #![cfg_attr(any(unix, target_os = "cloudabi", target_os = "redox"), feature(libc))] -#![rustc_alloc_kind = "lib"] // The minimum alignment guaranteed by the architecture. This value is used to // add fast paths for low alignment values. #[cfg(all(any(target_arch = "x86", diff --git a/example/example.rs b/example/example.rs index d7fbb932240..e8ddc4aaea1 100644 --- a/example/example.rs +++ b/example/example.rs @@ -137,10 +137,6 @@ unsafe fn transmute(c: char) -> u32 { intrinsics::transmute(c) } -unsafe fn call_uninit() -> u8 { - intrinsics::uninit() -} - unsafe fn deref_str_ptr(s: *const str) -> &'static str { &*s } diff --git a/example/mini_core.rs b/example/mini_core.rs index 56ab9578e78..d900776c55c 100644 --- a/example/mini_core.rs +++ b/example/mini_core.rs @@ -1,4 +1,4 @@ -#![feature(no_core, lang_items, intrinsics, unboxed_closures, type_ascription, extern_types)] +#![feature(no_core, lang_items, intrinsics, unboxed_closures, type_ascription, extern_types, untagged_unions)] #![no_core] #![allow(dead_code)] @@ -371,6 +371,11 @@ pub trait Drop { fn drop(&mut self); } +pub union MaybeUninit { + pub uninit: (), + pub value: T, +} + pub mod intrinsics { extern "rust-intrinsic" { pub fn abort() -> !; @@ -380,7 +385,6 @@ pub mod intrinsics { pub fn min_align_of_val(val: &T) -> usize; pub fn copy(src: *const T, dst: *mut T, count: usize); pub fn transmute(e: T) -> U; - pub fn uninit() -> T; pub fn init() -> T; pub fn ctlz_nonzero(x: T) -> T; pub fn needs_drop() -> bool; diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs index f9e820da76c..e51f257f6b4 100644 --- a/example/mini_core_hello_world.rs +++ b/example/mini_core_hello_world.rs @@ -181,15 +181,15 @@ fn main() { } unsafe fn uninitialized() -> T { - intrinsics::uninit::() + MaybeUninit { uninit: () }.value } + zeroed::<(u8, u8)>(); #[allow(unreachable_code)] { if false { zeroed::(); zeroed::(); - zeroed::<(u8, u8)>(); uninitialized::(); } } diff --git a/src/constant.rs b/src/constant.rs index c13cc72b88d..94007c83587 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -5,7 +5,7 @@ use rustc::mir::interpret::{ }; use rustc::ty::Const; use rustc_mir::interpret::{ - InterpretCx, ImmTy, Machine, Memory, MemoryKind, OpTy, PlaceTy, + InterpCx, ImmTy, Machine, Memory, MemoryKind, OpTy, PlaceTy, StackPopCleanup, }; @@ -141,10 +141,11 @@ fn trans_const_place<'a, 'tcx: 'a>( ) -> CPlace<'tcx> { // Adapted from https://github.com/rust-lang/rust/pull/53671/files#diff-e0b58bb6712edaa8595ad7237542c958L551 let result = || -> InterpResult<'tcx, &'tcx Allocation> { - let mut ecx = InterpretCx::new( + let mut ecx = InterpCx::new( fx.tcx.at(DUMMY_SP), ty::ParamEnv::reveal_all(), TransPlaceInterpreter, + (), ); ecx.push_stack_frame( fx.instance, @@ -242,7 +243,7 @@ fn define_all_allocs( module: &mut Module, cx: &mut ConstantCx, ) { - let memory = Memory::::new(tcx.at(DUMMY_SP)); + let memory = Memory::::new(tcx.at(DUMMY_SP), ()); while let Some(todo_item) = pop_set(&mut cx.todo) { let (data_id, alloc) = match todo_item { @@ -338,23 +339,25 @@ struct TransPlaceInterpreter; impl<'mir, 'tcx> Machine<'mir, 'tcx> for TransPlaceInterpreter { type MemoryKinds = !; + type ExtraFnVal = !; type PointerTag = (); type AllocExtra = (); type MemoryExtra = (); type FrameExtra = (); type MemoryMap = FxHashMap, Allocation<()>)>; + const STATIC_KIND: Option = None; - fn enforce_validity(_: &InterpretCx<'mir, 'tcx, Self>) -> bool { + fn enforce_validity(_: &InterpCx<'mir, 'tcx, Self>) -> bool { false } - fn before_terminator(_: &mut InterpretCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> { + fn before_terminator(_: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> { panic!(); } fn find_fn( - _: &mut InterpretCx<'mir, 'tcx, Self>, + _: &mut InterpCx<'mir, 'tcx, Self>, _: Instance<'tcx>, _: &[OpTy<'tcx>], _: Option>, @@ -364,7 +367,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for TransPlaceInterpreter { } fn call_intrinsic( - _: &mut InterpretCx<'mir, 'tcx, Self>, + _: &mut InterpCx<'mir, 'tcx, Self>, _: Instance<'tcx>, _: &[OpTy<'tcx>], _: PlaceTy<'tcx>, @@ -373,14 +376,14 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for TransPlaceInterpreter { } fn find_foreign_static( + _: TyCtxt<'tcx>, _: DefId, - _: ::rustc::ty::query::TyCtxtAt<'tcx>, ) -> InterpResult<'tcx, Cow<'tcx, Allocation>> { panic!(); } fn ptr_op( - _: &InterpretCx<'mir, 'tcx, Self>, + _: &InterpCx<'mir, 'tcx, Self>, _: mir::BinOp, _: ImmTy<'tcx>, _: ImmTy<'tcx>, @@ -388,28 +391,38 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for TransPlaceInterpreter { panic!(); } - fn box_alloc(_: &mut InterpretCx<'mir, 'tcx, Self>, _: PlaceTy<'tcx>) -> InterpResult<'tcx> { + fn box_alloc(_: &mut InterpCx<'mir, 'tcx, Self>, _: PlaceTy<'tcx>) -> InterpResult<'tcx> { panic!(); } fn tag_allocation<'b>( + _: &(), _: AllocId, alloc: Cow<'b, Allocation>, _: Option>, - _: &Memory<'mir, 'tcx, Self>, ) -> (Cow<'b, Allocation<(), ()>>, ()) { (alloc, ()) } - fn tag_static_base_pointer(_: AllocId, _: &Memory<'mir, 'tcx, Self>) -> Self::PointerTag { + fn tag_static_base_pointer(_: &(), _: AllocId) -> Self::PointerTag { () } - fn stack_push(_: &mut InterpretCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> { + fn call_extra_fn( + _: &mut InterpCx<'mir, 'tcx, Self>, + _: !, + _: &[OpTy<'tcx, ()>], + _: Option>, + _: Option, + ) -> InterpResult<'tcx> { + unreachable!(); + } + + fn stack_push(_: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> { Ok(()) } - fn stack_pop(_: &mut InterpretCx<'mir, 'tcx, Self>, _: ()) -> InterpResult<'tcx> { + fn stack_pop(_: &mut InterpCx<'mir, 'tcx, Self>, _: ()) -> InterpResult<'tcx> { Ok(()) } } diff --git a/src/intrinsics.rs b/src/intrinsics.rs index f8d5c0c0da4..fbdbf927e2d 100644 --- a/src/intrinsics.rs +++ b/src/intrinsics.rs @@ -389,16 +389,6 @@ pub fn codegen_intrinsic_call<'a, 'tcx: 'a>( let dst_ptr = dst.load_scalar(fx); fx.bcx.call_memset(fx.module.target_config(), dst_ptr, val, count); }; - uninit, () { - if ret.layout().abi == Abi::Uninhabited { - crate::trap::trap_panic(fx, "[panic] Called intrinsic::uninit for uninhabited type."); - return; - } - - let uninit_place = CPlace::new_stack_slot(fx, T); - let uninit_val = uninit_place.to_cvalue(fx); - ret.write_cvalue(fx, uninit_val); - }; ctlz | ctlz_nonzero, (v arg) { let res = CValue::by_val(fx.bcx.ins().clz(arg), fx.layout_of(T)); ret.write_cvalue(fx, res);