Skip to content

Commit 03994e4

Browse files
committed
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`
2 parents df8ac8f + 140b4c6 commit 03994e4

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
}
@@ -548,6 +550,7 @@ impl<'a> Parser<'a> {
548550
///
549551
/// This method will automatically add `tok` to `expected_tokens` if `tok` is not
550552
/// encountered.
553+
#[inline]
551554
fn check(&mut self, tok: &TokenKind) -> bool {
552555
let is_present = self.token == *tok;
553556
if !is_present {
@@ -556,6 +559,7 @@ impl<'a> Parser<'a> {
556559
is_present
557560
}
558561

562+
#[inline]
559563
fn check_noexpect(&self, tok: &TokenKind) -> bool {
560564
self.token == *tok
561565
}
@@ -564,6 +568,7 @@ impl<'a> Parser<'a> {
564568
///
565569
/// the main purpose of this function is to reduce the cluttering of the suggestions list
566570
/// which using the normal eat method could introduce in some cases.
571+
#[inline]
567572
pub fn eat_noexpect(&mut self, tok: &TokenKind) -> bool {
568573
let is_present = self.check_noexpect(tok);
569574
if is_present {
@@ -573,6 +578,7 @@ impl<'a> Parser<'a> {
573578
}
574579

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

584590
/// If the next token is the given keyword, returns `true` without eating it.
585591
/// An expectation is also added for diagnostics purposes.
592+
#[inline]
586593
fn check_keyword(&mut self, kw: Symbol) -> bool {
587594
self.expected_tokens.push(TokenType::Keyword(kw));
588595
self.token.is_keyword(kw)
589596
}
590597

598+
#[inline]
591599
fn check_keyword_case(&mut self, kw: Symbol, case: Case) -> bool {
592600
if self.check_keyword(kw) {
593601
return true;
@@ -606,6 +614,7 @@ impl<'a> Parser<'a> {
606614
/// If the next token is the given keyword, eats it and returns `true`.
607615
/// Otherwise, returns `false`. An expectation is also added for diagnostics purposes.
608616
// Public for rustfmt usage.
617+
#[inline]
609618
pub fn eat_keyword(&mut self, kw: Symbol) -> bool {
610619
if self.check_keyword(kw) {
611620
self.bump();
@@ -618,6 +627,7 @@ impl<'a> Parser<'a> {
618627
/// Eats a keyword, optionally ignoring the case.
619628
/// If the case differs (and is ignored) an error is issued.
620629
/// This is useful for recovery.
630+
#[inline]
621631
fn eat_keyword_case(&mut self, kw: Symbol, case: Case) -> bool {
622632
if self.eat_keyword(kw) {
623633
return true;
@@ -635,6 +645,7 @@ impl<'a> Parser<'a> {
635645
false
636646
}
637647

648+
#[inline]
638649
fn eat_keyword_noexpect(&mut self, kw: Symbol) -> bool {
639650
if self.token.is_keyword(kw) {
640651
self.bump();
@@ -656,6 +667,7 @@ impl<'a> Parser<'a> {
656667
self.token.is_keyword(kw) && self.look_ahead(1, |t| t.is_ident() && !t.is_reserved_ident())
657668
}
658669

670+
#[inline]
659671
fn check_or_expected(&mut self, ok: bool, typ: TokenType) -> bool {
660672
if ok {
661673
true
@@ -703,6 +715,7 @@ impl<'a> Parser<'a> {
703715

704716
/// Checks to see if the next token is either `+` or `+=`.
705717
/// Otherwise returns `false`.
718+
#[inline]
706719
fn check_plus(&mut self) -> bool {
707720
self.check_or_expected(
708721
self.token.is_like_plus(),

0 commit comments

Comments
 (0)