mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-06 20:28:33 +00:00
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).
This commit is contained in:
commit
74c4821045
@ -76,7 +76,7 @@ pub struct RegionInferenceContext<'tcx> {
|
|||||||
/// Reverse of the SCC constraint graph -- i.e., an edge `A -> B` exists if
|
/// 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
|
/// `B: A`. This is used to compute the universal regions that are required
|
||||||
/// to outlive a given SCC. Computed lazily.
|
/// 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.
|
/// The "R0 member of [R1..Rn]" constraints, indexed by SCC.
|
||||||
member_constraints: Rc<MemberConstraintSet<'tcx, ConstraintSccIndex>>,
|
member_constraints: Rc<MemberConstraintSet<'tcx, ConstraintSccIndex>>,
|
||||||
@ -813,9 +813,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||||||
// free region that must outlive the member region `R0` (`UB:
|
// free region that must outlive the member region `R0` (`UB:
|
||||||
// R0`). Therefore, we need only keep an option `O` if `UB: O`
|
// R0`). Therefore, we need only keep an option `O` if `UB: O`
|
||||||
// for all UB.
|
// for all UB.
|
||||||
let rev_scc_graph = self.reverse_scc_graph();
|
self.compute_reverse_scc_graph();
|
||||||
let universal_region_relations = &self.universal_region_relations;
|
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);
|
debug!(?ub);
|
||||||
choice_regions.retain(|&o_r| universal_region_relations.outlives(ub, o_r));
|
choice_regions.retain(|&o_r| universal_region_relations.outlives(ub, o_r));
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ use rustc_data_structures::graph::vec_graph::VecGraph;
|
|||||||
use rustc_data_structures::graph::WithSuccessors;
|
use rustc_data_structures::graph::WithSuccessors;
|
||||||
use rustc_middle::ty::RegionVid;
|
use rustc_middle::ty::RegionVid;
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
pub(crate) struct ReverseSccGraph {
|
pub(crate) struct ReverseSccGraph {
|
||||||
graph: VecGraph<ConstraintSccIndex>,
|
graph: VecGraph<ConstraintSccIndex>,
|
||||||
@ -40,10 +39,10 @@ impl ReverseSccGraph {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl RegionInferenceContext<'_> {
|
impl RegionInferenceContext<'_> {
|
||||||
/// Compute and return the reverse SCC-based constraint graph (lazily).
|
/// Compute the reverse SCC-based constraint graph (lazily).
|
||||||
pub(super) fn reverse_scc_graph(&mut self) -> Rc<ReverseSccGraph> {
|
pub(super) fn compute_reverse_scc_graph(&mut self) {
|
||||||
if let Some(g) = &self.rev_scc_graph {
|
if self.rev_scc_graph.is_some() {
|
||||||
return g.clone();
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let graph = self.constraint_sccs.reverse();
|
let graph = self.constraint_sccs.reverse();
|
||||||
@ -63,8 +62,6 @@ impl RegionInferenceContext<'_> {
|
|||||||
start += group_size;
|
start += group_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
let rev_graph = Rc::new(ReverseSccGraph { graph, scc_regions, universal_regions });
|
self.rev_scc_graph = Some(ReverseSccGraph { graph, scc_regions, universal_regions });
|
||||||
self.rev_scc_graph = Some(rev_graph.clone());
|
|
||||||
rev_graph
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,6 +88,7 @@ use rustc_span::Span;
|
|||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::collections::hash_map::Entry::{Occupied, Vacant};
|
use std::collections::hash_map::Entry::{Occupied, Vacant};
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
/// A unit within a matcher that a `MatcherPos` can refer to. Similar to (and derived from)
|
/// 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.
|
/// `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
|
/// against the relevant metavar by the black box parser. An element will be a `MatchedSeq` if
|
||||||
/// the corresponding metavar decl is within a sequence.
|
/// 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
|
/// processing sequences. Mostly for sequence-ending possibilities that must be tried but end
|
||||||
/// up failing.
|
/// up failing.
|
||||||
matches: Lrc<Vec<NamedMatch>>,
|
matches: Rc<Vec<NamedMatch>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// This type is used a lot. Make sure it doesn't unintentionally get bigger.
|
// 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.
|
/// and both are hot enough to be always worth inlining.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn push_match(&mut self, metavar_idx: usize, seq_depth: usize, m: NamedMatch) {
|
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 {
|
match seq_depth {
|
||||||
0 => {
|
0 => {
|
||||||
// We are not within a sequence. Just append `m`.
|
// 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
|
/// Pre-allocate an empty match array, so it can be cloned cheaply for macros with many rules
|
||||||
/// that have no metavars.
|
/// that have no metavars.
|
||||||
empty_matches: Lrc<Vec<NamedMatch>>,
|
empty_matches: Rc<Vec<NamedMatch>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TtParser {
|
impl TtParser {
|
||||||
@ -437,7 +438,7 @@ impl TtParser {
|
|||||||
cur_mps: vec![],
|
cur_mps: vec![],
|
||||||
next_mps: vec![],
|
next_mps: vec![],
|
||||||
bb_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.
|
// Try zero matches of this sequence, by skipping over it.
|
||||||
self.cur_mps.push(MatcherPos {
|
self.cur_mps.push(MatcherPos {
|
||||||
idx: idx_first_after,
|
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.
|
// processed next time around the loop.
|
||||||
let ending_mp = MatcherPos {
|
let ending_mp = MatcherPos {
|
||||||
idx: mp.idx + 1, // +1 skips the Kleene op
|
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);
|
self.cur_mps.push(ending_mp);
|
||||||
|
|
||||||
@ -537,7 +538,7 @@ impl TtParser {
|
|||||||
// will fail quietly when it is processed next time around the loop.
|
// will fail quietly when it is processed next time around the loop.
|
||||||
let ending_mp = MatcherPos {
|
let ending_mp = MatcherPos {
|
||||||
idx: mp.idx + 2, // +2 skips the separator and the Kleene op
|
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);
|
self.cur_mps.push(ending_mp);
|
||||||
|
|
||||||
@ -587,9 +588,9 @@ impl TtParser {
|
|||||||
if *token == token::Eof {
|
if *token == token::Eof {
|
||||||
Some(match eof_mps {
|
Some(match eof_mps {
|
||||||
EofMatcherPositions::One(mut eof_mp) => {
|
EofMatcherPositions::One(mut eof_mp) => {
|
||||||
// Need to take ownership of the matches from within the `Lrc`.
|
// Need to take ownership of the matches from within the `Rc`.
|
||||||
Lrc::make_mut(&mut eof_mp.matches);
|
Rc::make_mut(&mut eof_mp.matches);
|
||||||
let matches = Lrc::try_unwrap(eof_mp.matches).unwrap().into_iter();
|
let matches = Rc::try_unwrap(eof_mp.matches).unwrap().into_iter();
|
||||||
self.nameize(matcher, matches)
|
self.nameize(matcher, matches)
|
||||||
}
|
}
|
||||||
EofMatcherPositions::Multiple => {
|
EofMatcherPositions::Multiple => {
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use hir::CRATE_HIR_ID;
|
use hir::CRATE_HIR_ID;
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
|
use rustc_data_structures::sync::Lrc;
|
||||||
use rustc_expand::base::resolve_path;
|
use rustc_expand::base::resolve_path;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::HirId;
|
use rustc_hir::HirId;
|
||||||
@ -9,8 +10,6 @@ use rustc_middle::ty::TyCtxt;
|
|||||||
use rustc_middle::{query::LocalCrate, ty::query::Providers};
|
use rustc_middle::{query::LocalCrate, ty::query::Providers};
|
||||||
use rustc_span::{sym, DebuggerVisualizerFile, DebuggerVisualizerType};
|
use rustc_span::{sym, DebuggerVisualizerFile, DebuggerVisualizerType};
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use crate::errors::DebugVisualizerUnreadable;
|
use crate::errors::DebugVisualizerUnreadable;
|
||||||
|
|
||||||
fn check_for_debugger_visualizer(
|
fn check_for_debugger_visualizer(
|
||||||
@ -52,7 +51,7 @@ fn check_for_debugger_visualizer(
|
|||||||
match std::fs::read(&file) {
|
match std::fs::read(&file) {
|
||||||
Ok(contents) => {
|
Ok(contents) => {
|
||||||
debugger_visualizers
|
debugger_visualizers
|
||||||
.insert(DebuggerVisualizerFile::new(Arc::from(contents), visualizer_type));
|
.insert(DebuggerVisualizerFile::new(Lrc::from(contents), visualizer_type));
|
||||||
}
|
}
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
tcx.sess.emit_err(DebugVisualizerUnreadable {
|
tcx.sess.emit_err(DebugVisualizerUnreadable {
|
||||||
|
@ -69,7 +69,6 @@ use std::hash::Hash;
|
|||||||
use std::ops::{Add, Range, Sub};
|
use std::ops::{Add, Range, Sub};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use md5::Digest;
|
use md5::Digest;
|
||||||
use md5::Md5;
|
use md5::Md5;
|
||||||
@ -1269,13 +1268,13 @@ pub enum DebuggerVisualizerType {
|
|||||||
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Encodable, Decodable)]
|
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Encodable, Decodable)]
|
||||||
pub struct DebuggerVisualizerFile {
|
pub struct DebuggerVisualizerFile {
|
||||||
/// The complete debugger visualizer source.
|
/// The complete debugger visualizer source.
|
||||||
pub src: Arc<[u8]>,
|
pub src: Lrc<[u8]>,
|
||||||
/// Indicates which visualizer type this targets.
|
/// Indicates which visualizer type this targets.
|
||||||
pub visualizer_type: DebuggerVisualizerType,
|
pub visualizer_type: DebuggerVisualizerType,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DebuggerVisualizerFile {
|
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 }
|
DebuggerVisualizerFile { src, visualizer_type }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user