Skip to content
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

Spin the Java Starlark interpreter into a stand-alone library #2367

Closed
johnynek opened this issue Jan 17, 2017 · 24 comments
Closed

Spin the Java Starlark interpreter into a stand-alone library #2367

johnynek opened this issue Jan 17, 2017 · 24 comments
Labels
P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) stale Issues or PRs that are stale (no activity for 30 days) team-Starlark-Interpreter Issues involving the Starlark interpreter used by Bazel type: process

Comments

@johnynek
Copy link
Member

there are many use case for the skylark and the build language.

It would be great to have the BUILD language for many configuration problems on the JVM. It would be cool for this code to be available as a maven jar, or if that is not possible as a bazel repository we can cleanly depend on.

I imagine the user plugs in the standard library of functions that can be called. So, bazel proper would give access to all the built-ins of skylark's current implementation.

Basically, at this point skylark looks like a total, dynamically typed programming language (one could even imagine a project to add type inference to skylark, which I think may be possible pretty easily since it lacks recursion).

/cc @jart @laurentlb

@ittaiz
Copy link
Member

ittaiz commented Jan 17, 2017

@mikelalcon is this something that is interesting for copybara as well?

@jart
Copy link
Contributor

jart commented Jan 17, 2017

Congratulations @laurentlb it looks like you're going to be the next Guido van Rossum.

@mikelalcon
Copy link
Contributor

We already use Skylark as a standalone library :). Well not really standalone, but almost :) https://github.com/google/copybara/blob/master/WORKSPACE#L90

@laurentlb
Copy link
Contributor

We're working on it. :)

We're doing some experimentation (e.g. with copybara), but it's not ready yet for prime-time.

There's a standalone binary here if you want to play with it: https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/skylark/Skylark.java
Please don't depend on it or on the libraries, we're likely to change the interface at some point.

Thank you for the request/feedback, this is very useful for us to prioritize the work!

@laszlocsomor
Copy link
Contributor

@laurentlb : Could you prioritize this issue please?

@laurentlb laurentlb added the P3 We're not considering working on this, but happy to review a PR. (No assignee) label Jan 25, 2017
@ttsugriy
Copy link
Contributor

I also like the idea of making skylark a standalone library and I'm very much interested in using it. I used a hacky way to get a skylark standalone jar:

@laurentlb
Copy link
Contributor

laurentlb commented Oct 4, 2017

For the record, there is now a separate implementation of the interpreter in Go: https://github.com/google/skylark/

We still plan to remove Bazel dependencies from the Java interpreter.

Edit: i.e. we still want to provide a standalone Skylark library, to be used by Bazel and other projects.

@ittaiz
Copy link
Member

ittaiz commented Oct 4, 2017 via email

@dslomov
Copy link
Contributor

dslomov commented Oct 4, 2017 via email

@ittaiz
Copy link
Member

ittaiz commented Oct 4, 2017 via email

@laurentlb
Copy link
Contributor

Yes, that's what I meant (sorry if I was unclear). We're still cleaning and improving the Java code.

@johnynek
Copy link
Member Author

johnynek commented Oct 4, 2017 via email

@ttsugriy
Copy link
Contributor

ttsugriy commented Oct 8, 2017

@johnynek, JVM already has a JIT, so hot Skylark code should be optimized as long as it's executed enough times, which depends on the complexity of your project. In practice, most likely most of the Java functions will be compiled, leaving only Skylark functions not compiled, since it's unlikely that they will reach JVM's second tier threshold.

@johnynek
Copy link
Member Author

johnynek commented Oct 9, 2017

@ttsugriy I'm not sure that's really true. The interpreter code is jitted, but the skylark code itself won't be very effectively optimized by the JIT. If it were, then interpreter patterns seen in FP (see free monad, etc...) would not suffer a slow-down on the jvm.

I hear you that there should be a small amount of code in skylark and that a high fraction of build time should be in actions that are not skylark related. I have seen posts where people had O(n^2) work in skylark and things took a long time. Certainly O(n^2) work is no good, but the geek in me wonders if any off-the-shelf JITs (pypy, v8) could be leveraged to make skylark actually fast.

