Skip to content

Commit 13a6aaf

Browse files
committed
Auto merge of #101017 - JohnTitor:rollup-73f2fhb, r=JohnTitor
Rollup of 8 pull requests Successful merges: - #99064 (distinguish the method and associated function diagnostic information) - #99920 (Custom allocator support in `rustc_serialize`) - #100034 ( Elaborate all box dereferences in `ElaborateBoxDerefs`) - #100076 (make slice::{split_at,split_at_unchecked} const functions) - #100604 (Remove unstable Result::into_ok_or_err) - #100933 (Reduce code size of `assert_matches_failed`) - #100978 (Handle `Err` in `ast::LitKind::to_token_lit`.) - #101010 (rustdoc: remove unused CSS for `.multi-column`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 76f3b89 + b4d5f48 commit 13a6aaf

File tree

27 files changed

+187
-255
lines changed

27 files changed

+187
-255
lines changed

compiler/rustc_ast/src/util/literal.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ impl LitKind {
199199
let symbol = if value { kw::True } else { kw::False };
200200
(token::Bool, symbol, None)
201201
}
202-
LitKind::Err => unreachable!(),
202+
// This only shows up in places like `-Zunpretty=hir` output, so we
203+
// don't bother to produce something useful.
204+
LitKind::Err => (token::Err, Symbol::intern("<bad-literal>"), None),
203205
};
204206

205207
token::Lit::new(kind, symbol, suffix)

compiler/rustc_codegen_gcc/patches/0024-core-Disable-portable-simd-test.patch

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ index 06c7be0..359e2e7 100644
1414
@@ -75,7 +75,6 @@
1515
#![feature(never_type)]
1616
#![feature(unwrap_infallible)]
17-
#![feature(result_into_ok_or_err)]
1817
-#![feature(portable_simd)]
1918
#![feature(ptr_metadata)]
2019
#![feature(once_cell)]

compiler/rustc_middle/src/mir/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1531,6 +1531,7 @@ impl<'tcx> Place<'tcx> {
15311531
}
15321532

15331533
impl From<Local> for Place<'_> {
1534+
#[inline]
15341535
fn from(local: Local) -> Self {
15351536
Place { local, projection: List::empty() }
15361537
}

compiler/rustc_mir_dataflow/src/impls/liveness.rs

