Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(es/lexer): Use logos lexer as a sub-lexer #9807

Draft
wants to merge 201 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
201 commits
Select commit Hold shift + click to select a range
cac6c27
raw_lexer
kdy1 Dec 19, 2024
c283516
edition
kdy1 Dec 19, 2024
8296f04
raw token
kdy1 Dec 19, 2024
6605c44
Dep
kdy1 Dec 19, 2024
1f530f0
Dep
kdy1 Dec 19, 2024
6c9e5b8
raw token
kdy1 Dec 19, 2024
87a88dc
Fix string input
kdy1 Dec 19, 2024
13291db
raw token
kdy1 Dec 19, 2024
91cbf62
bump
kdy1 Dec 19, 2024
0d66e65
mod
kdy1 Dec 19, 2024
5a0254a
bump(1)
kdy1 Dec 19, 2024
13563e4
cargo lockfile
kdy1 Dec 19, 2024
38b063b
bump
kdy1 Dec 19, 2024
ad86d37
LexError
kdy1 Dec 19, 2024
3adc46d
self.input.bump(1)
kdy1 Dec 19, 2024
9200463
RawBuffer
kdy1 Dec 19, 2024
68321b1
RawBuffer
kdy1 Dec 19, 2024
b84a9e7
raw buffer work
kdy1 Dec 19, 2024
52265b4
RawBuffer
kdy1 Dec 19, 2024
28414ec
lexerror
kdy1 Dec 19, 2024
3861977
more lexer work
kdy1 Dec 19, 2024
e9ea1cf
more lexer work
kdy1 Dec 19, 2024
a7ee322
more lexer work
kdy1 Dec 19, 2024
74de14a
remove unused
kdy1 Dec 19, 2024
9cb5e4f
RawBuffer
kdy1 Dec 19, 2024
a75fa54
eat()
kdy1 Dec 19, 2024
ed5736a
more lexer work
kdy1 Dec 19, 2024
7c89de7
cargo lockfile
kdy1 Dec 19, 2024
fd69001
more lexer work
kdy1 Dec 19, 2024
95b5b10
more lexer work
kdy1 Dec 19, 2024
650f1e0
input
kdy1 Dec 19, 2024
7c6dd06
input
kdy1 Dec 19, 2024
9758b9b
bump(1)
kdy1 Dec 19, 2024
f9cb822
more lexer work
kdy1 Dec 19, 2024
1c9e44f
more lexer work
kdy1 Dec 19, 2024
fcde3e2
more lexer work
kdy1 Dec 19, 2024
a0984e9
more lexer work
kdy1 Dec 19, 2024
adbd654
more lexer work
kdy1 Dec 19, 2024
86963a5
more lexer work
kdy1 Dec 19, 2024
674d96f
len
kdy1 Dec 19, 2024
99d0214
RawToken::LegacyCommentOpen
kdy1 Dec 19, 2024
6bd5942
more lexer work
kdy1 Dec 19, 2024
b4728b6
more lexer work
kdy1 Dec 19, 2024
5926c0a
more lexer work
kdy1 Dec 19, 2024
f64b811
more lexer work
kdy1 Dec 19, 2024
df75aa8
more lexer work
kdy1 Dec 19, 2024
54da67e
state
kdy1 Dec 19, 2024
cef364e
doc
kdy1 Dec 19, 2024
b8afac5
reset_to
kdy1 Dec 19, 2024
a9d0eb1
more methods
kdy1 Dec 19, 2024
3fb3f5b
newline callback
kdy1 Dec 19, 2024
2674ecd
extra tokens
kdy1 Dec 19, 2024
d00d09c
More token work
kdy1 Dec 19, 2024
8fdcbc4
Fix Ident
kdy1 Dec 20, 2024
644368d
fixup
kdy1 Dec 20, 2024
fa287da
More regex
kdy1 Dec 20, 2024
492b2b4
Cleanup tokens
kdy1 Dec 20, 2024
5afb9bf
more keywords
kdy1 Dec 20, 2024
b3ba909
WIP
kdy1 Dec 20, 2024
80bd19c
comment regex
kdy1 Dec 20, 2024
4916c24
baseline
kdy1 Dec 20, 2024
161b1b4
more numeric
kdy1 Dec 20, 2024
667bbe6
even more numeric
kdy1 Dec 20, 2024
d01c30d
even more numeric
kdy1 Dec 20, 2024
2d521a9
dbg
kdy1 Dec 20, 2024
093a826
Str
kdy1 Dec 20, 2024
e69862b
more tokens
kdy1 Dec 20, 2024
390e19f
-?
kdy1 Dec 20, 2024
f4d70ca
#
kdy1 Dec 20, 2024
5e6bd13
Improve tokens
kdy1 Dec 20, 2024
2f9d814
WIP
kdy1 Dec 20, 2024
73134e7
Remove `-?` from num
kdy1 Dec 20, 2024
41cba39
Fix bigint
kdy1 Dec 20, 2024
2f3a56c
LegacyOctalNum
kdy1 Dec 20, 2024
1f3ed4d
Remove Regex from raw token
kdy1 Dec 20, 2024
2ee54af
Revert "WIP"
kdy1 Dec 20, 2024
8d5d0cc
mod jsx
kdy1 Dec 20, 2024
17c6b29
UnknownChar
kdy1 Dec 20, 2024
569c324
Remove some
kdy1 Dec 20, 2024
1b7d4cf
more work
kdy1 Dec 20, 2024
363a1ef
Remove `read_token_zero`
kdy1 Dec 20, 2024
5a8d955
Remove `read_token_logical`
kdy1 Dec 20, 2024
9fb6f3a
Remove `read_token_plus_minus`
kdy1 Dec 20, 2024
b157aef
Remove `read_token_bang_or_eq`
kdy1 Dec 20, 2024
489e768
more lexer work
kdy1 Dec 20, 2024
bc2eff7
Remove mod whitespac
kdy1 Dec 20, 2024
372b787
Remove `read_token_dot`
kdy1 Dec 20, 2024
45e4336
Remove `read_str_lit`
kdy1 Dec 20, 2024
807fbce
small
kdy1 Dec 20, 2024
ac8d45b
more lexer work
kdy1 Dec 20, 2024
128f4c0
more lexer work
kdy1 Dec 20, 2024
b3551c9
flags
kdy1 Dec 20, 2024
1784e8c
Remove `read_word_as_str_with`
kdy1 Dec 20, 2024
3a35451
cur_char
kdy1 Dec 28, 2024
eecc679
chars
kdy1 Dec 28, 2024
7791ee2
Use chars
kdy1 Dec 28, 2024
fc2e28b
more work
kdy1 Dec 28, 2024
1005e3a
more work
kdy1 Dec 28, 2024
ac2d376
eat_char
kdy1 Dec 28, 2024
fe45e69
eat_ascii
kdy1 Dec 28, 2024
8e01383
is_ascii
kdy1 Dec 28, 2024
0283f88
more work
kdy1 Dec 28, 2024
88e8f08
more work
kdy1 Dec 28, 2024
bf897ee
more work
kdy1 Dec 28, 2024
614909f
more work
kdy1 Dec 28, 2024
ed18943
more work
kdy1 Dec 28, 2024
35f1cad
fix more
kdy1 Dec 28, 2024
c9bcce9
allow unused
kdy1 Dec 28, 2024
57703dc
skip current
kdy1 Dec 28, 2024
fcfb2f9
next()
kdy1 Dec 28, 2024
f36bf7a
panic message
kdy1 Dec 28, 2024
8748a42
WIP
kdy1 Dec 28, 2024
ef81ddc
wtf?
kdy1 Dec 28, 2024
e130b61
fixed
kdy1 Dec 28, 2024
29f607e
Remove dbg
kdy1 Dec 28, 2024
ef37a7c
Remove dbg
kdy1 Dec 28, 2024
4cd0cdb
skip space using raw tokens
kdy1 Dec 28, 2024
6e4216a
peeking
kdy1 Dec 28, 2024
3259bc0
dbg!(cur)
kdy1 Dec 28, 2024
23d4639
dbg! more
kdy1 Dec 28, 2024
9a712e7
fixup
kdy1 Dec 28, 2024
47d505c
Adjust start position
kdy1 Dec 31, 2024
e589969
eat
kdy1 Dec 31, 2024
ac3e7d6
Remove skip_space call
kdy1 Dec 31, 2024
9174d2a
Do not skip newlines
kdy1 Dec 31, 2024
dfcf5b7
trivia
kdy1 Dec 31, 2024
edb2172
ConflictMarker
kdy1 Dec 31, 2024
8cd59e5
Token::Str: Exclude quotes
kdy1 Jan 2, 2025
f7111d5
git conflict marker
kdy1 Jan 2, 2025
0ca456f
jsx ident
kdy1 Jan 2, 2025
efce79d
self.input.next().transpose()?;
kdy1 Jan 2, 2025
0d7b87a
self.input.next().transpose()?;
kdy1 Jan 2, 2025
1621e62
Use next instead of bump
kdy1 Jan 2, 2025
e76f8eb
next() instead of bump()
kdy1 Jan 2, 2025
c76f81a
proceed on error
kdy1 Jan 2, 2025
47c8662
fix eat()
kdy1 Jan 2, 2025
95be7bd
Rename: UnexpectedCharFromLexer
kdy1 Jan 2, 2025
f178a5c
str
kdy1 Jan 2, 2025
7d5c47d
raw token
kdy1 Jan 2, 2025
943dd78
move log
kdy1 Jan 2, 2025
115b2d6
fixup
kdy1 Jan 2, 2025
898c8c4
Revert "raw token"
kdy1 Jan 2, 2025
9a67320
Fix raw tokens
kdy1 Jan 2, 2025
57b3608
Improve debug of Token
kdy1 Jan 2, 2025
67a78d7
read_any_token
kdy1 Jan 2, 2025
28c389d
Fix read_jsx_str
kdy1 Jan 2, 2025
65e3f9f
order
kdy1 Jan 2, 2025
995fbc5
XID
kdy1 Jan 2, 2025
014230b
test raw lexer
kdy1 Jan 2, 2025
e15f602
test
kdy1 Jan 2, 2025
514ea97
fixup
kdy1 Jan 2, 2025
d32a98f
more test for escapes
kdy1 Jan 2, 2025
3ecce69
Dep
kdy1 Jan 2, 2025
1b2ca16
Dep
kdy1 Jan 2, 2025
870b2e0
cargo lockfile
kdy1 Jan 2, 2025
b1929a9
print input
kdy1 Jan 2, 2025
036af8b
dep
kdy1 Jan 2, 2025
af3a9dc
debugging logos
kdy1 Jan 2, 2025
0277816
Dep
kdy1 Jan 2, 2025
34160ef
cargo lockfile
kdy1 Jan 2, 2025
7311c97
more work
kdy1 Jan 2, 2025
83d337c
Remove dbg
kdy1 Jan 2, 2025
10d4b37
Enable more tests
kdy1 Jan 2, 2025
370c70b
test
kdy1 Jan 2, 2025
cdc3a74
Dep
kdy1 Jan 2, 2025
e8121a5
cargo lockfile
kdy1 Jan 2, 2025
6798e48
str escape
kdy1 Jan 2, 2025
ec1357a
Add a test
kdy1 Jan 2, 2025
e14d1ec
add a test
kdy1 Jan 2, 2025
4e40d2e
test
kdy1 Jan 2, 2025
f2f2a1f
fix lexing of str
kdy1 Jan 2, 2025
1872dff
LogosError
kdy1 Jan 2, 2025
9bdcd58
Lexer.cur()
kdy1 Jan 2, 2025
53403fc
return error
kdy1 Jan 2, 2025
1b95950
Rename
kdy1 Jan 2, 2025
ef91c15
more escape
kdy1 Jan 2, 2025
bd8ffc2
Remove dbg
kdy1 Jan 2, 2025
cf136e4
Use next instead of bump
kdy1 Jan 2, 2025
dff3492
Optimize reset_peeked
kdy1 Jan 2, 2025
df33a39
cleanup
kdy1 Jan 2, 2025
ba267d8
Reuse `RawToken`
kdy1 Jan 2, 2025
5e8d34c
dbg
kdy1 Jan 2, 2025
c000ccb
Optimize `eat_ascii`
kdy1 Jan 2, 2025
aa150e8
Optimize `cur_char`
kdy1 Jan 2, 2025
5df3fa1
Revert "Optimize `eat_ascii`"
kdy1 Jan 2, 2025
cefd09b
Use bump
kdy1 Jan 2, 2025
b427d68
Optimize newline
kdy1 Jan 2, 2025
39f4f7a
next() instead of bump
kdy1 Jan 2, 2025
6506bf1
whitespace_callback
kdy1 Jan 3, 2025
d6be0d0
Skip whitespace
kdy1 Jan 3, 2025
92bd6ef
Add raw token types
kdy1 Jan 3, 2025
9fb8734
skip newlines
kdy1 Jan 3, 2025
c95190a
Change assertion
kdy1 Jan 3, 2025
16dbbaf
update_cur_pos
kdy1 Jan 3, 2025
cc2d26b
Rename
kdy1 Jan 3, 2025
644da8f
Doc
kdy1 Jan 3, 2025
a34ced4
WIP: read_regexp
kdy1 Jan 3, 2025
3df1326
read_regexp
kdy1 Jan 7, 2025
7729f5f
Use it
kdy1 Jan 7, 2025
cd9fe06
Disable number tests
kdy1 Jan 7, 2025
c862038
Fix Lexer.span
kdy1 Jan 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 56 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ resolver = "2"
jsonc-parser = "0.21.0"
lazy_static = "1.4.0"
lexical = "6.1.0"
logos = "0.15.0"
lru = "0.10.0"
memchr = "2.6.1"
miette = "7.2.0"
Expand Down Expand Up @@ -129,7 +130,7 @@ lto = true
# We use CARGO_PROFILE_RELEASE_LTO for production builds
# lto = "fat"

