Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rust製TypeScriptコンパイラ stcの現状と今後

Rust製TypeScriptコンパイラ stcの現状と今後

Yoshiaki Togami/戸上義章

February 28, 2023
Tweet

Transcript

  1. 話すこと • そもそもstcとは? • 今どんな状況? • Weekly report(status)の読み方 • これからの計画は?

    話さないこと • Rust周りの技術的な詳細 • TypeScript型システムに関する詳細
  2. STC(Speedy TypeScript Compiler)とは • SWCの作者@kdy1氏が開発しているRust製TypeScriptコンパイラ ◦ 正真正銘型チェックができる ▪ swcは単にTSの型注釈を落とすだけだった ◦

    2022年10月にオープンソース化。現在鋭意開発中 • tsc互換な代替 & 高速化を目指す ◦ Rust製 ◦ Parallelに解析 ▪ 一応tscにもworker_threadを使ったコンパイルのissueは立っている • https://github.com/microsoft/TypeScript/issues/30235
  3. 他言語によるrewriteの難しさ 1. Specがない • PRから読み解く(多くは@ahejlsberg氏のもの。めっちゃPRに説明書いてる) • Release note • Testケースから推測

    • tscのソースコード・コメントを読む 2. tsc自体のソースコードが複雑 • checker.tsだけで約2.6MBあるのは有名(github上で表示できない) • 10年くらい開発されている
  4. stcの現状 • TypeScript4.9とそのブランチのconformance testsを元に開発 ◦ 多数のfalse-positive, false-negativeが存在 ▪ class構文周りやthisが絡むケースに結構多い ▪

    ただしエッジケースも大量に含まれる • 主要な構文や演算子はほぼ動く ◦ Satisfies operator ◦ Generics ◦ Conditional type ◦ Mapped Typesなど...
  5. • Matched ◦ tscでもstcでもエラーが正しく出ている状態。 増やしたい値 • Bad(required) ◦ tscでは出てるがstcでは出ていないエラーの数 (false-negative)。減らしたい値

    • Bad(excess) ◦ tscでは出ないがstcでは出ているエラーの数 (false-positive)。最優先で減らしたい値 • Bad(panic) ◦ panicするテストファイルの数。減らしたい値
  6. 独自でTypeScriptの構文を拡張する可能性は? • (私見ですが)@kdy1氏が関わっている限り可能性は低い ◦ 標準順守の意識が強い ◦ BunのJSXに対する構文拡張にかなり難色を示していた ▪ https://twitter.com/kdy1dev/status/1609013152590725120 ◦

    swcはESM->cjs変換も最終的に標準順守を選んだ(workaroundな処理をrevert) ▪ jest.mock of ESM should fail, and it’s correct. • https://github.com/swc-project/swc/issues/5205 • ただしエラーメッセージの改善などはあるかも ◦ tscのエラーのわかりにくさには度々言及している
  7. • Financial support ◦ Open Collective(stc) ▪ https://opencollective.com/stc ◦ Github

    sponsors ▪ @kdy1: https://github.com/sponsors/kdy1 ▪ stc: https://github.com/sponsors/dudykr • Contributing ◦ https://github.com/dudykr/stc Support
  8. References • stc ◦ https://stc.dudy.dev/ ◦ https://github.com/dudykr/stc • TypeScript ◦

    https://github.com/microsoft/TypeScript • Rewriting TypeScript in Rust? You’d have to be(@kdy1へのインタビュー) ◦ https://www.totaltypescript.com/rewriting-typescript-in-rust