@laurentlb
Copy link
Contributor

There are many ways to improve the performance. If we want JIT, we can compile the Skylark code to JVM bytecode and run it. Using LLVM or V8 doesn't make sense for Bazel, since the data structure should be shared with the rest of Bazel.

To be honest, we haven't optimized the interpreter yet. There are many things we could do (do faster variable lookups, optimize method resolution, etc.), but that's a separate discussion. Feel free to file a separate issue for that.

I keep this issue open for providing a nice, self-contained library. This will be useful for Buck, among others.

@ittaiz
Copy link
Member

ittaiz commented Oct 10, 2017 via email

@ittaiz
Copy link
Member

ittaiz commented Mar 18, 2018

cc @or-shachar (as our maintainer of a very poor WORKSPACE + BUILD file parsers)

@dtretyakov
Copy link

Any progress on providing Skylark Java language library? It would be very useful for parsing BUILD/WORKSPACE files.

@ittaiz
Copy link
Member

ittaiz commented Sep 19, 2018 via email

@laurentlb
Copy link
Contributor

@alandonovan has recently made a lot of cleanup and some progress in this area.
Do you have any update to share, Alan? Maybe you could associate your future commits with this issue.

@alandonovan
Copy link
Contributor

I've been working towards splitting the interpreter out for over 6 months, primarily for the health of the Blaze and Copybara code bases, not to support other clients. There remains much to do in terms of breaking dependencies and cleaning up API mistakes---another quarter I suspect.

Once that's done, we can discuss the bigger question of whether to publish the package, move it into a separate repository, and permanently freeze its API. I don't think any decision to do that has yet been made.

@brandjon
Copy link
Member

Update:

The Go Starlark implementation (google/starlark-go) exists and is relatively stable. Use this if you're looking for a reliable Starlark implementation, are ok with writing your application in Go, and don't need strict bug-for-bug compatibility with Bazel's Starlark interpreter (which is unlikely, since at that point you'd probably want to run Bazel itself).

The Java interpreter is still hosted inside Bazel's source repository (bazelbuild/bazel). However, it has been moved to its own path (src/main/java/net/starlark) outside of Bazel's core logic, and does not depend on "Bazel-isms" anymore. That said, we are not encouraging new uses of this interpreter at this time. Its API is still not stable, and we will make breaking changes as needed (coordinating them with the only supported clients, Bazel and Copybara). Alan has done a tremendous job cleaning up the interpreter's API, but finalizing that work at this point is not a priority, thought it's conceivable it could still happen at some point in the future.

@brandjon brandjon changed the title Spin Starlark into a stand-alone library Spin the Java Starlark interpreter into a stand-alone library Feb 13, 2021
@brandjon brandjon added P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) team-Starlark-Interpreter Issues involving the Starlark interpreter used by Bazel and removed P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Starlark labels Feb 13, 2021
@sgowroji sgowroji added the stale Issues or PRs that are stale (no activity for 30 days) label Feb 17, 2023
@sgowroji
Copy link
Member

Hi there! We're doing a clean up of old issues and will be closing this one. Please reopen (or ping me to reopen) if you’d like to discuss anything further. We’ll respond as soon as we have the bandwidth/resources to do so.

@sgowroji sgowroji closed this as not planned Won't fix, can't repro, duplicate, stale Feb 17, 2023
@ittaiz
Copy link
Member

ittaiz commented Dec 6, 2023

@brandjon @alandonovan almost 3 years later- any chance that the java interpreter API has stabilized?
We're working on an internal tool that aims to give you feedback when you change a semantic macro in a backward incompatible way. Part of the need is to parse the BUILD.bazel file and that macro into java.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) stale Issues or PRs that are stale (no activity for 30 days) team-Starlark-Interpreter Issues involving the Starlark interpreter used by Bazel type: process
Projects
None yet
Development

No branches or pull requests