Skip to content

Commit 0bcd6d7

Browse files
committed
Auto merge of rust-lang#136174 - Zalathar:rollup-bgdzjlo, r=Zalathar
Rollup of 7 pull requests Successful merges: - rust-lang#133151 (Trim extra whitespace in fn ptr suggestion span) - rust-lang#133929 (Remove -Zinline-in-all-cgus and clean up tests/codegen-units/) - rust-lang#135886 (Document purpose of closure in from_fn.rs more clearly) - rust-lang#135961 (Fix 2/4 tests skipped by opt-dist) - rust-lang#136104 (Add mermaid graphs of NLL regions and SCCs to polonius MIR dump) - rust-lang#136124 (Arbitrary self types v2: explain test.) - rust-lang#136153 (Locate asan-odr-win with other sanitizer tests) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 66d6064 + 4716296 commit 0bcd6d7

Some content is hidden

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

48 files changed

+455
-441
lines changed

compiler/rustc_borrowck/src/polonius/dump.rs

+136-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
use std::io;
22

3+
use rustc_data_structures::fx::FxHashSet;
4+
use rustc_index::IndexVec;
35
use rustc_middle::mir::pretty::{
46
PassWhere, PrettyPrintMirOptions, create_dump_file, dump_enabled, dump_mir_to_writer,
57
};
68
use rustc_middle::mir::{Body, ClosureRegionRequirements};
7-
use rustc_middle::ty::TyCtxt;
9+
use rustc_middle::ty::{RegionVid, TyCtxt};
810
use rustc_session::config::MirIncludeSpans;
911

1012
use crate::borrow_set::BorrowSet;
13+
use crate::constraints::OutlivesConstraint;
1114
use crate::polonius::{LocalizedOutlivesConstraint, LocalizedOutlivesConstraintSet};
15+
use crate::type_check::Locations;
1216
use crate::{BorrowckInferCtxt, RegionInferenceContext};
1317

1418
/// `-Zdump-mir=polonius` dumps MIR annotated with NLL and polonius specific information.
@@ -50,6 +54,8 @@ pub(crate) fn dump_polonius_mir<'tcx>(
5054
/// - the NLL MIR
5155
/// - the list of polonius localized constraints
5256
/// - a mermaid graph of the CFG
57+
/// - a mermaid graph of the NLL regions and the constraints between them
58+
/// - a mermaid graph of the NLL SCCs and the constraints between them
5359
fn emit_polonius_dump<'tcx>(
5460
tcx: TyCtxt<'tcx>,
5561
body: &Body<'tcx>,
@@ -68,7 +74,7 @@ fn emit_polonius_dump<'tcx>(
6874
// Section 1: the NLL + Polonius MIR.
6975
writeln!(out, "<div>")?;
7076
writeln!(out, "Raw MIR dump")?;
71-
writeln!(out, "<code><pre>")?;
77+
writeln!(out, "<pre><code>")?;
7278
emit_html_mir(
7379
tcx,
7480
body,
@@ -78,15 +84,31 @@ fn emit_polonius_dump<'tcx>(
7884
closure_region_requirements,
7985
out,
8086
)?;
81-
writeln!(out, "</pre></code>")?;
87+
writeln!(out, "</code></pre>")?;
8288
writeln!(out, "</div>")?;
8389

8490
// Section 2: mermaid visualization of the CFG.
8591
writeln!(out, "<div>")?;
8692
writeln!(out, "Control-flow graph")?;
87-
writeln!(out, "<code><pre class='mermaid'>")?;
93+
writeln!(out, "<pre class='mermaid'>")?;
8894
emit_mermaid_cfg(body, out)?;
89-
writeln!(out, "</pre></code>")?;
95+
writeln!(out, "</pre>")?;
96+
writeln!(out, "</div>")?;
97+
98+
// Section 3: mermaid visualization of the NLL region graph.
99+
writeln!(out, "<div>")?;
100+
writeln!(out, "NLL regions")?;
101+
writeln!(out, "<pre class='mermaid'>")?;
102+
emit_mermaid_nll_regions(regioncx, out)?;
103+
writeln!(out, "</pre>")?;
104+
writeln!(out, "</div>")?;
105+
106+
// Section 4: mermaid visualization of the NLL SCC graph.
107+
writeln!(out, "<div>")?;
108+
writeln!(out, "NLL SCCs")?;
109+
writeln!(out, "<pre class='mermaid'>")?;
110+
emit_mermaid_nll_sccs(regioncx, out)?;
111+
writeln!(out, "</pre>")?;
90112
writeln!(out, "</div>")?;
91113

