Wiki Discussion: SWI-Prolog in the browser using WASM

Interesting :slight_smile: :slight_smile: :slight_smile: ! FF=FireFox? Do you have Chrome?

(Trying to give this thread a balance, it has too many frownies and too few smileys)

Only Chromium. Times are pretty much the same.

Got the following error while building:

[10/11] Generating wasm-preload/boot.prc
FAILED: src/wasm-preload/boot.prc
cd /home/jdroo/github.com/SWI-Prolog/swipl-devel/build.wasm/src && /usr/bin/cmake -E make_directory wasm-preload && /usr/bin/cmake -E copy /home/jdroo/github.com/SWI-Prolog/swipl-devel/build.wasm/home/boot.prc wasm-preload/boot.prc && /usr/bin/cmake -E copy_directory /home/jdroo/github.com/SWI-Prolog/swipl-devel/build.wasm/home/library wasm-preload/library && /usr/bin/cmake -E copy ../packages/chr/chr.pl ../packages/chr/chr_translate.pl wasm-preload/library
Error copying file "../packages/chr/chr.pl" to "wasm-preload/library".
Error copying file "../packages/chr/chr_translate.pl" to "wasm-preload/library".

but can temporarily work around by removing it from cmake/EmscriptenTargets.cmake

I know. Need to find a clean work around :frowning:

1 Like

This is now working fine i.e. returning true

1 Like

If you want to keep up with the changes as fast as they are committed and can read Prolog, C, CMake, JSON, HTML and JavaScript then just check the SWI-Prolog development repository commits that start with WASM

Note: AFAIK there is no way on GitHub to limit the search for commits by name.

1 Like

Nice to see that many people love it https://twitter.com/josderoo/status/1554960976553844743 esp. also for semantic web https://twitter.com/josderoo/status/1555934486545801217

Excuse me but I need to clarify some things:

  • 48 hours do not reflect all the work and people involved in this work
  • academic papers are not just code that do what others have done before (if it does not teach anything that people knew before, there is no point in publishing it)
  • there exists excellent research papers about implementation details, where multiple decisions were considered and benchmarking evaluates them

Research is complementary to this industrial work. Sometimes 3 years are really necessary to find, write, and review a solution. Usually it is much less (around 6 months).

I sincerely believe that Prolog ignoring research is shooting oneself in the foot. If the language is nice, runs fast, or can do things that others cannot do, it is because someone did really hard research work.

Thanks @jan. We have the same set of benchmarks then. I’m curious about other aspects of the execution (loading code, indexing, etc.) that may affect uses of Prolog code in real life.

I would not like to get into a discussion of “industrial work” vs “academia”, first because this is not the forum and also because it should be obvious to everyone that they are both necessary and quite complementary, but an important characteristic of academic research is that it is refereed, to ensure correctness, relevance, and originality. All of this is important and takes time, and is how we ‘build on the shoulders of giants’. Without this process we are condemned to reinvent the wheel, as mentioned by @jfmc.

2 Likes

Pushed some cmake magic to fix this. Note that the build dependencies are still incorrect in the sense that just pulling the source and running ninja doesn’t always get the preload directory right. The ugly but safe way to rebuild after pulling the source is

rm -rf src/wasm-preload && ninja

The src/wasm-preload directory must be populated with what must appear in the /swipl directory of the WASM version (the Prolog home). That needs to be assembled from home and generated Prolog files for the various packages and may (unlike home) not use symlinks as that will result in symlinks to nowhere in the final WASM .data file :frowning: So, we copy some directories using cmake -E, but this is not automatically redone if some Prolog library file changes :frowning:

1 Like

As for Lightweight compilation of (C)LP to JavaScript I think you are being a bit dismissive? Just to give some examples, it talks about several problems and possible solutions, and, it provides some performance figures, which have allowed other people to have an idea about how far you can get with that approach, without having to redo all the work (which is the point of publishing research). And all of that checked by reviewers, with references, etc. I honestly do not understand why you have a problem with it.
And yes, if to explain something well it takes several papers or a book, there is no problem with that. And note that that paper came with publicly available code in a repo.

I do agree that blogs, stack overflow, etc., are wonderfully useful, but they do not replace academic publications. Looking at some language implementations nowadays this is painfully obvious: many great ideas that are very carefully described in papers are systematically ignored and the mistakes and solutions are repeated over an over again, with the respective authors living in the illusion that they have invented something.
But, hey, I may just be an oldtimer, totally willing to accept that. :wink:

1 Like
bar :- bar.

Seems to hang forever in SWI WASM and it cannot be aborted.

1 Like

BTW, we do not need 10 years to produce something useful :wink:

Good to know that the traditional Prolog toxic discussions are also possible in Discourse :slight_smile:

:grinning: :grinning: Long live Prolog!
Thanks @j4n_bur53 for the nice words on Ciao, btw.

It is not the cache but the browser localStorage. The cache merely avoids re-fetching pages. The localStorage is a way to associate key/value pairs with a given document (web page) that persist. Deleting works (for me) in Chromium as well. Note that it deletes the current file and switches to “program.pl”. You cannot delete “program.pl” itself (but you can blank it).

That is now allowed. It only allows for a limited set of characters to avoid nasty injection attacks. Simple but effective :slight_smile:

That was a bit of a challenge. That it behaves badly was to be expected: it executes a sleep in WASM, so if all is right it nicely writes, but as the browser event loop isn’t triggered nothing appears. This is now handled by redefining sleep/1 in library(wasm) to use js_yield/2. Then the wrapper around yieldable calls returns an object classified as builtin that can be executed and aborted. The execution calls setTimeout() and the abort clearTimeout() followed by resuming using wasm_abort.

Thanks.

For others using Chrome and wondering how to see Local Storage see


Of note to other using Chrome on Windows

While I can see the entry for the key and value removed (deleted) in the Chrome developer tools (F12) I can not see the file removed on the site. At present I am not worried about this nor is it high enough on my list to hunt down the root cause for this.



Thanks.

Saw the commit yesterday.



Thanks.
Now works as expected.

image


Note that this defines sleep/1 in user, overruling system:sleep/1.

That just reaffirms

“Learn the rules like a pro, so you can break them like an artist.”

― Pablo Picasso

@jan

So as not to overload you with a large number of possible issues by doing this all at once I plan during those short pauses in the day to use code I find on SWISH and try them with #wasm_demo.

Are there items you want me to prioritize and others that I should disregard?

To me it seems that having a working terminal for wasm version of SWI-Prolog is essentially a solved problem :slight_smile:

The last commits by @jan are especially nice.

Since we use some JSON to communicate with JavaScript now (WASM: Handle sleep/1 using JavaScript setTimeout() · SWI-Prolog/swipl-devel@7be5b60 · GitHub) then would it be possible to use full JSON support (from http package) so that we would not have to manually construct JSON strings? Could we extract it from http and put it into the core?