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 182 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
182 commits
Select commit Hold shift + click to select a range
f74c421
raw_lexer
kdy1 Dec 19, 2024
b463798
edition
kdy1 Dec 19, 2024
876ef56
cargo lockfile
kdy1 Dec 19, 2024
60513c5
raw token
kdy1 Dec 19, 2024
5cba3b9
Dep
kdy1 Dec 19, 2024
fd8df12
Dep
kdy1 Dec 19, 2024
6e93aa1
raw token
kdy1 Dec 19, 2024
ed50ae1
Fix string input
kdy1 Dec 19, 2024
ca9a417
raw token
kdy1 Dec 19, 2024
af61431
bump
kdy1 Dec 19, 2024
0fa1218
mod
kdy1 Dec 19, 2024
336f04f
bump(1)
kdy1 Dec 19, 2024
b1e091f
cargo lockfile
kdy1 Dec 19, 2024
2e4ce31
bump
kdy1 Dec 19, 2024
14f49b6
LexError
kdy1 Dec 19, 2024
cc2d967
self.input.bump(1)
kdy1 Dec 19, 2024
8da4740
RawBuffer
kdy1 Dec 19, 2024
6c24674
RawBuffer
kdy1 Dec 19, 2024
a38d83b
raw buffer work
kdy1 Dec 19, 2024
610ddfb
RawBuffer
kdy1 Dec 19, 2024
2fe1087
lexerror
kdy1 Dec 19, 2024
dc809fc
more lexer work
kdy1 Dec 19, 2024
7a9d2cf
more lexer work
kdy1 Dec 19, 2024
829df0e
more lexer work
kdy1 Dec 19, 2024
d450f38
remove unused
kdy1 Dec 19, 2024
9beef3f
RawBuffer
kdy1 Dec 19, 2024
b22a467
eat()
kdy1 Dec 19, 2024
fc8465d
more lexer work
kdy1 Dec 19, 2024
1ac0720
cargo lockfile
kdy1 Dec 19, 2024
a4efbd9
more lexer work
kdy1 Dec 19, 2024
6c5fb25
more lexer work
kdy1 Dec 19, 2024
97e3e90
input
kdy1 Dec 19, 2024
632bf15
input
kdy1 Dec 19, 2024
206f3db
bump(1)
kdy1 Dec 19, 2024
14b3014
more lexer work
kdy1 Dec 19, 2024
93dd671
more lexer work
kdy1 Dec 19, 2024
5421733
more lexer work
kdy1 Dec 19, 2024
386c285
more lexer work
kdy1 Dec 19, 2024
a464f75
more lexer work
kdy1 Dec 19, 2024
43eae5a
more lexer work
kdy1 Dec 19, 2024
88536bb
len
kdy1 Dec 19, 2024
88afa84
RawToken::LegacyCommentOpen
kdy1 Dec 19, 2024
3f1f0a6
more lexer work
kdy1 Dec 19, 2024
6deecfc
more lexer work
kdy1 Dec 19, 2024
f623721
more lexer work
kdy1 Dec 19, 2024
61817f7
more lexer work
kdy1 Dec 19, 2024
d29766e
more lexer work
kdy1 Dec 19, 2024
10ac069
state
kdy1 Dec 19, 2024
88f9c1c
doc
kdy1 Dec 19, 2024
5c4e606
reset_to
kdy1 Dec 19, 2024
8292818
more methods
kdy1 Dec 19, 2024
7a70195
newline callback
kdy1 Dec 19, 2024
520a1d7
extra tokens
kdy1 Dec 19, 2024
8d1bc2c
More token work
kdy1 Dec 19, 2024
db58b51
Fix Ident
kdy1 Dec 20, 2024
da2ac0a
fixup
kdy1 Dec 20, 2024
90f21c8
More regex
kdy1 Dec 20, 2024
53bf30f
Cleanup tokens
kdy1 Dec 20, 2024
18fdd8d
more keywords
kdy1 Dec 20, 2024
2c81cdd
WIP
kdy1 Dec 20, 2024
6f99dca
comment regex
kdy1 Dec 20, 2024
f6aa1e2
baseline
kdy1 Dec 20, 2024
9dd66d9
more numeric
kdy1 Dec 20, 2024
0d22974
even more numeric
kdy1 Dec 20, 2024
f63ba4c
even more numeric
kdy1 Dec 20, 2024
fe67369
dbg
kdy1 Dec 20, 2024
d0c13be
Str
kdy1 Dec 20, 2024
7a53bce
more tokens
kdy1 Dec 20, 2024
3561ce1
-?
kdy1 Dec 20, 2024
f591ac7
#
kdy1 Dec 20, 2024
375d0e4
Improve tokens
kdy1 Dec 20, 2024
d33293f
WIP
kdy1 Dec 20, 2024
be7cc1d
Remove `-?` from num
kdy1 Dec 20, 2024
a99611a
Fix bigint
kdy1 Dec 20, 2024
405e28d
LegacyOctalNum
kdy1 Dec 20, 2024
8b944a8
Remove Regex from raw token
kdy1 Dec 20, 2024
b3d0475
Revert "WIP"
kdy1 Dec 20, 2024
2738bb0
mod jsx
kdy1 Dec 20, 2024
25a95bd
UnknownChar
kdy1 Dec 20, 2024
c512b49
Remove some
kdy1 Dec 20, 2024
87c4478
more work
kdy1 Dec 20, 2024
f84a3e8
Remove `read_token_zero`
kdy1 Dec 20, 2024
c634831
Remove `read_token_logical`
kdy1 Dec 20, 2024
ce55dfb
Remove `read_token_plus_minus`
kdy1 Dec 20, 2024
46e2261
Remove `read_token_bang_or_eq`
kdy1 Dec 20, 2024
70acb1d
more lexer work
kdy1 Dec 20, 2024
2228498
Remove mod whitespac
kdy1 Dec 20, 2024
e8f07c2
Remove `read_token_dot`
kdy1 Dec 20, 2024
fd946dd
Remove `read_str_lit`
kdy1 Dec 20, 2024
60e2e33
small
kdy1 Dec 20, 2024
1ec9828
more lexer work
kdy1 Dec 20, 2024
6694086
more lexer work
kdy1 Dec 20, 2024
6e74b50
flags
kdy1 Dec 20, 2024
2a14e5b
Remove `read_word_as_str_with`
kdy1 Dec 20, 2024
341625c
cur_char
kdy1 Dec 28, 2024
d57175f
chars
kdy1 Dec 28, 2024
083c0db
Use chars
kdy1 Dec 28, 2024
3ec74eb
more work
kdy1 Dec 28, 2024
7f5c968
more work
kdy1 Dec 28, 2024
7ce5dfe
eat_char
kdy1 Dec 28, 2024
8543a01
eat_ascii
kdy1 Dec 28, 2024
6286bdd
is_ascii
kdy1 Dec 28, 2024
29362bf
more work
kdy1 Dec 28, 2024
d448271
more work
kdy1 Dec 28, 2024
adbc5de
more work
kdy1 Dec 28, 2024
4ad2651
more work
kdy1 Dec 28, 2024
23084cd
more work
kdy1 Dec 28, 2024
e32eab3
fix more
kdy1 Dec 28, 2024
33c04ff
allow unused
kdy1 Dec 28, 2024
3a7d494
skip current
kdy1 Dec 28, 2024
2a85ac8
next()
kdy1 Dec 28, 2024
25efed1
panic message
kdy1 Dec 28, 2024
83ffccb
WIP
kdy1 Dec 28, 2024
aebf505
wtf?
kdy1 Dec 28, 2024
d204ca1
fixed
kdy1 Dec 28, 2024
8733bc9
Remove dbg
kdy1 Dec 28, 2024
199f3e1
Remove dbg
kdy1 Dec 28, 2024
e71d3e5
skip space using raw tokens
kdy1 Dec 28, 2024
819bcf8
peeking
kdy1 Dec 28, 2024
b6769d6
dbg!(cur)
kdy1 Dec 28, 2024
237acd8
dbg! more
kdy1 Dec 28, 2024
981319b
fixup
kdy1 Dec 28, 2024
8c5b8a0
Adjust start position
kdy1 Dec 31, 2024
da125be
eat
kdy1 Dec 31, 2024
ca2b2d7
Remove skip_space call
kdy1 Dec 31, 2024
03e0211
Do not skip newlines
kdy1 Dec 31, 2024
74caaf1
trivia
kdy1 Dec 31, 2024
33d2de6
ConflictMarker
kdy1 Dec 31, 2024
ae00753
Token::Str: Exclude quotes
kdy1 Jan 2, 2025
16656f1
git conflict marker
kdy1 Jan 2, 2025
581d496
jsx ident
kdy1 Jan 2, 2025
40a290f
self.input.next().transpose()?;
kdy1 Jan 2, 2025
94b697f
self.input.next().transpose()?;
kdy1 Jan 2, 2025
118fa33
Use next instead of bump
kdy1 Jan 2, 2025
15aae6f
next() instead of bump()
kdy1 Jan 2, 2025
224192d
proceed on error
kdy1 Jan 2, 2025
6dd5a42
fix eat()
kdy1 Jan 2, 2025
10abf17
Rename: UnexpectedCharFromLexer
kdy1 Jan 2, 2025
12118be
str
kdy1 Jan 2, 2025
72746ec
raw token
kdy1 Jan 2, 2025
151b9e5
move log
kdy1 Jan 2, 2025
484e53c
fixup
kdy1 Jan 2, 2025
ef7b9f0
Revert "raw token"
kdy1 Jan 2, 2025
30f1ef5
Fix raw tokens
kdy1 Jan 2, 2025
502f235
Improve debug of Token
kdy1 Jan 2, 2025
5ec9242
read_any_token
kdy1 Jan 2, 2025
f3e9176
Fix read_jsx_str
kdy1 Jan 2, 2025
1653b19
order
kdy1 Jan 2, 2025
78dc266
XID
kdy1 Jan 2, 2025
f11a8cf
test raw lexer
kdy1 Jan 2, 2025
0722cd1
test
kdy1 Jan 2, 2025
05ecdfb
fixup
kdy1 Jan 2, 2025
b5dfc4d
more test for escapes
kdy1 Jan 2, 2025
551a9cd
Dep
kdy1 Jan 2, 2025
4c0489e
Dep
kdy1 Jan 2, 2025
3f8ade1
cargo lockfile
kdy1 Jan 2, 2025
51a6cd0
print input
kdy1 Jan 2, 2025
5813856
dep
kdy1 Jan 2, 2025
7087a54
debugging logos
kdy1 Jan 2, 2025
61744ca
Dep
kdy1 Jan 2, 2025
0ff8c3b
cargo lockfile
kdy1 Jan 2, 2025
f874216
more work
kdy1 Jan 2, 2025
95bf6be
Remove dbg
kdy1 Jan 2, 2025
d33415a
Enable more tests
kdy1 Jan 2, 2025
64618e6
test
kdy1 Jan 2, 2025
938d5f4
Dep
kdy1 Jan 2, 2025
db8c13e
cargo lockfile
kdy1 Jan 2, 2025
5006008
str escape
kdy1 Jan 2, 2025
eafc7ec
Add a test
kdy1 Jan 2, 2025
fce1ce9
add a test
kdy1 Jan 2, 2025
01290fa
test
kdy1 Jan 2, 2025
fd5a6f3
fix lexing of str
kdy1 Jan 2, 2025
f15e523
LogosError
kdy1 Jan 2, 2025
fe6526f
Lexer.cur()
kdy1 Jan 2, 2025
e344c14
return error
kdy1 Jan 2, 2025
cb946da
Rename
kdy1 Jan 2, 2025
03ad7af
more escape
kdy1 Jan 2, 2025
62da5c9
Remove dbg
kdy1 Jan 2, 2025
c524318
Use next instead of bump
kdy1 Jan 2, 2025
e04bf70
Optimize reset_peeked
kdy1 Jan 2, 2025
d0f8f8b
cleanup
kdy1 Jan 2, 2025
036bc21
Reuse `RawToken`
kdy1 Jan 2, 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.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ members = [
"crates/swc_fast_ts_strip",
"tools/generate-code",
"tools/swc-releaser",
"crates/swc_ecma_raw_lexer",
]
resolver = "2"

[workspace.package]
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/swc-project/swc.git"

Expand Down Expand Up @@ -85,6 +87,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 @@ -156,7 +159,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.0", path = "../swc_atoms" }
swc_common = { version = "5.0.0", path = "../swc_common" }
swc_ecma_ast = { version = "5.0.0", 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.0", path = "../swc_atoms" }
swc_common = { version = "5.0.0", path = "../swc_common" }
swc_ecma_ast = { version = "5.0.0", 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