Skip to content

Commit 3e51277

Browse files
committed
Auto merge of #99014 - Dylan-DPC:rollup-n84y0jk, r=Dylan-DPC
Rollup of 8 pull requests Successful merges: - #96856 (Fix ProjectionElem validation) - #97711 (Improve soundness of rustc_arena) - #98507 (Finishing touches for `#[expect]` (RFC 2383)) - #98692 (rustdoc: Cleanup more FIXMEs) - #98901 (incr: cache dwarf objects in work products) - #98930 (Make MIR basic blocks field public) - #98973 (Remove (unused) inherent impl anchors) - #98981 ( Edit `rustc_mir_dataflow::framework` documentation ) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 20dd693 + 6910d84 commit 3e51277

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+634
-355
lines changed

Diff for: compiler/rustc_arena/src/lib.rs

+19-8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#![feature(rustc_attrs)]
2020
#![cfg_attr(test, feature(test))]
2121
#![feature(strict_provenance)]
22+
#![feature(ptr_const_cast)]
2223

2324
use smallvec::SmallVec;
2425

@@ -27,7 +28,7 @@ use std::cell::{Cell, RefCell};
2728
use std::cmp;
2829
use std::marker::{PhantomData, Send};
2930
use std::mem::{self, MaybeUninit};
30-
use std::ptr;
31+
use std::ptr::{self, NonNull};
3132
use std::slice;
3233

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

5657
struct ArenaChunk<T = u8> {
5758
/// The raw storage for the arena chunk.
58-
storage: Box<[MaybeUninit<T>]>,
59+
storage: NonNull<[MaybeUninit<T>]>,
5960
/// The number of valid entries in the chunk.
6061
entries: usize,
6162
}
6263

