Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 9 pull requests #61016

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
af6ace6
convert custom try macro to `?`
hellow554 May 6, 2019
5458b65
use exhaustive_patterns to be able to use `?`
hellow554 May 6, 2019
c5d9401
Avoid symbol interning in `file_metadata`.
nnethercote May 6, 2019
a7e1431
Update boxed::Box docs on memory layout
blkerby May 19, 2019
178b753
Remove trailing whitespaces to satisfy tidy
blkerby May 19, 2019
d320c7c
Do not fail on child without DefId
estebank May 20, 2019
419ca9d
LocalDecl push returns Local len
spastorino May 20, 2019
4e37785
Create and reference Memory Layout section of boxed docs
blkerby May 21, 2019
e186d3f
Add stream_to_parser_with_base_dir
topecongiro May 21, 2019
5ea5fe3
static_assert: make use of anonymous constants
RalfJung May 21, 2019
dd94dc3
Emit error when trying to use PGO in conjunction with unwinding on Wi…
michaelwoerister May 21, 2019
61735ab
adjust deprecation date of mem::uninitialized
RalfJung May 21, 2019
b07dbe1
Add doc comment
topecongiro May 21, 2019
1f1a917
Fix tidy: remove a trailing whitespace
topecongiro May 21, 2019
a2168b0
update doc comment
RalfJung May 21, 2019
0650084
Rollup merge of #60581 - hellow554:fix_60580, r=alexcrichton
Centril May 21, 2019
253c26b
Rollup merge of #60963 - blkerby:boxed_docs, r=alexcrichton
Centril May 21, 2019
9e11b48
Rollup merge of #60973 - nnethercote:fix-file_metadata-more, r=michae…
Centril May 21, 2019
d063b74
Rollup merge of #60982 - estebank:fix-60976, r=petrochenkov
Centril May 21, 2019
d18b4c1
Rollup merge of #60991 - spastorino:local-decls-push, r=oli-obk
Centril May 21, 2019
e0aaa72
Rollup merge of #60995 - topecongiro:parser-from-stream-and-base-dir,…
Centril May 21, 2019
c778205
Rollup merge of #60998 - RalfJung:static_assert, r=Centril
Centril May 21, 2019
18d728c
Rollup merge of #61005 - michaelwoerister:error-pgo-windows-unwind, r…
Centril May 21, 2019
c6427e3
Rollup merge of #61006 - RalfJung:maybe-uninit, r=Centril
Centril May 21, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 64 additions & 25 deletions src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@
//! heap allocation in Rust. Boxes provide ownership for this allocation, and
//! drop their contents when they go out of scope.
//!
//! For non-zero-sized values, a [`Box`] will use the [`Global`] allocator for
//! its allocation. It is valid to convert both ways between a [`Box`] and a
//! raw pointer allocated with the [`Global`] allocator, given that the
//! [`Layout`] used with the allocator is correct for the type. More precisely,
//! a `value: *mut T` that has been allocated with the [`Global`] allocator
//! with `Layout::for_value(&*value)` may be converted into a box using
//! `Box::<T>::from_raw(value)`. Conversely, the memory backing a `value: *mut
//! T` obtained from `Box::<T>::into_raw` may be deallocated using the
//! [`Global`] allocator with `Layout::for_value(&*value)`.
//!
//! # Examples
//!
//! Move a value from the stack to the heap by creating a [`Box`]:
Expand Down Expand Up @@ -61,6 +51,19 @@
//! for a `Cons`. By introducing a `Box`, which has a defined size, we know how
//! big `Cons` needs to be.
//!
//! # Memory layout
//!
//! For non-zero-sized values, a [`Box`] will use the [`Global`] allocator for
//! its allocation. It is valid to convert both ways between a [`Box`] and a
//! raw pointer allocated with the [`Global`] allocator, given that the
//! [`Layout`] used with the allocator is correct for the type. More precisely,
//! a `value: *mut T` that has been allocated with the [`Global`] allocator
//! with `Layout::for_value(&*value)` may be converted into a box using
//! `Box::<T>::from_raw(value)`. Conversely, the memory backing a `value: *mut
//! T` obtained from `Box::<T>::into_raw` may be deallocated using the
//! [`Global`] allocator with `Layout::for_value(&*value)`.
//!
//!
//! [dereferencing]: ../../std/ops/trait.Deref.html
//! [`Box`]: struct.Box.html
//! [`Global`]: ../alloc/struct.Global.html
Expand Down Expand Up @@ -127,24 +130,38 @@ impl<T: ?Sized> Box<T> {
///
/// After calling this function, the raw pointer is owned by the
/// resulting `Box`. Specifically, the `Box` destructor will call
/// the destructor of `T` and free the allocated memory. Since the
/// way `Box` allocates and releases memory is unspecified, the
/// only valid pointer to pass to this function is the one taken
/// from another `Box` via the [`Box::into_raw`] function.
/// the destructor of `T` and free the allocated memory. For this
/// to be safe, the memory must have been allocated in accordance
/// with the [memory layout] used by `Box` .
///
/// # Safety
///
/// This function is unsafe because improper use may lead to
/// memory problems. For example, a double-free may occur if the
/// function is called twice on the same raw pointer.
///
/// [`Box::into_raw`]: struct.Box.html#method.into_raw
///
/// # Examples
///
/// Recreate a `Box` which was previously converted to a raw pointer
/// using [`Box::into_raw`]:
/// ```
/// let x = Box::new(5);
/// let ptr = Box::into_raw(x);
/// let x = unsafe { Box::from_raw(ptr) };
/// ```
/// Manually create a `Box` from scratch by using the global allocator:
/// ```
/// use std::alloc::{alloc, Layout};
///
/// unsafe {
/// let ptr = alloc(Layout::new::<i32>()) as *mut i32;
/// *ptr = 5;
/// let x = Box::from_raw(ptr);
/// }
/// ```
///
/// [memory layout]: index.html#memory-layout
/// [`Layout`]: ../alloc/struct.Layout.html
/// [`Box::into_raw`]: struct.Box.html#method.into_raw
#[stable(feature = "box_raw", since = "1.4.0")]
#[inline]
pub unsafe fn from_raw(raw: *mut T) -> Self {
Expand All @@ -157,22 +174,40 @@ impl<T: ?Sized> Box<T> {
///
/// After calling this function, the caller is responsible for the
/// memory previously managed by the `Box`. In particular, the
/// caller should properly destroy `T` and release the memory. The
/// proper way to do so is to convert the raw pointer back into a
/// `Box` with the [`Box::from_raw`] function.
/// caller should properly destroy `T` and release the memory, taking
/// into account the [memory layout] used by `Box`. The easiest way to
/// do this is to convert the raw pointer back into a `Box` with the
/// [`Box::from_raw`] function, allowing the `Box` destructor to perform
/// the cleanup.
///
/// Note: this is an associated function, which means that you have
/// to call it as `Box::into_raw(b)` instead of `b.into_raw()`. This
/// is so that there is no conflict with a method on the inner type.
///
/// [`Box::from_raw`]: struct.Box.html#method.from_raw
///
/// # Examples
///
/// Converting the raw pointer back into a `Box` with [`Box::from_raw`]
/// for automatic cleanup:
/// ```
/// let x = Box::new(5);
/// let x = Box::new(String::from("Hello"));
/// let ptr = Box::into_raw(x);
/// let x = unsafe { Box::from_raw(ptr) };
/// ```
/// Manual cleanup by explicitly running the destructor and deallocating
/// the memory:
/// ```
/// use std::alloc::{dealloc, Layout};
/// use std::ptr;
///
/// let x = Box::new(String::from("Hello"));
/// let p = Box::into_raw(x);
/// unsafe {
/// ptr::drop_in_place(p);
/// dealloc(p as *mut u8, Layout::new::<String>());
/// }
/// ```
///
/// [memory layout]: index.html#memory-layout
/// [`Box::from_raw`]: struct.Box.html#method.from_raw
#[stable(feature = "box_raw", since = "1.4.0")]
#[inline]
pub fn into_raw(b: Box<T>) -> *mut T {
Expand All @@ -184,7 +219,7 @@ impl<T: ?Sized> Box<T> {
/// After calling this function, the caller is responsible for the
/// memory previously managed by the `Box`. In particular, the
/// caller should properly destroy `T` and release the memory. The
/// proper way to do so is to convert the `NonNull<T>` pointer
/// easiest way to do so is to convert the `NonNull<T>` pointer
/// into a raw pointer and back into a `Box` with the [`Box::from_raw`]
/// function.
///
Expand All @@ -203,6 +238,10 @@ impl<T: ?Sized> Box<T> {
/// fn main() {
/// let x = Box::new(5);
/// let ptr = Box::into_raw_non_null(x);
///
/// // Clean up the memory by converting the NonNull pointer back
/// // into a Box and letting the Box be dropped.
/// let x = unsafe { Box::from_raw(ptr.as_ptr()) };
/// }
/// ```
#[unstable(feature = "box_into_raw_non_null", issue = "47336")]
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ pub unsafe fn zeroed<T>() -> T {
/// [`MaybeUninit<T>`]: union.MaybeUninit.html
/// [inv]: union.MaybeUninit.html#initialization-invariant
#[inline]
#[rustc_deprecated(since = "1.40.0", reason = "use `mem::MaybeUninit` instead")]
#[rustc_deprecated(since = "1.38.0", reason = "use `mem::MaybeUninit` instead")]
#[stable(feature = "rust1", since = "1.0.0")]
pub unsafe fn uninitialized<T>() -> T {
intrinsics::panic_if_uninhabited::<T>();
Expand Down
12 changes: 12 additions & 0 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,18 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
sess.err("Linker plugin based LTO is not supported together with \
`-C prefer-dynamic` when targeting MSVC");
}

// PGO does not work reliably with panic=unwind on Windows. Let's make it
// an error to combine the two for now. It always runs into an assertions
// if LLVM is built with assertions, but without assertions it sometimes
// does not crash and will probably generate a corrupted binary.
if sess.opts.debugging_opts.pgo_gen.enabled() &&
sess.target.target.options.is_like_windows &&
sess.panic_strategy() == PanicStrategy::Unwind {
sess.err("Profile-guided optimization does not yet work in conjunction \
with `-Cpanic=unwind` on Windows. \
See https://github.com/rust-lang/rust/issues/61002 for details.");
}
}

/// Hash value constructed out of all the `-C metadata` arguments passed to the
Expand Down
64 changes: 32 additions & 32 deletions src/librustc_codegen_llvm/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ use rustc_data_structures::small_c_str::SmallCStr;
use rustc_target::abi::HasDataLayout;

use libc::{c_uint, c_longlong};
use std::collections::hash_map::Entry;
use std::ffi::CString;
use std::fmt::{self, Write};
use std::hash::{Hash, Hasher};
use std::iter;
use std::ptr;
use std::path::{Path, PathBuf};
use syntax::ast;
use syntax::symbol::{Interner, InternedString, Symbol};
use syntax::symbol::{Interner, InternedString};
use syntax_pos::{self, Span, FileName};

impl PartialEq for llvm::Metadata {
Expand Down Expand Up @@ -787,49 +788,48 @@ pub fn file_metadata(cx: &CodegenCx<'ll, '_>,
file_name,
defining_crate);

let file_name = &file_name.to_string();
let file_name_symbol = Symbol::intern(file_name);
if defining_crate == LOCAL_CRATE {
let directory = &cx.sess().working_dir.0.to_string_lossy();
file_metadata_raw(cx, file_name, Some(file_name_symbol),
directory, Some(Symbol::intern(directory)))
let file_name = Some(file_name.to_string());
let directory = if defining_crate == LOCAL_CRATE {
Some(cx.sess().working_dir.0.to_string_lossy().to_string())
} else {
// If the path comes from an upstream crate we assume it has been made
// independent of the compiler's working directory one way or another.
file_metadata_raw(cx, file_name, Some(file_name_symbol), "", None)
}
None
};
file_metadata_raw(cx, file_name, directory)
}

pub fn unknown_file_metadata(cx: &CodegenCx<'ll, '_>) -> &'ll DIFile {
file_metadata_raw(cx, "<unknown>", None, "", None)
file_metadata_raw(cx, None, None)
}

fn file_metadata_raw(cx: &CodegenCx<'ll, '_>,
file_name: &str,
file_name_symbol: Option<Symbol>,
directory: &str,
directory_symbol: Option<Symbol>)
file_name: Option<String>,
directory: Option<String>)
-> &'ll DIFile {
let key = (file_name_symbol, directory_symbol);
let key = (file_name, directory);

match debug_context(cx).created_files.borrow_mut().entry(key) {
Entry::Occupied(o) => return o.get(),
Entry::Vacant(v) => {
let (file_name, directory) = v.key();
debug!("file_metadata: file_name: {:?}, directory: {:?}", file_name, directory);

let file_name = SmallCStr::new(
if let Some(file_name) = file_name { &file_name } else { "<unknown>" });
let directory = SmallCStr::new(
if let Some(directory) = directory { &directory } else { "" });

let file_metadata = unsafe {
llvm::LLVMRustDIBuilderCreateFile(DIB(cx),
file_name.as_ptr(),
directory.as_ptr())
};

if let Some(file_metadata) = debug_context(cx).created_files.borrow().get(&key) {
return *file_metadata;
v.insert(file_metadata);
file_metadata
}
}

debug!("file_metadata: file_name: {}, directory: {}", file_name, directory);

let file_name = SmallCStr::new(file_name);
let directory = SmallCStr::new(directory);

let file_metadata = unsafe {
llvm::LLVMRustDIBuilderCreateFile(DIB(cx),
file_name.as_ptr(),
directory.as_ptr())
};

let mut created_files = debug_context(cx).created_files.borrow_mut();
created_files.insert(key, file_metadata);
file_metadata
}

fn basic_type_metadata(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll DIType {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_llvm/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use std::ffi::CString;

use syntax_pos::{self, Span, Pos};
use syntax::ast;
use syntax::symbol::{Symbol, InternedString};
use syntax::symbol::InternedString;
use rustc::ty::layout::{self, LayoutOf, HasTyCtxt};
use rustc_codegen_ssa::traits::*;

Expand All @@ -63,7 +63,7 @@ pub struct CrateDebugContext<'a, 'tcx> {
llcontext: &'a llvm::Context,
llmod: &'a llvm::Module,
builder: &'a mut DIBuilder<'a>,
created_files: RefCell<FxHashMap<(Option<Symbol>, Option<Symbol>), &'a DIFile>>,
created_files: RefCell<FxHashMap<(Option<String>, Option<String>), &'a DIFile>>,
created_enum_disr_types: RefCell<FxHashMap<(DefId, layout::Primitive), &'a DIType>>,

type_map: RefCell<TypeMap<'a, 'tcx>>,
Expand Down
9 changes: 4 additions & 5 deletions src/librustc_data_structures/macros.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/// A simple static assertion macro. The first argument should be a unique
/// ALL_CAPS identifier that describes the condition.
/// A simple static assertion macro.
#[macro_export]
#[allow_internal_unstable(type_ascription)]
#[allow_internal_unstable(type_ascription, underscore_const_names)]
macro_rules! static_assert {
($name:ident: $test:expr) => {
($test:expr) => {
// Use the bool to access an array such that if the bool is false, the access
// is out-of-bounds.
#[allow(dead_code)]
static $name: () = [()][!($test: bool) as usize];
const _: () = [()][!($test: bool) as usize];
}
}

Expand Down
22 changes: 11 additions & 11 deletions src/librustc_metadata/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,20 +355,20 @@ pub fn provide<'tcx>(providers: &mut Providers<'tcx>) {
return;
}

let child = child.res.def_id();

match visible_parent_map.entry(child) {
Entry::Occupied(mut entry) => {
// If `child` is defined in crate `cnum`, ensure
// that it is mapped to a parent in `cnum`.
if child.krate == cnum && entry.get().krate != cnum {
if let Some(child) = child.res.opt_def_id() {
match visible_parent_map.entry(child) {
Entry::Occupied(mut entry) => {
// If `child` is defined in crate `cnum`, ensure
// that it is mapped to a parent in `cnum`.
if child.krate == cnum && entry.get().krate != cnum {
entry.insert(parent);
}
}
Entry::Vacant(entry) => {
entry.insert(parent);
bfs_queue.push_back(child);
}
}
Entry::Vacant(entry) => {
entry.insert(parent);
bfs_queue.push_back(child);
}
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/transform/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ impl<'a, 'tcx> TransformVisitor<'a, 'tcx> {
// Create a statement which reads the discriminant into a temporary
fn get_discr(&self, mir: &mut Mir<'tcx>) -> (Statement<'tcx>, Place<'tcx>) {
let temp_decl = LocalDecl::new_internal(self.tcx.types.isize, mir.span);
let temp = Place::Base(PlaceBase::Local(Local::new(mir.local_decls.len())));
mir.local_decls.push(temp_decl);
let local_decls_len = mir.local_decls.push(temp_decl);
let temp = Place::Base(PlaceBase::Local(local_decls_len));

let self_place = Place::Base(PlaceBase::Local(self_arg()));
let assign = Statement {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/transform/qualify_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,14 +544,14 @@ impl Qualif for IsNotImplicitlyPromotable {
// Ensure the `IDX` values are sequential (`0..QUALIF_COUNT`).
macro_rules! static_assert_seq_qualifs {
($i:expr => $first:ident $(, $rest:ident)*) => {
static_assert!(SEQ_QUALIFS: {
static_assert!({
static_assert_seq_qualifs!($i + 1 => $($rest),*);

$first::IDX == $i
});
};
($i:expr =>) => {
static_assert!(SEQ_QUALIFS: QUALIF_COUNT == $i);
static_assert!(QUALIF_COUNT == $i);
};
}
static_assert_seq_qualifs!(
Expand Down
Loading