JavaScript implementation of Julia's dispatch rules

I’ve thought for a while that it would be neat to have interactive javascript components for docs pages where you can select the methods you’re interested in for a given function. I’m thinking of some kind of multiple-dropdowns widget that determines which methods match given some input types a user selects. But it should not call out to Julia given it would need to run on docs pages without a Julia server backing it. So some (reduced) type tree needs to be stored as well as all the signatures of functions one cares about.

When I last looked into it, I quickly found though that I wasn’t sure how to write down Julia’s dispatch algorithm. Especially where it gets more complicated with ambiguity, unionalls, etc. Does anyone know of an accessible source somewhere that explains how that algorithm works exactly, such that one can recreate it one-to-one in Javascript?

3 Likes

Probably a silly question, but is dispatch implemented in C? If so, could it be compiled to WASM?

Maybe, but I guess it’s tied into a lot of Julia internals that I wouldn’t want to mirror over to the JavaScript side. Types have a lot of fields that aren’t really necessary for the base functionality, I think.

1 Like

A good starting point (and maybe your best bet at the moment) is this paper on subtyping in Julia. The link to the main project page also includes a reference implementation.

I’m not sure that paper or implementation is still useful for such a purpose, because it’s outdated.

AFAIK this is defined by the reference implementation, and certainly changes from time to time. Such as that time when a discussion here lead to bug fixes in the subtyping.

I’ll have a look at that paper. Even if it doesn’t 100% match the reference implementation I guess those edge cases are less important for a UI prototype that I’m not even sure will work at all