refactor(lexer): compile find_line_terminator separately for each CPU feature set (#28618)

Part of effort to move to runtime CPU feature detection.

Apply `cpu_versions!` to `find_line_terminator`, keeping its `#[inline]` attribute. It doesn't use `cpu` yet. `carve_js`, `carve_jsx` and `jsx_skip_trivia` pass it `cpu`. The cold `lex_html_open_comment` and `lex_html_close_comment` are compiled only once, so they pass `BASELINE`.

No change to codegen.
This commit is contained in:
overlookmotel committed 2026-11-01 21:38:51 +00:00
1 parent 03e5c94296
commit 82a7db401c
5 files changed
+14 -8

No files matched your search

@@ -142,7 +142,7 @@ pub(super) unsafe fn lex_html_open_comment(
if lanes.module {
lanes.push_diag(s as u32, 4, DiagCode::HtmlCommentInModule);
}
let end = find_line_terminator(src, n, s + 4);
let end = find_line_terminator(src, n, s + 4, cpu);
*kind.add(s) = tk!(LineComment);
if end > s + 1 {
bm_clear_range(st, s + 1, end - 1);
@@ -193,7 +193,7 @@ pub(super) unsafe fn lex_html_close_comment(
let cpu = BASELINE;
let start = s - 2;
let end = find_line_terminator(src, n, s + 1);
let end = find_line_terminator(src, n, s + 1, cpu);
*kind.add(start) = tk!(LineComment);
bm_set(st, start);
if end > start + 1 {
@@ -3,7 +3,7 @@ use crate::{error::DiagCode, token::tk};
use crate::pipeline::{
bitmap::{bm_clear, bm_clear_range, bm_get, bm_next0},
bytes::hex_val,
cpu::Cpu,
cpu::{Cpu, apply, cpu_versions},
disambiguate::not_operator_position,
find::find,
lanes::Lanes,
@@ -192,8 +192,14 @@ pub(super) unsafe fn skip_unicode_brace_escape(src: *const u8, n: usize, s: usiz
/// (U+2028/U+2029). Stops at LS/PS too, so the hashbang scan cannot run
/// through one. A 0xE2 that isn't LS/PS keeps scanning; the 2-byte confirm
/// past a trailing 0xE2 reads the pad, which can never match 0x80.
#[apply(cpu_versions)]
#[inline]
pub(super) unsafe fn find_line_terminator(src: *const u8, n: usize, mut i: usize) -> usize {
pub(super) unsafe fn find_line_terminator(
src: *const u8,
n: usize,
mut i: usize,
_cpu: impl Cpu,
) -> usize {
loop {
let p = find(src, n, i, [b'\n', b'\r', 0xE2]);
if p >= n {
+1 -1
View File
@@ -33,7 +33,7 @@ pub(super) unsafe fn carve_js(
let mut depth: Vec<u32> = Vec::with_capacity(64);
let mut i = 0usize;
if n >= 2 && *src == b'#' && *src.add(1) == b'!' {
let end = find_line_terminator(src, n, 2);
let end = find_line_terminator(src, n, 2, cpu);
*kind = tk!(Hashbang);
bm_clear_range(st, 1, end - 1);
if end < n {
@@ -104,7 +104,7 @@ pub(super) unsafe fn carve_jsx(
let mut text_start = 0usize;
let mut i = 0usize;
if n >= 2 && *src == b'#' && *src.add(1) == b'!' {
let end = find_line_terminator(src, n, 2);
let end = find_line_terminator(src, n, 2, cpu);
*kind = tk!(Hashbang);
bm_clear_range(st, 1, end - 1);
if end < n {
@@ -78,7 +78,7 @@ pub(super) unsafe fn jsx_skip_trivia(
src: *const u8,
n: usize,
mut i: usize,
_cpu: impl Cpu,
cpu: impl Cpu,
) -> usize {
loop {
if i >= n {
@@ -100,7 +100,7 @@ pub(super) unsafe fn jsx_skip_trivia(
continue;
}
b'/' => {
i = find_line_terminator(src, n, i + 2);
i = find_line_terminator(src, n, i + 2, cpu);
continue;
}
_ => {}