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 8 pull requests #73823

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
358dc1d
Added io forwarding methods to the stdio structs
Lucretiel May 28, 2020
93cbad6
Add documentation to point to `!is_dir` instead of `is_file`
poliorcetics Jun 11, 2020
ec63f9d
Added the note to Metadata too
poliorcetics Jun 11, 2020
c1243db
Make a note about is_dir vs is_file in Path too
poliorcetics Jun 11, 2020
b60cefe
Removed write_fmt forwarding, to fix recursive borrow issues
Lucretiel Jun 17, 2020
14d385b
Restore some write_fmts
Lucretiel Jun 17, 2020
810f309
MIR sanity check: validate types on assignment
RalfJung May 30, 2020
50d7dea
prepare visit_statement for checking more kinds of statements
RalfJung May 31, 2020
93e3552
also normalize constants when comparing types
RalfJung May 31, 2020
9576e30
also normalize_erasing_regions
RalfJung Jun 1, 2020
8200771
reveal_all when sanity-checking MIR assignment types
RalfJung Jun 6, 2020
978470f
no need to normalize mutability any more
RalfJung Jun 21, 2020
91f73fb
use a TypeRelation to compare the types
RalfJung Jun 21, 2020
7754322
fix typo
RalfJung Jun 22, 2020
7f8fe6a
also use relator in interpreter assignment sanity check
RalfJung Jun 22, 2020
5e5ae8b
expand a comment
RalfJung Jun 22, 2020
a593728
make layout check a mere sanity check
RalfJung Jun 22, 2020
35911ee
reduce sanity check in debug mode
RalfJung Jun 24, 2020
5e28eb5
Adds a clearer message for when the async keyword is missing from a f…
nellshamrell Jun 18, 2020
49f6166
Prepare for LLVM 11
cuviper Jun 26, 2020
df88972
Update psm version
nagisa Jun 26, 2020
9308860
fix typo in self-profile.md
atetubou Jun 27, 2020
4c14f9d
Forward Hash::write_iN to Hash::write_uN
nikic Jun 27, 2020
d25d6c5
Update the documentation to point to open instead of is_file and is_dir
poliorcetics Jun 27, 2020
8e8c54a
Added the parapgrah to path::Path::is_file too
poliorcetics Jun 27, 2020
a973c5d
Rollup merge of #72705 - Lucretiel:stdio-forwarding, r=Amanieu
Dylan-DPC Jun 28, 2020
92c474a
Rollup merge of #72796 - RalfJung:mir-assign-sanity, r=matthewjasper
Dylan-DPC Jun 28, 2020
325e83a
Rollup merge of #73243 - poliorcetics:discourage-is-file, r=Amanieu
Dylan-DPC Jun 28, 2020
601371c
Rollup merge of #73525 - cuviper:llvm11, r=nikic
Dylan-DPC Jun 28, 2020
1ded36b
Rollup merge of #73672 - nellshamrell:async-fix, r=estebank
Dylan-DPC Jun 28, 2020
cc8cd6d
Rollup merge of #73781 - nagisa:psm-up, r=Mark-Simulacrum
Dylan-DPC Jun 28, 2020
db4467f
Rollup merge of #73797 - atetubou:patch-1, r=jonas-schievink
Dylan-DPC Jun 28, 2020
3bf9c9d
Rollup merge of #73800 - nikic:hash_i, r=kennytm
Dylan-DPC Jun 28, 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
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2347,9 +2347,9 @@ dependencies = [

[[package]]
name = "psm"
version = "0.1.8"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "659ecfea2142a458893bb7673134bad50b752fea932349c213d6a23874ce3aa7"
checksum = "092d385624a084892d07374caa7b0994956692cf40650419a1f1a787a8d229cf"
dependencies = [
"cc",
]
Expand Down
2 changes: 1 addition & 1 deletion src/doc/unstable-book/src/compiler-flags/self-profile.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ For example:
First, run a compilation session and provide the `-Zself-profile` flag:

```console
$ rustc --crate-name foo -Zself-profile`
$ rustc --crate-name foo -Zself-profile
```

This will generate three files in the working directory such as:
Expand Down
1 change: 1 addition & 0 deletions src/libcore/future/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use crate::task::{Context, Poll};
#[must_use = "futures do nothing unless you `.await` or poll them"]
#[stable(feature = "futures_api", since = "1.36.0")]
#[lang = "future_trait"]
#[rustc_on_unimplemented(label = "`{Self}` is not a future", message = "`{Self}` is not a future")]
pub trait Future {
/// The type of value produced on completion.
#[stable(feature = "futures_api", since = "1.36.0")]
Expand Down
10 changes: 5 additions & 5 deletions src/libcore/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,31 +333,31 @@ pub trait Hasher {
#[inline]
#[stable(feature = "hasher_write", since = "1.3.0")]
fn write_i16(&mut self, i: i16) {
self.write(&i.to_ne_bytes())
self.write_u16(i as u16)
}
/// Writes a single `i32` into this hasher.
#[inline]
#[stable(feature = "hasher_write", since = "1.3.0")]
fn write_i32(&mut self, i: i32) {
self.write(&i.to_ne_bytes())
self.write_u32(i as u32)
}
/// Writes a single `i64` into this hasher.
#[inline]
#[stable(feature = "hasher_write", since = "1.3.0")]
fn write_i64(&mut self, i: i64) {
self.write(&i.to_ne_bytes())
self.write_u64(i as u64)
}
/// Writes a single `i128` into this hasher.
#[inline]
#[stable(feature = "i128", since = "1.26.0")]
fn write_i128(&mut self, i: i128) {
self.write(&i.to_ne_bytes())
self.write_u128(i as u128)
}
/// Writes a single `isize` into this hasher.
#[inline]
#[stable(feature = "hasher_write", since = "1.3.0")]
fn write_isize(&mut self, i: isize) {
self.write(&i.to_ne_bytes())
self.write_usize(i as usize)
}
}

Expand Down
16 changes: 10 additions & 6 deletions src/libprofiler_builtins/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ fn main() {
"InstrProfilingUtil.c",
"InstrProfilingValue.c",
"InstrProfilingWriter.c",
// This file was renamed in LLVM 10.
"InstrProfilingRuntime.cc",
"InstrProfilingRuntime.cpp",
// These files were added in LLVM 11.
"InstrProfilingInternal.c",
"InstrProfilingBiasVar.c",
];

if target.contains("msvc") {
Expand Down Expand Up @@ -69,14 +75,12 @@ fn main() {

let src_root = root.join("lib").join("profile");
for src in profile_sources {
cfg.file(src_root.join(src));
let path = src_root.join(src);
if path.exists() {
cfg.file(path);
}
}

// The file was renamed in LLVM 10.
let old_runtime_path = src_root.join("InstrProfilingRuntime.cc");
let new_runtime_path = src_root.join("InstrProfilingRuntime.cpp");
cfg.file(if old_runtime_path.exists() { old_runtime_path } else { new_runtime_path });

cfg.include(root.join("include"));
cfg.warnings(false);
cfg.compile("profiler-rt");
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_codegen_llvm/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,7 @@ pub unsafe fn optimize_thin_module(
kind: ModuleKind::Regular,
};
{
let target = &*module.module_llvm.tm;
let llmod = module.module_llvm.llmod();
save_temp_bitcode(&cgcx, &module, "thin-lto-input");

Expand Down Expand Up @@ -833,7 +834,7 @@ pub unsafe fn optimize_thin_module(
{
let _timer =
cgcx.prof.generic_activity_with_arg("LLVM_thin_lto_rename", thin_module.name());
if !llvm::LLVMRustPrepareThinLTORename(thin_module.shared.data.0, llmod) {
if !llvm::LLVMRustPrepareThinLTORename(thin_module.shared.data.0, llmod, target) {
let msg = "failed to prepare thin LTO module";
return Err(write::llvm_err(&diag_handler, msg));
}
Expand Down Expand Up @@ -865,7 +866,7 @@ pub unsafe fn optimize_thin_module(
{
let _timer =
cgcx.prof.generic_activity_with_arg("LLVM_thin_lto_import", thin_module.name());
if !llvm::LLVMRustPrepareThinLTOImport(thin_module.shared.data.0, llmod) {
if !llvm::LLVMRustPrepareThinLTOImport(thin_module.shared.data.0, llmod, target) {
let msg = "failed to prepare thin LTO module";
return Err(write::llvm_err(&diag_handler, msg));
}
Expand Down
16 changes: 14 additions & 2 deletions src/librustc_codegen_llvm/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ pub enum TypeKind {
Metadata = 14,
X86_MMX = 15,
Token = 16,
ScalableVector = 17,
BFloat = 18,
}

impl TypeKind {
Expand All @@ -255,6 +257,8 @@ impl TypeKind {
TypeKind::Metadata => rustc_codegen_ssa::common::TypeKind::Metadata,
TypeKind::X86_MMX => rustc_codegen_ssa::common::TypeKind::X86_MMX,
TypeKind::Token => rustc_codegen_ssa::common::TypeKind::Token,
TypeKind::ScalableVector => rustc_codegen_ssa::common::TypeKind::ScalableVector,
TypeKind::BFloat => rustc_codegen_ssa::common::TypeKind::BFloat,
}
}
}
Expand Down Expand Up @@ -2141,10 +2145,18 @@ extern "C" {
PreservedSymbols: *const *const c_char,
PreservedSymbolsLen: c_uint,
) -> Option<&'static mut ThinLTOData>;
pub fn LLVMRustPrepareThinLTORename(Data: &ThinLTOData, Module: &Module) -> bool;
pub fn LLVMRustPrepareThinLTORename(
Data: &ThinLTOData,
Module: &Module,
Target: &TargetMachine,
) -> bool;
pub fn LLVMRustPrepareThinLTOResolveWeak(Data: &ThinLTOData, Module: &Module) -> bool;
pub fn LLVMRustPrepareThinLTOInternalize(Data: &ThinLTOData, Module: &Module) -> bool;
pub fn LLVMRustPrepareThinLTOImport(Data: &ThinLTOData, Module: &Module) -> bool;
pub fn LLVMRustPrepareThinLTOImport(
Data: &ThinLTOData,
Module: &Module,
Target: &TargetMachine,
) -> bool;
pub fn LLVMRustGetThinLTOModuleImports(
Data: *const ThinLTOData,
ModuleNameCallback: ThinLTOModuleNameCallback,
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_codegen_ssa/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ pub enum TypeKind {
Metadata,
X86_MMX,
Token,
ScalableVector,
BFloat,
}

// FIXME(mw): Anything that is produced via DepGraph::with_task() must implement
Expand Down
59 changes: 23 additions & 36 deletions src/librustc_mir/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use rustc_middle::mir::interpret::{
};
use rustc_middle::ty::layout::{self, TyAndLayout};
use rustc_middle::ty::{
self, fold::BottomUpFolder, query::TyCtxtAt, subst::SubstsRef, Ty, TyCtxt, TypeFoldable,
self, query::TyCtxtAt, subst::SubstsRef, ParamEnv, Ty, TyCtxt, TypeFoldable,
};
use rustc_span::{source_map::DUMMY_SP, Span};
use rustc_target::abi::{Align, HasDataLayout, LayoutOf, Size, TargetDataLayout};
Expand All @@ -24,6 +24,7 @@ use super::{
Immediate, MPlaceTy, Machine, MemPlace, MemPlaceMeta, Memory, OpTy, Operand, Place, PlaceTy,
ScalarMaybeUninit, StackPopJump,
};
use crate::transform::validate::equal_up_to_regions;
use crate::util::storage::AlwaysLiveLocals;

pub struct InterpCx<'mir, 'tcx, M: Machine<'mir, 'tcx>> {
Expand Down Expand Up @@ -220,49 +221,35 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> LayoutOf for InterpCx<'mir, 'tcx,
/// This test should be symmetric, as it is primarily about layout compatibility.
pub(super) fn mir_assign_valid_types<'tcx>(
tcx: TyCtxt<'tcx>,
param_env: ParamEnv<'tcx>,
src: TyAndLayout<'tcx>,
dest: TyAndLayout<'tcx>,
) -> bool {
if src.ty == dest.ty {
// Equal types, all is good.
return true;
}
if src.layout != dest.layout {
// Layout differs, definitely not equal.
// We do this here because Miri would *do the wrong thing* if we allowed layout-changing
// assignments.
return false;
}

// Type-changing assignments can happen for (at least) two reasons:
// 1. `&mut T` -> `&T` gets optimized from a reborrow to a mere assignment.
// 2. Subtyping is used. While all normal lifetimes are erased, higher-ranked types
// with their late-bound lifetimes are still around and can lead to type differences.
// Normalize both of them away.
let normalize = |ty: Ty<'tcx>| {
ty.fold_with(&mut BottomUpFolder {
tcx,
// Normalize all references to immutable.
ty_op: |ty| match ty.kind {
ty::Ref(_, pointee, _) => tcx.mk_imm_ref(tcx.lifetimes.re_erased, pointee),
_ => ty,
},
// We just erase all late-bound lifetimes, but this is not fully correct (FIXME):
// lifetimes in invariant positions could matter (e.g. through associated types).
// We rely on the fact that layout was confirmed to be equal above.
lt_op: |_| tcx.lifetimes.re_erased,
// Leave consts unchanged.
ct_op: |ct| ct,
})
};
normalize(src.ty) == normalize(dest.ty)
// Type-changing assignments can happen when subtyping is used. While
// all normal lifetimes are erased, higher-ranked types with their
// late-bound lifetimes are still around and can lead to type
// differences. So we compare ignoring lifetimes.
if equal_up_to_regions(tcx, param_env, src.ty, dest.ty) {
// Make sure the layout is equal, too -- just to be safe. Miri really
// needs layout equality. For performance reason we skip this check when
// the types are equal. Equal types *can* have different layouts when
// enum downcast is involved (as enum variants carry the type of the
// enum), but those should never occur in assignments.
if cfg!(debug_assertions) || src.ty != dest.ty {
assert_eq!(src.layout, dest.layout);
}
true
} else {
false
}
}

/// Use the already known layout if given (but sanity check in debug mode),
/// or compute the layout.
#[cfg_attr(not(debug_assertions), inline(always))]
pub(super) fn from_known_layout<'tcx>(
tcx: TyCtxtAt<'tcx>,
param_env: ParamEnv<'tcx>,
known_layout: Option<TyAndLayout<'tcx>>,
compute: impl FnOnce() -> InterpResult<'tcx, TyAndLayout<'tcx>>,
) -> InterpResult<'tcx, TyAndLayout<'tcx>> {
Expand All @@ -271,7 +258,7 @@ pub(super) fn from_known_layout<'tcx>(
Some(known_layout) => {
if cfg!(debug_assertions) {
let check_layout = compute()?;
if !mir_assign_valid_types(tcx.tcx, check_layout, known_layout) {
if !mir_assign_valid_types(tcx.tcx, param_env, check_layout, known_layout) {
span_bug!(
tcx.span,
"expected type differs from actual type.\nexpected: {:?}\nactual: {:?}",
Expand Down Expand Up @@ -475,7 +462,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
// have to support that case (mostly by skipping all caching).
match frame.locals.get(local).and_then(|state| state.layout.get()) {
None => {
let layout = from_known_layout(self.tcx, layout, || {
let layout = from_known_layout(self.tcx, self.param_env, layout, || {
let local_ty = frame.body.local_decls[local].ty;
let local_ty =
self.subst_from_frame_and_normalize_erasing_regions(frame, local_ty);
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_mir/interpret/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
// Sanity-check the type we ended up with.
debug_assert!(mir_assign_valid_types(
*self.tcx,
self.param_env,
self.layout_of(self.subst_from_current_frame_and_normalize_erasing_regions(
place.ty(&self.frame().body.local_decls, *self.tcx).ty
))?,
Expand Down Expand Up @@ -570,7 +571,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
// documentation).
let val_val = M::adjust_global_const(self, val_val)?;
// Other cases need layout.
let layout = from_known_layout(self.tcx, layout, || self.layout_of(val.ty))?;
let layout =
from_known_layout(self.tcx, self.param_env, layout, || self.layout_of(val.ty))?;
let op = match val_val {
ConstValue::ByRef { alloc, offset } => {
let id = self.tcx.create_memory_alloc(alloc);
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_mir/interpret/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@ where
// Sanity-check the type we ended up with.
debug_assert!(mir_assign_valid_types(
*self.tcx,
self.param_env,
self.layout_of(self.subst_from_current_frame_and_normalize_erasing_regions(
place.ty(&self.frame().body.local_decls, *self.tcx).ty
))?,
Expand Down Expand Up @@ -855,7 +856,7 @@ where
) -> InterpResult<'tcx> {
// We do NOT compare the types for equality, because well-typed code can
// actually "transmute" `&mut T` to `&T` in an assignment without a cast.
if !mir_assign_valid_types(*self.tcx, src.layout, dest.layout) {
if !mir_assign_valid_types(*self.tcx, self.param_env, src.layout, dest.layout) {
span_bug!(
self.cur_span(),
"type mismatch when copying!\nsrc: {:?},\ndest: {:?}",
Expand Down Expand Up @@ -912,7 +913,7 @@ where
src: OpTy<'tcx, M::PointerTag>,
dest: PlaceTy<'tcx, M::PointerTag>,
) -> InterpResult<'tcx> {
if mir_assign_valid_types(*self.tcx, src.layout, dest.layout) {
if mir_assign_valid_types(*self.tcx, self.param_env, src.layout, dest.layout) {
// Fast path: Just use normal `copy_op`
return self.copy_op(src, dest);
}
Expand Down
Loading