From b02ed1e1d495e25252dc49c5f0f5e1da1b24b78e Mon Sep 17 00:00:00 2001 From: Aaron Turon Date: Wed, 14 Dec 2016 12:27:30 -0800 Subject: Stabilize: - `std::rc::Rc::{strong_count, weak_count}` - `std::sync::Arc::{strong_count, weak_count}` Deprecate: - `std::rc::Rc::{would_unwrap, is_unique}` --- src/liballoc/arc.rs | 10 ++-------- src/liballoc/rc.rs | 13 +++++-------- 2 files changed, 7 insertions(+), 16 deletions(-) (limited to 'src/liballoc') diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index 3a7da18c8de..1cad8f7f407 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -392,8 +392,6 @@ impl Arc { /// # Examples /// /// ``` - /// #![feature(arc_counts)] - /// /// use std::sync::Arc; /// /// let five = Arc::new(5); @@ -404,8 +402,7 @@ impl Arc { /// assert_eq!(1, Arc::weak_count(&five)); /// ``` #[inline] - #[unstable(feature = "arc_counts", reason = "not clearly useful, and racy", - issue = "28356")] + #[stable(feature = "arc_counts", since = "1.15.0")] pub fn weak_count(this: &Self) -> usize { this.inner().weak.load(SeqCst) - 1 } @@ -421,8 +418,6 @@ impl Arc { /// # Examples /// /// ``` - /// #![feature(arc_counts)] - /// /// use std::sync::Arc; /// /// let five = Arc::new(5); @@ -433,8 +428,7 @@ impl Arc { /// assert_eq!(2, Arc::strong_count(&five)); /// ``` #[inline] - #[unstable(feature = "arc_counts", reason = "not clearly useful, and racy", - issue = "28356")] + #[stable(feature = "arc_counts", since = "1.15.0")] pub fn strong_count(this: &Self) -> usize { this.inner().strong.load(SeqCst) } diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index d1e0e333b8f..8d2b1a770b2 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -363,6 +363,7 @@ impl Rc { #[unstable(feature = "rc_would_unwrap", reason = "just added for niche usecase", issue = "28356")] + #[rustc_deprecated(since = "1.15.0", reason = "too niche; use `strong_count` instead")] pub fn would_unwrap(this: &Self) -> bool { Rc::strong_count(&this) == 1 } @@ -482,8 +483,6 @@ impl Rc { /// # Examples /// /// ``` - /// #![feature(rc_counts)] - /// /// use std::rc::Rc; /// /// let five = Rc::new(5); @@ -492,8 +491,7 @@ impl Rc { /// assert_eq!(1, Rc::weak_count(&five)); /// ``` #[inline] - #[unstable(feature = "rc_counts", reason = "not clearly useful", - issue = "28356")] + #[stable(feature = "rc_counts", since = "1.15.0")] pub fn weak_count(this: &Self) -> usize { this.weak() - 1 } @@ -503,8 +501,6 @@ impl Rc { /// # Examples /// /// ``` - /// #![feature(rc_counts)] - /// /// use std::rc::Rc; /// /// let five = Rc::new(5); @@ -513,8 +509,7 @@ impl Rc { /// assert_eq!(2, Rc::strong_count(&five)); /// ``` #[inline] - #[unstable(feature = "rc_counts", reason = "not clearly useful", - issue = "28356")] + #[stable(feature = "rc_counts", since = "1.15.0")] pub fn strong_count(this: &Self) -> usize { this.strong() } @@ -538,6 +533,8 @@ impl Rc { #[inline] #[unstable(feature = "rc_counts", reason = "uniqueness has unclear meaning", issue = "28356")] + #[rustc_deprecated(since = "1.15.0", + reason = "too niche; use `strong_count` and `weak_count` instead")] pub fn is_unique(this: &Self) -> bool { Rc::weak_count(this) == 0 && Rc::strong_count(this) == 1 } -- cgit 1.4.1-3-g733a5 From 9a5cef4de51c1c90fb2d05b0c7e6feb9cf0224d6 Mon Sep 17 00:00:00 2001 From: Aaron Turon Date: Wed, 14 Dec 2016 13:02:00 -0800 Subject: Address fallout --- src/liballoc/rc.rs | 33 ++--------------------------- src/libcollectionstest/lib.rs | 1 - src/libcore/cell.rs | 2 ++ src/libcore/fmt/mod.rs | 10 ++++----- src/libcore/iter/iterator.rs | 2 -- src/libcoretest/cell.rs | 37 ++++++++++++++++++++------------- src/libcoretest/lib.rs | 4 ---- src/librustc/dep_graph/shadow.rs | 16 ++++++-------- src/librustc/lib.rs | 1 - src/librustc_resolve/lib.rs | 1 - src/librustc_resolve/resolve_imports.rs | 8 +++---- src/librustc_trans/lib.rs | 1 - src/libstd/io/stdio.rs | 6 +++--- src/libstd/sys/redox/ext/process.rs | 2 +- src/libstd_unicode/char.rs | 2 -- src/libstd_unicode/lib.rs | 1 - 16 files changed, 44 insertions(+), 83 deletions(-) (limited to 'src/liballoc') diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 8d2b1a770b2..86f8c746646 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -320,7 +320,7 @@ impl Rc { #[inline] #[stable(feature = "rc_unique", since = "1.4.0")] pub fn try_unwrap(this: Self) -> Result { - if Rc::would_unwrap(&this) { + if Rc::strong_count(&this) == 1 { unsafe { let val = ptr::read(&*this); // copy the contained object @@ -343,23 +343,6 @@ impl Rc { /// /// [try_unwrap]: struct.Rc.html#method.try_unwrap /// [`Ok`]: ../../std/result/enum.Result.html#variant.Ok - /// - /// # Examples - /// - /// ``` - /// #![feature(rc_would_unwrap)] - /// - /// use std::rc::Rc; - /// - /// let x = Rc::new(3); - /// assert!(Rc::would_unwrap(&x)); - /// assert_eq!(Rc::try_unwrap(x), Ok(3)); - /// - /// let x = Rc::new(4); - /// let _y = x.clone(); - /// assert!(!Rc::would_unwrap(&x)); - /// assert_eq!(*Rc::try_unwrap(x).unwrap_err(), 4); - /// ``` #[unstable(feature = "rc_would_unwrap", reason = "just added for niche usecase", issue = "28356")] @@ -518,20 +501,8 @@ impl Rc { /// this inner value. /// /// [weak]: struct.Weak.html - /// - /// # Examples - /// - /// ``` - /// #![feature(rc_counts)] - /// - /// use std::rc::Rc; - /// - /// let five = Rc::new(5); - /// - /// assert!(Rc::is_unique(&five)); - /// ``` #[inline] - #[unstable(feature = "rc_counts", reason = "uniqueness has unclear meaning", + #[unstable(feature = "is_unique", reason = "uniqueness has unclear meaning", issue = "28356")] #[rustc_deprecated(since = "1.15.0", reason = "too niche; use `strong_count` and `weak_count` instead")] diff --git a/src/libcollectionstest/lib.rs b/src/libcollectionstest/lib.rs index 0fe0a1bad64..d4fb5ea03ad 100644 --- a/src/libcollectionstest/lib.rs +++ b/src/libcollectionstest/lib.rs @@ -29,7 +29,6 @@ #![feature(test)] #![feature(unboxed_closures)] #![feature(unicode)] -#![feature(vec_into_iter_as_slice)] extern crate collections; extern crate test; diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index efba8798309..c3f862e7c54 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -394,6 +394,7 @@ pub struct RefCell { #[derive(Copy, Clone, PartialEq, Eq, Debug)] #[unstable(feature = "borrow_state", issue = "27733")] #[rustc_deprecated(since = "1.15.0", reason = "use `try_borrow` instead")] +#[allow(deprecated)] pub enum BorrowState { /// The cell is currently being read, there is at least one active `borrow`. Reading, @@ -513,6 +514,7 @@ impl RefCell { /// ``` #[unstable(feature = "borrow_state", issue = "27733")] #[rustc_deprecated(since = "1.15.0", reason = "use `try_borrow` instead")] + #[allow(deprecated)] #[inline] pub fn borrow_state(&self) -> BorrowState { match self.borrow.get() { diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 9167264ba9d..2ba7d6e8bd1 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -12,7 +12,7 @@ #![stable(feature = "rust1", since = "1.0.0")] -use cell::{UnsafeCell, Cell, RefCell, Ref, RefMut, BorrowState}; +use cell::{UnsafeCell, Cell, RefCell, Ref, RefMut}; use marker::PhantomData; use mem; use num::flt2dec; @@ -1634,13 +1634,13 @@ impl Debug for Cell { #[stable(feature = "rust1", since = "1.0.0")] impl Debug for RefCell { fn fmt(&self, f: &mut Formatter) -> Result { - match self.borrow_state() { - BorrowState::Unused | BorrowState::Reading => { + match self.try_borrow() { + Ok(borrow) => { f.debug_struct("RefCell") - .field("value", &self.borrow()) + .field("value", &borrow) .finish() } - BorrowState::Writing => { + Err(_) => { f.debug_struct("RefCell") .field("value", &"") .finish() diff --git a/src/libcore/iter/iterator.rs b/src/libcore/iter/iterator.rs index cdc804b9ad6..ec590d2bd06 100644 --- a/src/libcore/iter/iterator.rs +++ b/src/libcore/iter/iterator.rs @@ -1696,7 +1696,6 @@ pub trait Iterator { /// # Examples /// /// ``` - /// #![feature(iter_max_by)] /// let a = [-3_i32, 0, 1, 5, -10]; /// assert_eq!(*a.iter().max_by(|x, y| x.cmp(y)).unwrap(), 5); /// ``` @@ -1746,7 +1745,6 @@ pub trait Iterator { /// # Examples /// /// ``` - /// #![feature(iter_min_by)] /// let a = [-3_i32, 0, 1, 5, -10]; /// assert_eq!(*a.iter().min_by(|x, y| x.cmp(y)).unwrap(), -10); /// ``` diff --git a/src/libcoretest/cell.rs b/src/libcoretest/cell.rs index a7c230ba979..724a312ea79 100644 --- a/src/libcoretest/cell.rs +++ b/src/libcoretest/cell.rs @@ -59,22 +59,22 @@ fn double_imm_borrow() { fn no_mut_then_imm_borrow() { let x = RefCell::new(0); let _b1 = x.borrow_mut(); - assert_eq!(x.borrow_state(), BorrowState::Writing); + assert!(x.try_borrow().is_err()); } #[test] fn no_imm_then_borrow_mut() { let x = RefCell::new(0); let _b1 = x.borrow(); - assert_eq!(x.borrow_state(), BorrowState::Reading); + assert!(x.try_borrow_mut().is_err()); } #[test] fn no_double_borrow_mut() { let x = RefCell::new(0); - assert_eq!(x.borrow_state(), BorrowState::Unused); + assert!(x.try_borrow().is_ok()); let _b1 = x.borrow_mut(); - assert_eq!(x.borrow_state(), BorrowState::Writing); + assert!(x.try_borrow().is_err()); } #[test] @@ -102,7 +102,8 @@ fn double_borrow_single_release_no_borrow_mut() { { let _b2 = x.borrow(); } - assert_eq!(x.borrow_state(), BorrowState::Reading); + assert!(x.try_borrow().is_ok()); + assert!(x.try_borrow_mut().is_err()); } #[test] @@ -119,14 +120,18 @@ fn ref_clone_updates_flag() { let x = RefCell::new(0); { let b1 = x.borrow(); - assert_eq!(x.borrow_state(), BorrowState::Reading); + assert!(x.try_borrow().is_ok()); + assert!(x.try_borrow_mut().is_err()); { let _b2 = Ref::clone(&b1); - assert_eq!(x.borrow_state(), BorrowState::Reading); + assert!(x.try_borrow().is_ok()); + assert!(x.try_borrow_mut().is_err()); } - assert_eq!(x.borrow_state(), BorrowState::Reading); + assert!(x.try_borrow().is_ok()); + assert!(x.try_borrow_mut().is_err()); } - assert_eq!(x.borrow_state(), BorrowState::Unused); + assert!(x.try_borrow().is_ok()); + assert!(x.try_borrow_mut().is_ok()); } #[test] @@ -134,15 +139,19 @@ fn ref_map_does_not_update_flag() { let x = RefCell::new(Some(5)); { let b1: Ref> = x.borrow(); - assert_eq!(x.borrow_state(), BorrowState::Reading); + assert!(x.try_borrow().is_ok()); + assert!(x.try_borrow_mut().is_err()); { let b2: Ref = Ref::map(b1, |o| o.as_ref().unwrap()); assert_eq!(*b2, 5); - assert_eq!(x.borrow_state(), BorrowState::Reading); + assert!(x.try_borrow().is_ok()); + assert!(x.try_borrow_mut().is_err()); } - assert_eq!(x.borrow_state(), BorrowState::Unused); + assert!(x.try_borrow().is_ok()); + assert!(x.try_borrow_mut().is_ok()); } - assert_eq!(x.borrow_state(), BorrowState::Unused); + assert!(x.try_borrow().is_ok()); + assert!(x.try_borrow_mut().is_ok()); } #[test] @@ -247,5 +256,3 @@ fn refcell_ref_coercion() { assert_eq!(&*coerced, comp); } } - - diff --git a/src/libcoretest/lib.rs b/src/libcoretest/lib.rs index 05d98d4a212..d12616a97a6 100644 --- a/src/libcoretest/lib.rs +++ b/src/libcoretest/lib.rs @@ -10,9 +10,7 @@ #![deny(warnings)] -#![feature(borrow_state)] #![feature(box_syntax)] -#![feature(cell_extras)] #![feature(char_escape_debug)] #![feature(const_fn)] #![feature(core_private_bignum)] @@ -32,8 +30,6 @@ #![feature(try_from)] #![feature(unicode)] #![feature(unique)] -#![feature(iter_max_by)] -#![feature(iter_min_by)] #![feature(ordering_chaining)] #![feature(result_unwrap_or_default)] #![feature(ptr_unaligned)] diff --git a/src/librustc/dep_graph/shadow.rs b/src/librustc/dep_graph/shadow.rs index 06def4bf19a..5d4190a8ae1 100644 --- a/src/librustc/dep_graph/shadow.rs +++ b/src/librustc/dep_graph/shadow.rs @@ -27,7 +27,7 @@ //! created. See `./README.md` for details. use hir::def_id::DefId; -use std::cell::{BorrowState, RefCell}; +use std::cell::RefCell; use std::env; use super::DepNode; @@ -71,15 +71,11 @@ impl ShadowGraph { pub fn enqueue(&self, message: &DepMessage) { if ENABLED { - match self.stack.borrow_state() { - BorrowState::Unused => {} - _ => { - // When we apply edge filters, that invokes the - // Debug trait on DefIds, which in turn reads from - // various bits of state and creates reads! Ignore - // those recursive reads. - return; - } + if self.stack.try_borrow().is_err() { + // When we apply edge filters, that invokes the Debug trait on + // DefIds, which in turn reads from various bits of state and + // creates reads! Ignore those recursive reads. + return; } let mut stack = self.stack.borrow_mut(); diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 7c26b710a53..17cc34fcd83 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -24,7 +24,6 @@ #![cfg_attr(not(stage0), deny(warnings))] #![feature(associated_consts)] -#![feature(borrow_state)] #![feature(box_patterns)] #![feature(box_syntax)] #![feature(collections)] diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index ea5aa5be013..509ee704e2e 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -18,7 +18,6 @@ #![cfg_attr(not(stage0), deny(warnings))] #![feature(associated_consts)] -#![feature(borrow_state)] #![feature(rustc_diagnostic_macros)] #![feature(rustc_private)] #![feature(staged_api)] diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index b634d57a842..890891fd090 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -144,11 +144,9 @@ impl<'a> Resolver<'a> { -> Result<&'a NameBinding<'a>, Determinacy> { self.populate_module_if_necessary(module); - let resolution = self.resolution(module, name, ns); - let resolution = match resolution.borrow_state() { - ::std::cell::BorrowState::Unused => resolution.borrow_mut(), - _ => return Err(Determined), // This happens when there is a cycle of imports - }; + let resolution = self.resolution(module, name, ns) + .try_borrow_mut() + .map_err(|_| Determined)?; // This happens when there is a cycle of imports if let Some(span) = record_used { if let Some(binding) = resolution.binding { diff --git a/src/librustc_trans/lib.rs b/src/librustc_trans/lib.rs index e2da635b159..d842827b6fe 100644 --- a/src/librustc_trans/lib.rs +++ b/src/librustc_trans/lib.rs @@ -26,7 +26,6 @@ #![feature(associated_consts)] #![feature(box_patterns)] #![feature(box_syntax)] -#![feature(cell_extras)] #![feature(const_fn)] #![feature(custom_attribute)] #![allow(unused_attributes)] diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index 6419a9ff683..1a65bee13b8 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -10,7 +10,7 @@ use io::prelude::*; -use cell::{RefCell, BorrowState}; +use cell::RefCell; use fmt; use io::lazy::Lazy; use io::{self, BufReader, LineWriter}; @@ -638,8 +638,8 @@ pub fn _print(args: fmt::Arguments) { LocalKeyState::Destroyed => stdout().write_fmt(args), LocalKeyState::Valid => { LOCAL_STDOUT.with(|s| { - if s.borrow_state() == BorrowState::Unused { - if let Some(w) = s.borrow_mut().as_mut() { + if let Ok(mut borrowed) = s.try_borrow_mut() { + if let Some(w) = borrowed.as_mut() { return w.write_fmt(args); } } diff --git a/src/libstd/sys/redox/ext/process.rs b/src/libstd/sys/redox/ext/process.rs index 1472242d3db..c59524974bf 100644 --- a/src/libstd/sys/redox/ext/process.rs +++ b/src/libstd/sys/redox/ext/process.rs @@ -56,7 +56,7 @@ pub trait CommandExt { /// When this closure is run, aspects such as the stdio file descriptors and /// working directory have successfully been changed, so output to these /// locations may not appear where intended. - #[unstable(feature = "process_exec", issue = "31398")] + #[stable(feature = "process_exec", since = "1.15.0")] fn before_exec(&mut self, f: F) -> &mut process::Command where F: FnMut() -> io::Result<()> + Send + Sync + 'static; diff --git a/src/libstd_unicode/char.rs b/src/libstd_unicode/char.rs index b6a502e8c1a..53dafadb5d5 100644 --- a/src/libstd_unicode/char.rs +++ b/src/libstd_unicode/char.rs @@ -460,7 +460,6 @@ impl char { /// A buffer that's too small: /// /// ``` - /// #![feature(unicode)] /// use std::thread; /// /// let result = thread::spawn(|| { @@ -501,7 +500,6 @@ impl char { /// A buffer that's too small: /// /// ``` - /// #![feature(unicode)] /// use std::thread; /// /// let result = thread::spawn(|| { diff --git a/src/libstd_unicode/lib.rs b/src/libstd_unicode/lib.rs index b086658ee0d..11724e74cda 100644 --- a/src/libstd_unicode/lib.rs +++ b/src/libstd_unicode/lib.rs @@ -39,7 +39,6 @@ #![feature(lang_items)] #![feature(staged_api)] #![feature(try_from)] -#![feature(unicode)] mod tables; mod u_str; -- cgit 1.4.1-3-g733a5 From dda6c8cf2f035d23ff3f67c5fc0e805bb18cd0a4 Mon Sep 17 00:00:00 2001 From: Mark-Simulacrum Date: Thu, 15 Dec 2016 18:00:19 -0700 Subject: Inline base::malloc_raw_dyn. Move comment about not unwinding into liballoc. --- src/liballoc/heap.rs | 1 + src/librustc/middle/lang_items.rs | 2 -- src/librustc_trans/base.rs | 29 +---------------------------- src/librustc_trans/mir/rvalue.rs | 14 +++++++++++++- 4 files changed, 15 insertions(+), 31 deletions(-) (limited to 'src/liballoc') diff --git a/src/liballoc/heap.rs b/src/liballoc/heap.rs index 12809171b74..a1e32636980 100644 --- a/src/liballoc/heap.rs +++ b/src/liballoc/heap.rs @@ -127,6 +127,7 @@ pub fn usable_size(size: usize, align: usize) -> usize { pub const EMPTY: *mut () = 0x1 as *mut (); /// The allocator for unique pointers. +// This function must not unwind. If it does, MIR trans will fail. #[cfg(not(test))] #[lang = "exchange_malloc"] #[inline] diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index 3bc39fad7f1..1efc211b8c3 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -327,8 +327,6 @@ language_item_table! { PanicBoundsCheckFnLangItem, "panic_bounds_check", panic_bounds_check_fn; PanicFmtLangItem, "panic_fmt", panic_fmt; - // ExchangeMallocFnLangItem cannot unwind, or MIR trans will break. See note - // on `malloc_raw_dyn` in librustc_trans/base.rs. ExchangeMallocFnLangItem, "exchange_malloc", exchange_malloc_fn; ExchangeFreeFnLangItem, "exchange_free", exchange_free_fn; BoxFreeFnLangItem, "box_free", box_free_fn; diff --git a/src/librustc_trans/base.rs b/src/librustc_trans/base.rs index 011552b3962..3f477a463ab 100644 --- a/src/librustc_trans/base.rs +++ b/src/librustc_trans/base.rs @@ -37,7 +37,7 @@ use back::symbol_export::{self, ExportedSymbols}; use llvm::{Linkage, ValueRef, Vector, get_param}; use llvm; use rustc::hir::def_id::{DefId, LOCAL_CRATE}; -use middle::lang_items::{LangItem, ExchangeMallocFnLangItem, StartFnLangItem}; +use middle::lang_items::StartFnLangItem; use rustc::ty::subst::Substs; use rustc::traits; use rustc::ty::{self, Ty, TyCtxt, TypeFoldable}; @@ -168,33 +168,6 @@ pub fn get_dataptr(bcx: &Builder, fat_ptr: ValueRef) -> ValueRef { bcx.struct_gep(fat_ptr, abi::FAT_PTR_ADDR) } -fn require_alloc_fn<'blk, 'tcx>( - bcx: &BlockAndBuilder<'blk, 'tcx>, info_ty: Ty<'tcx>, it: LangItem -) -> DefId { - match bcx.tcx().lang_items.require(it) { - Ok(id) => id, - Err(s) => { - bcx.sess().fatal(&format!("allocation of `{}` {}", info_ty, s)); - } - } -} - -// malloc_raw_dyn allocates a box to contain a given type, but with a potentially dynamic size. -// -// MIR requires that ExchangeMallocFnLangItem cannot unwind. -pub fn malloc_raw_dyn<'blk, 'tcx>(bcx: &BlockAndBuilder<'blk, 'tcx>, - llty_ptr: Type, - info_ty: Ty<'tcx>, - size: ValueRef, - align: ValueRef) - -> ValueRef { - // Allocate space: - let def_id = require_alloc_fn(bcx, info_ty, ExchangeMallocFnLangItem); - let r = Callee::def(bcx.ccx(), def_id, bcx.tcx().intern_substs(&[])).reify(bcx.ccx()); - bcx.pointercast(bcx.call(r, &[size, align], None), llty_ptr) -} - - pub fn bin_op_to_icmp_predicate(op: hir::BinOp_, signed: bool) -> llvm::IntPredicate { diff --git a/src/librustc_trans/mir/rvalue.rs b/src/librustc_trans/mir/rvalue.rs index 5aba7160c23..d15598e76af 100644 --- a/src/librustc_trans/mir/rvalue.rs +++ b/src/librustc_trans/mir/rvalue.rs @@ -13,6 +13,7 @@ use rustc::ty::{self, Ty}; use rustc::ty::cast::{CastTy, IntTy}; use rustc::ty::layout::Layout; use rustc::mir; +use middle::lang_items::ExchangeMallocFnLangItem; use asm; use base; @@ -449,7 +450,18 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> { let llalign = C_uint(bcx.ccx(), align); let llty_ptr = llty.ptr_to(); let box_ty = bcx.tcx().mk_box(content_ty); - let val = base::malloc_raw_dyn(&bcx, llty_ptr, box_ty, llsize, llalign); + + // Allocate space: + let def_id = match bcx.tcx().lang_items.require(ExchangeMallocFnLangItem) { + Ok(id) => id, + Err(s) => { + bcx.sess().fatal(&format!("allocation of `{}` {}", box_ty, s)); + } + }; + let r = Callee::def(bcx.ccx(), def_id, bcx.tcx().intern_substs(&[])) + .reify(bcx.ccx()); + let val = bcx.pointercast(bcx.call(r, &[llsize, llalign], None), llty_ptr); + let operand = OperandRef { val: OperandValue::Immediate(val), ty: box_ty, -- cgit 1.4.1-3-g733a5 From ca115dd083a1fe1d2b4892c5e50e49eb83ff1f3c Mon Sep 17 00:00:00 2001 From: Mark Simulacrum Date: Wed, 21 Dec 2016 14:29:34 -0700 Subject: Remove extra lang item, exchange_free; use box_free instead. Trans used to insert code equivalent to box_free in a wrapper around exchange_free, and that code is now removed from trans. --- src/liballoc/heap.rs | 1 + src/librustc/middle/lang_items.rs | 1 - src/librustc_trans/collector.rs | 28 +++++++---------- src/librustc_trans/glue.rs | 66 +++++++++++---------------------------- 4 files changed, 32 insertions(+), 64 deletions(-) (limited to 'src/liballoc') diff --git a/src/liballoc/heap.rs b/src/liballoc/heap.rs index a1e32636980..81ed4be7763 100644 --- a/src/liballoc/heap.rs +++ b/src/liballoc/heap.rs @@ -144,6 +144,7 @@ unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 { } #[cfg(not(test))] +#[cfg(stage0)] #[lang = "exchange_free"] #[inline] unsafe fn exchange_free(ptr: *mut u8, old_size: usize, align: usize) { diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index 1efc211b8c3..029a1d66add 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -328,7 +328,6 @@ language_item_table! { PanicFmtLangItem, "panic_fmt", panic_fmt; ExchangeMallocFnLangItem, "exchange_malloc", exchange_malloc_fn; - ExchangeFreeFnLangItem, "exchange_free", exchange_free_fn; BoxFreeFnLangItem, "box_free", box_free_fn; StrDupUniqFnLangItem, "strdup_uniq", strdup_uniq_fn; diff --git a/src/librustc_trans/collector.rs b/src/librustc_trans/collector.rs index d8c21274537..84222bfe56e 100644 --- a/src/librustc_trans/collector.rs +++ b/src/librustc_trans/collector.rs @@ -193,9 +193,9 @@ use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::hir::map as hir_map; use rustc::hir::def_id::DefId; -use rustc::middle::lang_items::{ExchangeFreeFnLangItem, ExchangeMallocFnLangItem}; +use rustc::middle::lang_items::{BoxFreeFnLangItem, ExchangeMallocFnLangItem}; use rustc::traits; -use rustc::ty::subst::{Substs, Subst}; +use rustc::ty::subst::{Kind, Substs, Subst}; use rustc::ty::{self, TypeFoldable, TyCtxt}; use rustc::ty::adjustment::CustomCoerceUnsized; use rustc::mir::{self, Location}; @@ -215,6 +215,8 @@ use util::nodemap::{FxHashSet, FxHashMap, DefIdMap}; use trans_item::{TransItem, DefPathBasedNames}; +use std::iter; + #[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)] pub enum TransItemCollectionMode { Eager, @@ -723,23 +725,17 @@ fn find_drop_glue_neighbors<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>, debug!("find_drop_glue_neighbors: {}", type_to_string(scx.tcx(), ty)); - // Make sure the exchange_free_fn() lang-item gets translated if - // there is a boxed value. - if let ty::TyBox(_) = ty.sty { - let exchange_free_fn_def_id = scx.tcx() - .lang_items - .require(ExchangeFreeFnLangItem) - .unwrap_or_else(|e| scx.sess().fatal(&e)); - - assert!(can_have_local_instance(scx.tcx(), exchange_free_fn_def_id)); - let fn_substs = scx.empty_substs_for_def_id(exchange_free_fn_def_id); - let exchange_free_fn_trans_item = + // Make sure the BoxFreeFn lang-item gets translated if there is a boxed value. + if let ty::TyBox(content_type) = ty.sty { + let def_id = scx.tcx().require_lang_item(BoxFreeFnLangItem); + assert!(can_have_local_instance(scx.tcx(), def_id)); + let box_free_fn_trans_item = create_fn_trans_item(scx, - exchange_free_fn_def_id, - fn_substs, + def_id, + scx.tcx().mk_substs(iter::once(Kind::from(content_type))), scx.tcx().intern_substs(&[])); - output.push(exchange_free_fn_trans_item); + output.push(box_free_fn_trans_item); } // If the type implements Drop, also add a translation item for the diff --git a/src/librustc_trans/glue.rs b/src/librustc_trans/glue.rs index 7549f80f94d..3989dae553f 100644 --- a/src/librustc_trans/glue.rs +++ b/src/librustc_trans/glue.rs @@ -13,13 +13,15 @@ // Code relating to drop glue. use std; +use std::iter; use llvm; use llvm::{ValueRef, get_param}; -use middle::lang_items::ExchangeFreeFnLangItem; +use middle::lang_items::BoxFreeFnLangItem; use rustc::ty::subst::{Substs}; use rustc::traits; use rustc::ty::{self, AdtKind, Ty, TypeFoldable}; +use rustc::ty::subst::Kind; use adt::{self, MaybeSizedValue}; use base::*; use callee::Callee; @@ -36,38 +38,22 @@ use cleanup::CleanupScope; use syntax_pos::DUMMY_SP; -pub fn trans_exchange_free_dyn<'a, 'tcx>( +pub fn trans_exchange_free_ty<'a, 'tcx>( bcx: &BlockAndBuilder<'a, 'tcx>, - v: ValueRef, - size: ValueRef, - align: ValueRef + ptr: MaybeSizedValue, + content_ty: Ty<'tcx> ) { - let def_id = langcall(bcx.tcx(), None, "", ExchangeFreeFnLangItem); - let args = [bcx.pointercast(v, Type::i8p(bcx.ccx)), size, align]; - let callee = Callee::def(bcx.ccx, def_id, bcx.tcx().intern_substs(&[])); + let def_id = langcall(bcx.tcx(), None, "", BoxFreeFnLangItem); + let substs = bcx.tcx().mk_substs(iter::once(Kind::from(content_ty))); + let callee = Callee::def(bcx.ccx, def_id, substs); - let ccx = bcx.ccx; - let fn_ty = callee.direct_fn_type(ccx, &[]); + let fn_ty = callee.direct_fn_type(bcx.ccx, &[]); - let llret = bcx.call(callee.reify(ccx), &args[..], None); + let llret = bcx.call(callee.reify(bcx.ccx), + &[ptr.value, ptr.meta][..1 + ptr.has_meta() as usize], None); fn_ty.apply_attrs_callsite(llret); } -pub fn trans_exchange_free_ty<'a, 'tcx>( - bcx: &BlockAndBuilder<'a, 'tcx>, ptr: ValueRef, content_ty: Ty<'tcx> -) { - assert!(bcx.ccx.shared().type_is_sized(content_ty)); - let sizing_type = sizing_type_of(bcx.ccx, content_ty); - let content_size = llsize_of_alloc(bcx.ccx, sizing_type); - - // `Box` does not allocate. - if content_size != 0 { - let content_align = align_of(bcx.ccx, content_ty); - let ccx = bcx.ccx; - trans_exchange_free_dyn(bcx, ptr, C_uint(ccx, content_size), C_uint(ccx, content_align)); - } -} - pub fn get_drop_glue_type<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>, t: Ty<'tcx>) -> Ty<'tcx> { assert!(t.is_normalized_for_trans()); @@ -224,30 +210,16 @@ pub fn implement_drop_glue<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, g: DropGlueKi // special. It may move to library and have Drop impl. As // a safe-guard, assert TyBox not used with TyContents. assert!(!skip_dtor); - if !bcx.ccx.shared().type_is_sized(content_ty) { + let ptr = if !bcx.ccx.shared().type_is_sized(content_ty) { let llbox = bcx.load(get_dataptr(&bcx, ptr.value)); let info = bcx.load(get_meta(&bcx, ptr.value)); - drop_ty(&bcx, MaybeSizedValue::unsized_(llbox, info), content_ty); - let (llsize, llalign) = size_and_align_of_dst(&bcx, content_ty, info); - - // `Box` does not allocate. - let needs_free = bcx.icmp(llvm::IntNE, llsize, C_uint(bcx.ccx, 0u64)); - if const_to_opt_uint(needs_free) == Some(0) { - bcx - } else { - let next_cx = bcx.fcx().build_new_block("next"); - let cond_cx = bcx.fcx().build_new_block("cond"); - bcx.cond_br(needs_free, cond_cx.llbb(), next_cx.llbb()); - trans_exchange_free_dyn(&cond_cx, llbox, llsize, llalign); - cond_cx.br(next_cx.llbb()); - next_cx - } + MaybeSizedValue::unsized_(llbox, info) } else { - let llbox = bcx.load(ptr.value); - drop_ty(&bcx, MaybeSizedValue::sized(llbox), content_ty); - trans_exchange_free_ty(&bcx, llbox, content_ty); - bcx - } + MaybeSizedValue::sized(bcx.load(ptr.value)) + }; + drop_ty(&bcx, ptr, content_ty); + trans_exchange_free_ty(&bcx, ptr, content_ty); + bcx } ty::TyDynamic(..) => { // No support in vtable for distinguishing destroying with -- cgit 1.4.1-3-g733a5