Skip to content

Commit

Permalink
Auto merge of rust-lang#97825 - Dylan-DPC:rollup-ya51k1k, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 5 pull requests

Successful merges:

 - rust-lang#97058 (Various refactors to the incr comp workproduct handling)
 - rust-lang#97301 (Allow unstable items to be re-exported unstably without requiring the feature be enabled)
 - rust-lang#97738 (Fix ICEs from zsts within unsized types with non-zero offsets)
 - rust-lang#97771 (Remove SIGIO reference on Haiku)
 - rust-lang#97808 (Add some unstable target features for the wasm target codegen)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Jun 7, 2022
2 parents 91cacb3 + 9526653 commit 7fe2c4b
Show file tree
Hide file tree
Showing 18 changed files with 284 additions and 115 deletions.
33 changes: 12 additions & 21 deletions compiler/rustc_codegen_cranelift/src/driver/aot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,7 @@ fn emit_module(
let work_product = if backend_config.disable_incr_cache {
None
} else {
rustc_incremental::copy_cgu_workproduct_to_incr_comp_cache_dir(
tcx.sess,
&name,
&Some(tmp_file.clone()),
)
rustc_incremental::copy_cgu_workproduct_to_incr_comp_cache_dir(tcx.sess, &name, &tmp_file)
};

ModuleCodegenResult(
Expand All @@ -84,29 +80,24 @@ fn reuse_workproduct_for_cgu(
cgu: &CodegenUnit<'_>,
work_products: &mut FxHashMap<WorkProductId, WorkProduct>,
) -> CompiledModule {
let mut object = None;
let work_product = cgu.work_product(tcx);
if let Some(saved_file) = &work_product.saved_file {
let obj_out =
tcx.output_filenames(()).temp_path(OutputType::Object, Some(cgu.name().as_str()));
object = Some(obj_out.clone());
let source_file = rustc_incremental::in_incr_comp_dir_sess(&tcx.sess, &saved_file);
if let Err(err) = rustc_fs_util::link_or_copy(&source_file, &obj_out) {
tcx.sess.err(&format!(
"unable to copy {} to {}: {}",
source_file.display(),
obj_out.display(),
err
));
}
let work_product = cgu.previous_work_product(tcx);
let obj_out = tcx.output_filenames(()).temp_path(OutputType::Object, Some(cgu.name().as_str()));
let source_file = rustc_incremental::in_incr_comp_dir_sess(&tcx.sess, &work_product.saved_file);
if let Err(err) = rustc_fs_util::link_or_copy(&source_file, &obj_out) {
tcx.sess.err(&format!(
"unable to copy {} to {}: {}",
source_file.display(),
obj_out.display(),
err
));
}

work_products.insert(cgu.work_product_id(), work_product);

CompiledModule {
name: cgu.name().to_string(),
kind: ModuleKind::Regular,
object,
object: Some(obj_out),
dwarf_object: None,
bytecode: None,
}
Expand Down
54 changes: 25 additions & 29 deletions compiler/rustc_codegen_ssa/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,12 +494,12 @@ fn copy_all_cgu_workproducts_to_incr_comp_cache_dir(
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 path = module.object.as_ref().cloned();

if let Some((id, product)) =
copy_cgu_workproduct_to_incr_comp_cache_dir(sess, &module.name, &path)
{
work_products.insert(id, product);
if let Some(path) = &module.object {
if let Some((id, product)) =
copy_cgu_workproduct_to_incr_comp_cache_dir(sess, &module.name, path)
{
work_products.insert(id, product);
}
}
}

Expand Down Expand Up @@ -853,35 +853,31 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
module: CachedModuleCodegen,
module_config: &ModuleConfig,
) -> WorkItemResult<B> {
assert!(module_config.emit_obj != EmitObj::None);

let incr_comp_session_dir = cgcx.incr_comp_session_dir.as_ref().unwrap();
let mut object = None;
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);
debug!(
"copying pre-existing module `{}` from {:?} to {}",
module.name,
source_file,
obj_out.display()
);
if let Err(err) = link_or_copy(&source_file, &obj_out) {
let diag_handler = cgcx.create_diag_handler();
diag_handler.err(&format!(
"unable to copy {} to {}: {}",
source_file.display(),
obj_out.display(),
err
));
}
let obj_out = cgcx.output_filenames.temp_path(OutputType::Object, Some(&module.name));
let source_file = in_incr_comp_dir(&incr_comp_session_dir, &module.source.saved_file);
debug!(
"copying pre-existing module `{}` from {:?} to {}",
module.name,
source_file,
obj_out.display()
);
if let Err(err) = link_or_copy(&source_file, &obj_out) {
let diag_handler = cgcx.create_diag_handler();
diag_handler.err(&format!(
"unable to copy {} to {}: {}",
source_file.display(),
obj_out.display(),
err
));
}

assert_eq!(object.is_some(), module_config.emit_obj != EmitObj::None);

WorkItemResult::Compiled(CompiledModule {
name: module.name,
kind: ModuleKind::Regular,
object,
object: Some(obj_out),
dwarf_object: None,
bytecode: None,
})
Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,12 @@ pub fn unsize_ptr<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
let mut result = None;
for i in 0..src_layout.fields.count() {
let src_f = src_layout.field(bx.cx(), i);
assert_eq!(src_layout.fields.offset(i).bytes(), 0);
assert_eq!(dst_layout.fields.offset(i).bytes(), 0);
if src_f.is_zst() {
continue;
}

assert_eq!(src_layout.fields.offset(i).bytes(), 0);
assert_eq!(dst_layout.fields.offset(i).bytes(), 0);
assert_eq!(src_layout.size, src_f.size);

let dst_f = dst_layout.field(bx.cx(), i);
Expand Down Expand Up @@ -716,7 +717,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
&ongoing_codegen.coordinator_send,
CachedModuleCodegen {
name: cgu.name().to_string(),
source: cgu.work_product(tcx),
source: cgu.previous_work_product(tcx),
},
);
true
Expand All @@ -727,7 +728,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
&ongoing_codegen.coordinator_send,
CachedModuleCodegen {
name: cgu.name().to_string(),
source: cgu.work_product(tcx),
source: cgu.previous_work_product(tcx),
},
);
true
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_codegen_ssa/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ const WASM_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
("simd128", None),
("atomics", Some(sym::wasm_target_feature)),
("nontrapping-fptoint", Some(sym::wasm_target_feature)),
("bulk-memory", Some(sym::wasm_target_feature)),
("mutable-globals", Some(sym::wasm_target_feature)),
("reference-types", Some(sym::wasm_target_feature)),
];

const BPF_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[("alu32", Some(sym::bpf_target_feature))];
Expand Down
20 changes: 9 additions & 11 deletions compiler/rustc_incremental/src/persist/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,16 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {

for swp in work_products {
let mut all_files_exist = true;
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;

if sess.opts.debugging_opts.incremental_info {
eprintln!(
"incremental: could not find file for work \
let path = in_incr_comp_dir_sess(sess, &swp.work_product.saved_file);
if !path.exists() {
all_files_exist = false;

if sess.opts.debugging_opts.incremental_info {
eprintln!(
"incremental: could not find file for work \
product: {}",
path.display()
);
}
path.display()
);
}
}

Expand Down
9 changes: 2 additions & 7 deletions compiler/rustc_incremental/src/persist/save.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,15 @@ pub fn save_work_product_index(
for (id, wp) in previous_work_products.iter() {
if !new_work_products.contains_key(id) {
work_product::delete_workproduct_files(sess, wp);
debug_assert!(
wp.saved_file.as_ref().map_or(true, |file_name| {
!in_incr_comp_dir_sess(sess, &file_name).exists()
})
);
debug_assert!(!in_incr_comp_dir_sess(sess, &wp.saved_file).exists());
}
}

// Check that we did not delete one of the current work-products:
debug_assert!({
new_work_products
.iter()
.flat_map(|(_, wp)| wp.saved_file.iter())
.map(|name| in_incr_comp_dir_sess(sess, name))
.map(|(_, wp)| in_incr_comp_dir_sess(sess, &wp.saved_file))
.all(|path| path.exists())
});
}
Expand Down
52 changes: 23 additions & 29 deletions compiler/rustc_incremental/src/persist/work_product.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,30 @@ use rustc_fs_util::link_or_copy;
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
use rustc_session::Session;
use std::fs as std_fs;
use std::path::PathBuf;
use std::path::Path;

/// Copies a CGU work product to the incremental compilation directory, so next compilation can find and reuse it.
pub fn copy_cgu_workproduct_to_incr_comp_cache_dir(
sess: &Session,
cgu_name: &str,
path: &Option<PathBuf>,
path: &Path,
) -> Option<(WorkProductId, WorkProduct)> {
debug!("copy_cgu_workproduct_to_incr_comp_cache_dir({:?},{:?})", cgu_name, path);
sess.opts.incremental.as_ref()?;

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;
}
let file_name = format!("{}.o", cgu_name);
let path_in_incr_dir = in_incr_comp_dir_sess(sess, &file_name);
let saved_file = match link_or_copy(path, &path_in_incr_dir) {
Ok(_) => 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;
}
} else {
None
};

let work_product = WorkProduct { cgu_name: cgu_name.to_string(), saved_file };
Expand All @@ -45,17 +41,15 @@ pub fn copy_cgu_workproduct_to_incr_comp_cache_dir(

/// Removes files for a given work product.
pub fn delete_workproduct_files(sess: &Session, work_product: &WorkProduct) {
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(()) => {}
Err(err) => {
sess.warn(&format!(
"file-system error deleting outdated file `{}`: {}",
path.display(),
err
));
}
let path = in_incr_comp_dir_sess(sess, &work_product.saved_file);
match std_fs::remove_file(&path) {
Ok(()) => {}
Err(err) => {
sess.warn(&format!(
"file-system error deleting outdated file `{}`: {}",
path.display(),
err
));
}
}
}
Loading

0 comments on commit 7fe2c4b

Please sign in to comment.