refactor(lexer): #[inline(always)] on small Walk methods called from Walk::step (#28653)

Part of effort to move to runtime CPU feature detection. Fixes codegen drift in Level 3 of `disambiguate` from an earlier step in this stack.

Before the migration, `Walk::asi`, `Walk::continues_after_type_break`, `Walk::end_region_for`, `Walk::pop` and `Walk::pop_concise` were inlined everywhere. Since C7, `Walk::step` called them out of line. LLVM now rates those call sites as cold, so it inlines nothing there which costs more than 45.

They get `#[inline(always)]`. They're Level 3 code, compiled only once, so they take no CPU type.

Codegen: they're all inlined everywhere again, in all builds. `Walk::step` still calls `Tokens::base_kind` out of line, from inside the inlined `asi`, and so does `Tokens::word_kw` on aarch64. aarch64 shrinks from 35,445 instructions to 35,333. In the x86_64 build, the generic code shrinks from 36,586 instructions to 36,506, and the AVX2 copies are unchanged.
This commit is contained in:
overlookmotel committed 2026-11-02 00:20:26 +00:00
1 parent 30e09a4126
commit 5095cbe6bb
3 files changed
+5

No files matched your search

@@ -127,6 +127,7 @@ impl Walk {
end
}
#[inline(always)]
fn asi(&mut self, tokens: &Tokens, pos: usize) {
let cpu = BASELINE;
@@ -170,6 +171,7 @@ impl Walk {
}
/// Can the token at pos go on after a type that ended the previous line?
#[inline(always)]
fn continues_after_type_break(&self, tokens: &Tokens, pos: usize) -> bool {
let cpu = BASELINE;
@@ -12,6 +12,7 @@ impl Walk {
}
/// End the type region on top because the token after it belongs to the expression.
#[inline(always)]
pub(super) fn end_region_for(&mut self) {
if self.top_kind() != FrameKind::TypeRegion {
return;
@@ -114,6 +114,7 @@ impl Walk {
self.frames.last_mut().unwrap()
}
#[inline(always)]
pub(super) fn pop(&mut self) -> Frame {
if self.frames.len() > 1 { self.frames.pop().unwrap() } else { *self.top() }
}
@@ -191,6 +192,7 @@ impl Walk {
}
/// Pop concise arrow bodies sitting on top of the stack.
#[inline(always)]
pub(super) fn pop_concise(&mut self) {
while self.top_kind() == FrameKind::Concise {
self.pop();