# debug = true
debug = true
# opt-level = 'z'

[profile.bench]
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_common/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl<'a> StringInput<'a> {
}

#[inline(always)]
pub fn as_str(&self) -> &str {
pub fn as_str(&self) -> &'a str {
self.iter.as_str()
}

Expand Down
28 changes: 15 additions & 13 deletions crates/swc_ecma_parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,23 @@ typescript = []
verify = ["swc_ecma_visit"]

[dependencies]
either = { workspace = true }
num-bigint = { workspace = true }
num-traits = { workspace = true }
serde = { workspace = true, features = ["derive"] }
smallvec = { workspace = true }
smartstring = { workspace = true }
tracing = { workspace = true }
typed-arena = { workspace = true }

either = { workspace = true }
logos = { workspace = true }
new_debug_unreachable = { workspace = true }
num-bigint = { workspace = true }
num-traits = { workspace = true }
phf = { workspace = true, features = ["macros"] }
swc_atoms = { version = "3.0.2", path = "../swc_atoms" }
swc_common = { version = "5.0.0", path = "../swc_common" }
swc_ecma_ast = { version = "5.0.1", path = "../swc_ecma_ast" }
swc_ecma_visit = { version = "5.0.0", path = "../swc_ecma_visit", optional = true }
serde = { workspace = true, features = ["derive"] }
smallvec = { workspace = true }
smartstring = { workspace = true }
tracing = { workspace = true }
typed-arena = { workspace = true }

