-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Suggestion: Compilation targets other than JavaScript #9202
Comments
There is no such support that I am aware of. WebAssembly as it stands today is not a good target for TS/JS as it does not have manged memory support; it would be ideal for a c/c++ language that manages its own memory. As you noted, this is out of scope for the the TS project. However, the compiler API allows for skipping emit, and you can implement your emitter to write to any other language. There is a TS2Dart tool in https://github.com/angular/ts2dart that might be relevant. |
I would think this would be an end-goal of TypeScript. It would mean that developers who adopted TypeScript today could eventually be distributing the code of tomorrow, i.e. Web Assembly. It also would mean that until browser support of Web Assembly had landed in all browsers, developers could choose both targets, JavaScript and WASM. If it's out of scope, perhaps it should be reconsidered to be entirely within the scope. This would be a game changer for TypeScript. |
JS engines already turn JS code into assembly at runtime, and can do a very good job of it because they have a complete runtime profile. There's really no obvious upfront gains to be had from translating a working JS program into WASM - if there were, that's what browsers would already do with JS code in the first place. Existing JS patterns around virtual method dispatch, polymorphism, objects, etc, make it virtually impossible to turn directly into bytecode even with type information. If you're looking for a typed language with the proper restrictions in place to be able to generate explicit-memory-managed bytecode-ready IL: C |
@RyanCavanaugh As per my understand goes WASM is faster then Javascript or TS compiled to Javascript. Its a different thing if TS does not goal up this compiler feature to WASM due to current incapabilities of WASM to support objects. @ TS Team: But its going to be a pain area for Javascript sooner, especially enterprise apps that run huge TS or JS or for that matter even Coffeescript code bases. Frankly, it seems the code bases are getting bigger (definitely) day by day with transpilation based languages as well. Seems there's resistance at a lot of places to get things up and going (which I feel is possible). Sorry for trying to push hard. But things might need changes here. Please share your thoughts on it. Update: I am not sure if this work url makes sense for any support from the support request in NodeJS team on --expose-wasm on WASM tests here https://github.com/nodejs/node/tree/master/deps/v8/test/mjsunit/wasm |
The WASM devs, in the thread you linked, clarified this:
There's no level of "pushing" here that will somehow turn this into a tractable problem. Just to repeat myself: Existing JS patterns around virtual method dispatch, polymorphism, objects, etc, make it virtually impossible to turn directly into bytecode even with type information. Even if it were somehow possible, any solution would almost certainly have to work with arbitrary non-typed JS as well, at which point you may as well use whatever magic make-JS-faster perpetual motion machine someone invented. I don't want to sound rude here but if the TS devs tell you it can't really happen and the WASM devs tell you it can't really happen... why come here and 👎 me for telling you as such? Rarely in the history of software have developers overestimated the difficulty of a problem, after all. |
I don't believe anyone is asking to compile JavaScript into WASM. The question is about TypeScript at some point in the future, which would rely, of course, on an expanded feature set of WASM. TypeScript can already allow a developer to restrict what patterns are allowed, which, on compilation, limits the amount of polymorphism of function results, for example. That's not to say it's an easy problem by any stretch of the imagination. But, theoretically, at a point when WASM can support some basic features of a few more languages, it's conceivable that TypeScript could continue on its course of a "JavaScript-like" syntax that has a strict and predictable compilation target that's compatible with WASM. If TypeScript can throw compilation errors for illegal type-casting before converting to JavaScript, it could theoretically do the same with objects and patterns incompatible with WASM 2.0, etc. It's a long goal far from the present, but right now the TypeScript workflow is positioned as the closest language where that idea is even remotely possible, where it could guide a developer into highly-optimized patterns which compile into a fast compilation and execution format. Nothing else really targets the web platform in a way that forces the developer to adapt and enforce strict patterns, or generates strict JS patterns based on language-specific features of TypeScript. That said, I trust the language designers and WASM engineers who say it's kind of a moon shot. Perhaps just wishful thinking at this point. But.... from what I understand of the long-term goals of WASM, not necessarily impossible. |
I have looked across some codes seriously here. There are four things I would want to point out:
|
Similar to what I said although I'm not sure about the "quite easily". But I would say that TypeScript support of WASM is likely much easier than any other language transpiled to JavaScript, because of the way its designed. |
Yes exactly What I wanted to mean. |
Maybe worth taking a look:
|
AssemblyScript, TurboScript and Speedy.js Playground: Assembleash |
is this related? https://github.com/rsms/wasm-util |
Another somewhat related project is walt. |
This has become more relevant as the of the aspnet/blazor project 🤔 |
Feel free to close this issue under the grounds of "outrageously out-of-scope". I wasn't able to find any other information on this subject, but I'm sure I'm not the first to raise the issue.
TypeScript's typing seems like a natural fit for compilation targets such as the .NET CLR or LLVM / WebAssembly. Of course this would likely involve operating against a subset of the TypeScript language to make it less dynamic and more compiler-friendly.
This seems to me like a good move to ensure the continued growth of the language. Is there any support for such a project within the TypeScript team, Microsoft, or elsewhere?
The text was updated successfully, but these errors were encountered: