-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
try to downgrade Arc -> Lrc -> Rc -> no-Rc in few places #111014
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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(); | ||||||||||||||
Comment on lines
+592
to
+593
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to just
Suggested change
or even
Suggested change
|
||||||||||||||
self.nameize(matcher, matches) | ||||||||||||||
} | ||||||||||||||
EofMatcherPositions::Multiple => { | ||||||||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could this be
Rc<[NamedMatch]>
? would it be better?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe. I've tried to only change rc stuff. This thing noted as
hot
, so changing vec<->slice can potentially shadow other changes. @nnethercote changed this last time, maybe he already tried that and found, that there no gains?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, we can leave those nits for the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just tried it, there are tons of problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh.
Clone
requiringSized
was a mistake :(There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps, but that's not the only problem here.