64+
unsafe impl<#[may_dangle] T> Drop for ArenaChunk<T> {
65+
fn drop(&mut self) {
66+
unsafe { Box::from_raw(self.storage.as_mut()) };
67+
}
68+
}
69+
6370
impl<T> ArenaChunk<T> {
6471
#[inline]
6572
unsafe fn new(capacity: usize) -> ArenaChunk<T> {
66-
ArenaChunk { storage: Box::new_uninit_slice(capacity), entries: 0 }
73+
ArenaChunk {
74+
storage: NonNull::new(Box::into_raw(Box::new_uninit_slice(capacity))).unwrap(),
75+
entries: 0,
76+
}
6777
}
6878

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

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

8596
// Returns a pointer to the end of the allocated space.
@@ -90,7 +101,7 @@ impl<T> ArenaChunk<T> {
90101
// A pointer as large as possible for zero-sized elements.
91102
ptr::invalid_mut(!0)
92103
} else {
93-
self.start().add(self.storage.len())
104+
self.start().add((*self.storage.as_ptr()).len())
94105
}
95106
}
96107
}
@@ -274,7 +285,7 @@ impl<T> TypedArena<T> {
274285
// If the previous chunk's len is less than HUGE_PAGE
275286
// bytes, then this chunk will be least double the previous
276287
// chunk's size.
277-
new_cap = last_chunk.storage.len().min(HUGE_PAGE / elem_size / 2);
288+
new_cap = (*last_chunk.storage.as_ptr()).len().min(HUGE_PAGE / elem_size / 2);
278289
new_cap *= 2;
279290
} else {
280291
new_cap = PAGE / elem_size;
@@ -382,7 +393,7 @@ impl DroplessArena {
382393
// If the previous chunk's len is less than HUGE_PAGE
383394
// bytes, then this chunk will be least double the previous
384395
// chunk's size.
385-
new_cap = last_chunk.storage.len().min(HUGE_PAGE / 2);
396+
new_cap = (*last_chunk.storage.as_ptr()).len().min(HUGE_PAGE / 2);
386397
new_cap *= 2;
387398
} else {
388399
new_cap = PAGE;

Diff for: compiler/rustc_arena/src/tests.rs

+20-4
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ fn test_arena_alloc_nested() {
7979
#[test]
8080
pub fn test_copy() {
8181
let arena = TypedArena::default();
82-
for _ in 0..100000 {
82+
#[cfg(not(miri))]
83+
const N: usize = 100000;
84+
#[cfg(miri)]
85+
const N: usize = 1000;
86+
for _ in 0..N {
8387
arena.alloc(Point { x: 1, y: 2, z: 3 });
8488
}
8589
}
@@ -106,15 +110,23 @@ struct Noncopy {
106110
#[test]
107111
pub fn test_noncopy() {
108112
let arena = TypedArena::default();
109-
for _ in 0..100000 {
113+
#[cfg(not(miri))]
114+
const N: usize = 100000;
115+
#[cfg(miri)]
116+
const N: usize = 1000;
117+
for _ in 0..N {
110118
arena.alloc(Noncopy { string: "hello world".to_string(), array: vec![1, 2, 3, 4, 5] });
111119
}
112120
}
113121

114122
#[test]
115123
pub fn test_typed_arena_zero_sized() {
116124
let arena = TypedArena::default();
117-
for _ in 0..100000 {
125+
#[cfg(not(miri))]
126+
const N: usize = 100000;
127+
#[cfg(miri)]
128+
const N: usize = 1000;
129+
for _ in 0..N {
118130
arena.alloc(());
119131
}
120132
}
@@ -124,7 +136,11 @@ pub fn test_typed_arena_clear() {
124136
let mut arena = TypedArena::default();
125137
for _ in 0..10 {
126138
arena.clear();
127-
for _ in 0..10000 {
139+
#[cfg(not(miri))]
140+
const N: usize = 10000;
141+
#[cfg(miri)]
142+
const N: usize = 100;
143+
for _ in 0..N {
128144
arena.alloc(Point { x: 1, y: 2, z: 3 });
129145
}
130146
}

Diff for: compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1628,7 +1628,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
16281628
location: Location,
16291629
) -> impl Iterator<Item = Location> + Captures<'tcx> + 'a {
16301630
if location.statement_index == 0 {
1631-
let predecessors = body.predecessors()[location.block].to_vec();
1631+
let predecessors = body.basic_blocks.predecessors()[location.block].to_vec();
16321632
Either::Left(predecessors.into_iter().map(move |bb| body.terminator_loc(bb)))
16331633
} else {
16341634
Either::Right(std::iter::once(Location {

Diff for: compiler/rustc_borrowck/src/invalidation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub(super) fn generate_invalidates<'tcx>(
2626

2727
if let Some(all_facts) = all_facts {
2828
let _prof_timer = tcx.prof.generic_activity("polonius_fact_generation");
29-
let dominators = body.dominators();
29+
let dominators = body.basic_blocks.dominators();
3030
let mut ig = InvalidationGenerator {
3131
all_facts,
3232
borrow_set,

Diff for: compiler/rustc_borrowck/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ fn do_mir_borrowck<'a, 'tcx>(
334334
};
335335
}
336336

337-
let dominators = body.dominators();
337+
let dominators = body.basic_blocks.dominators();
338338

339339
let mut mbcx = MirBorrowckCtxt {
340340
infcx,

Diff for: compiler/rustc_borrowck/src/type_check/liveness/trace.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ impl<'me, 'typeck, 'flow, 'tcx> LivenessResults<'me, 'typeck, 'flow, 'tcx> {
258258

259259
let block = self.cx.elements.to_location(block_start).block;
260260
self.stack.extend(
261-
self.cx.body.predecessors()[block]
261+
self.cx.body.basic_blocks.predecessors()[block]
262262
.iter()
263263
.map(|&pred_bb| self.cx.body.terminator_loc(pred_bb))
264264
.map(|pred_loc| self.cx.elements.point_from_location(pred_loc)),
@@ -354,7 +354,7 @@ impl<'me, 'typeck, 'flow, 'tcx> LivenessResults<'me, 'typeck, 'flow, 'tcx> {
354354
}
355355

356356
let body = self.cx.body;
357-
for &pred_block in body.predecessors()[block].iter() {
357+
for &pred_block in body.basic_blocks.predecessors()[block].iter() {
358358
debug!("compute_drop_live_points_for_block: pred_block = {:?}", pred_block,);
359359

360360
// Check whether the variable is (at least partially)

Diff for: compiler/rustc_codegen_cranelift/src/driver/aot.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ fn emit_module(
6666
let work_product = if backend_config.disable_incr_cache {
6767
None
6868
} else {
69-
rustc_incremental::copy_cgu_workproduct_to_incr_comp_cache_dir(tcx.sess, &name, &tmp_file)
69+
rustc_incremental::copy_cgu_workproduct_to_incr_comp_cache_dir(
70+
tcx.sess,
71+
&name,
72+
&[("o", &tmp_file)],
73+
)
7074
};
7175

7276
ModuleCodegenResult(
@@ -82,7 +86,10 @@ fn reuse_workproduct_for_cgu(
8286
) -> CompiledModule {
8387
let work_product = cgu.previous_work_product(tcx);
8488
let obj_out = tcx.output_filenames(()).temp_path(OutputType::Object, Some(cgu.name().as_str()));
85-
let source_file = rustc_incremental::in_incr_comp_dir_sess(&tcx.sess, &work_product.saved_file);
89+
let source_file = rustc_incremental::in_incr_comp_dir_sess(
90+
&tcx.sess,
91+
&work_product.saved_files.get("o").expect("no saved object file in work product"),
92+
);
8693
if let Err(err) = rustc_fs_util::link_or_copy(&source_file, &obj_out) {
8794
tcx.sess.err(&format!(
8895
"unable to copy {} to {}: {}",

Diff for: compiler/rustc_codegen_ssa/src/back/link.rs

+19-14
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,23 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>(
151151
return;
152152
}
153153

154-
let remove_temps_from_module = |module: &CompiledModule| {
155-
if let Some(ref obj) = module.object {
156-
ensure_removed(sess.diagnostic(), obj);
157-
}
158-
};
154+
let maybe_remove_temps_from_module =
155+
|preserve_objects: bool, preserve_dwarf_objects: bool, module: &CompiledModule| {
156+
if !preserve_objects {
157+
if let Some(ref obj) = module.object {
158+
ensure_removed(sess.diagnostic(), obj);
159+
}
160+
}
161+
162+
if !preserve_dwarf_objects {
163+
if let Some(ref dwo_obj) = module.dwarf_object {
164+
ensure_removed(sess.diagnostic(), dwo_obj);
165+
}
166+
}
167+
};
168+
169+
let remove_temps_from_module =
170+
|module: &CompiledModule| maybe_remove_temps_from_module(false, false, module);
159171

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

179191
for module in &codegen_results.modules {
180-
if !preserve_objects {
181-
remove_temps_from_module(module);
182-
}
183-
184-
if !preserve_dwarf_objects {
185-
if let Some(ref obj) = module.dwarf_object {
186-
ensure_removed(sess.diagnostic(), obj);
187-
}
188-
}
192+
maybe_remove_temps_from_module(preserve_objects, preserve_dwarf_objects, module);
189193
}
190194
});
191195

@@ -649,6 +653,7 @@ fn link_dwarf_object<'a>(
649653
sess.struct_err("linking dwarf objects with thorin failed")
650654
.note(&format!("{:?}", e))
651655
.emit();
656+
sess.abort_if_errors();
652657
}
653658
}
654659
}

Diff for: compiler/rustc_codegen_ssa/src/back/write.rs

+51-24
Original file line numberDiff line numberDiff line change
@@ -494,12 +494,18 @@ fn copy_all_cgu_workproducts_to_incr_comp_cache_dir(
494494
let _timer = sess.timer("copy_all_cgu_workproducts_to_incr_comp_cache_dir");
495495

496496
for module in compiled_modules.modules.iter().filter(|m| m.kind == ModuleKind::Regular) {
497-
if let Some(path) = &module.object {
498-
if let Some((id, product)) =
499-
copy_cgu_workproduct_to_incr_comp_cache_dir(sess, &module.name, path)
500-
{
501-
work_products.insert(id, product);
502-
}
497+
let mut files = Vec::new();
498+
if let Some(object_file_path) = &module.object {
499+
files.push(("o", object_file_path.as_path()));
500+
}
501+
if let Some(dwarf_object_file_path) = &module.dwarf_object {
502+
files.push(("dwo", dwarf_object_file_path.as_path()));
503+
}
504+
505+
if let Some((id, product)) =
506+
copy_cgu_workproduct_to_incr_comp_cache_dir(sess, &module.name, files.as_slice())
507+
{
508+
work_products.insert(id, product);
503509
}
504510
}
505511

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

858864
let incr_comp_session_dir = cgcx.incr_comp_session_dir.as_ref().unwrap();
859-
let obj_out = cgcx.output_filenames.temp_path(OutputType::Object, Some(&module.name));
860-
let source_file = in_incr_comp_dir(&incr_comp_session_dir, &module.source.saved_file);
861-
debug!(
862-
"copying pre-existing module `{}` from {:?} to {}",
863-
module.name,
864-
source_file,
865-
obj_out.display()
865+
866+
let load_from_incr_comp_dir = |output_path: PathBuf, saved_path: &str| {
867+
let source_file = in_incr_comp_dir(&incr_comp_session_dir, saved_path);
868+
debug!(
869+
"copying pre-existing module `{}` from {:?} to {}",
870+
module.name,
871+
source_file,
872+
output_path.display()
873+
);
874+
match link_or_copy(&source_file, &output_path) {
875+
Ok(_) => Some(output_path),
876+
Err(err) => {
877+
let diag_handler = cgcx.create_diag_handler();
878+
diag_handler.err(&format!(
879+
"unable to copy {} to {}: {}",
880+
source_file.display(),
881+
output_path.display(),
882+
err
883+
));
884+
None
885+
}
886+
}
887+
};
888+
889+
let object = load_from_incr_comp_dir(
890+
cgcx.output_filenames.temp_path(OutputType::Object, Some(&module.name)),
891+
&module.source.saved_files.get("o").expect("no saved object file in work product"),
866892
);
867-
if let Err(err) = link_or_copy(&source_file, &obj_out) {
868-
let diag_handler = cgcx.create_diag_handler();
869-
diag_handler.err(&format!(
870-
"unable to copy {} to {}: {}",
871-
source_file.display(),
872-
obj_out.display(),
873-
err
874-
));
875-
}
893+
let dwarf_object =
894+
module.source.saved_files.get("dwo").as_ref().and_then(|saved_dwarf_object_file| {
895+
let dwarf_obj_out = cgcx
896+
.output_filenames
897+
.split_dwarf_path(cgcx.split_debuginfo, cgcx.split_dwarf_kind, Some(&module.name))
898+
.expect(
899+
"saved dwarf object in work product but `split_dwarf_path` returned `None`",
900+
);
901+
load_from_incr_comp_dir(dwarf_obj_out, &saved_dwarf_object_file)
902+
});
876903

877904
WorkItemResult::Compiled(CompiledModule {
878905
name: module.name,
879906
kind: ModuleKind::Regular,
880-
object: Some(obj_out),
881-
dwarf_object: None,
907+
object,
908+
dwarf_object,
882909
bytecode: None,
883910
})
884911
}

Diff for: compiler/rustc_codegen_ssa/src/mir/analyze.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub fn non_ssa_locals<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
1515
fx: &FunctionCx<'a, 'tcx, Bx>,
1616
) -> BitSet<mir::Local> {
1717
let mir = fx.mir;
18-
let dominators = mir.dominators();
18+
let dominators = mir.basic_blocks.dominators();
1919
let locals = mir
2020
.local_decls
2121
.iter()

Diff for: compiler/rustc_const_eval/src/transform/promote_consts.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,8 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
856856
literal: ConstantKind::from_const(_const, tcx),
857857
}))
858858
};
859-
let (blocks, local_decls) = self.source.basic_blocks_and_local_decls_mut();
859+
let blocks = self.source.basic_blocks.as_mut();
860+
let local_decls = &mut self.source.local_decls;
860861
let loc = candidate.location;
861862
let statement = &mut blocks[loc.block].statements[loc.statement_index];
862863
match statement.kind {
@@ -865,7 +866,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
865866
Rvalue::Ref(ref mut region, borrow_kind, ref mut place),
866867
)) => {
867868
// Use the underlying local for this (necessarily interior) borrow.
868-
let ty = local_decls.local_decls()[place.local].ty;
869+
let ty = local_decls[place.local].ty;
869870
let span = statement.source_info.span;
870871

871872
let ref_ty = tcx.mk_ref(

0 commit comments

Comments
 (0)