swc_atoms = { version = "3.0.2", path = "../swc_atoms" }
swc_common = { version = "5.0.0", path = "../swc_common" }
swc_ecma_ast = { version = "5.0.1", path = "../swc_ecma_ast" }
swc_ecma_raw_lexer = { version = "0.1.0", path = "../swc_ecma_raw_lexer" }
swc_ecma_visit = { version = "5.0.0", path = "../swc_ecma_visit", optional = true }

[target.'cfg(not(any(target_arch = "wasm32", target_arch = "arm")))'.dependencies]
stacker = { version = "0.1.15", optional = true }
Expand Down
13 changes: 13 additions & 0 deletions crates/swc_ecma_parser/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use swc_common::{
errors::{DiagnosticBuilder, Handler},
Span, Spanned,
};
use swc_ecma_raw_lexer::LogosError;

use crate::token::Token;

Expand Down Expand Up @@ -292,6 +293,8 @@ pub enum SyntaxError {

ReservedTypeAssertion,
ReservedArrowTypeParam,

UnexpectedCharFromLexer,
}

impl SyntaxError {
Expand Down Expand Up @@ -758,6 +761,7 @@ impl SyntaxError {
as in `<T,>() => ...`."
.into(),
SyntaxError::InvalidAssignTarget => "Invalid assignment target".into(),
SyntaxError::UnexpectedCharFromLexer => "Unexpected character".into(),
}
}
}
Expand Down Expand Up @@ -800,3 +804,12 @@ impl Error {
fn size_of_error() {
assert_eq!(std::mem::size_of::<Error>(), 8);
}

impl From<LogosError> for SyntaxError {
fn from(e: LogosError) -> Self {
match e {
LogosError::UnterminatedStr => SyntaxError::UnterminatedStrLit,
LogosError::UnknownChar => SyntaxError::UnexpectedCharFromLexer,
}
}
}
Loading
Loading