Skip to content

Commit 5fa0a16

Browse files
committed
Auto merge of rust-lang#122718 - workingjubilee:eyeliner-for-contrast, r=<try>
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 196ff44 + a81d020 commit 5fa0a16

File tree

1 file changed

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

1 file changed

+16
-0
lines changed

compiler/rustc_parse/src/parser/mod.rs

+16
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(),
@@ -737,6 +750,7 @@ impl<'a> Parser<'a> {
737750
}
738751

739752
/// Eats `+` possibly breaking tokens like `+=` in process.
753+
#[inline]
740754
fn eat_plus(&mut self) -> bool {
741755
self.break_and_eat(token::BinOp(token::Plus))
742756
}
@@ -754,6 +768,7 @@ impl<'a> Parser<'a> {
754768
}
755769

756770
/// Eats `<` possibly breaking tokens like `<<` in process.
771+
#[inline]
757772
fn eat_lt(&mut self) -> bool {
758773
let ate = self.break_and_eat(token::Lt);
759774
if ate {
@@ -1503,6 +1518,7 @@ impl<'a> Parser<'a> {
15031518
}
15041519

15051520
/// `::{` or `::*`
1521+
#[inline]
15061522
fn is_import_coupler(&mut self) -> bool {
15071523
self.check(&token::ModSep)
15081524
&& self.look_ahead(1, |t| {

0 commit comments

Comments
 (0)