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 7 pull requests #66259

Merged
merged 27 commits into from
Nov 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2ab812c
Rename state to state_and_queue
pitdicker Oct 23, 2019
7f1e166
Simplify loop conditions in RUNNING and add comments
pitdicker Oct 23, 2019
1479c22
Don't mutate waiter nodes
pitdicker Oct 23, 2019
fbc242f
Turn Finish into WaiterQueue
pitdicker Oct 23, 2019
2e8eb5f
Move thread parking to a seperate function
pitdicker Oct 23, 2019
4b8da9c
Reduce the amount of comments in call_inner
pitdicker Oct 23, 2019
88c70ed
In Waiter use interior mutability for thread
pitdicker Oct 23, 2019
c11a44a
Use more precise atomic orderings
pitdicker Oct 23, 2019
c2bbfea
Always align Waiter to 4 bytes
pitdicker Oct 24, 2019
3712bb6
Mention park guarantee
pitdicker Oct 25, 2019
972c3be
Don't cast directly from `&[T; N]` to `*const T`
matthewjasper Oct 25, 2019
6eddf5c
Correct error in documentation for Ipv4Addr method
mjptree Nov 2, 2019
6f79b71
Correct deprecated `is_global` IPv6 documentation
mjptree Nov 3, 2019
4c66658
Don't mutate node.next
pitdicker Nov 4, 2019
0da85d6
rustc_metadata: don't let LLVM confuse rmeta blobs for COFF object fi…
eddyb Nov 9, 2019
8316701
[mir-opt] Handle const-prop for the return place
wesleywiser Nov 8, 2019
4505ff4
[mir-opt] Handle aggregates in SimplifyLocals pass
wesleywiser Nov 8, 2019
769d527
partially port invalid_value lint to diagnostic items
RalfJung Nov 9, 2019
b05e200
Run rustfmt on libstd/sync/once.rs
pitdicker Nov 9, 2019
15863a6
Update src/libstd/net/ip.rs
mjptree Nov 9, 2019
e88aa39
Rollup merge of #65719 - pitdicker:refactor_sync_once, r=Amanieu
JohnTitor Nov 10, 2019
401d9e1
Rollup merge of #65831 - matthewjasper:array-ptr-cast, r=oli-obk
JohnTitor Nov 10, 2019
41d335e
Rollup merge of #66048 - mjptree:patch-1, r=Dylan-DPC
JohnTitor Nov 10, 2019
f135e33
Rollup merge of #66058 - mjptree:patch-2, r=kennytm
JohnTitor Nov 10, 2019
f166609
Rollup merge of #66216 - wesleywiser:const_prop_codegen_improvements,…
JohnTitor Nov 10, 2019
9db3fdd
Rollup merge of #66217 - RalfJung:diagnostic-items, r=Centril
JohnTitor Nov 10, 2019
0fec5ab
Rollup merge of #66235 - eddyb:coff-syrup, r=nagisa
JohnTitor Nov 10, 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
2 changes: 2 additions & 0 deletions src/libcore/mem/maybe_uninit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ impl<T> MaybeUninit<T> {
/// [type]: union.MaybeUninit.html
#[stable(feature = "maybe_uninit", since = "1.36.0")]
#[inline(always)]
#[cfg_attr(all(not(bootstrap)), rustc_diagnostic_item = "maybe_uninit_uninit")]
pub const fn uninit() -> MaybeUninit<T> {
MaybeUninit { uninit: () }
}
Expand Down Expand Up @@ -339,6 +340,7 @@ impl<T> MaybeUninit<T> {
/// ```
#[stable(feature = "maybe_uninit", since = "1.36.0")]
#[inline]
#[cfg_attr(all(not(bootstrap)), rustc_diagnostic_item = "maybe_uninit_zeroed")]
pub fn zeroed() -> MaybeUninit<T> {
let mut u = MaybeUninit::<T>::uninit();
unsafe {
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ pub const fn needs_drop<T>() -> bool {
#[stable(feature = "rust1", since = "1.0.0")]
#[allow(deprecated_in_future)]
#[allow(deprecated)]
#[cfg_attr(all(not(bootstrap)), rustc_diagnostic_item = "mem_zeroed")]
pub unsafe fn zeroed<T>() -> T {
intrinsics::panic_if_uninhabited::<T>();
intrinsics::init()
Expand Down Expand Up @@ -496,6 +497,7 @@ pub unsafe fn zeroed<T>() -> T {
#[stable(feature = "rust1", since = "1.0.0")]
#[allow(deprecated_in_future)]
#[allow(deprecated)]
#[cfg_attr(all(not(bootstrap)), rustc_diagnostic_item = "mem_uninitialized")]
pub unsafe fn uninitialized<T>() -> T {
intrinsics::panic_if_uninhabited::<T>();
intrinsics::uninit()
Expand Down
3 changes: 3 additions & 0 deletions src/librustc/ty/adjustment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ pub enum PointerCast {
/// Go from a mut raw pointer to a const raw pointer.
MutToConstPointer,

/// Go from `*const [T; N]` to `*const T`
ArrayToPointer,

/// Unsize a pointer/reference value, e.g., `&[T; n]` to
/// `&[T]`. Note that the source could be a thin or fat pointer.
/// This will do things like convert thin pointers to fat
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_codegen_ssa/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ pub struct ModuleCodegen<M> {
pub kind: ModuleKind,
}

pub const METADATA_FILENAME: &str = "rust.metadata.bin";
// FIXME(eddyb) maybe include the crate name in this?
pub const METADATA_FILENAME: &str = "lib.rmeta";
pub const RLIB_BYTECODE_EXTENSION: &str = "bc.z";


Expand Down
1 change: 1 addition & 0 deletions src/librustc_codegen_ssa/mir/rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
}
}
mir::CastKind::Pointer(PointerCast::MutToConstPointer)
| mir::CastKind::Pointer(PointerCast::ArrayToPointer)
| mir::CastKind::Misc => {
assert!(bx.cx().is_backend_immediate(cast));
let ll_t_out = bx.cx().immediate_backend_type(cast);
Expand Down
21 changes: 8 additions & 13 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1903,29 +1903,23 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidValue {

/// Determine if this expression is a "dangerous initialization".
fn is_dangerous_init(cx: &LateContext<'_, '_>, expr: &hir::Expr) -> Option<InitKind> {
const ZEROED_PATH: &[Symbol] = &[sym::core, sym::mem, sym::zeroed];
const UININIT_PATH: &[Symbol] = &[sym::core, sym::mem, sym::uninitialized];
// `transmute` is inside an anonymous module (the `extern` block?);
// `Invalid` represents the empty string and matches that.
// FIXME(#66075): use diagnostic items. Somehow, that does not seem to work
// on intrinsics right now.
const TRANSMUTE_PATH: &[Symbol] =
&[sym::core, sym::intrinsics, kw::Invalid, sym::transmute];
const MU_ZEROED_PATH: &[Symbol] =
&[sym::core, sym::mem, sym::maybe_uninit, sym::MaybeUninit, sym::zeroed];
const MU_UNINIT_PATH: &[Symbol] =
&[sym::core, sym::mem, sym::maybe_uninit, sym::MaybeUninit, sym::uninit];

if let hir::ExprKind::Call(ref path_expr, ref args) = expr.kind {
// Find calls to `mem::{uninitialized,zeroed}` methods.
if let hir::ExprKind::Path(ref qpath) = path_expr.kind {
let def_id = cx.tables.qpath_res(qpath, path_expr.hir_id).opt_def_id()?;

if cx.match_def_path(def_id, ZEROED_PATH) {
if cx.tcx.is_diagnostic_item(sym::mem_zeroed, def_id) {
return Some(InitKind::Zeroed);
}
if cx.match_def_path(def_id, UININIT_PATH) {
} else if cx.tcx.is_diagnostic_item(sym::mem_uninitialized, def_id) {
return Some(InitKind::Uninit);
}
if cx.match_def_path(def_id, TRANSMUTE_PATH) {
} else if cx.match_def_path(def_id, TRANSMUTE_PATH) {
if is_zero(&args[0]) {
return Some(InitKind::Zeroed);
}
Expand All @@ -1940,9 +1934,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidValue {
if let hir::ExprKind::Call(ref path_expr, _) = args[0].kind {
if let hir::ExprKind::Path(ref qpath) = path_expr.kind {
let def_id = cx.tables.qpath_res(qpath, path_expr.hir_id).opt_def_id()?;
if cx.match_def_path(def_id, MU_ZEROED_PATH) {

if cx.tcx.is_diagnostic_item(sym::maybe_uninit_zeroed, def_id) {
return Some(InitKind::Zeroed);
} else if cx.match_def_path(def_id, MU_UNINIT_PATH) {
} else if cx.tcx.is_diagnostic_item(sym::maybe_uninit_uninit, def_id) {
return Some(InitKind::Uninit);
}
}
Expand Down
9 changes: 3 additions & 6 deletions src/librustc_metadata/rmeta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,15 @@ crate fn rustc_version() -> String {
/// Metadata encoding version.
/// N.B., increment this if you change the format of metadata such that
/// the rustc version can't be found to compare with `rustc_version()`.
const METADATA_VERSION: u8 = 4;
const METADATA_VERSION: u8 = 5;

/// Metadata header which includes `METADATA_VERSION`.
/// To get older versions of rustc to ignore this metadata,
/// there are 4 zero bytes at the start, which are treated
/// as a length of 0 by old compilers.
///
/// This header is followed by the position of the `CrateRoot`,
/// which is encoded as a 32-bit big-endian unsigned integer,
/// and further followed by the rustc version string.
crate const METADATA_HEADER: &[u8; 12] =
&[0, 0, 0, 0, b'r', b'u', b's', b't', 0, 0, 0, METADATA_VERSION];
crate const METADATA_HEADER: &[u8; 8] =
&[b'r', b'u', b's', b't', 0, 0, 0, METADATA_VERSION];

/// Additional metadata for a `Lazy<T>` where `T` may not be `Sized`,
/// e.g. for `Lazy<[T]>`, this is the length (count of `T` values).
Expand Down
162 changes: 108 additions & 54 deletions src/librustc_mir/borrow_check/nll/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use rustc::traits::query::type_op::custom::CustomTypeOp;
use rustc::traits::query::{Fallible, NoSolution};
use rustc::traits::{self, ObligationCause, PredicateObligations};
use rustc::ty::adjustment::{PointerCast};
use rustc::ty::cast::CastTy;
use rustc::ty::fold::TypeFoldable;
use rustc::ty::subst::{Subst, SubstsRef, GenericArgKind, UserSubsts};
use rustc::ty::{
Expand Down Expand Up @@ -2177,72 +2178,125 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
ty_from,
ty_to,
terr
)
);
}
}

CastKind::Misc => {
if let ty::Ref(_, mut ty_from, _) = op.ty(body, tcx).kind {
let (mut ty_to, mutability) = if let ty::RawPtr(ty::TypeAndMut {
ty: ty_to,
mutbl,
}) = ty.kind {
(ty_to, mutbl)
} else {
CastKind::Pointer(PointerCast::ArrayToPointer) => {
let ty_from = op.ty(body, tcx);

let opt_ty_elem = match ty_from.kind {
ty::RawPtr(
ty::TypeAndMut { mutbl: hir::MutImmutable, ty: array_ty }
) => {
match array_ty.kind {
ty::Array(ty_elem, _) => Some(ty_elem),
_ => None,
}
}
_ => None,
};

let ty_elem = match opt_ty_elem {
Some(ty_elem) => ty_elem,
None => {
span_mirbug!(
self,
rvalue,
"invalid cast types {:?} -> {:?}",
op.ty(body, tcx),
"ArrayToPointer cast from unexpected type {:?}",
ty_from,
);
return;
}
};

let ty_to = match ty.kind {
ty::RawPtr(
ty::TypeAndMut { mutbl: hir::MutImmutable, ty: ty_to }
) => {
ty_to
}
_ => {
span_mirbug!(
self,
rvalue,
"ArrayToPointer cast to unexpected type {:?}",
ty,
);
return;
};

// Handle the direct cast from `&[T; N]` to `*const T` by unwrapping
// any array we find.
while let ty::Array(ty_elem_from, _) = ty_from.kind {
ty_from = ty_elem_from;
if let ty::Array(ty_elem_to, _) = ty_to.kind {
ty_to = ty_elem_to;
} else {
break;
}
}
};

if let hir::MutMutable = mutability {
if let Err(terr) = self.eq_types(
ty_from,
ty_to,
location.to_locations(),
ConstraintCategory::Cast,
) {
span_mirbug!(
self,
rvalue,
"equating {:?} with {:?} yields {:?}",
ty_from,
ty_to,
terr
)
}
} else {
if let Err(terr) = self.sub_types(
ty_from,
ty_to,
location.to_locations(),
ConstraintCategory::Cast,
) {
span_mirbug!(
self,
rvalue,
"relating {:?} with {:?} yields {:?}",
ty_from,
ty_to,
terr
)
if let Err(terr) = self.sub_types(
ty_elem,
ty_to,
location.to_locations(),
ConstraintCategory::Cast,
) {
span_mirbug!(
self,
rvalue,
"relating {:?} with {:?} yields {:?}",
ty_elem,
ty_to,
terr
)
}
}

CastKind::Misc => {
let ty_from = op.ty(body, tcx);
let cast_ty_from = CastTy::from_ty(ty_from);
let cast_ty_to = CastTy::from_ty(ty);
match (cast_ty_from, cast_ty_to) {
(Some(CastTy::RPtr(ref_tm)), Some(CastTy::Ptr(ptr_tm))) => {
if let hir::MutMutable = ptr_tm.mutbl {
if let Err(terr) = self.eq_types(
ref_tm.ty,
ptr_tm.ty,
location.to_locations(),
ConstraintCategory::Cast,
) {
span_mirbug!(
self,
rvalue,
"equating {:?} with {:?} yields {:?}",
ref_tm.ty,
ptr_tm.ty,
terr
)
}
} else {
if let Err(terr) = self.sub_types(
ref_tm.ty,
ptr_tm.ty,
location.to_locations(),
ConstraintCategory::Cast,
) {
span_mirbug!(
self,
rvalue,
"relating {:?} with {:?} yields {:?}",
ref_tm.ty,
ptr_tm.ty,
terr
)
}
}
}
},
(None, _)
| (_, None)
| (_, Some(CastTy::FnPtr))
| (Some(CastTy::Float), Some(CastTy::Ptr(_)))
| (Some(CastTy::Ptr(_)), Some(CastTy::Float))
| (Some(CastTy::FnPtr), Some(CastTy::Float)) => span_mirbug!(
self,
rvalue,
"Invalid cast {:?} -> {:?}",
ty_from,
ty,
),
_ => (),
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/librustc_mir/hair/cx/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,11 @@ fn make_mirror_unadjusted<'a, 'tcx>(
let cast = if cx.tables().is_coercion_cast(source.hir_id) {
// Convert the lexpr to a vexpr.
ExprKind::Use { source: source.to_ref() }
} else if cx.tables().expr_ty(source).is_region_ptr() {
// Special cased so that we can type check that the element
// type of the source matches the pointed to type of the
// destination.
ExprKind::Pointer { source: source.to_ref(), cast: PointerCast::ArrayToPointer }
} else {
// check whether this is casting an enum variant discriminant
// to prevent cycles, we refer to the discriminant initializer
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_mir/interpret/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
self.unsize_into(src, dest)?;
}

Misc | Pointer(PointerCast::MutToConstPointer) => {
Misc
| Pointer(PointerCast::MutToConstPointer)
| Pointer(PointerCast::ArrayToPointer) => {
let src = self.read_immediate(src)?;
let res = self.cast_immediate(src, dest.layout)?;
self.write_immediate(res, dest)?;
Expand Down
Loading