Skip to content

Commit ddf70f1

Browse files
committed
Auto merge of rust-lang#129994 - matthiaskrgr:rollup-zkj4ekl, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#128820 (fix: get llvm type of global val) - rust-lang#129028 (`impl_trait_overcaptures`: Don't worry about uncaptured contravariant lifetimes if they outlive a captured lifetime) - rust-lang#129471 ([rustdoc] Sort impl associated items by kinds and then by appearance) - rust-lang#129706 (Rename dump of coroutine by-move-body to be more consistent, fix ICE in dump_mir) - rust-lang#129720 (Simplify DestProp memory management) - rust-lang#129796 (Unify scraped examples with other code examples) - rust-lang#129938 (Elaborate on deriving vs implementing `Copy`) - rust-lang#129973 (run_make_support: rename `Command::stdin` to `stdin_buf` and add `std{in,out,err}` config helpers) r? `@ghost` `@rustbot` modify labels: rollup
2 parents eb33b43 + fee6c0a commit ddf70f1

File tree

60 files changed

+1074
-450
lines changed

Some content is hidden

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

60 files changed

+1074
-450
lines changed

Diff for: compiler/rustc_codegen_llvm/src/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ impl<'ll> CodegenCx<'ll, '_> {
390390
let val_llty = self.val_ty(v);
391391

392392
let g = self.get_static_inner(def_id, val_llty);
393-
let llty = self.val_ty(g);
393+
let llty = llvm::LLVMGlobalGetValueType(g);
394394

