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 #99003

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b22450f
created tcpstream quickack trait
Apr 22, 2022
907ea55
Adapt tests to be able to run in miri
Nilstrieb Jun 3, 2022
4d67f5b
Remove needless FIXME
camelid Jun 29, 2022
8192288
Replace weird handling of edge case with panic
camelid Jun 29, 2022
2d2fd31
Remove FIXME that hasn't been an issue in practice
camelid Jun 29, 2022
a2799b2
fix projectionelem validation
beepster4096 May 9, 2022
8371a03
incr: cache dwarf objects in work products
davidtwco Jul 4, 2022
fc641f2
ssa: remove dwo of metadata and allocator module
davidtwco Jul 6, 2022
e106523
ssa: abort if dwarf packaging fails
davidtwco Jul 6, 2022
211fb66
Fix stacked borrows violation in rustc_arena
Nilstrieb Jun 3, 2022
14d288f
socket `set_mark` addition.
devnexen Apr 23, 2022
48ef00e
doc additions
devnexen Apr 27, 2022
10f5a19
changes from feedback
devnexen Jul 6, 2022
6c6388c
Document, that some lint have to be expected on the crate level (RFC …
xFrednet Jun 16, 2022
c8b4873
Add function to manually fulfill lint expectations (RFC 2383)
xFrednet Jun 16, 2022
a2810cd
Fix `#[expect]` and `#[allow]` for `clippy::duplicate_mod`
xFrednet Jun 25, 2022
825fedd
Rollup merge of #96324 - berendjan:set_tcp_quickack, r=dtolnay
Dylan-DPC Jul 7, 2022
973a3e9
Rollup merge of #96334 - devnexen:socket_mark, r=dtolnay
Dylan-DPC Jul 7, 2022
7a9ca42
Rollup merge of #96856 - DrMeepster:fix_projection_validation, r=Icnr
Dylan-DPC Jul 7, 2022
43d07ca
Rollup merge of #97711 - Nilstrieb:rustc-arena-ub, r=wesleywiser
Dylan-DPC Jul 7, 2022
93ce6fd
Rollup merge of #98507 - xFrednet:rfc-2383-manual-expectation-magic, …
Dylan-DPC Jul 7, 2022
b049ed6
Rollup merge of #98692 - camelid:more-fixmes, r=GuillaumeGomez
Dylan-DPC Jul 7, 2022
05ba538
Rollup merge of #98901 - davidtwco:split-dwarf-incr-workproduct, r=mi…
Dylan-DPC Jul 7, 2022
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
27 changes: 19 additions & 8 deletions compiler/rustc_arena/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#![feature(rustc_attrs)]
#![cfg_attr(test, feature(test))]
#![feature(strict_provenance)]
#![feature(ptr_const_cast)]

use smallvec::SmallVec;

Expand All @@ -27,7 +28,7 @@ use std::cell::{Cell, RefCell};
use std::cmp;
use std::marker::{PhantomData, Send};
use std::mem::{self, MaybeUninit};
use std::ptr;
use std::ptr::{self, NonNull};
use std::slice;

#[inline(never)]
Expand Down Expand Up @@ -55,15 +56,24 @@ pub struct TypedArena<T> {

struct ArenaChunk<T = u8> {
/// The raw storage for the arena chunk.
storage: Box<[MaybeUninit<T>]>,
storage: NonNull<[MaybeUninit<T>]>,
/// The number of valid entries in the chunk.
entries: usize,
}

unsafe impl<#[may_dangle] T> Drop for ArenaChunk<T> {
fn drop(&mut self) {
unsafe { Box::from_raw(self.storage.as_mut()) };
}
}

impl<T> ArenaChunk<T> {
#[inline]
unsafe fn new(capacity: usize) -> ArenaChunk<T> {
ArenaChunk { storage: Box::new_uninit_slice(capacity), entries: 0 }
ArenaChunk {
storage: NonNull::new(Box::into_raw(Box::new_uninit_slice(capacity))).unwrap(),
entries: 0,
}
}

/// Destroys this arena chunk.
Expand All @@ -72,14 +82,15 @@ impl<T> ArenaChunk<T> {
// The branch on needs_drop() is an -O1 performance optimization.
// Without the branch, dropping TypedArena<u8> takes linear time.
if mem::needs_drop::<T>() {
ptr::drop_in_place(MaybeUninit::slice_assume_init_mut(&mut self.storage[..len]));
let slice = &mut *(self.storage.as_mut());
ptr::drop_in_place(MaybeUninit::slice_assume_init_mut(&mut slice[..len]));
}
}

// Returns a pointer to the first allocated object.
#[inline]
fn start(&mut self) -> *mut T {
MaybeUninit::slice_as_mut_ptr(&mut self.storage)
self.storage.as_ptr() as *mut T
}

// Returns a pointer to the end of the allocated space.
Expand All @@ -90,7 +101,7 @@ impl<T> ArenaChunk<T> {
// A pointer as large as possible for zero-sized elements.
ptr::invalid_mut(!0)
} else {
self.start().add(self.storage.len())
self.start().add((*self.storage.as_ptr()).len())
}
}
}
Expand Down Expand Up @@ -274,7 +285,7 @@ impl<T> TypedArena<T> {
// If the previous chunk's len is less than HUGE_PAGE
// bytes, then this chunk will be least double the previous
// chunk's size.
new_cap = last_chunk.storage.len().min(HUGE_PAGE / elem_size / 2);
new_cap = (*last_chunk.storage.as_ptr()).len().min(HUGE_PAGE / elem_size / 2);
new_cap *= 2;
} else {
new_cap = PAGE / elem_size;
Expand Down Expand Up @@ -382,7 +393,7 @@ impl DroplessArena {
// If the previous chunk's len is less than HUGE_PAGE
// bytes, then this chunk will be least double the previous
// chunk's size.
new_cap = last_chunk.storage.len().min(HUGE_PAGE / 2);
new_cap = (*last_chunk.storage.as_ptr()).len().min(HUGE_PAGE / 2);
new_cap *= 2;
} else {
new_cap = PAGE;
Expand Down
24 changes: 20 additions & 4 deletions compiler/rustc_arena/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ fn test_arena_alloc_nested() {
#[test]
pub fn test_copy() {
let arena = TypedArena::default();
for _ in 0..100000 {
#[cfg(not(miri))]
const N: usize = 100000;
#[cfg(miri)]
const N: usize = 1000;
for _ in 0..N {
arena.alloc(Point { x: 1, y: 2, z: 3 });
}
}
Expand All @@ -106,15 +110,23 @@ struct Noncopy {
#[test]
pub fn test_noncopy() {
let arena = TypedArena::default();
for _ in 0..100000 {
#[cfg(not(miri))]
const N: usize = 100000;
#[cfg(miri)]
const N: usize = 1000;
for _ in 0..N {
arena.alloc(Noncopy { string: "hello world".to_string(), array: vec![1, 2, 3, 4, 5] });
}
}

#[test]
pub fn test_typed_arena_zero_sized() {
let arena = TypedArena::default();
for _ in 0..100000 {
#[cfg(not(miri))]
const N: usize = 100000;
#[cfg(miri)]
const N: usize = 1000;
for _ in 0..N {
arena.alloc(());
}
}
Expand All @@ -124,7 +136,11 @@ pub fn test_typed_arena_clear() {
let mut arena = TypedArena::default();
for _ in 0..10 {
arena.clear();
for _ in 0..10000 {
#[cfg(not(miri))]
const N: usize = 10000;
#[cfg(miri)]
const N: usize = 100;
for _ in 0..N {
arena.alloc(Point { x: 1, y: 2, z: 3 });
}
}
Expand Down
11 changes: 9 additions & 2 deletions compiler/rustc_codegen_cranelift/src/driver/aot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ 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, &tmp_file)
rustc_incremental::copy_cgu_workproduct_to_incr_comp_cache_dir(
tcx.sess,
&name,
&[("o", &tmp_file)],
)
};

ModuleCodegenResult(
Expand All @@ -82,7 +86,10 @@ fn reuse_workproduct_for_cgu(
) -> CompiledModule {
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);
let source_file = rustc_incremental::in_incr_comp_dir_sess(
&tcx.sess,
&work_product.saved_files.get("o").expect("no saved object file in work product"),
);
if let Err(err) = rustc_fs_util::link_or_copy(&source_file, &obj_out) {
tcx.sess.err(&format!(
"unable to copy {} to {}: {}",
Expand Down
33 changes: 19 additions & 14 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,23 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>(
return;
}

let remove_temps_from_module = |module: &CompiledModule| {
if let Some(ref obj) = module.object {
ensure_removed(sess.diagnostic(), obj);
}
};
let maybe_remove_temps_from_module =
|preserve_objects: bool, preserve_dwarf_objects: bool, module: &CompiledModule| {
if !preserve_objects {
if let Some(ref obj) = module.object {
ensure_removed(sess.diagnostic(), obj);
}
}

if !preserve_dwarf_objects {
if let Some(ref dwo_obj) = module.dwarf_object {
ensure_removed(sess.diagnostic(), dwo_obj);
}
}
};

let remove_temps_from_module =
|module: &CompiledModule| maybe_remove_temps_from_module(false, false, module);

// Otherwise, always remove the metadata and allocator module temporaries.
if let Some(ref metadata_module) = codegen_results.metadata_module {
Expand All @@ -177,15 +189,7 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>(
debug!(?preserve_objects, ?preserve_dwarf_objects);

for module in &codegen_results.modules {
if !preserve_objects {
remove_temps_from_module(module);
}

if !preserve_dwarf_objects {
if let Some(ref obj) = module.dwarf_object {
ensure_removed(sess.diagnostic(), obj);
}
}
maybe_remove_temps_from_module(preserve_objects, preserve_dwarf_objects, module);
}
});

Expand Down Expand Up @@ -649,6 +653,7 @@ fn link_dwarf_object<'a>(
sess.struct_err("linking dwarf objects with thorin failed")
.note(&format!("{:?}", e))
.emit();
sess.abort_if_errors();
}
}
}
Expand Down
75 changes: 51 additions & 24 deletions compiler/rustc_codegen_ssa/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,12 +494,18 @@ 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) {
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);
}
let mut files = Vec::new();
if let Some(object_file_path) = &module.object {
files.push(("o", object_file_path.as_path()));
}
if let Some(dwarf_object_file_path) = &module.dwarf_object {
files.push(("dwo", dwarf_object_file_path.as_path()));
}

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

Expand Down Expand Up @@ -856,29 +862,50 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
assert!(module_config.emit_obj != EmitObj::None);

let incr_comp_session_dir = cgcx.incr_comp_session_dir.as_ref().unwrap();
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()

let load_from_incr_comp_dir = |output_path: PathBuf, saved_path: &str| {
let source_file = in_incr_comp_dir(&incr_comp_session_dir, saved_path);
debug!(
"copying pre-existing module `{}` from {:?} to {}",
module.name,
source_file,
output_path.display()
);
match link_or_copy(&source_file, &output_path) {
Ok(_) => Some(output_path),
Err(err) => {
let diag_handler = cgcx.create_diag_handler();
diag_handler.err(&format!(
"unable to copy {} to {}: {}",
source_file.display(),
output_path.display(),
err
));
None
}
}
};

let object = load_from_incr_comp_dir(
cgcx.output_filenames.temp_path(OutputType::Object, Some(&module.name)),
&module.source.saved_files.get("o").expect("no saved object file in work product"),
);
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 dwarf_object =
module.source.saved_files.get("dwo").as_ref().and_then(|saved_dwarf_object_file| {
let dwarf_obj_out = cgcx
.output_filenames
.split_dwarf_path(cgcx.split_debuginfo, cgcx.split_dwarf_kind, Some(&module.name))
.expect(
"saved dwarf object in work product but `split_dwarf_path` returned `None`",
);
load_from_incr_comp_dir(dwarf_obj_out, &saved_dwarf_object_file)
});

WorkItemResult::Compiled(CompiledModule {
name: module.name,
kind: ModuleKind::Regular,
object: Some(obj_out),
dwarf_object: None,
object,
dwarf_object,
bytecode: None,
})
}
Expand Down
49 changes: 43 additions & 6 deletions compiler/rustc_const_eval/src/transform/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use rustc_middle::mir::{
Statement, StatementKind, Terminator, TerminatorKind, UnOp, START_BLOCK,
};
use rustc_middle::ty::fold::BottomUpFolder;
use rustc_middle::ty::subst::Subst;
use rustc_middle::ty::{self, InstanceDef, ParamEnv, Ty, TyCtxt, TypeFoldable, TypeVisitable};
use rustc_mir_dataflow::impls::MaybeStorageLive;
use rustc_mir_dataflow::storage::always_live_locals;
Expand Down Expand Up @@ -275,7 +276,14 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
}
};

match parent_ty.ty.kind() {
let kind = match parent_ty.ty.kind() {
&ty::Opaque(def_id, substs) => {
self.tcx.bound_type_of(def_id).subst(self.tcx, substs).kind()
}
kind => kind,
};

match kind {
ty::Tuple(fields) => {
let Some(f_ty) = fields.get(f.as_usize()) else {
fail_out_of_bounds(self, location);
Expand All @@ -299,12 +307,39 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
};
check_equal(self, location, f_ty);
}
ty::Generator(_, substs, _) => {
let substs = substs.as_generator();
let Some(f_ty) = substs.upvar_tys().nth(f.as_usize()) else {
fail_out_of_bounds(self, location);
return;
&ty::Generator(def_id, substs, _) => {
let f_ty = if let Some(var) = parent_ty.variant_index {
let gen_body = if def_id == self.body.source.def_id() {
self.body
} else {
self.tcx.optimized_mir(def_id)
};

let Some(layout) = gen_body.generator_layout() else {
self.fail(location, format!("No generator layout for {:?}", parent_ty));
return;
};

let Some(&local) = layout.variant_fields[var].get(f) else {
fail_out_of_bounds(self, location);
return;
};

let Some(&f_ty) = layout.field_tys.get(local) else {
self.fail(location, format!("Out of bounds local {:?} for {:?}", local, parent_ty));
return;
};

f_ty
} else {
let Some(f_ty) = substs.as_generator().prefix_tys().nth(f.index()) else {
fail_out_of_bounds(self, location);
return;
};

f_ty
};

check_equal(self, location, f_ty);
}
_ => {
Expand All @@ -328,6 +363,8 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
{
self.fail(location, format!("{:?}, has deref at the wrong place", place));
}

self.super_place(place, cntxt, location);
}

fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) {
Expand Down
Loading