Skip to content

Commit 74c4821

Browse files
committed
Auto merge of rust-lang#111014 - klensy:no-rc, r=WaffleLapkin
try to downgrade Arc -> Lrc -> Rc -> no-Rc in few places Expecting this be not slower on non-parallel compiler and probably faster on parallel (checked that this PR builds on it).
2 parents eb7a743 + 0726636 commit 74c4821

File tree

5 files changed

+24
-28
lines changed

5 files changed

+24
-28
lines changed

compiler/rustc_borrowck/src/region_infer/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub struct RegionInferenceContext<'tcx> {
7676
/// Reverse of the SCC constraint graph -- i.e., an edge `A -> B` exists if
7777
/// `B: A`. This is used to compute the universal regions that are required
7878
/// to outlive a given SCC. Computed lazily.
79-
rev_scc_graph: Option<Rc<ReverseSccGraph>>,
79+
rev_scc_graph: Option<ReverseSccGraph>,
8080

8181
/// The "R0 member of [R1..Rn]" constraints, indexed by SCC.
8282
member_constraints: Rc<MemberConstraintSet<'tcx, ConstraintSccIndex>>,
@@ -813,9 +813,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
813813
// free region that must outlive the member region `R0` (`UB:
814814
// R0`). Therefore, we need only keep an option `O` if `UB: O`
815815
// for all UB.
816-
let rev_scc_graph = self.reverse_scc_graph();
816+
self.compute_reverse_scc_graph();
817817
let universal_region_relations = &self.universal_region_relations;
818-
for ub in rev_scc_graph.upper_bounds(scc) {
818+
for ub in self.rev_scc_graph.as_ref().unwrap().upper_bounds(scc) {
819819
debug!(?ub);
820820
choice_regions.retain(|&o_r| universal_region_relations.outlives(ub, o_r));
821821
}

compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use rustc_data_structures::graph::vec_graph::VecGraph;
88
use rustc_data_structures::graph::WithSuccessors;
99
use rustc_middle::ty::RegionVid;
1010
use std::ops::Range;
11-
use std::rc::Rc;
1211

1312
pub(crate) struct ReverseSccGraph {
1413
graph: VecGraph<ConstraintSccIndex>,
@@ -40,10 +39,10 @@ impl ReverseSccGraph {
4039
}
4140

4241
impl RegionInferenceContext<'_> {
43-
/// Compute and return the reverse SCC-based constraint graph (lazily).
44-
pub(super) fn reverse_scc_graph(&mut self) -> Rc<ReverseSccGraph> {
45-
if let Some(g) = &self.rev_scc_graph {
46-
return g.clone();
42+
/// Compute the reverse SCC-based constraint graph (lazily).
43+
pub(super) fn compute_reverse_scc_graph(&mut self) {
44+
if self.rev_scc_graph.is_some() {
45+
return;
4746
}
4847

4948
let graph = self.constraint_sccs.reverse();
@@ -63,8 +62,6 @@ impl RegionInferenceContext<'_> {
6362
start += group_size;
6463
}
6564

66-
let rev_graph = Rc::new(ReverseSccGraph { graph, scc_regions, universal_regions });
67-
self.rev_scc_graph = Some(rev_graph.clone());
68-
rev_graph
65+
self.rev_scc_graph = Some(ReverseSccGraph { graph, scc_regions, universal_regions });
6966
}
7067
}

compiler/rustc_expand/src/mbe/macro_parser.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ use rustc_span::Span;
8888
use std::borrow::Cow;
8989
use std::collections::hash_map::Entry::{Occupied, Vacant};
9090
use std::fmt::Display;
91+
use std::rc::Rc;
9192

9293
/// A unit within a matcher that a `MatcherPos` can refer to. Similar to (and derived from)
9394
/// `mbe::TokenTree`, but designed specifically for fast and easy traversal during matching.
@@ -257,10 +258,10 @@ struct MatcherPos {
257258
/// against the relevant metavar by the black box parser. An element will be a `MatchedSeq` if
258259
/// the corresponding metavar decl is within a sequence.
259260
///
260-
/// It is critical to performance that this is an `Lrc`, because it gets cloned frequently when
261+
/// It is critical to performance that this is an `Rc`, because it gets cloned frequently when
261262
/// processing sequences. Mostly for sequence-ending possibilities that must be tried but end
262263
/// up failing.
263-
matches: Lrc<Vec<NamedMatch>>,
264+
matches: Rc<Vec<NamedMatch>>,
264265
}
265266

266267
// This type is used a lot. Make sure it doesn't unintentionally get bigger.
@@ -272,7 +273,7 @@ impl MatcherPos {
272273
/// and both are hot enough to be always worth inlining.
273274
#[inline(always)]
274275
fn push_match(&mut self, metavar_idx: usize, seq_depth: usize, m: NamedMatch) {
275-
let matches = Lrc::make_mut(&mut self.matches);
276+
let matches = Rc::make_mut(&mut self.matches);
276277
match seq_depth {
277278
0 => {
278279
// We are not within a sequence. Just append `m`.
@@ -427,7 +428,7 @@ pub struct TtParser {
427428

428429
/// Pre-allocate an empty match array, so it can be cloned cheaply for macros with many rules
429430
/// that have no metavars.
430-
empty_matches: Lrc<Vec<NamedMatch>>,
431+
empty_matches: Rc<Vec<NamedMatch>>,
431432
}
432433

433434
impl TtParser {
@@ -437,7 +438,7 @@ impl TtParser {
437438
cur_mps: vec![],
438439
next_mps: vec![],
439440
bb_mps: vec![],
440-
empty_matches: Lrc::new(vec![]),
441+
empty_matches: Rc::new(vec![]),
441442
}
442443
}
443444

@@ -507,7 +508,7 @@ impl TtParser {
507508
// Try zero matches of this sequence, by skipping over it.
508509
self.cur_mps.push(MatcherPos {
509510
idx: idx_first_after,
510-
matches: Lrc::clone(&mp.matches),
511+
matches: Rc::clone(&mp.matches),
511512
});
512513
}
513514

@@ -521,7 +522,7 @@ impl TtParser {
521522
// processed next time around the loop.
522523
let ending_mp = MatcherPos {
523524
idx: mp.idx + 1, // +1 skips the Kleene op
524-
matches: Lrc::clone(&mp.matches),
525+
matches: Rc::clone(&mp.matches),
525526
};
526527
self.cur_mps.push(ending_mp);
527528

@@ -537,7 +538,7 @@ impl TtParser {
537538
// will fail quietly when it is processed next time around the loop.
538539
let ending_mp = MatcherPos {
539540
idx: mp.idx + 2, // +2 skips the separator and the Kleene op
540-
matches: Lrc::clone(&mp.matches),
541+
matches: Rc::clone(&mp.matches),
541542
};
542543
self.cur_mps.push(ending_mp);
543544

@@ -587,9 +588,9 @@ impl TtParser {
587588
if *token == token::Eof {
588589
Some(match eof_mps {
589590
EofMatcherPositions::One(mut eof_mp) => {
590-
// Need to take ownership of the matches from within the `Lrc`.
591-
Lrc::make_mut(&mut eof_mp.matches);
592-
let matches = Lrc::try_unwrap(eof_mp.matches).unwrap().into_iter();
591+
// Need to take ownership of the matches from within the `Rc`.
592+
Rc::make_mut(&mut eof_mp.matches);
593+
let matches = Rc::try_unwrap(eof_mp.matches).unwrap().into_iter();
593594
self.nameize(matcher, matches)
594595
}
595596
EofMatcherPositions::Multiple => {

compiler/rustc_passes/src/debugger_visualizer.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
33
use hir::CRATE_HIR_ID;
44
use rustc_data_structures::fx::FxHashSet;
5+
use rustc_data_structures::sync::Lrc;
56
use rustc_expand::base::resolve_path;
67
use rustc_hir as hir;
78
use rustc_hir::HirId;
89
use rustc_middle::ty::TyCtxt;
910
use rustc_middle::{query::LocalCrate, ty::query::Providers};
1011
use rustc_span::{sym, DebuggerVisualizerFile, DebuggerVisualizerType};
1112

12-
use std::sync::Arc;
13-
1413
use crate::errors::DebugVisualizerUnreadable;
1514

1615
fn check_for_debugger_visualizer(
@@ -52,7 +51,7 @@ fn check_for_debugger_visualizer(
5251
match std::fs::read(&file) {
5352
Ok(contents) => {
5453
debugger_visualizers
55-
.insert(DebuggerVisualizerFile::new(Arc::from(contents), visualizer_type));
54+
.insert(DebuggerVisualizerFile::new(Lrc::from(contents), visualizer_type));
5655
}
5756
Err(error) => {
5857
tcx.sess.emit_err(DebugVisualizerUnreadable {

compiler/rustc_span/src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ use std::hash::Hash;
6969
use std::ops::{Add, Range, Sub};
7070
use std::path::{Path, PathBuf};
7171
use std::str::FromStr;
72-
use std::sync::Arc;
7372

7473
use md5::Digest;
7574
use md5::Md5;
@@ -1269,13 +1268,13 @@ pub enum DebuggerVisualizerType {
12691268
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Encodable, Decodable)]
12701269
pub struct DebuggerVisualizerFile {
12711270
/// The complete debugger visualizer source.
1272-
pub src: Arc<[u8]>,
1271+
pub src: Lrc<[u8]>,
12731272
/// Indicates which visualizer type this targets.
12741273
pub visualizer_type: DebuggerVisualizerType,
12751274
}
12761275

12771276
impl DebuggerVisualizerFile {
1278-
pub fn new(src: Arc<[u8]>, visualizer_type: DebuggerVisualizerType) -> Self {
1277+
pub fn new(src: Lrc<[u8]>, visualizer_type: DebuggerVisualizerType) -> Self {
12791278
DebuggerVisualizerFile { src, visualizer_type }
12801279
}
12811280
}

0 commit comments

Comments
 (0)