-
Notifications
You must be signed in to change notification settings - Fork 85
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
Macros in wppl programs #153
Comments
I've been trying to figure out how best to get sweet.js + webppl working in the browser. (As you probably know, a straight-forward application of our current browserify approach doesn't work.) So far I have two possible approaches, neither of which are ideal. Load sweet.js with RequireJS This is how the library is loaded into the online sweet.js editor. I got this working with webppl by loading sweet.js with RequireJS and modifying webppl so that sweet.js is passed into
If you want to try this:
Patch sweet.js so it can be browserified It turns out that there are two problems in applying browserify to sweet.js. One comes from the use of
If you want to try this:
Since this will patch sweet.js, you should probably Both of these branches include a couple of macros in |
The second solution looks promising! How about we proceed as follows:
Do the same thing to make The drawback of this approach is that we have to maintain I'm also open to other approaches—this is just what seems good to me right now based on the ideas in your comment; there may well be other paths that I'm missing. |
I agree that of the two this would be the better way to go. I've spent some time tracking down exactly where things go wrong with brfs. One possible snag I came across is that the problem we're hitting may (at it's core) be a design decision rather than a bug, which might make changing things upstream trickier. I've opened a ticket in the hope of finding out whether or not we're likely to make any progress with this. The changes that need to be made to sweet.js are somewhat dependant on what happens with brfs, so I think it makes sense to hold off doing anything with that for now. |
I have a new branch which is a little easier to set-up than those I linked to earlier. To use it with node just |
The way that I'm currently integrating sweet.js into the compilation pipeline looks something like this:
This works, but the concatenation of the header and program makes the following tricky:
The approach I'd like to take is to do something like:
But that doesn't work because This raises the question: Is it necessary to expand the macros in a single global pass, or is it possible to do it per-file while retaining hygiene. (I've not been able to convince myself either way yet.) I noticed that @iffsid uses the sweet.js |
I've also been using One other thing: at least in the case of AD, it might also be a good idea to have the macro transform be a conditional transform (as in, only apply it if an inference algorithm that needs it is used). The AD operator overloading adds dynamic type checks that, from the experiments I did a little while ago, slow things down by at least factor of ~2 for numerics-heavy code. |
Nice, worked for me in the browser. For example (to make it easier for others who might want to try this):
One thing we'd like to do is define macros in the header and in packages, and have them applied to the (user-specified) program code. So, any per-file expansion would have to allow for that. |
Great, thanks! I've switched my branch to use this too. One possible problem is that it doesn't work with ES6 syntax at present, though that's unlikely to be permanent. I doubt this is a problem for us, but I thought I should mention it.
For macros in the header, the way I'm doing this right now is by having the contents of a new file ( Since we concatenate all Even if that behavior is desired, this approach breaks down if we choose to make it possible for individual |
Sounds good.
My first reaction was that macros in user-specified programs shouldn't transform the header, but actually it's not obvious. Let's go ahead with the solution you propose, and then if it turns out that we want to do things with macros that it doesn't support, it hopefully won't be too difficult to adjust.
Including the |
That seems reasonable. What about |
I think a good solution would rely on explicit dependencies between packages for this (#139, #209, #211), and would only apply macros that are provided by other packages that a package depends on. So, if the top-level program requires two packages in parallel, neither of these would affect the other with respect to macro expansion. If you agree that that's a reasonable direction going forward, then maybe the thing to do now is to make the macro system behave such that it is consistent with what will happen when we introduce dependencies between packages. That is, core webppl macros apply to everything, including packages, and macros in a package apply to |
It sounds reasonable, although I guess we may want them to interact for the same reason we might want user macros to transform the header.
I've updated the branch to do this and it's working in node and the browser. (It's still work-in-progress though, the |
For reference, here's my understanding of the situation with sweet.js and ES6. As mentioned earlier, the The reason for this is that sweet.js depends on escope to do the heavy lifting behind I should note that while the use of |
If having |
sweet.js is refactoring on Babel. sweet-js/sweet-core#485 |
thanks for the pointer! i guess we'll have to wait and see if this impacts us. |
It would be useful to have macros in webppl. It should be able to do this without interfering much with the system by running webppl files through sweet.js before everything else happens. (Perhaps only when a macro is detected?)
If we have macros like this, are there other things that can be simplified by relying on them? E.g. AD, desugarring assignment, ..
The text was updated successfully, but these errors were encountered: