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 10 pull requests #69085

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
91cf0e7
Don't requery the param_env of a union
matthewjasper Jan 30, 2020
570c161
Remove unnecessary features in rustc_ty
matthewjasper Jan 30, 2020
3973322
Add IS_MANUALLY_DROP to AdtFlags
matthewjasper Jan 30, 2020
d196521
Improve needs_drop query
matthewjasper Jan 30, 2020
d20646b
Address review comments
matthewjasper Jan 31, 2020
465b862
Use correct `ParamEnv` in `Instance::resolve`
matthewjasper Feb 1, 2020
6bf2cc2
Avoid instantiating many `Parser` structs in `generic_extension`.
nnethercote Feb 4, 2020
f840a95
Remove the `Cow` from `Directory`.
nnethercote Feb 5, 2020
2a13b24
Change condition ordering in `parse_tt`.
nnethercote Feb 5, 2020
3eb5241
Apply suggestions from code review
matthewjasper Feb 9, 2020
842938a
cache adt_drop_tys
matthewjasper Feb 9, 2020
9e78ce0
handle TerminatorKind::Yield by returning Err(Unpromotable)
chrissimpkins Feb 10, 2020
fc3ecb2
add issue 69017 test
chrissimpkins Feb 10, 2020
97d1f8d
Add missing `_zeroed` varants to `AllocRef`
TimDiekmann Feb 10, 2020
53b16fb
add main function to issue-69017 test
chrissimpkins Feb 10, 2020
e2b9d6e
Add a `contains` method to `ResultsCursor`
ecstatic-morse Jan 20, 2020
1ec9917
Add an `into_engine` method to `Analysis`
ecstatic-morse Jan 20, 2020
c64dfd7
Add a `Visitor` for dataflow results
ecstatic-morse Jan 20, 2020
702096d
Implement a `find_descendant` method for `MovePath`
ecstatic-morse Jan 20, 2020
ce3f37b
Use new dataflow interface for initialization/borrows analyses
ecstatic-morse Jan 20, 2020
76aa29f
Preparation for allocator aware `Box`
TimDiekmann Feb 11, 2020
3884311
Add self to .mailmap
Bassetts Feb 11, 2020
30a8353
Specify overflow checks behaviour in test
matthewjasper Feb 10, 2020
f639607
Use new dataflow framework for drop elaboration and borrow checking
ecstatic-morse Jan 20, 2020
42d19a4
Use new dataflow framework for `rustc_peek` tests
ecstatic-morse Jan 20, 2020
5860e78
Skip caching block transfer functions for acyclic MIR
ecstatic-morse Jan 20, 2020
168ca9a
Add note about `elaborate_drops::InitializationData`
ecstatic-morse Jan 21, 2020
3ac920f
Use exhaustive matching
ecstatic-morse Feb 11, 2020
5f40fe9
Clarify why you shouldn't override `Analysis::into_engine`
ecstatic-morse Feb 11, 2020
8e26ad0
Keyword docs
Feb 11, 2020
683ebc2
On mismatched argument count point at arguments
estebank Feb 6, 2020
c1ed84e
Fix outdated doc comment.
jumbatm Feb 11, 2020
c7addfb
Rollup merge of #67695 - gilescope:truth, r=centril
Dylan-DPC Feb 12, 2020
eb80eec
Rollup merge of #68241 - ecstatic-morse:unified-dataflow-impls, r=pnk…
Dylan-DPC Feb 12, 2020
410b326
Rollup merge of #68679 - matthewjasper:needs-type-op, r=varkor
Dylan-DPC Feb 12, 2020
8f813b7
Rollup merge of #68848 - nnethercote:hasten-macro-parsing, r=petroche…
Dylan-DPC Feb 12, 2020
c33d531
Rollup merge of #68877 - estebank:point-at-params, r=petrochenkov
Dylan-DPC Feb 12, 2020
4b556ce
Rollup merge of #69027 - TimDiekmann:zeroed-alloc, r=Amanieu
Dylan-DPC Feb 12, 2020
0d15165
Rollup merge of #69032 - chrissimpkins:ice-yield-println-#69017, r=pe…
Dylan-DPC Feb 12, 2020
6d7bbcb
Rollup merge of #69058 - TimDiekmann:box, r=Amanieu
Dylan-DPC Feb 12, 2020
440e5c7
Rollup merge of #69070 - Bassetts:master, r=alexcrichton
Dylan-DPC Feb 12, 2020
19bd8af
Rollup merge of #69077 - jumbatm:fix-comment, r=Dylan-DPC
Dylan-DPC Feb 12, 2020
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
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ James Deng <[email protected]> <[email protected]>
James Miller <[email protected]> <[email protected]>
James Perry <[email protected]>
Jason Fager <[email protected]>
Jason Liquorish <[email protected]> <[email protected]>
Jason Orendorff <[email protected]> <[email protected]>
Jason Orendorff <[email protected]> <[email protected]>
Jason Toffaletti <[email protected]> Jason Toffaletti <[email protected]>
Expand Down
18 changes: 12 additions & 6 deletions src/liballoc/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,21 +200,27 @@ unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 {
align as *mut u8
} else {
let layout = Layout::from_size_align_unchecked(size, align);
let ptr = alloc(layout);
if !ptr.is_null() { ptr } else { handle_alloc_error(layout) }
match Global.alloc(layout) {
Ok(ptr) => ptr.as_ptr(),
Err(_) => handle_alloc_error(layout),
}
}
}

#[cfg_attr(not(test), lang = "box_free")]
#[inline]
// This signature has to be the same as `Box`, otherwise an ICE will happen.
// When an additional parameter to `Box` is added (like `A: AllocRef`), this has to be added here as
// well.
// For example if `Box` is changed to `struct Box<T: ?Sized, A: AllocRef>(Unique<T>, A)`,
// this function has to be changed to `fn box_free<T: ?Sized, A: AllocRef>(Unique<T>, A)` as well.
pub(crate) unsafe fn box_free<T: ?Sized>(ptr: Unique<T>) {
let ptr = ptr.as_ptr();
let size = size_of_val(&*ptr);
let align = min_align_of_val(&*ptr);
let size = size_of_val(ptr.as_ref());
let align = min_align_of_val(ptr.as_ref());
// We do not allocate for Box<T> when T is ZST, so deallocation is also not necessary.
if size != 0 {
let layout = Layout::from_size_align_unchecked(size, align);
dealloc(ptr as *mut u8, layout);
Global.dealloc(ptr.cast().into(), layout);
}
}

Expand Down
31 changes: 16 additions & 15 deletions src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,14 @@ impl<T> Box<T> {
#[unstable(feature = "new_uninit", issue = "63291")]
pub fn new_uninit() -> Box<mem::MaybeUninit<T>> {
let layout = alloc::Layout::new::<mem::MaybeUninit<T>>();
if layout.size() == 0 {
return Box(NonNull::dangling().into());
unsafe {
let ptr = if layout.size() == 0 {
NonNull::dangling()
} else {
Global.alloc(layout).unwrap_or_else(|_| alloc::handle_alloc_error(layout)).cast()
};
Box::from_raw(ptr.as_ptr())
}
let ptr =
unsafe { Global.alloc(layout).unwrap_or_else(|_| alloc::handle_alloc_error(layout)) };
Box(ptr.cast().into())
}

/// Constructs a new `Box` with uninitialized contents, with the memory
Expand Down Expand Up @@ -264,15 +266,14 @@ impl<T> Box<[T]> {
#[unstable(feature = "new_uninit", issue = "63291")]
pub fn new_uninit_slice(len: usize) -> Box<[mem::MaybeUninit<T>]> {
let layout = alloc::Layout::array::<mem::MaybeUninit<T>>(len).unwrap();
let ptr = if layout.size() == 0 {
NonNull::dangling()
} else {
unsafe {
unsafe {
let ptr = if layout.size() == 0 {
NonNull::dangling()
} else {
Global.alloc(layout).unwrap_or_else(|_| alloc::handle_alloc_error(layout)).cast()
}
};
let slice = unsafe { slice::from_raw_parts_mut(ptr.as_ptr(), len) };
Box(Unique::from(slice))
};
Box::from_raw(slice::from_raw_parts_mut(ptr.as_ptr(), len))
}
}
}

Expand Down Expand Up @@ -308,7 +309,7 @@ impl<T> Box<mem::MaybeUninit<T>> {
#[unstable(feature = "new_uninit", issue = "63291")]
#[inline]
pub unsafe fn assume_init(self) -> Box<T> {
Box(Box::into_unique(self).cast())
Box::from_raw(Box::into_raw(self) as *mut T)
}
}

Expand Down Expand Up @@ -346,7 +347,7 @@ impl<T> Box<[mem::MaybeUninit<T>]> {
#[unstable(feature = "new_uninit", issue = "63291")]
#[inline]
pub unsafe fn assume_init(self) -> Box<[T]> {
Box(Unique::new_unchecked(Box::into_raw(self) as _))
Box::from_raw(Box::into_raw(self) as *mut [T])
}
}

Expand Down
137 changes: 137 additions & 0 deletions src/libcore/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,59 @@ pub unsafe trait AllocRef {
result
}

/// Behaves like `realloc`, but also ensures that the new contents
/// are set to zero before being returned.
///
/// # Safety
///
/// This function is unsafe for the same reasons that `realloc` is.
///
/// # Errors
///
/// Returns `Err` only if the new layout
/// does not meet the allocator's size
/// and alignment constraints of the allocator, or if reallocation
/// otherwise fails.
///
/// Implementations are encouraged to return `Err` on memory
/// exhaustion rather than panicking or aborting, but this is not
/// a strict requirement. (Specifically: it is *legal* to
/// implement this trait atop an underlying native allocation
/// library that aborts on memory exhaustion.)
///
/// Clients wishing to abort computation in response to a
/// reallocation error are encouraged to call the [`handle_alloc_error`] function,
/// rather than directly invoking `panic!` or similar.
///
/// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html
unsafe fn realloc_zeroed(
&mut self,
ptr: NonNull<u8>,
layout: Layout,
new_size: usize,
) -> Result<NonNull<u8>, AllocErr> {
let old_size = layout.size();

if new_size >= old_size {
if let Ok(()) = self.grow_in_place_zeroed(ptr, layout, new_size) {
return Ok(ptr);
}
} else if new_size < old_size {
if let Ok(()) = self.shrink_in_place(ptr, layout, new_size) {
return Ok(ptr);
}
}

// otherwise, fall back on alloc + copy + dealloc.
let new_layout = Layout::from_size_align_unchecked(new_size, layout.align());
let result = self.alloc_zeroed(new_layout);
if let Ok(new_ptr) = result {
ptr::copy_nonoverlapping(ptr.as_ptr(), new_ptr.as_ptr(), cmp::min(old_size, new_size));
self.dealloc(ptr, layout);
}
result
}

/// Behaves like `alloc`, but also ensures that the contents
/// are set to zero before being returned.
///
Expand Down Expand Up @@ -904,6 +957,31 @@ pub unsafe trait AllocRef {
self.alloc(layout).map(|p| Excess(p, usable_size.1))
}

/// Behaves like `alloc`, but also returns the whole size of
/// the returned block. For some `layout` inputs, like arrays, this
/// may include extra storage usable for additional data.
/// Also it ensures that the contents are set to zero before being returned.
///
/// # Safety
///
/// This function is unsafe for the same reasons that `alloc` is.
///
/// # Errors
///
/// Returning `Err` indicates that either memory is exhausted or
/// `layout` does not meet allocator's size or alignment
/// constraints, just as in `alloc`.
///
/// Clients wishing to abort computation in response to an
/// allocation error are encouraged to call the [`handle_alloc_error`] function,
/// rather than directly invoking `panic!` or similar.
///
/// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html
unsafe fn alloc_excess_zeroed(&mut self, layout: Layout) -> Result<Excess, AllocErr> {
let usable_size = self.usable_size(&layout);
self.alloc_zeroed(layout).map(|p| Excess(p, usable_size.1))
}

/// Behaves like `realloc`, but also returns the whole size of
/// the returned block. For some `layout` inputs, like arrays, this
/// may include extra storage usable for additional data.
Expand Down Expand Up @@ -934,6 +1012,37 @@ pub unsafe trait AllocRef {
self.realloc(ptr, layout, new_size).map(|p| Excess(p, usable_size.1))
}

/// Behaves like `realloc`, but also returns the whole size of
/// the returned block. For some `layout` inputs, like arrays, this
/// may include extra storage usable for additional data.
/// Also it ensures that the contents are set to zero before being returned.
///
/// # Safety
///
/// This function is unsafe for the same reasons that `realloc` is.
///
/// # Errors
///
/// Returning `Err` indicates that either memory is exhausted or
/// `layout` does not meet allocator's size or alignment
/// constraints, just as in `realloc`.
///
/// Clients wishing to abort computation in response to a
/// reallocation error are encouraged to call the [`handle_alloc_error`] function,
/// rather than directly invoking `panic!` or similar.
///
/// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html
unsafe fn realloc_excess_zeroed(
&mut self,
ptr: NonNull<u8>,
layout: Layout,
new_size: usize,
) -> Result<Excess, AllocErr> {
let new_layout = Layout::from_size_align_unchecked(new_size, layout.align());
let usable_size = self.usable_size(&new_layout);
self.realloc_zeroed(ptr, layout, new_size).map(|p| Excess(p, usable_size.1))
}

/// Attempts to extend the allocation referenced by `ptr` to fit `new_size`.
///
/// If this returns `Ok`, then the allocator has asserted that the
Expand Down Expand Up @@ -983,6 +1092,34 @@ pub unsafe trait AllocRef {
if new_size <= u { Ok(()) } else { Err(CannotReallocInPlace) }
}

/// Behaves like `grow_in_place`, but also ensures that the new
/// contents are set to zero before being returned.
///
/// # Safety
///
/// This function is unsafe for the same reasons that `grow_in_place` is.
///
/// # Errors
///
/// Returns `Err(CannotReallocInPlace)` when the allocator is
/// unable to assert that the memory block referenced by `ptr`
/// could fit `layout`.
///
/// Note that one cannot pass `CannotReallocInPlace` to the `handle_alloc_error`
/// function; clients are expected either to be able to recover from
/// `grow_in_place` failures without aborting, or to fall back on
/// another reallocation method before resorting to an abort.
unsafe fn grow_in_place_zeroed(
&mut self,
ptr: NonNull<u8>,
layout: Layout,
new_size: usize,
) -> Result<(), CannotReallocInPlace> {
self.grow_in_place(ptr, layout, new_size)?;
ptr.as_ptr().add(layout.size()).write_bytes(0, new_size - layout.size());
Ok(())
}

/// Attempts to shrink the allocation referenced by `ptr` to fit `new_size`.
///
/// If this returns `Ok`, then the allocator has asserted that the
Expand Down
7 changes: 3 additions & 4 deletions src/librustc/mir/interpret/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,9 @@ impl<'tcx> ConstEvalErr<'tcx> {
}
}

/// Sets the message passed in via `message`, then adds the span labels for you, before applying
/// further modifications in `emit`. It's up to you to call emit(), stash(..), etc. within the
/// `emit` method. If you don't need to do any additional processing, just use
/// struct_generic.
/// Sets the message passed in via `message` and adds span labels before handing control back
/// to `emit` to do any final processing. It's the caller's responsibility to call emit(),
/// stash(), etc. within the `emit` function to dispose of the diagnostic properly.
fn struct_generic(
&self,
tcx: TyCtxtAt<'tcx>,
Expand Down
19 changes: 11 additions & 8 deletions src/librustc/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,26 +669,29 @@ rustc_queries! {
no_force
desc { "computing whether `{}` is `Copy`", env.value }
}
/// Query backing `TyS::is_sized`.
query is_sized_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
no_force
desc { "computing whether `{}` is `Sized`", env.value }
}
/// Query backing `TyS::is_freeze`.
query is_freeze_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
no_force
desc { "computing whether `{}` is freeze", env.value }
}

// The cycle error here should be reported as an error by `check_representable`.
// We consider the type as not needing drop in the meanwhile to avoid
// further errors (done in impl Value for NeedsDrop).
// Use `cycle_delay_bug` to delay the cycle error here to be emitted later
// in case we accidentally otherwise don't emit an error.
query needs_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> NeedsDrop {
cycle_delay_bug
/// Query backing `TyS::needs_drop`.
query needs_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
no_force
desc { "computing whether `{}` needs drop", env.value }
}

/// A list of types where the ADT requires drop if and only if any of
/// those types require drop. If the ADT is known to always need drop
/// then `Err(AlwaysRequiresDrop)` is returned.
query adt_drop_tys(_: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
cache_on_disk_if { true }
}

query layout_raw(
env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
) -> Result<&'tcx ty::layout::LayoutDetails, ty::layout::LayoutError<'tcx>> {
Expand Down
Loading