92114
// Finalize the dump with the HTML epilogue.
@@ -261,3 +283,112 @@ fn emit_mermaid_cfg(body: &Body<'_>, out: &mut dyn io::Write) -> io::Result<()>
261283

262284
Ok(())
263285
}
286+
287+
/// Emits a region's label: index, universe, external name.
288+
fn render_region(
289+
region: RegionVid,
290+
regioncx: &RegionInferenceContext<'_>,
291+
out: &mut dyn io::Write,
292+
) -> io::Result<()> {
293+
let def = regioncx.region_definition(region);
294+
let universe = def.universe;
295+
296+
write!(out, "'{}", region.as_usize())?;
297+
if !universe.is_root() {
298+
write!(out, "/{universe:?}")?;
299+
}
300+
if let Some(name) = def.external_name.and_then(|e| e.get_name()) {
301+
write!(out, " ({name})")?;
302+
}
303+
Ok(())
304+
}
305+
306+
/// Emits a mermaid flowchart of the NLL regions and the outlives constraints between them, similar
307+
/// to the graphviz version.
308+
fn emit_mermaid_nll_regions<'tcx>(
309+
regioncx: &RegionInferenceContext<'tcx>,
310+
out: &mut dyn io::Write,
311+
) -> io::Result<()> {
312+
// The mermaid chart type: a top-down flowchart.
313+
writeln!(out, "flowchart TD")?;
314+
315+
// Emit the region nodes.
316+
for region in regioncx.var_infos.indices() {
317+
write!(out, "{}[\"", region.as_usize())?;
318+
render_region(region, regioncx, out)?;
319+
writeln!(out, "\"]")?;
320+
}
321+
322+
// Get a set of edges to check for the reverse edge being present.
323+
let edges: FxHashSet<_> = regioncx.outlives_constraints().map(|c| (c.sup, c.sub)).collect();
324+
325+
// Order (and deduplicate) edges for traversal, to display them in a generally increasing order.
326+
let constraint_key = |c: &OutlivesConstraint<'_>| {
327+
let min = c.sup.min(c.sub);
328+
let max = c.sup.max(c.sub);
329+
(min, max)
330+
};
331+
let mut ordered_edges: Vec<_> = regioncx.outlives_constraints().collect();
332+
ordered_edges.sort_by_key(|c| constraint_key(c));
333+
ordered_edges.dedup_by_key(|c| constraint_key(c));
334+
335+
for outlives in ordered_edges {
336+
// Source node.
337+
write!(out, "{} ", outlives.sup.as_usize())?;
338+
339+
// The kind of arrow: bidirectional if the opposite edge exists in the set.
340+
if edges.contains(&(outlives.sub, outlives.sup)) {
341+
write!(out, "&lt;")?;
342+
}
343+
write!(out, "-- ")?;
344+
345+
// Edge label from its `Locations`.
346+
match outlives.locations {
347+
Locations::All(_) => write!(out, "All")?,
348+
Locations::Single(location) => write!(out, "{:?}", location)?,
349+
}
350+
351+
// Target node.
352+
writeln!(out, " --> {}", outlives.sub.as_usize())?;
353+
}
354+
Ok(())
355+
}
356+
357+
/// Emits a mermaid flowchart of the NLL SCCs and the outlives constraints between them, similar
358+
/// to the graphviz version.
359+
fn emit_mermaid_nll_sccs<'tcx>(
360+
regioncx: &RegionInferenceContext<'tcx>,
361+
out: &mut dyn io::Write,
362+
) -> io::Result<()> {
363+
// The mermaid chart type: a top-down flowchart.
364+
writeln!(out, "flowchart TD")?;
365+
366+
// Gather and emit the SCC nodes.
367+
let mut nodes_per_scc: IndexVec<_, _> =
368+
regioncx.constraint_sccs().all_sccs().map(|_| Vec::new()).collect();
369+
for region in regioncx.var_infos.indices() {
370+
let scc = regioncx.constraint_sccs().scc(region);
371+
nodes_per_scc[scc].push(region);
372+
}
373+
for (scc, regions) in nodes_per_scc.iter_enumerated() {
374+
// The node label: the regions contained in the SCC.
375+
write!(out, "{scc}[\"SCC({scc}) = {{", scc = scc.as_usize())?;
376+
for (idx, &region) in regions.iter().enumerate() {
377+
render_region(region, regioncx, out)?;
378+
if idx < regions.len() - 1 {
379+
write!(out, ",")?;
380+
}
381+
}
382+
writeln!(out, "}}\"]")?;
383+
}
384+
385+
// Emit the edges between SCCs.
386+
let edges = regioncx.constraint_sccs().all_sccs().flat_map(|source| {
387+
regioncx.constraint_sccs().successors(source).iter().map(move |&target| (source, target))
388+
});
389+
for (source, target) in edges {
390+
writeln!(out, "{} --> {}", source.as_usize(), target.as_usize())?;
391+
}
392+
393+
Ok(())
394+
}

