Skip to content

Commit 140b4c6

Browse files
Inline conditionals in the parser
There are a bunch of small helper conditionals we use. Inline them to get slightly better perf in a few cases, especially when rustc is compiled without PGO.
1 parent 148a41c commit 140b4c6

File tree

1 file changed

+13
-0
lines changed
  • compiler/rustc_parse/src/parser

1 file changed

+13
-0
lines changed

compiler/rustc_parse/src/parser/mod.rs

+13
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ impl<'a> Parser<'a> {
449449
parser
450450
}
451451

452+
#[inline]
452453
pub fn recovery(mut self, recovery: Recovery) -> Self {
453454
self.recovery = recovery;
454455
self
@@ -461,6 +462,7 @@ impl<'a> Parser<'a> {
461462
///
462463
/// Technically, this only needs to restrict eager recovery by doing lookahead at more tokens.
463464
/// But making the distinction is very subtle, and simply forbidding all recovery is a lot simpler to uphold.
465+
#[inline]
464466
fn may_recover(&self) -> bool {
465467
matches!(self.recovery, Recovery::Allowed)
466468
}
@@ -542,6 +544,7 @@ impl<'a> Parser<'a> {
542544
///
543545
/// This method will automatically add `tok` to `expected_tokens` if `tok` is not
544546
/// encountered.
547+
#[inline]
545548
fn check(&mut self, tok: &TokenKind) -> bool {
546549
let is_present = self.token == *tok;
547550
if !is_present {
@@ -550,6 +553,7 @@ impl<'a> Parser<'a> {
550553
is_present
551554
}
552555

556+
#[inline]
553557
fn check_noexpect(&self, tok: &TokenKind) -> bool {
554558
self.token == *tok
555559
}
@@ -558,6 +562,7 @@ impl<'a> Parser<'a> {
558562
///
559563
/// the main purpose of this function is to reduce the cluttering of the suggestions list
560564
/// which using the normal eat method could introduce in some cases.
565+
#[inline]
561566
pub fn eat_noexpect(&mut self, tok: &TokenKind) -> bool {
562567
let is_present = self.check_noexpect(tok);
563568
if is_present {
@@ -567,6 +572,7 @@ impl<'a> Parser<'a> {
567572
}
568573

569574
/// Consumes a token 'tok' if it exists. Returns whether the given token was present.
575+
#[inline]
570576
pub fn eat(&mut self, tok: &TokenKind) -> bool {
571577
let is_present = self.check(tok);
572578
if is_present {
@@ -577,11 +583,13 @@ impl<'a> Parser<'a> {
577583

578584
/// If the next token is the given keyword, returns `true` without eating it.
579585
/// An expectation is also added for diagnostics purposes.
586+
#[inline]
580587
fn check_keyword(&mut self, kw: Symbol) -> bool {
581588
self.expected_tokens.push(TokenType::Keyword(kw));
582589
self.token.is_keyword(kw)
583590
}
584591

592+
#[inline]
585593
fn check_keyword_case(&mut self, kw: Symbol, case: Case) -> bool {
586594
if self.check_keyword(kw) {
587595
return true;
@@ -600,6 +608,7 @@ impl<'a> Parser<'a> {
600608
/// If the next token is the given keyword, eats it and returns `true`.
601609
/// Otherwise, returns `false`. An expectation is also added for diagnostics purposes.
602610
// Public for rustfmt usage.
611+
#[inline]
603612
pub fn eat_keyword(&mut self, kw: Symbol) -> bool {
604613
if self.check_keyword(kw) {
605614
self.bump();
@@ -612,6 +621,7 @@ impl<'a> Parser<'a> {
612621
/// Eats a keyword, optionally ignoring the case.
613622
/// If the case differs (and is ignored) an error is issued.
614623
/// This is useful for recovery.
624+
#[inline]
615625
fn eat_keyword_case(&mut self, kw: Symbol, case: Case) -> bool {
616626
if self.eat_keyword(kw) {
617627
return true;
@@ -629,6 +639,7 @@ impl<'a> Parser<'a> {
629639
false
630640
}
631641

642+
#[inline]
632643
fn eat_keyword_noexpect(&mut self, kw: Symbol) -> bool {
633644
if self.token.is_keyword(kw) {
634645
self.bump();
@@ -650,6 +661,7 @@ impl<'a> Parser<'a> {
650661
self.token.is_keyword(kw) && self.look_ahead(1, |t| t.is_ident() && !t.is_reserved_ident())
651662
}
652663

664+
#[inline]
653665
fn check_or_expected(&mut self, ok: bool, typ: TokenType) -> bool {
654666
if ok {
655667
true
@@ -697,6 +709,7 @@ impl<'a> Parser<'a> {
697709

698710
/// Checks to see if the next token is either `+` or `+=`.
699711
/// Otherwise returns `false`.
712+
#[inline]
700713
fn check_plus(&mut self) -> bool {
701714
self.check_or_expected(
702715
self.token.is_like_plus(),

0 commit comments

Comments
 (0)