Auto merge of #122718 - workingjubilee:eyeliner-for-contrast, r=lcnr

Inline a bunch of trivial conditions in parser

It is often the case that these small, conditional functions, when inlined, reveal notable optimization opportunities to LLVM. While saethlin has done a lot of good work on making these kinds of small functions not need `#[inline]` tags as much, being clearer about what we want inlined will get both the MIR opts and LLVM to pursue it more aggressively.

On local perf runs, this seems fruitful. Let's see what rust-timer says.

r? `@ghost`
This commit is contained in:
bors 2024-03-21 11:03:35 +00:00
commit 03994e498d

View file

@ -449,6 +449,7 @@ impl<'a> Parser<'a> {
parser parser
} }
#[inline]
pub fn recovery(mut self, recovery: Recovery) -> Self { pub fn recovery(mut self, recovery: Recovery) -> Self {
self.recovery = recovery; self.recovery = recovery;
self self
@ -461,6 +462,7 @@ impl<'a> Parser<'a> {
/// ///
/// Technically, this only needs to restrict eager recovery by doing lookahead at more tokens. /// Technically, this only needs to restrict eager recovery by doing lookahead at more tokens.
/// But making the distinction is very subtle, and simply forbidding all recovery is a lot simpler to uphold. /// But making the distinction is very subtle, and simply forbidding all recovery is a lot simpler to uphold.
#[inline]
fn may_recover(&self) -> bool { fn may_recover(&self) -> bool {
matches!(self.recovery, Recovery::Allowed) matches!(self.recovery, Recovery::Allowed)
} }
@ -548,6 +550,7 @@ impl<'a> Parser<'a> {
/// ///
/// This method will automatically add `tok` to `expected_tokens` if `tok` is not /// This method will automatically add `tok` to `expected_tokens` if `tok` is not
/// encountered. /// encountered.
#[inline]
fn check(&mut self, tok: &TokenKind) -> bool { fn check(&mut self, tok: &TokenKind) -> bool {
let is_present = self.token == *tok; let is_present = self.token == *tok;
if !is_present { if !is_present {
@ -556,6 +559,7 @@ impl<'a> Parser<'a> {
is_present is_present
} }
#[inline]
fn check_noexpect(&self, tok: &TokenKind) -> bool { fn check_noexpect(&self, tok: &TokenKind) -> bool {
self.token == *tok self.token == *tok
} }
@ -564,6 +568,7 @@ impl<'a> Parser<'a> {
/// ///
/// the main purpose of this function is to reduce the cluttering of the suggestions list /// the main purpose of this function is to reduce the cluttering of the suggestions list
/// which using the normal eat method could introduce in some cases. /// which using the normal eat method could introduce in some cases.
#[inline]
pub fn eat_noexpect(&mut self, tok: &TokenKind) -> bool { pub fn eat_noexpect(&mut self, tok: &TokenKind) -> bool {
let is_present = self.check_noexpect(tok); let is_present = self.check_noexpect(tok);
if is_present { if is_present {
@ -573,6 +578,7 @@ impl<'a> Parser<'a> {
} }
/// Consumes a token 'tok' if it exists. Returns whether the given token was present. /// Consumes a token 'tok' if it exists. Returns whether the given token was present.
#[inline]
pub fn eat(&mut self, tok: &TokenKind) -> bool { pub fn eat(&mut self, tok: &TokenKind) -> bool {
let is_present = self.check(tok); let is_present = self.check(tok);
if is_present { if is_present {
@ -583,11 +589,13 @@ impl<'a> Parser<'a> {
/// If the next token is the given keyword, returns `true` without eating it. /// If the next token is the given keyword, returns `true` without eating it.
/// An expectation is also added for diagnostics purposes. /// An expectation is also added for diagnostics purposes.
#[inline]
fn check_keyword(&mut self, kw: Symbol) -> bool { fn check_keyword(&mut self, kw: Symbol) -> bool {
self.expected_tokens.push(TokenType::Keyword(kw)); self.expected_tokens.push(TokenType::Keyword(kw));
self.token.is_keyword(kw) self.token.is_keyword(kw)
} }
#[inline]
fn check_keyword_case(&mut self, kw: Symbol, case: Case) -> bool { fn check_keyword_case(&mut self, kw: Symbol, case: Case) -> bool {
if self.check_keyword(kw) { if self.check_keyword(kw) {
return true; return true;
@ -606,6 +614,7 @@ impl<'a> Parser<'a> {
/// If the next token is the given keyword, eats it and returns `true`. /// If the next token is the given keyword, eats it and returns `true`.
/// Otherwise, returns `false`. An expectation is also added for diagnostics purposes. /// Otherwise, returns `false`. An expectation is also added for diagnostics purposes.
// Public for rustfmt usage. // Public for rustfmt usage.
#[inline]
pub fn eat_keyword(&mut self, kw: Symbol) -> bool { pub fn eat_keyword(&mut self, kw: Symbol) -> bool {
if self.check_keyword(kw) { if self.check_keyword(kw) {
self.bump(); self.bump();
@ -618,6 +627,7 @@ impl<'a> Parser<'a> {
/// Eats a keyword, optionally ignoring the case. /// Eats a keyword, optionally ignoring the case.
/// If the case differs (and is ignored) an error is issued. /// If the case differs (and is ignored) an error is issued.
/// This is useful for recovery. /// This is useful for recovery.
#[inline]
fn eat_keyword_case(&mut self, kw: Symbol, case: Case) -> bool { fn eat_keyword_case(&mut self, kw: Symbol, case: Case) -> bool {
if self.eat_keyword(kw) { if self.eat_keyword(kw) {
return true; return true;
@ -635,6 +645,7 @@ impl<'a> Parser<'a> {
false false
} }
#[inline]
fn eat_keyword_noexpect(&mut self, kw: Symbol) -> bool { fn eat_keyword_noexpect(&mut self, kw: Symbol) -> bool {
if self.token.is_keyword(kw) { if self.token.is_keyword(kw) {
self.bump(); self.bump();
@ -656,6 +667,7 @@ impl<'a> Parser<'a> {
self.token.is_keyword(kw) && self.look_ahead(1, |t| t.is_ident() && !t.is_reserved_ident()) self.token.is_keyword(kw) && self.look_ahead(1, |t| t.is_ident() && !t.is_reserved_ident())
} }
#[inline]
fn check_or_expected(&mut self, ok: bool, typ: TokenType) -> bool { fn check_or_expected(&mut self, ok: bool, typ: TokenType) -> bool {
if ok { if ok {
true true
@ -703,6 +715,7 @@ impl<'a> Parser<'a> {
/// Checks to see if the next token is either `+` or `+=`. /// Checks to see if the next token is either `+` or `+=`.
/// Otherwise returns `false`. /// Otherwise returns `false`.
#[inline]
fn check_plus(&mut self) -> bool { fn check_plus(&mut self) -> bool {
self.check_or_expected( self.check_or_expected(
self.token.is_like_plus(), self.token.is_like_plus(),