compiler/rustc_interface/src/tests.rs

-1
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,6 @@ fn test_unstable_options_tracking_hash() {
797797
tracked!(function_sections, Some(false));
798798
tracked!(human_readable_cgu_names, true);
799799
tracked!(incremental_ignore_spans, true);
800-
tracked!(inline_in_all_cgus, Some(true));
801800
tracked!(inline_mir, Some(true));
802801
tracked!(inline_mir_hint_threshold, Some(123));
803802
tracked!(inline_mir_threshold, Some(123));

compiler/rustc_middle/src/mir/mono.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,8 @@ impl<'tcx> MonoItem<'tcx> {
9191
}
9292

9393
pub fn instantiation_mode(&self, tcx: TyCtxt<'tcx>) -> InstantiationMode {
94-
let generate_cgu_internal_copies = tcx
95-
.sess
96-
.opts
97-
.unstable_opts
98-
.inline_in_all_cgus
99-
.unwrap_or_else(|| tcx.sess.opts.optimize != OptLevel::No)
100-
&& !tcx.sess.link_dead_code();
94+
let generate_cgu_internal_copies =
95+
(tcx.sess.opts.optimize != OptLevel::No) && !tcx.sess.link_dead_code();
10196

10297
match *self {
10398
MonoItem::Fn(ref instance) => {
@@ -121,8 +116,8 @@ impl<'tcx> MonoItem<'tcx> {
121116
}
122117

123118
// At this point we don't have explicit linkage and we're an
124-
// inlined function. If we're inlining into all CGUs then we'll
125-
// be creating a local copy per CGU.
119+
// inlined function. If this crate's build settings permit,
120+
// we'll be creating a local copy per CGU.
126121
if generate_cgu_internal_copies {
127122
return InstantiationMode::LocalCopy;
128123
}

compiler/rustc_parse/src/errors.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -2830,19 +2830,21 @@ pub(crate) struct DynAfterMut {
28302830
pub(crate) struct FnPointerCannotBeConst {
28312831
#[primary_span]
28322832
pub span: Span,
2833-
#[suggestion(code = "", applicability = "maybe-incorrect", style = "verbose")]
28342833
#[label]
28352834
pub qualifier: Span,
2835+
#[suggestion(code = "", applicability = "maybe-incorrect", style = "verbose")]
2836+
pub suggestion: Span,
28362837
}
28372838

28382839
#[derive(Diagnostic)]
28392840
#[diag(parse_fn_pointer_cannot_be_async)]
28402841
pub(crate) struct FnPointerCannotBeAsync {
28412842
#[primary_span]
28422843
pub span: Span,
2843-
#[suggestion(code = "", applicability = "maybe-incorrect", style = "verbose")]
28442844
#[label]
28452845
pub qualifier: Span,
2846+
#[suggestion(code = "", applicability = "maybe-incorrect", style = "verbose")]
2847+
pub suggestion: Span,
28462848
}
28472849

28482850
#[derive(Diagnostic)]

compiler/rustc_parse/src/parser/ty.rs

+46-4
Original file line numberDiff line numberDiff line change
@@ -609,16 +609,58 @@ impl<'a> Parser<'a> {
609609
let span_start = self.token.span;
610610
let ast::FnHeader { ext, safety, constness, coroutine_kind } =
611611
self.parse_fn_front_matter(&inherited_vis, Case::Sensitive)?;
612+
let fn_start_lo = self.prev_token.span.lo();
612613
if self.may_recover() && self.token == TokenKind::Lt {
613614
self.recover_fn_ptr_with_generics(lo, &mut params, param_insertion_point)?;
614615
}
615616
let decl = self.parse_fn_decl(|_| false, AllowPlus::No, recover_return_sign)?;
616617
let whole_span = lo.to(self.prev_token.span);
617-
if let ast::Const::Yes(span) = constness {
618-
self.dcx().emit_err(FnPointerCannotBeConst { span: whole_span, qualifier: span });
618+
619+
// Order/parsing of "front matter" follows:
620+
// `<constness> <coroutine_kind> <safety> <extern> fn()`
621+
// ^ ^ ^ ^ ^
622+
// | | | | fn_start_lo
623+
// | | | ext_sp.lo
624+
// | | safety_sp.lo
625+
// | coroutine_sp.lo
626+
// const_sp.lo
627+
if let ast::Const::Yes(const_span) = constness {
628+
let next_token_lo = if let Some(
629+
ast::CoroutineKind::Async { span, .. }
630+
| ast::CoroutineKind::Gen { span, .. }
631+
| ast::CoroutineKind::AsyncGen { span, .. },
632+
) = coroutine_kind
633+
{
634+
span.lo()
635+
} else if let ast::Safety::Unsafe(span) | ast::Safety::Safe(span) = safety {
636+
span.lo()
637+
} else if let ast::Extern::Implicit(span) | ast::Extern::Explicit(_, span) = ext {
638+
span.lo()
639+
} else {
640+
fn_start_lo
641+
};
642+
let sugg_span = const_span.with_hi(next_token_lo);
643+
self.dcx().emit_err(FnPointerCannotBeConst {
644+
span: whole_span,
645+
qualifier: const_span,
646+
suggestion: sugg_span,
647+
});
619648
}
620-
if let Some(ast::CoroutineKind::Async { span, .. }) = coroutine_kind {
621-
self.dcx().emit_err(FnPointerCannotBeAsync { span: whole_span, qualifier: span });
649+
if let Some(ast::CoroutineKind::Async { span: async_span, .. }) = coroutine_kind {
650+
let next_token_lo = if let ast::Safety::Unsafe(span) | ast::Safety::Safe(span) = safety
651+
{
652+
span.lo()
653+
} else if let ast::Extern::Implicit(span) | ast::Extern::Explicit(_, span) = ext {
654+
span.lo()
655+
} else {
656+
fn_start_lo
657+
};
658+
let sugg_span = async_span.with_hi(next_token_lo);
659+
self.dcx().emit_err(FnPointerCannotBeAsync {
660+
span: whole_span,
661+
qualifier: async_span,
662+
suggestion: sugg_span,
663+
});
622664
}
623665
// FIXME(gen_blocks): emit a similar error for `gen fn()`
624666
let decl_span = span_start.to(self.prev_token.span);

compiler/rustc_session/src/options.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1870,8 +1870,6 @@ options! {
18701870
"verify extended properties for incr. comp. (default: no):
18711871
- hashes of green query instances
18721872
- hash collisions of query keys"),
1873-
inline_in_all_cgus: Option<bool> = (None, parse_opt_bool, [TRACKED],
1874-
"control whether `#[inline]` functions are in all CGUs"),
18751873
inline_llvm: bool = (true, parse_bool, [TRACKED],
18761874
"enable LLVM inlining (default: yes)"),
18771875
inline_mir: Option<bool> = (None, parse_opt_bool, [TRACKED],

library/core/src/iter/sources/from_fn.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::fmt;
22

3-
/// Creates a new iterator where each iteration calls the provided closure
4-
/// `F: FnMut() -> Option<T>`.
3+
/// Creates an iterator with the provided closure
4+
/// `F: FnMut() -> Option<T>` as its `[next](Iterator::next)` method.
55
///
66
/// The iterator will yield the `T`s returned from the closure.
77
///

src/ci/docker/host-aarch64/dist-aarch64-linux/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ RUN yum upgrade -y && \
2020
gcc-c++ \
2121
git \
2222
glibc-devel \
23+
glibc-static \
2324
libedit-devel \
2425
libstdc++-devel \
2526
make \

src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ RUN yum upgrade -y && \
2121
git \
2222
glibc-devel.i686 \
2323
glibc-devel.x86_64 \
24+
glibc-static.i686 \
25+
glibc-static.x86_64 \
2426
libedit-devel \
2527
libstdc++-devel.i686 \
2628
libstdc++-devel.x86_64 \

src/ci/github-actions/jobs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ envs:
8686
# builds)
8787
# - not running `opt-dist`'s post-optimization smoke tests on the resulting toolchain
8888
#
89-
# If you *want* these to happen however, temporarily uncomment it before triggering a try build.
89+
# If you *want* these to happen however, temporarily comment it before triggering a try build.
9090
DIST_TRY_BUILD: 1
9191

9292
auto:

src/tools/opt-dist/src/main.rs

+7-13
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,15 @@ fn create_environment(args: Args) -> anyhow::Result<(Environment, Vec<String>)>
148148

149149
let is_aarch64 = target_triple.starts_with("aarch64");
150150

151-
let mut skip_tests = vec![
152-
// Fails because of linker errors, as of June 2023.
153-
"tests/ui/process/nofile-limit.rs".to_string(),
154-
];
155-
156-
if is_aarch64 {
157-
skip_tests.extend([
151+
let skip_tests = if is_aarch64 {
152+
vec![
158153
// Those tests fail only inside of Docker on aarch64, as of December 2024
159154
"tests/ui/consts/promoted_running_out_of_memory_issue-130687.rs".to_string(),
160155
"tests/ui/consts/large_const_alloc.rs".to_string(),
161-
]);
162-
}
156+
]
157+
} else {
158+
vec![]
159+
};
163160

164161
let checkout_dir = Utf8PathBuf::from("/checkout");
165162
let env = EnvironmentBuilder::default()
@@ -191,10 +188,7 @@ fn create_environment(args: Args) -> anyhow::Result<(Environment, Vec<String>)>
191188
.build_dir(checkout_dir)
192189
.shared_llvm(false)
193190
.use_bolt(false)
194-
.skipped_tests(vec![
195-
// Fails as of June 2023.
196-
"tests\\codegen\\vec-shrink-panik.rs".to_string(),
197-
])
191+
.skipped_tests(vec![])
198192
.build()?;
199193

200194
(env, shared.build_args)

tests/codegen-units/item-collection/drop_in_place_intrinsic.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
//
21
//@ compile-flags:-Zprint-mono-items=eager
3-
//@ compile-flags:-Zinline-in-all-cgus
42
//@ compile-flags:-Zinline-mir=no
3+
//@ compile-flags: -O
54

65
#![crate_type = "lib"]
76

0 commit comments

Comments
 (0)