+65-40
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ use crate::{Analysis, AnalysisDomain, Backward, CallReturnPlaces, GenKill, GenKi
2323
/// [liveness]: https://en.wikipedia.org/wiki/Live_variable_analysis
2424
pub struct MaybeLiveLocals;
2525

26-
impl MaybeLiveLocals {
27-
fn transfer_function<'a, T>(&self, trans: &'a mut T) -> TransferFunction<'a, T> {
28-
TransferFunction(trans)
29-
}
30-
}
31-
3226
impl<'tcx> AnalysisDomain<'tcx> for MaybeLiveLocals {
3327
type Domain = ChunkedBitSet<Local>;
3428
type Direction = Backward;
@@ -54,7 +48,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeLiveLocals {
5448
statement: &mir::Statement<'tcx>,
5549
location: Location,
5650
) {
57-
self.transfer_function(trans).visit_statement(statement, location);
51+
TransferFunction(trans).visit_statement(statement, location);
5852
}
5953

6054
fn terminator_effect(
@@ -63,7 +57,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeLiveLocals {
6357
terminator: &mir::Terminator<'tcx>,
6458
location: Location,
6559
) {
66-
self.transfer_function(trans).visit_terminator(terminator, location);
60+
TransferFunction(trans).visit_terminator(terminator, location);
6761
}
6862

6963
fn call_return_effect(
@@ -85,9 +79,11 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeLiveLocals {
8579
_resume_block: mir::BasicBlock,
8680
resume_place: mir::Place<'tcx>,
8781
) {
88-
if let Some(local) = resume_place.as_local() {
89-
trans.kill(local);
90-
}
82+
YieldResumeEffect(trans).visit_place(
83+
&resume_place,
84+
PlaceContext::MutatingUse(MutatingUseContext::Yield),
85+
Location::START,
86+
)
9187
}
9288
}
9389

@@ -98,28 +94,51 @@ where
9894
T: GenKill<Local>,
9995
{
10096
fn visit_place(&mut self, place: &mir::Place<'tcx>, context: PlaceContext, location: Location) {
101-
let local = place.local;
102-
103-
// We purposefully do not call `super_place` here to avoid calling `visit_local` for this
104-
// place with one of the `Projection` variants of `PlaceContext`.
105-
self.visit_projection(place.as_ref(), context, location);
97+
if let PlaceContext::MutatingUse(MutatingUseContext::Yield) = context {
98+
// The resume place is evaluated and assigned to only after generator resumes, so its
99+
// effect is handled separately in `yield_resume_effect`.
100+
return;
101+
}
106102

107103
match DefUse::for_place(*place, context) {
108-
Some(DefUse::Def) => self.0.kill(local),
109-
Some(DefUse::Use) => self.0.gen(local),
104+
Some(DefUse::Def) => {
105+
if let PlaceContext::MutatingUse(
106+
MutatingUseContext::Call | MutatingUseContext::AsmOutput,
107+
) = context
108+
{
109+
// For the associated terminators, this is only a `Def` when the terminator returns
110+
// "successfully." As such, we handle this case separately in `call_return_effect`
111+
// above. However, if the place looks like `*_5`, this is still unconditionally a use of
112+
// `_5`.
113+
} else {
114+
self.0.kill(place.local);
115+
}
116+
}
117+
Some(DefUse::Use) => self.0.gen(place.local),
110118
None => {}
111119
}
120+
121+
self.visit_projection(place.as_ref(), context, location);
112122
}
113123

114124
fn visit_local(&mut self, local: Local, context: PlaceContext, _: Location) {
115-
// Because we do not call `super_place` above, `visit_local` is only called for locals that
116-
// do not appear as part of a `Place` in the MIR. This handles cases like the implicit use
117-
// of the return place in a `Return` terminator or the index in an `Index` projection.
118-
match DefUse::for_place(local.into(), context) {
119-
Some(DefUse::Def) => self.0.kill(local),
120-
Some(DefUse::Use) => self.0.gen(local),
121-
None => {}
122-
}
125+
DefUse::apply(self.0, local.into(), context);
126+
}
127+
}
128+
129+
struct YieldResumeEffect<'a, T>(&'a mut T);
130+
131+
impl<'tcx, T> Visitor<'tcx> for YieldResumeEffect<'_, T>
132+
where
133+
T: GenKill<Local>,
134+
{
135+
fn visit_place(&mut self, place: &mir::Place<'tcx>, context: PlaceContext, location: Location) {
136+
DefUse::apply(self.0, *place, context);
137+
self.visit_projection(place.as_ref(), context, location);
138+
}
139+
140+
fn visit_local(&mut self, local: Local, context: PlaceContext, _: Location) {
141+
DefUse::apply(self.0, local.into(), context);
123142
}
124143
}
125144

@@ -130,11 +149,25 @@ enum DefUse {
130149
}
131150

132151
impl DefUse {
152+
fn apply<'tcx>(trans: &mut impl GenKill<Local>, place: Place<'tcx>, context: PlaceContext) {
153+
match DefUse::for_place(place, context) {
154+
Some(DefUse::Def) => trans.kill(place.local),
155+
Some(DefUse::Use) => trans.gen(place.local),
156+
None => {}
157+
}
158+
}
159+
133160
fn for_place<'tcx>(place: Place<'tcx>, context: PlaceContext) -> Option<DefUse> {
134161
match context {
135162
PlaceContext::NonUse(_) => None,
136163

137-
PlaceContext::MutatingUse(MutatingUseContext::Store | MutatingUseContext::Deinit) => {
164+
PlaceContext::MutatingUse(
165+
MutatingUseContext::Call
166+
| MutatingUseContext::Yield
167+
| MutatingUseContext::AsmOutput
168+
| MutatingUseContext::Store
169+
| MutatingUseContext::Deinit,
170+
) => {
138171
if place.is_indirect() {
139172
// Treat derefs as a use of the base local. `*p = 4` is not a def of `p` but a
140173
// use.
@@ -152,16 +185,6 @@ impl DefUse {
152185
place.is_indirect().then_some(DefUse::Use)
153186
}
154187

155-
// For the associated terminators, this is only a `Def` when the terminator returns
156-
// "successfully." As such, we handle this case separately in `call_return_effect`
157-
// above. However, if the place looks like `*_5`, this is still unconditionally a use of
158-
// `_5`.
159-
PlaceContext::MutatingUse(
160-
MutatingUseContext::Call
161-
| MutatingUseContext::Yield
162-
| MutatingUseContext::AsmOutput,
163-
) => place.is_indirect().then_some(DefUse::Use),
164-
165188
// All other contexts are uses...
166189
PlaceContext::MutatingUse(
167190
MutatingUseContext::AddressOf
@@ -290,8 +313,10 @@ impl<'a, 'tcx> Analysis<'tcx> for MaybeTransitiveLiveLocals<'a> {
290313
_resume_block: mir::BasicBlock,
291314
resume_place: mir::Place<'tcx>,
292315
) {
293-
if let Some(local) = resume_place.as_local() {
294-
trans.remove(local);
295-
}
316+
YieldResumeEffect(trans).visit_place(
317+
&resume_place,
318+
PlaceContext::MutatingUse(MutatingUseContext::Yield),
319+
Location::START,
320+
)
296321
}
297322
}

compiler/rustc_mir_transform/src/elaborate_box_derefs.rs

+2-21
Original file line numberDiff line numberDiff line change
@@ -107,27 +107,8 @@ impl<'tcx> MirPass<'tcx> for ElaborateBoxDerefs {
107107
let mut visitor =
108108
ElaborateBoxDerefVisitor { tcx, unique_did, nonnull_did, local_decls, patch };
109109

110-
for (block, BasicBlockData { statements, terminator, .. }) in
111-
body.basic_blocks.as_mut_preserves_cfg().iter_enumerated_mut()
112-
{
113-
let mut index = 0;
114-
for statement in statements {
115-
let location = Location { block, statement_index: index };
116-
visitor.visit_statement(statement, location);
117-
index += 1;
118-
}
119-
120-
let location = Location { block, statement_index: index };
121-
match terminator {
122-
// yielding into a box is handled when lowering generators
123-
Some(Terminator { kind: TerminatorKind::Yield { value, .. }, .. }) => {
124-
visitor.visit_operand(value, location);
125-
}
126-
Some(terminator) => {
127-
visitor.visit_terminator(terminator, location);
128-
}
129-
None => {}
130-
}
110+
for (block, data) in body.basic_blocks.as_mut_preserves_cfg().iter_enumerated_mut() {
111+
visitor.visit_basic_block_data(block, data);
131112
}
132113

133114
visitor.patch.apply(body);

compiler/rustc_mir_transform/src/generator.rs

+7-81
Original file line numberDiff line numberDiff line change
@@ -1182,8 +1182,6 @@ fn create_cases<'tcx>(
11821182
transform: &TransformVisitor<'tcx>,
11831183
operation: Operation,
11841184
) -> Vec<(usize, BasicBlock)> {
1185-
let tcx = transform.tcx;
1186-
11871185
let source_info = SourceInfo::outermost(body.span);
11881186

11891187
transform
@@ -1216,85 +1214,13 @@ fn create_cases<'tcx>(
12161214
if operation == Operation::Resume {
12171215
// Move the resume argument to the destination place of the `Yield` terminator
12181216
let resume_arg = Local::new(2); // 0 = return, 1 = self
1219-
1220-
// handle `box yield` properly
1221-
let box_place = if let [projection @ .., ProjectionElem::Deref] =
1222-
&**point.resume_arg.projection
1223-
{
1224-
let box_place =
1225-
Place::from(point.resume_arg.local).project_deeper(projection, tcx);
1226-
1227-
let box_ty = box_place.ty(&body.local_decls, tcx).ty;
1228-
1229-
if box_ty.is_box() { Some((box_place, box_ty)) } else { None }
1230-
} else {
1231-
None
1232-
};
1233-
1234-
if let Some((box_place, box_ty)) = box_place {
1235-
let unique_did = box_ty
1236-
.ty_adt_def()
1237-
.expect("expected Box to be an Adt")
1238-
.non_enum_variant()
1239-
.fields[0]
1240-
.did;
1241-
1242-
let Some(nonnull_def) = tcx.type_of(unique_did).ty_adt_def() else {
1243-
span_bug!(tcx.def_span(unique_did), "expected Box to contain Unique")
1244-
};
1245-
1246-
let nonnull_did = nonnull_def.non_enum_variant().fields[0].did;
1247-
1248-
let (unique_ty, nonnull_ty, ptr_ty) =
1249-
crate::elaborate_box_derefs::build_ptr_tys(
1250-
tcx,
1251-
box_ty.boxed_ty(),
1252-
unique_did,
1253-
nonnull_did,
1254-
);
1255-
1256-
let ptr_local = body.local_decls.push(LocalDecl::new(ptr_ty, body.span));
1257-
1258-
statements.push(Statement {
1259-
source_info,
1260-
kind: StatementKind::StorageLive(ptr_local),
1261-
});
1262-
1263-
statements.push(Statement {
1264-
source_info,
1265-
kind: StatementKind::Assign(Box::new((
1266-
Place::from(ptr_local),
1267-
Rvalue::Use(Operand::Copy(box_place.project_deeper(
1268-
&crate::elaborate_box_derefs::build_projection(
1269-
unique_ty, nonnull_ty, ptr_ty,
1270-
),
1271-
tcx,
1272-
))),
1273-
))),
1274-
});
1275-
1276-
statements.push(Statement {
1277-
source_info,
1278-
kind: StatementKind::Assign(Box::new((
1279-
Place::from(ptr_local)
1280-
.project_deeper(&[ProjectionElem::Deref], tcx),
1281-
Rvalue::Use(Operand::Move(resume_arg.into())),
1282-
))),
1283-
});
1284-
1285-
statements.push(Statement {
1286-
source_info,
1287-
kind: StatementKind::StorageDead(ptr_local),
1288-
});
1289-
} else {
1290-
statements.push(Statement {
1291-
source_info,
1292-
kind: StatementKind::Assign(Box::new((
1293-
point.resume_arg,
1294-
Rvalue::Use(Operand::Move(resume_arg.into())),
1295-
))),
1296-
});
1297-
}
1217+
statements.push(Statement {
1218+
source_info,
1219+
kind: StatementKind::Assign(Box::new((
1220+
point.resume_arg,
1221+
Rvalue::Use(Operand::Move(resume_arg.into())),
1222+
))),
1223+
});
12981224
}
12991225

13001226
// Then jump to the real target

compiler/rustc_serialize/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Core encoding and decoding interfaces.
1616
#![feature(maybe_uninit_slice)]
1717
#![feature(let_else)]
1818
#![feature(new_uninit)]
19+
#![feature(allocator_api)]
1920
#![cfg_attr(test, feature(test))]
2021
#![allow(rustc::internal)]
2122
#![deny(rustc::untranslatable_diagnostic)]

compiler/rustc_serialize/src/serialize.rs

+15-11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Core encoding and decoding interfaces.
55
*/
66

7+
use std::alloc::Allocator;
78
use std::borrow::Cow;
89
use std::cell::{Cell, RefCell};
910
use std::marker::PhantomData;
@@ -229,9 +230,9 @@ impl<D: Decoder, T> Decodable<D> for PhantomData<T> {
229230
}
230231
}
231232

232-
impl<D: Decoder, T: Decodable<D>> Decodable<D> for Box<[T]> {
233-
fn decode(d: &mut D) -> Box<[T]> {
234-
let v: Vec<T> = Decodable::decode(d);
233+
impl<D: Decoder, A: Allocator + Default, T: Decodable<D>> Decodable<D> for Box<[T], A> {
234+
fn decode(d: &mut D) -> Box<[T], A> {
235+
let v: Vec<T, A> = Decodable::decode(d);
235236
v.into_boxed_slice()
236237
}
237238
}
@@ -264,12 +265,13 @@ impl<S: Encoder, T: Encodable<S>> Encodable<S> for Vec<T> {
264265
}
265266
}
266267

267-
impl<D: Decoder, T: Decodable<D>> Decodable<D> for Vec<T> {
268-
default fn decode(d: &mut D) -> Vec<T> {
268+
impl<D: Decoder, T: Decodable<D>, A: Allocator + Default> Decodable<D> for Vec<T, A> {
269+
default fn decode(d: &mut D) -> Vec<T, A> {
269270
let len = d.read_usize();
271+
let allocator = A::default();
270272
// SAFETY: we set the capacity in advance, only write elements, and
271273
// only set the length at the end once the writing has succeeded.
272-
let mut vec = Vec::with_capacity(len);
274+
let mut vec = Vec::with_capacity_in(len, allocator);
273275
unsafe {
274276
let ptr: *mut T = vec.as_mut_ptr();
275277
for i in 0..len {
@@ -457,13 +459,15 @@ impl<D: Decoder, T: Decodable<D>> Decodable<D> for Arc<T> {
457459
}
458460
}
459461

460-
impl<S: Encoder, T: ?Sized + Encodable<S>> Encodable<S> for Box<T> {
462+
impl<S: Encoder, T: ?Sized + Encodable<S>, A: Allocator + Default> Encodable<S> for Box<T, A> {
461463
fn encode(&self, s: &mut S) {
462-
(**self).encode(s);
464+
(**self).encode(s)
463465
}
464466
}
465-
impl<D: Decoder, T: Decodable<D>> Decodable<D> for Box<T> {
466-
fn decode(d: &mut D) -> Box<T> {
467-
Box::new(Decodable::decode(d))
467+
468+
impl<D: Decoder, A: Allocator + Default, T: Decodable<D>> Decodable<D> for Box<T, A> {
469+
fn decode(d: &mut D) -> Box<T, A> {
470+
let allocator = A::default();
471+
Box::new_in(Decodable::decode(d), allocator)
468472
}
469473
}

0 commit comments

Comments
 (0)