I'm making a Typescript type-checker in Rust
zackoverflow.dev
zackoverflow.dev
Projects are getting larger and more complex and tsc is often becoming the bottleneck performance wise: usually waiting for typechecking to finish, having your fans spinning in the background, type-stripping during development then type checking on CI. The performance needs from users seem to be outpacing what tsc can provide.
Something has to give, it would have been nice to see Microsoft create an official Rust implementation but i feel we’ll get one whether it’s from them or not.
And we’re all so happy that every time we install our node project we get a whole C build toolchain as part of the requirements…
One is the ESBuild path where they bundle the pre-built binaries for each platform so you don’t need to do any building/node-gyp on your machine (only the binary for your platform is downloaded, and because it’s via npm it shouldn’t hit any proxy issues, unlike gyp’s postInstall mess). The other is to compile down to WASM as the sibling mentioned.
I'm primarily Ruby developer, so I'm biased. But getting the right version of a Ruby runtime, then get the correct gems is a mess. Certainly not easier than getting some libc packages.
libsass (the c port) has been deprecated for a while because it couldn’t keep up featurewise. The reference compiler is now written in Dart.
Would be more exciting when there’s something to try out.
(Incidentally, would you mind reviewing the site guidelines at https://news.ycombinator.com/newsguidelines.html? You broke them with this comment.)
Actually, no. It looks fancy, sure, but error messages aren't there to be pretty, but to be usable.
1. I expect the first line of an error to give me a succinct, yet precise description of the problem.
Error: Incompatible types
It would never be possible for me to fix code based on this alone.
Contrast with Python: TypeError: unsupported operand type(s) for +: 'int' and 'str'.
I'm sure you can easily figure out what code triggered the above error just based on itself.At minimum, the first line should say which types are incompatible:
Error: Incompatible types MyType and MyType2
2. How am I supposed to read the Because of this type annotation
part? Is it MyFn has the type: X
Because of this type annotation
or Because of this type annotation
MyFn has the type: X
?To fix, include guiding punctuation:
MyFn has the type: X ...
... Because of this type annotation
or Because of this type annotation ...
... MyFn has the type: X.
Actually, it looks like it's neither and I'm somehow supposed to read it as Error: Incompatible types, because of this type annotation
... which is impossible to figure out without context. I should be able to read the error message top-down or bottom-up.To sum up, error messages are there for the programmer to be able to quickly get the gist of what happened, so they should be as obvious as possible. Check out Rust's errors for some inspiration: https://blog.rust-lang.org/2016/08/10/Shape-of-errors-to-com...
- The annotations shown look like a prettier version of the ones done by the Closure Compiler, which I find very helpful. - Some types can be really long, so putting two of them on the first line may not always be as readable as the TypeError example you gave. Putting them one above the other can make it much easier to spot the difference.
Other commenters have rightly called out the complexity of the type system as the reason why this is difficult. The other reason is that Typescript does not have a formal specification. The tsc compiler is the only reference for the correct behaviour. It would be great if the official compiler and these reimplementations could share a common test suite to ensure compatibility.
Sort of. The Rust compiler has gotten much faster in the last few years. On most common crates it's become 25-30% faster (https://arewefastyet.pages.dev). This page isn't up to date with the latest releases, which have also become faster.
During development the most typical configuration would be debug-incremental builds. Those are pretty damn fast. And personally, I don't even use rustc during development to figure out errors. rust-analyzer does a great job of giving all errors in line. I think most others who use one of the IDE options might not be waiting on rustc much.
Honestly, "rust is slow" is a bit of a meme at this point. There are engineers working on triaging compiler performance regressions every week, as well as engineers working on improving performance. But there's no concerted effort to communicate these efforts to the community. Which leads to this meme being perpetuated. I guarantee that even if the compiler improves by a further 50%, there will still be comments saying it's too slow, simply because commenters aren't aware of changes over time.
But it _is_ slow. Same as C++ and Haskell compilers are slow. And you cannot get it to really compile faster - like OCaml speed - because the language (macros and traits I guess are the worst) prohibits that. Of course, if all somebody knows are C++, Haskell and Rust the compilation doesn't seem slow to them.
So while most of the compile time is indeed usually in LLVM, there are still a lot of things rustc can do to give LLVM an easier time.
This is a common assumption but I've rarely see cargo check, which both expands macros and solves traits as well as runs the borrow checker take more than a few seconds on my machine, even when full compilation takes minutes. Most of the slowness is really in the parts that come afterwards, I suspect especially once you hit the generics explosion in later passes.
Microsoft packages a full set of binary libraries with a build.rs script for Rust/WinRT, otherwise no one would bother to wait for the build.
https://github.com/microsoft/windows-rs/tree/master/.windows
Also seeing the same crate consumed in multiple version being compiled multiple times isn't fun.
For example, the image crate.
I hope you fix this, because it is wrong. MyFun is the type. woops has the type because of the annotation.
https://github.com/swc-project/swc/issues/571#issuecomment-7...
I hope more contributors support this side project and push it to a non side project.
Use a dual license, open source and free use for everybody and commercial for companies (e.g. with minimum revnue of 1 million dollar).
I am sure this project could get easy sponsors, so no commercial license would be necessary.
I'm pretty sure I'm not the only esbuild user frustrated with having to `tsc --emitOnlyDeclaration`.
I love the idea behind it, but I'm also wary of now potentially having yet another tool that only solves "half of the problem". Could this potentially be contributed/merged with SWC in the future, seeing as it's also Rust-based?
Really exciting to see people exploring new and other idea of where to take typescript.