395395
let g = if val_llty == llty {
396396
g

Diff for: compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+1
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,7 @@ unsafe extern "C" {
974974
pub fn LLVMGetAlignment(Global: &Value) -> c_uint;
975975
pub fn LLVMSetAlignment(Global: &Value, Bytes: c_uint);
976976
pub fn LLVMSetDLLStorageClass(V: &Value, C: DLLStorageClass);
977+
pub fn LLVMGlobalGetValueType(Global: &Value) -> &Type;
977978

978979
// Operations on global variables
979980
pub fn LLVMIsAGlobalVariable(GlobalVar: &Value) -> Option<&Value>;

Diff for: compiler/rustc_lint/src/impl_trait_overcaptures.rs

+287-88
Large diffs are not rendered by default.

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

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
3131
#![doc(rust_logo)]
3232
#![feature(array_windows)]
33+
#![feature(assert_matches)]
3334
#![feature(box_patterns)]
3435
#![feature(control_flow_enum)]
3536
#![feature(extract_if)]

Diff for: compiler/rustc_middle/src/mir/pretty.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,9 @@ fn write_mir_sig(tcx: TyCtxt<'_>, body: &Body<'_>, w: &mut dyn io::Write) -> io:
612612
let def_id = body.source.def_id();
613613
let kind = tcx.def_kind(def_id);
614614
let is_function = match kind {
615-
DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(..) => true,
615+
DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(..) | DefKind::SyntheticCoroutineBody => {
616+
true
617+
}
616618
_ => tcx.is_closure_like(def_id),
617619
};
618620
match (kind, body.source.promoted) {

Diff for: compiler/rustc_mir_transform/src/coroutine/by_move_body.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,12 @@ pub fn coroutine_by_move_body_def_id<'tcx>(
207207

208208
let mut by_move_body = body.clone();
209209
MakeByMoveBody { tcx, field_remapping, by_move_coroutine_ty }.visit_body(&mut by_move_body);
210-
dump_mir(tcx, false, "coroutine_by_move", &0, &by_move_body, |_, _| Ok(()));
211210

212-
let body_def = tcx.create_def(coroutine_def_id, kw::Empty, DefKind::SyntheticCoroutineBody);
211+
// This will always be `{closure#1}`, since the original coroutine is `{closure#0}`.
212+
let body_def = tcx.create_def(parent_def_id, kw::Empty, DefKind::SyntheticCoroutineBody);
213213
by_move_body.source =
214214
mir::MirSource::from_instance(InstanceKind::Item(body_def.def_id().to_def_id()));
215+
dump_mir(tcx, false, "built", &"after", &by_move_body, |_, _| Ok(()));
215216

216217
// Inherited from the by-ref coroutine.
217218
body_def.codegen_fn_attrs(tcx.codegen_fn_attrs(coroutine_def_id).clone());

Diff for: compiler/rustc_mir_transform/src/dest_prop.rs

+46-67
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ impl<'tcx> crate::MirPass<'tcx> for DestinationPropagation {
163163

164164
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
165165
let def_id = body.source.def_id();
166-
let mut allocations = Allocations::default();
166+
let mut candidates = Candidates::default();
167+
let mut write_info = WriteInfo::default();
167168
trace!(func = ?tcx.def_path_str(def_id));
168169

169170
let borrowed = rustc_mir_dataflow::impls::borrowed_locals(body);
@@ -191,20 +192,15 @@ impl<'tcx> crate::MirPass<'tcx> for DestinationPropagation {
191192
loop {
192193
// PERF: Can we do something smarter than recalculating the candidates and liveness
193194
// results?
194-
let mut candidates = find_candidates(
195-
body,
196-
&borrowed,
197-
&mut allocations.candidates,
198-
&mut allocations.candidates_reverse,
199-
);
195+
candidates.reset_and_find(body, &borrowed);
200196
trace!(?candidates);
201197
dest_prop_mir_dump(tcx, body, &points, &live, round_count);
202198

203199
FilterInformation::filter_liveness(
204200
&mut candidates,
205201
&points,
206202
&live,
207-
&mut allocations.write_info,
203+
&mut write_info,
208204
body,
209205
);
210206

@@ -253,20 +249,8 @@ impl<'tcx> crate::MirPass<'tcx> for DestinationPropagation {
253249
}
254250
}
255251

256-
/// Container for the various allocations that we need.
257-
///
258-
/// We store these here and hand out `&mut` access to them, instead of dropping and recreating them
259-
/// frequently. Everything with a `&'alloc` lifetime points into here.
260-
#[derive(Default)]
261-
struct Allocations {
262-
candidates: FxIndexMap<Local, Vec<Local>>,
263-
candidates_reverse: FxIndexMap<Local, Vec<Local>>,
264-
write_info: WriteInfo,
265-
// PERF: Do this for `MaybeLiveLocals` allocations too.
266-
}
267-
268-
#[derive(Debug)]
269-
struct Candidates<'alloc> {
252+
#[derive(Debug, Default)]
253+
struct Candidates {
270254
/// The set of candidates we are considering in this optimization.
271255
///
272256
/// We will always merge the key into at most one of its values.
@@ -281,11 +265,12 @@ struct Candidates<'alloc> {
281265
///
282266
/// We will still report that we would like to merge `_1` and `_2` in an attempt to allow us to
283267
/// remove that assignment.
284-
c: &'alloc mut FxIndexMap<Local, Vec<Local>>,
268+
c: FxIndexMap<Local, Vec<Local>>,
269+
285270
/// A reverse index of the `c` set; if the `c` set contains `a => Place { local: b, proj }`,
286271
/// then this contains `b => a`.
287272
// PERF: Possibly these should be `SmallVec`s?
288-
reverse: &'alloc mut FxIndexMap<Local, Vec<Local>>,
273+
reverse: FxIndexMap<Local, Vec<Local>>,
289274
}
290275

291276
//////////////////////////////////////////////////////////
@@ -358,19 +343,40 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Merger<'a, 'tcx> {
358343
//
359344
// This section enforces bullet point 2
360345

361-
struct FilterInformation<'a, 'body, 'alloc, 'tcx> {
362-
body: &'body Body<'tcx>,
346+
struct FilterInformation<'a, 'tcx> {
347+
body: &'a Body<'tcx>,
363348
points: &'a DenseLocationMap,
364349
live: &'a SparseIntervalMatrix<Local, PointIndex>,
365-
candidates: &'a mut Candidates<'alloc>,
366-
write_info: &'alloc mut WriteInfo,
350+
candidates: &'a mut Candidates,
351+
write_info: &'a mut WriteInfo,
367352
at: Location,
368353
}
369354

370355
// We first implement some utility functions which we will expose removing candidates according to
371356
// different needs. Throughout the liveness filtering, the `candidates` are only ever accessed
372357
// through these methods, and not directly.
373-
impl<'alloc> Candidates<'alloc> {
358+
impl Candidates {
359+
/// Collects the candidates for merging.
360+
///
361+
/// This is responsible for enforcing the first and third bullet point.
362+
fn reset_and_find<'tcx>(&mut self, body: &Body<'tcx>, borrowed: &BitSet<Local>) {
363+
self.c.clear();
364+
self.reverse.clear();
365+
let mut visitor = FindAssignments { body, candidates: &mut self.c, borrowed };
366+
visitor.visit_body(body);
367+
// Deduplicate candidates.
368+
for (_, cands) in self.c.iter_mut() {
369+
cands.sort();
370+
cands.dedup();
371+
}
372+
// Generate the reverse map.
373+
for (src, cands) in self.c.iter() {
374+
for dest in cands.iter().copied() {
375+
self.reverse.entry(dest).or_default().push(*src);
376+
}
377+
}
378+
}
379+
374380
/// Just `Vec::retain`, but the condition is inverted and we add debugging output
375381
fn vec_filter_candidates(
376382
src: Local,
@@ -445,7 +451,7 @@ enum CandidateFilter {
445451
Remove,
446452
}
447453

448-
impl<'a, 'body, 'alloc, 'tcx> FilterInformation<'a, 'body, 'alloc, 'tcx> {
454+
impl<'a, 'tcx> FilterInformation<'a, 'tcx> {
449455
/// Filters the set of candidates to remove those that conflict.
450456
///
451457
/// The steps we take are exactly those that are outlined at the top of the file. For each
@@ -463,12 +469,12 @@ impl<'a, 'body, 'alloc, 'tcx> FilterInformation<'a, 'body, 'alloc, 'tcx> {
463469
/// before the statement/terminator will correctly report locals that are read in the
464470
/// statement/terminator to be live. We are additionally conservative by treating all written to
465471
/// locals as also being read from.
466-
fn filter_liveness<'b>(
467-
candidates: &mut Candidates<'alloc>,
472+
fn filter_liveness(
473+
candidates: &mut Candidates,
468474
points: &DenseLocationMap,
469475
live: &SparseIntervalMatrix<Local, PointIndex>,
470-
write_info_alloc: &'alloc mut WriteInfo,
471-
body: &'b Body<'tcx>,
476+
write_info: &mut WriteInfo,
477+
body: &Body<'tcx>,
472478
) {
473479
let mut this = FilterInformation {
474480
body,
@@ -477,7 +483,7 @@ impl<'a, 'body, 'alloc, 'tcx> FilterInformation<'a, 'body, 'alloc, 'tcx> {
477483
candidates,
478484
// We don't actually store anything at this scope, we just keep things here to be able
479485
// to reuse the allocation.
480-
write_info: write_info_alloc,
486+
write_info,
481487
// Doesn't matter what we put here, will be overwritten before being used
482488
at: Location::START,
483489
};
@@ -734,40 +740,13 @@ fn places_to_candidate_pair<'tcx>(
734740
Some((a, b))
735741
}
736742

737-
/// Collects the candidates for merging
738-
///
739-
/// This is responsible for enforcing the first and third bullet point.
740-
fn find_candidates<'alloc, 'tcx>(
741-
body: &Body<'tcx>,
742-
borrowed: &BitSet<Local>,
743-
candidates: &'alloc mut FxIndexMap<Local, Vec<Local>>,
744-
candidates_reverse: &'alloc mut FxIndexMap<Local, Vec<Local>>,
745-
) -> Candidates<'alloc> {
746-
candidates.clear();
747-
candidates_reverse.clear();
748-
let mut visitor = FindAssignments { body, candidates, borrowed };
749-
visitor.visit_body(body);
750-
// Deduplicate candidates
751-
for (_, cands) in candidates.iter_mut() {
752-
cands.sort();
753-
cands.dedup();
754-
}
755-
// Generate the reverse map
756-
for (src, cands) in candidates.iter() {
757-
for dest in cands.iter().copied() {
758-
candidates_reverse.entry(dest).or_default().push(*src);
759-
}
760-
}
761-
Candidates { c: candidates, reverse: candidates_reverse }
762-
}
763-
764-
struct FindAssignments<'a, 'alloc, 'tcx> {
743+
struct FindAssignments<'a, 'tcx> {
765744
body: &'a Body<'tcx>,
766-
candidates: &'alloc mut FxIndexMap<Local, Vec<Local>>,
745+
candidates: &'a mut FxIndexMap<Local, Vec<Local>>,
767746
borrowed: &'a BitSet<Local>,
768747
}
769748

770-
impl<'tcx> Visitor<'tcx> for FindAssignments<'_, '_, 'tcx> {
749+
impl<'tcx> Visitor<'tcx> for FindAssignments<'_, 'tcx> {
771750
fn visit_statement(&mut self, statement: &Statement<'tcx>, _: Location) {
772751
if let StatementKind::Assign(box (
773752
lhs,
@@ -819,9 +798,9 @@ fn is_local_required(local: Local, body: &Body<'_>) -> bool {
819798
/////////////////////////////////////////////////////////
820799
// MIR Dump
821800

822-
fn dest_prop_mir_dump<'body, 'tcx>(
801+
fn dest_prop_mir_dump<'tcx>(
823802
tcx: TyCtxt<'tcx>,
824-
body: &'body Body<'tcx>,
803+
body: &Body<'tcx>,
825804
points: &DenseLocationMap,
826805
live: &SparseIntervalMatrix<Local, PointIndex>,
827806
round: usize,

Diff for: library/core/src/marker.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,19 @@ marker_impls! {
288288
/// }
289289
/// ```
290290
///
291-
/// There is a small difference between the two: the `derive` strategy will also place a `Copy`
292-
/// bound on type parameters, which isn't always desired.
291+
/// There is a small difference between the two. The `derive` strategy will also place a `Copy`
292+
/// bound on type parameters:
293+
///
294+
/// ```
295+
/// #[derive(Clone)]
296+
/// struct MyStruct<T>(T);
297+
///
298+
/// impl<T: Copy> Copy for MyStruct<T> { }
299+
/// ```
300+
///
301+
/// This isn't always desired. For example, shared references (`&T`) can be copied regardless of
302+
/// whether `T` is `Copy`. Likewise, a generic struct containing markers such as [`PhantomData`]
303+
/// could potentially be duplicated with a bit-wise copy.
293304
///
294305
/// ## What's the difference between `Copy` and `Clone`?
295306
///

Diff for: src/librustdoc/html/render/mod.rs

+61-25
Original file line numberDiff line numberDiff line change
@@ -1794,13 +1794,64 @@ fn render_impl(
17941794
let mut default_impl_items = Buffer::empty_from(w);
17951795
let impl_ = i.inner_impl();
17961796

1797+
// Impl items are grouped by kinds:
1798+
//
1799+
// 1. Constants
1800+
// 2. Types
1801+
// 3. Functions
1802+
//
1803+
// This order is because you can have associated constants used in associated types (like array
1804+
// length), and both in associcated functions. So with this order, when reading from top to
1805+
// bottom, you should see items definitions before they're actually used most of the time.
1806+
let mut assoc_types = Vec::new();
1807+
let mut methods = Vec::new();
1808+
17971809
if !impl_.is_negative_trait_impl() {
17981810
for trait_item in &impl_.items {
1811+
match *trait_item.kind {
1812+
clean::MethodItem(..) | clean::TyMethodItem(_) => methods.push(trait_item),
1813+
clean::TyAssocTypeItem(..) | clean::AssocTypeItem(..) => {
1814+
assoc_types.push(trait_item)
1815+
}
1816+
clean::TyAssocConstItem(..) | clean::AssocConstItem(_) => {
1817+
// We render it directly since they're supposed to come first.
1818+
doc_impl_item(
1819+
&mut default_impl_items,
1820+
&mut impl_items,
1821+
cx,
1822+
trait_item,
1823+
if trait_.is_some() { &i.impl_item } else { parent },
1824+
link,
1825+
render_mode,
1826+
false,
1827+
trait_,
1828+
rendering_params,
1829+
);
1830+
}
1831+
_ => {}
1832+
}
1833+
}
1834+
1835+
for assoc_type in assoc_types {
17991836
doc_impl_item(
18001837
&mut default_impl_items,
18011838
&mut impl_items,
18021839
cx,
1803-
trait_item,
1840+
assoc_type,
1841+
if trait_.is_some() { &i.impl_item } else { parent },
1842+
link,
1843+
render_mode,
1844+
false,
1845+
trait_,
1846+
rendering_params,
1847+
);
1848+
}
1849+
for method in methods {
1850+
doc_impl_item(
1851+
&mut default_impl_items,
1852+
&mut impl_items,
1853+
cx,
1854+
method,
18041855
if trait_.is_some() { &i.impl_item } else { parent },
18051856
link,
18061857
render_mode,
@@ -2455,28 +2506,6 @@ fn render_call_locations<W: fmt::Write>(mut w: W, cx: &mut Context<'_>, item: &c
24552506
let needs_expansion = line_max - line_min > NUM_VISIBLE_LINES;
24562507
let locations_encoded = serde_json::to_string(&line_ranges).unwrap();
24572508

2458-
write!(
2459-
&mut w,
2460-
"<div class=\"scraped-example {expanded_cls}\" data-locs=\"{locations}\">\
2461-
<div class=\"scraped-example-title\">\
2462-
{name} (<a href=\"{url}\">{title}</a>)\
2463-
</div>\
2464-
<div class=\"code-wrapper\">",
2465-
expanded_cls = if needs_expansion { "" } else { "expanded" },
2466-
name = call_data.display_name,
2467-
url = init_url,
2468-
title = init_title,
2469-
// The locations are encoded as a data attribute, so they can be read
2470-
// later by the JS for interactions.
2471-
locations = Escape(&locations_encoded)
2472-
)
2473-
.unwrap();
2474-
2475-
if line_ranges.len() > 1 {
2476-
w.write_str(r#"<button class="prev">&pr;</button> <button class="next">&sc;</button>"#)
2477-
.unwrap();
2478-
}
2479-
24802509
// Look for the example file in the source map if it exists, otherwise return a dummy span
24812510
let file_span = (|| {
24822511
let source_map = tcx.sess.source_map();
@@ -2507,9 +2536,16 @@ fn render_call_locations<W: fmt::Write>(mut w: W, cx: &mut Context<'_>, item: &c
25072536
cx,
25082537
&cx.root_path(),
25092538
highlight::DecorationInfo(decoration_info),
2510-
sources::SourceContext::Embedded { offset: line_min, needs_expansion },
2539+
sources::SourceContext::Embedded(sources::ScrapedInfo {
2540+
needs_prev_next_buttons: line_ranges.len() > 1,
2541+
needs_expansion,
2542+
offset: line_min,
2543+
name: &call_data.display_name,
2544+
url: init_url,
2545+
title: init_title,
2546+
locations: locations_encoded,
2547+
}),
25112548
);
2512-
w.write_str("</div></div>").unwrap();
25132549

25142550
true
25152551
};

0 commit comments

Comments
 (0)