Skip to content

Commit a1894e4

Browse files
committed
Auto merge of rust-lang#76558 - tmandry:rollup-bskim2r, r=tmandry
Rollup of 7 pull requests Successful merges: - rust-lang#74787 (Move `rustllvm` into `compiler/rustc_llvm`) - rust-lang#76458 (Add drain_filter method to HashMap and HashSet) - rust-lang#76472 (rustbuild: don't set PYTHON_EXECUTABLE and WITH_POLLY cmake vars since they are no longer supported by llvm) - rust-lang#76497 (Use intra-doc links in `core::ptr`) - rust-lang#76500 (Add -Zgraphviz_dark_mode and monospace font fix) - rust-lang#76543 (Document btree's unwrap_unchecked) - rust-lang#76556 (Revert rust-lang#76285) Failed merges: r? `@ghost`
2 parents 97eb606 + 193503e commit a1894e4

File tree

40 files changed

+617
-212
lines changed

40 files changed

+617
-212
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ __pycache__/
3333
/mingw-build/
3434
# Created by default with `src/ci/docker/run.sh`:
3535
/obj/
36-
/rustllvm/
3736
/unicode-downloads
3837
/target
3938
# Generated by compiletest for incremental:

Cargo.lock

+4-5
Original file line numberDiff line numberDiff line change
@@ -1259,11 +1259,10 @@ dependencies = [
12591259

12601260
[[package]]
12611261
name = "hashbrown"
1262-
version = "0.8.2"
1262+
version = "0.9.0"
12631263
source = "registry+https://github.com/rust-lang/crates.io-index"
1264-
checksum = "e91b62f79061a0bc2e046024cb7ba44b08419ed238ecbd9adbd787434b9e8c25"
1264+
checksum = "00d63df3d41950fb462ed38308eea019113ad1508da725bbedcd0fa5a85ef5f7"
12651265
dependencies = [
1266-
"autocfg",
12671266
"compiler_builtins",
12681267
"rustc-std-workspace-alloc",
12691268
"rustc-std-workspace-core",
@@ -1401,9 +1400,9 @@ dependencies = [
14011400

14021401
[[package]]
14031402
name = "indexmap"
1404-
version = "1.5.1"
1403+
version = "1.6.0"
14051404
source = "registry+https://github.com/rust-lang/crates.io-index"
1406-
checksum = "86b45e59b16c76b11bf9738fd5d38879d3bd28ad292d7b313608becb17ae2df9"
1405+
checksum = "55e2e4c765aa53a0424761bf9f41aa7a6ac1efa87238f59560640e27fca028f2"
14071406
dependencies = [
14081407
"autocfg",
14091408
"hashbrown",

compiler/rustc_ast/src/tokenstream.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,8 @@ impl Cursor {
403403
self.index = index;
404404
}
405405

406-
pub fn look_ahead(&self, n: usize) -> Option<&TokenTree> {
407-
self.stream.0[self.index..].get(n).map(|(tree, _)| tree)
406+
pub fn look_ahead(&self, n: usize) -> Option<TokenTree> {
407+
self.stream.0[self.index..].get(n).map(|(tree, _)| tree.clone())
408408
}
409409
}
410410

compiler/rustc_codegen_llvm/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ rustc_fs_util = { path = "../rustc_fs_util" }
2525
rustc_hir = { path = "../rustc_hir" }
2626
rustc_incremental = { path = "../rustc_incremental" }
2727
rustc_index = { path = "../rustc_index" }
28-
rustc_llvm = { path = "../../src/librustc_llvm" }
28+
rustc_llvm = { path = "../rustc_llvm" }
2929
rustc_session = { path = "../rustc_session" }
3030
rustc_serialize = { path = "../rustc_serialize" }
3131
rustc_target = { path = "../rustc_target" }

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub enum DLLStorageClass {
9696
DllExport = 2, // Function to be accessible from DLL.
9797
}
9898

99-
/// Matches LLVMRustAttribute in rustllvm.h
99+
/// Matches LLVMRustAttribute in LLVMWrapper.h
100100
/// Semantically a subset of the C++ enum llvm::Attribute::AttrKind,
101101
/// though it is not ABI compatible (since it's a C++ enum)
102102
#[repr(C)]
@@ -1705,7 +1705,7 @@ extern "C" {
17051705
PM: &PassManager<'_>,
17061706
);
17071707

1708-
// Stuff that's in rustllvm/ because it's not upstream yet.
1708+
// Stuff that's in llvm-wrapper/ because it's not upstream yet.
17091709

17101710
/// Opens an object file.
17111711
pub fn LLVMCreateObjectFile(

compiler/rustc_expand/src/proc_macro_server.rs

+5-17
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,15 @@ impl ToInternal<token::DelimToken> for Delimiter {
4747
}
4848
}
4949

50-
impl
51-
FromInternal<(
52-
TreeAndJoint,
53-
Option<&'_ tokenstream::TokenTree>,
54-
&'_ ParseSess,
55-
&'_ mut Vec<Self>,
56-
)> for TokenTree<Group, Punct, Ident, Literal>
50+
impl FromInternal<(TreeAndJoint, &'_ ParseSess, &'_ mut Vec<Self>)>
51+
for TokenTree<Group, Punct, Ident, Literal>
5752
{
5853
fn from_internal(
59-
((tree, is_joint), look_ahead, sess, stack): (
60-
TreeAndJoint,
61-
Option<&tokenstream::TokenTree>,
62-
&ParseSess,
63-
&mut Vec<Self>,
64-
),
54+
((tree, is_joint), sess, stack): (TreeAndJoint, &ParseSess, &mut Vec<Self>),
6555
) -> Self {
6656
use rustc_ast::token::*;
6757

68-
let joint = is_joint == Joint
69-
&& matches!(look_ahead, Some(tokenstream::TokenTree::Token(t)) if t.is_op());
58+
let joint = is_joint == Joint;
7059
let Token { kind, span } = match tree {
7160
tokenstream::TokenTree::Delimited(span, delim, tts) => {
7261
let delimiter = Delimiter::from_internal(delim);
@@ -456,8 +445,7 @@ impl server::TokenStreamIter for Rustc<'_> {
456445
loop {
457446
let tree = iter.stack.pop().or_else(|| {
458447
let next = iter.cursor.next_with_joint()?;
459-
let lookahead = iter.cursor.look_ahead(0);
460-
Some(TokenTree::from_internal((next, lookahead, self.sess, &mut iter.stack)))
448+
Some(TokenTree::from_internal((next, self.sess, &mut iter.stack)))
461449
})?;
462450
// A hack used to pass AST fragments to attribute and derive macros
463451
// as a single nonterminal token instead of a token stream.

compiler/rustc_graphviz/src/lib.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,7 @@ pub enum RenderOption {
599599
NoNodeStyles,
600600

601601
Monospace,
602+
DarkTheme,
602603
}
603604

604605
/// Returns vec holding all the default render options.
@@ -630,10 +631,23 @@ where
630631
writeln!(w, "digraph {} {{", g.graph_id().as_slice())?;
631632

632633
// Global graph properties
634+
let mut graph_attrs = Vec::new();
635+
let mut content_attrs = Vec::new();
633636
if options.contains(&RenderOption::Monospace) {
634-
writeln!(w, r#" graph[fontname="monospace"];"#)?;
635-
writeln!(w, r#" node[fontname="monospace"];"#)?;
636-
writeln!(w, r#" edge[fontname="monospace"];"#)?;
637+
let font = r#"fontname="Courier, monospace""#;
638+
graph_attrs.push(font);
639+
content_attrs.push(font);
640+
};
641+
if options.contains(&RenderOption::DarkTheme) {
642+
graph_attrs.push(r#"bgcolor="black""#);
643+
content_attrs.push(r#"color="white""#);
644+
content_attrs.push(r#"fontcolor="white""#);
645+
}
646+
if !(graph_attrs.is_empty() && content_attrs.is_empty()) {
647+
writeln!(w, r#" graph[{}];"#, graph_attrs.join(" "))?;
648+
let content_attrs_str = content_attrs.join(" ");
649+
writeln!(w, r#" node[{}];"#, content_attrs_str)?;
650+
writeln!(w, r#" edge[{}];"#, content_attrs_str)?;
637651
}
638652

639653
for n in g.nodes().iter() {

src/librustc_llvm/Cargo.toml compiler/rustc_llvm/Cargo.toml

+1-4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ name = "rustc_llvm"
44
version = "0.0.0"
55
edition = "2018"
66

7-
[lib]
8-
path = "lib.rs"
9-
107
[features]
118
static-libstdcpp = []
129
emscripten = []
@@ -15,5 +12,5 @@ emscripten = []
1512
libc = "0.2.73"
1613

1714
[build-dependencies]
18-
build_helper = { path = "../build_helper" }
15+
build_helper = { path = "../../src/build_helper" }
1916
cc = "1.0.58"

src/librustc_llvm/build.rs compiler/rustc_llvm/build.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,15 @@ fn main() {
175175
cfg.debug(false);
176176
}
177177

178-
build_helper::rerun_if_changed_anything_in_dir(Path::new("../rustllvm"));
179-
cfg.file("../rustllvm/PassWrapper.cpp")
180-
.file("../rustllvm/RustWrapper.cpp")
181-
.file("../rustllvm/ArchiveWrapper.cpp")
182-
.file("../rustllvm/CoverageMappingWrapper.cpp")
183-
.file("../rustllvm/Linker.cpp")
178+
build_helper::rerun_if_changed_anything_in_dir(Path::new("llvm-wrapper"));
179+
cfg.file("llvm-wrapper/PassWrapper.cpp")
180+
.file("llvm-wrapper/RustWrapper.cpp")
181+
.file("llvm-wrapper/ArchiveWrapper.cpp")
182+
.file("llvm-wrapper/CoverageMappingWrapper.cpp")
183+
.file("llvm-wrapper/Linker.cpp")
184184
.cpp(true)
185185
.cpp_link_stdlib(None) // we handle this below
186-
.compile("rustllvm");
186+
.compile("llvm-wrapper");
187187

188188
let (llvm_kind, llvm_link_arg) = detect_llvm_link();
189189

@@ -259,7 +259,7 @@ fn main() {
259259
}
260260

261261
// Some LLVM linker flags (-L and -l) may be needed even when linking
262-
// librustc_llvm, for example when using static libc++, we may need to
262+
// rustc_llvm, for example when using static libc++, we may need to
263263
// manually specify the library search path and -ldl -lpthread as link
264264
// dependencies.
265265
let llvm_linker_flags = tracked_env_var_os("LLVM_LINKER_FLAGS");
File renamed without changes.

src/rustllvm/ArchiveWrapper.cpp compiler/rustc_llvm/llvm-wrapper/ArchiveWrapper.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "rustllvm.h"
1+
#include "LLVMWrapper.h"
22

33
#include "llvm/Object/Archive.h"
44
#include "llvm/Object/ArchiveWriter.h"

src/rustllvm/CoverageMappingWrapper.cpp compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "rustllvm.h"
1+
#include "LLVMWrapper.h"
22
#include "llvm/ProfileData/Coverage/CoverageMapping.h"
33
#include "llvm/ProfileData/Coverage/CoverageMappingWriter.h"
44
#include "llvm/ProfileData/InstrProf.h"
File renamed without changes.

src/rustllvm/Linker.cpp compiler/rustc_llvm/llvm-wrapper/Linker.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "llvm/Linker/Linker.h"
22

3-
#include "rustllvm.h"
3+
#include "LLVMWrapper.h"
44

55
using namespace llvm;
66

src/rustllvm/PassWrapper.cpp compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <vector>
44
#include <set>
55

6-
#include "rustllvm.h"
6+
#include "LLVMWrapper.h"
77

88
#include "llvm/Analysis/TargetLibraryInfo.h"
99
#include "llvm/Analysis/TargetTransformInfo.h"
File renamed without changes.

src/rustllvm/RustWrapper.cpp compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "rustllvm.h"
1+
#include "LLVMWrapper.h"
22
#include "llvm/IR/DebugInfoMetadata.h"
33
#include "llvm/IR/DiagnosticInfo.h"
44
#include "llvm/IR/DiagnosticPrinter.h"
File renamed without changes.

compiler/rustc_mir/src/dataflow/framework/engine.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,11 @@ where
306306
let mut buf = Vec::new();
307307

308308
let graphviz = graphviz::Formatter::new(body, def_id, results, style);
309-
dot::render_opts(&graphviz, &mut buf, &[dot::RenderOption::Monospace])?;
309+
let mut render_opts = vec![dot::RenderOption::Monospace];
310+
if tcx.sess.opts.debugging_opts.graphviz_dark_mode {
311+
render_opts.push(dot::RenderOption::DarkTheme);
312+
}
313+
dot::render_opts(&graphviz, &mut buf, &render_opts)?;
310314

311315
if let Some(parent) = path.parent() {
312316
fs::create_dir_all(parent)?;

compiler/rustc_mir/src/util/graphviz.rs

+22-7
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,28 @@ where
5555
writeln!(w, "{} {}Mir_{} {{", kind, cluster, def_name)?;
5656

5757
// Global graph properties
58-
writeln!(w, r#" graph [fontname="monospace"];"#)?;
59-
writeln!(w, r#" node [fontname="monospace"];"#)?;
60-
writeln!(w, r#" edge [fontname="monospace"];"#)?;
58+
let font = r#"fontname="Courier, monospace""#;
59+
let mut graph_attrs = vec![font];
60+
let mut content_attrs = vec![font];
61+
62+
let dark_mode = tcx.sess.opts.debugging_opts.graphviz_dark_mode;
63+
if dark_mode {
64+
graph_attrs.push(r#"bgcolor="black""#);
65+
content_attrs.push(r#"color="white""#);
66+
content_attrs.push(r#"fontcolor="white""#);
67+
}
68+
69+
writeln!(w, r#" graph [{}];"#, graph_attrs.join(" "))?;
70+
let content_attrs_str = content_attrs.join(" ");
71+
writeln!(w, r#" node [{}];"#, content_attrs_str)?;
72+
writeln!(w, r#" edge [{}];"#, content_attrs_str)?;
6173

6274
// Graph label
6375
write_graph_label(tcx, def_id, body, w)?;
6476

6577
// Nodes
6678
for (block, _) in body.basic_blocks().iter_enumerated() {
67-
write_node(def_id, block, body, w)?;
79+
write_node(def_id, block, body, dark_mode, w)?;
6880
}
6981

7082
// Edges
@@ -84,6 +96,7 @@ where
8496
pub fn write_node_label<W: Write, INIT, FINI>(
8597
block: BasicBlock,
8698
body: &Body<'_>,
99+
dark_mode: bool,
87100
w: &mut W,
88101
num_cols: u32,
89102
init: INIT,
@@ -100,8 +113,9 @@ where
100113
// Basic block number at the top.
101114
write!(
102115
w,
103-
r#"<tr><td {attrs} colspan="{colspan}">{blk}</td></tr>"#,
104-
attrs = r#"bgcolor="gray" align="center""#,
116+
r#"<tr><td bgcolor="{bgcolor}" {attrs} colspan="{colspan}">{blk}</td></tr>"#,
117+
bgcolor = if dark_mode { "dimgray" } else { "gray" },
118+
attrs = r#"align="center""#,
105119
colspan = num_cols,
106120
blk = block.index()
107121
)?;
@@ -134,11 +148,12 @@ fn write_node<W: Write>(
134148
def_id: DefId,
135149
block: BasicBlock,
136150
body: &Body<'_>,
151+
dark_mode: bool,
137152
w: &mut W,
138153
) -> io::Result<()> {
139154
// Start a new node with the label to follow, in one of DOT's pseudo-HTML tables.
140155
write!(w, r#" {} [shape="none", label=<"#, node(def_id, block))?;
141-
write_node_label(block, body, w, 1, |_| Ok(()), |_| Ok(()))?;
156+
write_node_label(block, body, dark_mode, w, 1, |_| Ok(()), |_| Ok(()))?;
142157
// Close the node label and the node itself.
143158
writeln!(w, ">];")
144159
}

compiler/rustc_parse/src/lexer/tokentrees.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,10 @@ impl<'a> TokenTreesReader<'a> {
262262
}
263263
_ => {
264264
let tt = TokenTree::Token(self.token.take());
265-
let is_joint = self.bump();
265+
let mut is_joint = self.bump();
266+
if !self.token.is_op() {
267+
is_joint = NonJoint;
268+
}
266269
Ok((tt, is_joint))
267270
}
268271
}

compiler/rustc_parse/src/parser/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -822,15 +822,15 @@ impl<'a> Parser<'a> {
822822
}
823823

824824
let frame = &self.token_cursor.frame;
825-
match frame.tree_cursor.look_ahead(dist - 1) {
825+
looker(&match frame.tree_cursor.look_ahead(dist - 1) {
826826
Some(tree) => match tree {
827-
TokenTree::Token(token) => looker(token),
827+
TokenTree::Token(token) => token,
828828
TokenTree::Delimited(dspan, delim, _) => {
829-
looker(&Token::new(token::OpenDelim(delim.clone()), dspan.open))
829+
Token::new(token::OpenDelim(delim), dspan.open)
830830
}
831831
},
832-
None => looker(&Token::new(token::CloseDelim(frame.delim), frame.span.close)),
833-
}
832+
None => Token::new(token::CloseDelim(frame.delim), frame.span.close),
833+
})
834834
}
835835

836836
/// Returns whether any of the given keywords are `dist` tokens ahead of the current one.

compiler/rustc_session/src/options.rs

+2
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
909909
"force all crates to be `rustc_private` unstable (default: no)"),
910910
fuel: Option<(String, u64)> = (None, parse_optimization_fuel, [TRACKED],
911911
"set the optimization fuel quota for a crate"),
912+
graphviz_dark_mode: bool = (false, parse_bool, [UNTRACKED],
913+
"use dark-themed colors in graphviz output (default: no)"),
912914
hir_stats: bool = (false, parse_bool, [UNTRACKED],
913915
"print some statistics about AST and HIR (default: no)"),
914916
human_readable_cgu_names: bool = (false, parse_bool, [TRACKED],

config.toml.example

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
# this flag will indicate that this version check should not be done.
4646
#version-check = true
4747

48-
# Link libstdc++ statically into the librustc_llvm instead of relying on a
48+
# Link libstdc++ statically into the rustc_llvm instead of relying on a
4949
# dynamic version to be available.
5050
#static-libstdcpp = false
5151

library/alloc/src/collections/btree/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ trait Recover<Q: ?Sized> {
1313
fn replace(&mut self, key: Self::Key) -> Option<Self::Key>;
1414
}
1515

16+
/// Same purpose as `Option::unwrap` but doesn't always guarantee a panic
17+
/// if the option contains no value.
18+
/// SAFETY: the caller must ensure that the option contains a value.
1619
#[inline(always)]
1720
pub unsafe fn unwrap_unchecked<T>(val: Option<T>) -> T {
1821
val.unwrap_or_else(|| {

0 commit comments

Comments
 (0)