about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-05-04 20:49:23 +0000
committerbors <bors@rust-lang.org>2023-05-04 20:49:23 +0000
commit74c4821045c68d42bb8b8a7c998bdb5c2a72bd0d (patch)
treeba442cf2a77a47739ffe3278df8f55dbd681d6dd
parenteb7a7434215dd9d4b7cc18746ad1d0e531c25325 (diff)
parent07266362c6b29139dc09ecd4b963722690eaa31f (diff)
downloadrust-74c4821045c68d42bb8b8a7c998bdb5c2a72bd0d.tar.gz
rust-74c4821045c68d42bb8b8a7c998bdb5c2a72bd0d.zip
Auto merge of #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).
-rw-r--r--compiler/rustc_borrowck/src/region_infer/mod.rs6
-rw-r--r--compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs13
-rw-r--r--compiler/rustc_expand/src/mbe/macro_parser.rs23
-rw-r--r--compiler/rustc_passes/src/debugger_visualizer.rs5
-rw-r--r--compiler/rustc_span/src/lib.rs5
5 files changed, 24 insertions, 28 deletions
diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs
index 65573c71f14..8fbe814c856 100644
--- a/compiler/rustc_borrowck/src/region_infer/mod.rs
+++ b/compiler/rustc_borrowck/src/region_infer/mod.rs
@@ -76,7 +76,7 @@ pub struct RegionInferenceContext<'tcx> {
     /// Reverse of the SCC constraint graph --  i.e., an edge `A -> B` exists if
     /// `B: A`. This is used to compute the universal regions that are required
     /// to outlive a given SCC. Computed lazily.
-    rev_scc_graph: Option<Rc<ReverseSccGraph>>,
+    rev_scc_graph: Option<ReverseSccGraph>,
 
     /// The "R0 member of [R1..Rn]" constraints, indexed by SCC.
     member_constraints: Rc<MemberConstraintSet<'tcx, ConstraintSccIndex>>,
@@ -813,9 +813,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
         // free region that must outlive the member region `R0` (`UB:
         // R0`). Therefore, we need only keep an option `O` if `UB: O`
         // for all UB.
-        let rev_scc_graph = self.reverse_scc_graph();
+        self.compute_reverse_scc_graph();
         let universal_region_relations = &self.universal_region_relations;
