-
Notifications
You must be signed in to change notification settings - Fork 694
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
Support for Prolog and Haskell #484
Comments
Supporting Prolog
It is normal in Prolog, for the garbage collector to also collect the stack. The cut operator in Prolog results in garbage stack entries. Supporting Haskell
|
Note that nothing prevents a prolog implementation on the web to heap-allocate stack-like data structures and use those as the high level stack. If a prolog implementation did this when generating to C code, how much worse would it be - in terms of overall benchmark performance - than an implementation that targets machine code and does something more clever?
Nothing prevents a custom GC implementation using linear memory.
|
A Prolog program simply does not correspond to a regular function. An exit from a Prolog program cannot be handled like a normal function return; and the corresponding call has more to do than a regular function call. Mapping this to C results in either extremely voluminous code or, more likely, an extra layer of interpretation. Most decent Prolog systems do not compile to C.
The key here is that you will get what looks like a type violation to the verifier. A pointer to a value may be a pointer to a pointer to a value or a pointer to a pointer to a pointer to a value; or it may just be a value. Compiling via C inevitably results in a substantial performance loss. A couple of places you say that one can just allocate a chunk of linear memory and play with it. This is true. But you cannot simultaneously use that as the preferred strategy and claim universality. An extreme example might illustrate: you can map all C programs to Haskell. One could then claim that, given an efficient Haskell implementation, you also have an efficient implementation of C and you have universality. I would doubt many people would accept that. On the other hand, it is not required to support either Prolog or Haskell. Just don't claim universality in that case. Some other languages that also have non-standard execution models include SQL, Scheme, Ruby, ... |
Just wanted to note that I think this is going to be common. There are just too many different GC models, no single VM can support them all (another example is languages that need GC finalizers, which JS lacks), and that's fine. The others can be implemented on top of linear memory (+ threads), with close to native speed. |
I don't think we are claiming strong universality in that sense. It's never been achieved, and is likely just not possible. |
Is WebAssembly's main goal to act as an assembler for JavaScript? I thought that we already had a wide-spread implementation of JS. I also thought that the initial goal was to be able to compile arbitrary C programs for distribution in browsers. I guess that I was upping the ante a little. I think that there is the potential for a universal assembler. |
WebAssembly's goals are spelled out here. The initial focus (MVP) is indeed on C/C++, but it is also very much the intent to "up the ante" beyond that and add support for many other kinds of languages. The FutureFeatures.md document is a list of some possible ideas (including fully general tail calls), and other ideas are possible too. It's not meant to be a comprehensive list; new ideas are welcome. For Haskell, a good starting point for exploration might be the GHC LLVM backend. What special features of LLVM does it depend on? What are its weaknesses? |
Closing as nothing specific enough has been identified, and if identified then it seems more appropriate to open new specific issues. |
CoreI’m surprised that Core hasn’t been brought up with respect to Haskell. Another targetOur goal should not be to compile Haskell to WebAssembly, but rather to compile Core to WebAssembly. The Haskell compiler GHC already compiles Haskell to Core, which is smaller and easier to work with but still portable. Haskell has already been compiled via Core to assembly (using GHC) and JVM bytecode, so I don’t see why we couldn’t do something similar for WebAssembly. GHC does even more workWe could even go further and intercept GHC later in compilation. For instance, GHC already compiles Core to the slightly simpler Spineless Tagless G-machine. It then converts STG code to a dialect of C--, at which point even function calls have been stripped away. See GHC § Architecture at Wikipedia for a holistic explanation. Just make it possibleOf course, the WebAssembly team need only take the design of Haskell’s compilation system into account. Someone else can write the compiler; we just need to make sure WebAssembly is a suitable target for such a compiler while remaining relatively small and efficient. In all likelihood, it already is, considering how much work GHC already does to compile Haskell to lower-level languages. |
Split from discussion in #483:
I'd like to see some effort made to map these use cases to the existing model and then evaluate what remains unsolvable or what remains inefficient. The use case of multiple return sites might relate to supporting a
catch
operation or exception handling, but not sure.On 11/30/2015 01:45 PM, Frank McCabe wrote:
Does prolog compiled to machine code keep a separate binding stack? How far can you get using a separate stack except for the control transfer? Even translated C is expected to have a separate stack for argument passing beyond the fixed arguments.
This sounds like a higher level issue. Machine code does not support this anyway, so surely it is translated into more primitive operations. For example arguments might be pointers to data structures, and perhaps these need to include an index to a function and a context?
Can this be handle by a single return site using multiple values (which are to be supported). The first value might be an index to dispatch to different range of return paths?
...
But they are compiled to machine code anyway, and machine code does not have specific support for 'asynchronous programming'. What we need to know is if the AST can efficiently support the primitive operations needed.
The text was updated successfully, but these errors were encountered: