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 6 pull requests #72144

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 6 additions & 3 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,16 @@ def format_build_time(duration):
def default_build_triple():
"""Build triple as in LLVM"""
default_encoding = sys.getdefaultencoding()
required = not sys.platform == 'win32'
ostype = require(["uname", "-s"], exit=required).decode(default_encoding)
cputype = require(['uname', '-m'], exit=required).decode(default_encoding)
required = sys.platform != 'win32'
ostype = require(["uname", "-s"], exit=required)
cputype = require(['uname', '-m'], exit=required)

if ostype is None or cputype is None:
return 'x86_64-pc-windows-msvc'

ostype = ostype.decode(default_encoding)
cputype = cputype.decode(default_encoding)

# The goal here is to come up with the same triple as LLVM would,
# at least for the subset of platforms we're willing to target.
ostype_mapper = {
Expand Down
14 changes: 5 additions & 9 deletions src/librustc_codegen_ssa/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use rustc_errors::{DiagnosticId, FatalError, Handler, Level};
use rustc_fs_util::link_or_copy;
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
use rustc_incremental::{
copy_cgu_workproducts_to_incr_comp_cache_dir, in_incr_comp_dir, in_incr_comp_dir_sess,
copy_cgu_workproduct_to_incr_comp_cache_dir, in_incr_comp_dir, in_incr_comp_dir_sess,
};
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
use rustc_middle::middle::cstore::EncodedMetadata;
Expand Down Expand Up @@ -465,17 +465,13 @@ fn copy_all_cgu_workproducts_to_incr_comp_cache_dir(
return work_products;
}

let _timer = sess.timer("incr_comp_copy_cgu_workproducts");
let _timer = sess.timer("copy_all_cgu_workproducts_to_incr_comp_cache_dir");

for module in compiled_modules.modules.iter().filter(|m| m.kind == ModuleKind::Regular) {
let mut files = vec![];

if let Some(ref path) = module.object {
files.push(path.clone());
}
let path = module.object.as_ref().map(|path| path.clone());

if let Some((id, product)) =
copy_cgu_workproducts_to_incr_comp_cache_dir(sess, &module.name, &files)
copy_cgu_workproduct_to_incr_comp_cache_dir(sess, &module.name, &path)
{
work_products.insert(id, product);
}
Expand Down Expand Up @@ -817,7 +813,7 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
) -> Result<WorkItemResult<B>, FatalError> {
let incr_comp_session_dir = cgcx.incr_comp_session_dir.as_ref().unwrap();
let mut object = None;
for saved_file in &module.source.saved_files {
if let Some(saved_file) = module.source.saved_file {
let obj_out = cgcx.output_filenames.temp_path(OutputType::Object, Some(&module.name));
object = Some(obj_out.clone());
let source_file = in_incr_comp_dir(&incr_comp_session_dir, &saved_file);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_incremental/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub mod assert_module_sources;
mod persist;

pub use assert_dep_graph::assert_dep_graph;
pub use persist::copy_cgu_workproducts_to_incr_comp_cache_dir;
pub use persist::copy_cgu_workproduct_to_incr_comp_cache_dir;
pub use persist::delete_workproduct_files;
pub use persist::dep_graph_tcx_init;
pub use persist::finalize_session_directory;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_incremental/persist/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {

for swp in work_products {
let mut all_files_exist = true;
for file_name in swp.work_product.saved_files.iter() {
if let Some(ref file_name) = swp.work_product.saved_file {
let path = in_incr_comp_dir_sess(sess, file_name);
if !path.exists() {
all_files_exist = false;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_incremental/persist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ pub use load::LoadResult;
pub use load::{load_dep_graph, DepGraphFuture};
pub use save::save_dep_graph;
pub use save::save_work_product_index;
pub use work_product::copy_cgu_workproducts_to_incr_comp_cache_dir;
pub use work_product::copy_cgu_workproduct_to_incr_comp_cache_dir;
pub use work_product::delete_workproduct_files;
8 changes: 4 additions & 4 deletions src/librustc_incremental/persist/save.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ pub fn save_work_product_index(
if !new_work_products.contains_key(id) {
work_product::delete_workproduct_files(sess, wp);
debug_assert!(
wp.saved_files
.iter()
.all(|file_name| { !in_incr_comp_dir_sess(sess, file_name).exists() })
wp.saved_file.as_ref().map_or(true, |file_name| {
!in_incr_comp_dir_sess(sess, &file_name).exists()
})
);
}
}
Expand All @@ -85,7 +85,7 @@ pub fn save_work_product_index(
debug_assert!({
new_work_products
.iter()
.flat_map(|(_, wp)| wp.saved_files.iter())
.flat_map(|(_, wp)| wp.saved_file.iter())
.map(|name| in_incr_comp_dir_sess(sess, name))
.all(|path| path.exists())
});
Expand Down
46 changes: 22 additions & 24 deletions src/librustc_incremental/persist/work_product.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,41 @@ use rustc_session::Session;
use std::fs as std_fs;
use std::path::PathBuf;

pub fn copy_cgu_workproducts_to_incr_comp_cache_dir(
pub fn copy_cgu_workproduct_to_incr_comp_cache_dir(
sess: &Session,
cgu_name: &str,
files: &[PathBuf],
path: &Option<PathBuf>,
) -> Option<(WorkProductId, WorkProduct)> {
debug!("copy_cgu_workproducts_to_incr_comp_cache_dir({:?},{:?})", cgu_name, files);
debug!("copy_cgu_workproduct_to_incr_comp_cache_dir({:?},{:?})", cgu_name, path);
sess.opts.incremental.as_ref()?;

let saved_files = files
.iter()
.map(|path| {
let file_name = format!("{}.o", cgu_name);
let path_in_incr_dir = in_incr_comp_dir_sess(sess, &file_name);
match link_or_copy(path, &path_in_incr_dir) {
Ok(_) => Some(file_name),
Err(err) => {
sess.warn(&format!(
"error copying object file `{}` \
to incremental directory as `{}`: {}",
path.display(),
path_in_incr_dir.display(),
err
));
None
}
let saved_file = if let Some(path) = path {
let file_name = format!("{}.o", cgu_name);
let path_in_incr_dir = in_incr_comp_dir_sess(sess, &file_name);
match link_or_copy(path, &path_in_incr_dir) {
Ok(_) => Some(file_name),
Err(err) => {
sess.warn(&format!(
"error copying object file `{}` to incremental directory as `{}`: {}",
path.display(),
path_in_incr_dir.display(),
err
));
return None;
}
})
.collect::<Option<Vec<_>>>()?;
}
} else {
None
};

let work_product = WorkProduct { cgu_name: cgu_name.to_string(), saved_files };
let work_product = WorkProduct { cgu_name: cgu_name.to_string(), saved_file };

let work_product_id = WorkProductId::from_cgu_name(cgu_name);
Some((work_product_id, work_product))
}

pub fn delete_workproduct_files(sess: &Session, work_product: &WorkProduct) {
for file_name in &work_product.saved_files {
if let Some(ref file_name) = work_product.saved_file {
let path = in_incr_comp_dir_sess(sess, file_name);
match std_fs::remove_file(&path) {
Ok(()) => {}
Expand Down
24 changes: 20 additions & 4 deletions src/librustc_lint/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,27 @@ trait UnusedDelimLint {
);

fn is_expr_delims_necessary(inner: &ast::Expr, followed_by_block: bool) -> bool {
followed_by_block
&& match inner.kind {
ExprKind::Ret(_) | ExprKind::Break(..) => true,
_ => parser::contains_exterior_struct_lit(&inner),
// Prevent false-positives in cases like `fn x() -> u8 { ({ 0 } + 1) }`
let lhs_needs_parens = {
let mut innermost = inner;
loop {
if let ExprKind::Binary(_, lhs, _rhs) = &innermost.kind {
innermost = lhs;
if !rustc_ast::util::classify::expr_requires_semi_to_be_stmt(innermost) {
break true;
}
} else {
break false;
}
}
};

lhs_needs_parens
|| (followed_by_block
&& match inner.kind {
ExprKind::Ret(_) | ExprKind::Break(..) => true,
_ => parser::contains_exterior_struct_lit(&inner),
})
}

fn emit_unused_delims_expr(
Expand Down
28 changes: 18 additions & 10 deletions src/librustc_middle/mir/interpret/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,27 +89,35 @@ pub struct Pointer<Tag = ()> {

static_assert_size!(Pointer, 16);

/// Print the address of a pointer (without the tag)
fn print_ptr_addr<Tag>(ptr: &Pointer<Tag>, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// Forward `alternate` flag to `alloc_id` printing.
if f.alternate() {
write!(f, "{:#?}", ptr.alloc_id)?;
} else {
write!(f, "{:?}", ptr.alloc_id)?;
}
// Print offset only if it is non-zero.
if ptr.offset.bytes() > 0 {
write!(f, "+0x{:x}", ptr.offset.bytes())?;
}
Ok(())
}

// We want the `Debug` output to be readable as it is used by `derive(Debug)` for
// all the Miri types.
// We have to use `Debug` output for the tag, because `()` does not implement
// `Display` so we cannot specialize that.
impl<Tag: fmt::Debug> fmt::Debug for Pointer<Tag> {
default fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if f.alternate() {
write!(f, "{:#?}+0x{:x}[{:?}]", self.alloc_id, self.offset.bytes(), self.tag)
} else {
write!(f, "{:?}+0x{:x}[{:?}]", self.alloc_id, self.offset.bytes(), self.tag)
}
print_ptr_addr(self, f)?;
write!(f, "[{:?}]", self.tag)
}
}
// Specialization for no tag
impl fmt::Debug for Pointer<()> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if f.alternate() {
write!(f, "{:#?}+0x{:x}", self.alloc_id, self.offset.bytes())
} else {
write!(f, "{:?}+0x{:x}", self.alloc_id, self.offset.bytes())
}
print_ptr_addr(self, f)
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/librustc_middle/mir/mono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ pub struct CodegenUnit<'tcx> {
size_estimate: Option<usize>,
}

/// Specifies the linkage type for a `MonoItem`.
///
/// See https://llvm.org/docs/LangRef.html#linkage-types for more details about these variants.
#[derive(Copy, Clone, PartialEq, Debug, RustcEncodable, RustcDecodable, HashStable)]
pub enum Linkage {
External,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_query_system/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -860,8 +860,8 @@ impl<K: DepKind> DepGraph<K> {
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
pub struct WorkProduct {
pub cgu_name: String,
/// Saved files associated with this CGU.
pub saved_files: Vec<String>,
/// Saved file associated with this CGU.
pub saved_file: Option<String>,
}

#[derive(Clone)]
Expand Down
29 changes: 14 additions & 15 deletions src/librustc_typeck/check/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -708,24 +708,24 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// For now, don't suggest casting with `as`.
let can_cast = false;

let mut prefix = String::new();
if let Some(hir::Node::Expr(hir::Expr {
kind: hir::ExprKind::Struct(_, fields, _), ..
let prefix = if let Some(hir::Node::Expr(hir::Expr {
kind: hir::ExprKind::Struct(_, fields, _),
..
})) = self.tcx.hir().find(self.tcx.hir().get_parent_node(expr.hir_id))
{
// `expr` is a literal field for a struct, only suggest if appropriate
for field in *fields {
if field.expr.hir_id == expr.hir_id && field.is_shorthand {
// This is a field literal
prefix = format!("{}: ", field.ident);
break;
}
}
if &prefix == "" {
match (*fields)
.iter()
.find(|field| field.expr.hir_id == expr.hir_id && field.is_shorthand)
{
// This is a field literal
Some(field) => format!("{}: ", field.ident),
// Likely a field was meant, but this field wasn't found. Do not suggest anything.
return false;
None => return false,
}
}
} else {
String::new()
};
if let hir::ExprKind::Call(path, args) = &expr.kind {
if let (hir::ExprKind::Path(hir::QPath::TypeRelative(base_ty, path_segment)), 1) =
(&path.kind, args.len())
Expand Down Expand Up @@ -817,7 +817,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

let suggest_to_change_suffix_or_into =
|err: &mut DiagnosticBuilder<'_>, is_fallible: bool| {
let into_sugg = into_suggestion.clone();
err.span_suggestion(
expr.span,
if literal_is_ty_suffixed(expr) {
Expand All @@ -832,7 +831,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} else if is_fallible {
try_into_suggestion
} else {
into_sugg
into_suggestion.clone()
},
Applicability::MachineApplicable,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ fn main() -> () {
_1 = const b"foo"; // scope 0 at $DIR/byte_slice.rs:5:13: 5:19
// ty::Const
// + ty: &[u8; 3]
// + val: Value(Scalar(alloc0+0x0))
// + val: Value(Scalar(alloc0))
// mir::Constant
// + span: $DIR/byte_slice.rs:5:13: 5:19
// + literal: Const { ty: &[u8; 3], val: Value(Scalar(alloc0+0x0)) }
// + literal: Const { ty: &[u8; 3], val: Value(Scalar(alloc0)) }
StorageLive(_2); // scope 1 at $DIR/byte_slice.rs:6:9: 6:10
_2 = [const 5u8, const 120u8]; // scope 1 at $DIR/byte_slice.rs:6:13: 6:24
// ty::Const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ promoted[0] in BAR: &[&i32; 1] = {
let mut _3: &i32; // in scope 0 at $DIR/const-promotion-extern-static.rs:9:33: 9:34

bb0: {
_3 = const {alloc0+0x0: &i32}; // scope 0 at $DIR/const-promotion-extern-static.rs:9:33: 9:34
_3 = const {alloc0: &i32}; // scope 0 at $DIR/const-promotion-extern-static.rs:9:33: 9:34
// ty::Const
// + ty: &i32
// + val: Value(Scalar(alloc0+0x0))
// + val: Value(Scalar(alloc0))
// mir::Constant
// + span: $DIR/const-promotion-extern-static.rs:9:33: 9:34
// + literal: Const { ty: &i32, val: Value(Scalar(alloc0+0x0)) }
// + literal: Const { ty: &i32, val: Value(Scalar(alloc0)) }
_2 = _3; // scope 0 at $DIR/const-promotion-extern-static.rs:9:32: 9:34
_1 = [move _2]; // scope 0 at $DIR/const-promotion-extern-static.rs:9:31: 9:35
_0 = &_1; // scope 0 at $DIR/const-promotion-extern-static.rs:9:31: 9:35
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
- StorageLive(_3); // scope 0 at $DIR/const-promotion-extern-static.rs:9:31: 9:35
- StorageLive(_4); // scope 0 at $DIR/const-promotion-extern-static.rs:9:32: 9:34
- StorageLive(_5); // scope 0 at $DIR/const-promotion-extern-static.rs:9:33: 9:34
- _5 = const {alloc0+0x0: &i32}; // scope 0 at $DIR/const-promotion-extern-static.rs:9:33: 9:34
- _5 = const {alloc0: &i32}; // scope 0 at $DIR/const-promotion-extern-static.rs:9:33: 9:34
+ _6 = const BAR::promoted[0]; // scope 0 at $DIR/const-promotion-extern-static.rs:9:31: 9:35
// ty::Const
- // + ty: &i32
- // + val: Value(Scalar(alloc0+0x0))
- // + val: Value(Scalar(alloc0))
+ // + ty: &[&i32; 1]
+ // + val: Unevaluated(DefId(0:6 ~ const_promotion_extern_static[317d]::BAR[0]), [], Some(promoted[0]))
// mir::Constant
- // + span: $DIR/const-promotion-extern-static.rs:9:33: 9:34
- // + literal: Const { ty: &i32, val: Value(Scalar(alloc0+0x0)) }
- // + literal: Const { ty: &i32, val: Value(Scalar(alloc0)) }
- _4 = &(*_5); // scope 0 at $DIR/const-promotion-extern-static.rs:9:32: 9:34
- _3 = [move _4]; // scope 0 at $DIR/const-promotion-extern-static.rs:9:31: 9:35
- _2 = &_3; // scope 0 at $DIR/const-promotion-extern-static.rs:9:31: 9:35
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ promoted[0] in FOO: &[&i32; 1] = {
}

bb0: {
_3 = const {alloc2+0x0: &i32}; // scope 0 at $DIR/const-promotion-extern-static.rs:13:42: 13:43
_3 = const {alloc2: &i32}; // scope 0 at $DIR/const-promotion-extern-static.rs:13:42: 13:43
// ty::Const
// + ty: &i32
// + val: Value(Scalar(alloc2+0x0))
// + val: Value(Scalar(alloc2))
// mir::Constant
// + span: $DIR/const-promotion-extern-static.rs:13:42: 13:43
// + literal: Const { ty: &i32, val: Value(Scalar(alloc2+0x0)) }
// + literal: Const { ty: &i32, val: Value(Scalar(alloc2)) }
_2 = _3; // scope 0 at $DIR/const-promotion-extern-static.rs:13:41: 13:43
_1 = [move _2]; // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46
_0 = &_1; // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46
Expand Down
Loading