-        for ub in rev_scc_graph.upper_bounds(scc) {
+        for ub in self.rev_scc_graph.as_ref().unwrap().upper_bounds(scc) {
             debug!(?ub);
             choice_regions.retain(|&o_r| universal_region_relations.outlives(ub, o_r));
         }
diff --git a/compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs b/compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs
index 23a59c12865..fe56bd54a3f 100644
--- a/compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs
+++ b/compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs
@@ -8,7 +8,6 @@ use rustc_data_structures::graph::vec_graph::VecGraph;
 use rustc_data_structures::graph::WithSuccessors;
 use rustc_middle::ty::RegionVid;
 use std::ops::Range;
-use std::rc::Rc;
 
 pub(crate) struct ReverseSccGraph {
     graph: VecGraph<ConstraintSccIndex>,
@@ -40,10 +39,10 @@ impl ReverseSccGraph {
 }
 
 impl RegionInferenceContext<'_> {
-    /// Compute and return the reverse SCC-based constraint graph (lazily).
-    pub(super) fn reverse_scc_graph(&mut self) -> Rc<ReverseSccGraph> {
-        if let Some(g) = &self.rev_scc_graph {
-            return g.clone();
+    /// Compute the reverse SCC-based constraint graph (lazily).
+    pub(super) fn compute_reverse_scc_graph(&mut self) {
+        if self.rev_scc_graph.is_some() {
+            return;
         }
 
         let graph = self.constraint_sccs.reverse();
@@ -63,8 +62,6 @@ impl RegionInferenceContext<'_> {
             start += group_size;
         }
 
-        let rev_graph = Rc::new(ReverseSccGraph { graph, scc_regions, universal_regions });
-        self.rev_scc_graph = Some(rev_graph.clone());
-        rev_graph
+        self.rev_scc_graph = Some(ReverseSccGraph { graph, scc_regions, universal_regions });
     }
 }
diff --git a/compiler/rustc_expand/src/mbe/macro_parser.rs b/compiler/rustc_expand/src/mbe/macro_parser.rs
index 283e68a68b5..1c222fb4a89 100644
--- a/compiler/rustc_expand/src/mbe/macro_parser.rs
+++ b/compiler/rustc_expand/src/mbe/macro_parser.rs
@@ -88,6 +88,7 @@ use rustc_span::Span;
 use std::borrow::Cow;
 use std::collections::hash_map::Entry::{Occupied, Vacant};
 use std::fmt::Display;
+use std::rc::Rc;
 
 /// A unit within a matcher that a `MatcherPos` can refer to. Similar to (and derived from)
 /// `mbe::TokenTree`, but designed specifically for fast and easy traversal during matching.
@@ -257,10 +258,10 @@ struct MatcherPos {
     /// against the relevant metavar by the black box parser. An element will be a `MatchedSeq` if
     /// the corresponding metavar decl is within a sequence.
     ///
-    /// It is critical to performance that this is an `Lrc`, because it gets cloned frequently when
+    /// It is critical to performance that this is an `Rc`, because it gets cloned frequently when
     /// processing sequences. Mostly for sequence-ending possibilities that must be tried but end
     /// up failing.
-    matches: Lrc<Vec<NamedMatch>>,
+    matches: Rc<Vec<NamedMatch>>,
 }
 
 // This type is used a lot. Make sure it doesn't unintentionally get bigger.
@@ -272,7 +273,7 @@ impl MatcherPos {
     /// and both are hot enough to be always worth inlining.
     #[inline(always)]
     fn push_match(&mut self, metavar_idx: usize, seq_depth: usize, m: NamedMatch) {
-        let matches = Lrc::make_mut(&mut self.matches);
+        let matches = Rc::make_mut(&mut self.matches);
         match seq_depth {
             0 => {
                 // We are not within a sequence. Just append `m`.
@@ -427,7 +428,7 @@ pub struct TtParser {
 
     /// Pre-allocate an empty match array, so it can be cloned cheaply for macros with many rules
     /// that have no metavars.
-    empty_matches: Lrc<Vec<NamedMatch>>,
+    empty_matches: Rc<Vec<NamedMatch>>,
 }
 
 impl TtParser {
@@ -437,7 +438,7 @@ impl TtParser {
             cur_mps: vec![],
             next_mps: vec![],
             bb_mps: vec![],
-            empty_matches: Lrc::new(vec![]),
+            empty_matches: Rc::new(vec![]),
         }
     }
 
@@ -507,7 +508,7 @@ impl TtParser {
                         // Try zero matches of this sequence, by skipping over it.
                         self.cur_mps.push(MatcherPos {
                             idx: idx_first_after,
-                            matches: Lrc::clone(&mp.matches),
+                            matches: Rc::clone(&mp.matches),
                         });
                     }
 
@@ -521,7 +522,7 @@ impl TtParser {
                     // processed next time around the loop.
                     let ending_mp = MatcherPos {
                         idx: mp.idx + 1, // +1 skips the Kleene op
-                        matches: Lrc::clone(&mp.matches),
+                        matches: Rc::clone(&mp.matches),
                     };
                     self.cur_mps.push(ending_mp);
 
@@ -537,7 +538,7 @@ impl TtParser {
                     // will fail quietly when it is processed next time around the loop.
                     let ending_mp = MatcherPos {
                         idx: mp.idx + 2, // +2 skips the separator and the Kleene op
-                        matches: Lrc::clone(&mp.matches),
+                        matches: Rc::clone(&mp.matches),
                     };
                     self.cur_mps.push(ending_mp);
 
@@ -587,9 +588,9 @@ impl TtParser {
         if *token == token::Eof {
             Some(match eof_mps {
                 EofMatcherPositions::One(mut eof_mp) => {
-                    // Need to take ownership of the matches from within the `Lrc`.
-                    Lrc::make_mut(&mut eof_mp.matches);
-                    let matches = Lrc::try_unwrap(eof_mp.matches).unwrap().into_iter();
+                    // Need to take ownership of the matches from within the `Rc`.
+                    Rc::make_mut(&mut eof_mp.matches);
+                    let matches = Rc::try_unwrap(eof_mp.matches).unwrap().into_iter();
                     self.nameize(matcher, matches)
                 }
                 EofMatcherPositions::Multiple => {
diff --git a/compiler/rustc_passes/src/debugger_visualizer.rs b/compiler/rustc_passes/src/debugger_visualizer.rs
index 9dd39a5c9fe..72371b9950b 100644
--- a/compiler/rustc_passes/src/debugger_visualizer.rs
+++ b/compiler/rustc_passes/src/debugger_visualizer.rs
@@ -2,6 +2,7 @@
 
 use hir::CRATE_HIR_ID;
 use rustc_data_structures::fx::FxHashSet;
+use rustc_data_structures::sync::Lrc;
 use rustc_expand::base::resolve_path;
 use rustc_hir as hir;
 use rustc_hir::HirId;
@@ -9,8 +10,6 @@ use rustc_middle::ty::TyCtxt;
 use rustc_middle::{query::LocalCrate, ty::query::Providers};
 use rustc_span::{sym, DebuggerVisualizerFile, DebuggerVisualizerType};
 
-use std::sync::Arc;
-
 use crate::errors::DebugVisualizerUnreadable;
 
 fn check_for_debugger_visualizer(
@@ -52,7 +51,7 @@ fn check_for_debugger_visualizer(
             match std::fs::read(&file) {
                 Ok(contents) => {
                     debugger_visualizers
-                        .insert(DebuggerVisualizerFile::new(Arc::from(contents), visualizer_type));
+                        .insert(DebuggerVisualizerFile::new(Lrc::from(contents), visualizer_type));
                 }
                 Err(error) => {
                     tcx.sess.emit_err(DebugVisualizerUnreadable {
diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs
index 8a900ca427e..341cc61fd1c 100644
--- a/compiler/rustc_span/src/lib.rs
+++ b/compiler/rustc_span/src/lib.rs
@@ -69,7 +69,6 @@ use std::hash::Hash;
 use std::ops::{Add, Range, Sub};
 use std::path::{Path, PathBuf};
 use std::str::FromStr;
-use std::sync::Arc;
 
 use md5::Digest;
 use md5::Md5;
@@ -1269,13 +1268,13 @@ pub enum DebuggerVisualizerType {
 #[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Encodable, Decodable)]
 pub struct DebuggerVisualizerFile {
     /// The complete debugger visualizer source.
-    pub src: Arc<[u8]>,
+    pub src: Lrc<[u8]>,
     /// Indicates which visualizer type this targets.
     pub visualizer_type: DebuggerVisualizerType,
 }
 
 impl DebuggerVisualizerFile {
-    pub fn new(src: Arc<[u8]>, visualizer_type: DebuggerVisualizerType) -> Self {
+    pub fn new(src: Lrc<[u8]>, visualizer_type: DebuggerVisualizerType) -> Self {
         DebuggerVisualizerFile { src, visualizer_type }
     }
 }