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

Tasks #4

Merged
merged 2 commits into from
Sep 18, 2017
Merged

Tasks #4

merged 2 commits into from
Sep 18, 2017

Conversation

fitzgen
Copy link
Collaborator

@fitzgen fitzgen commented Sep 14, 2017

Builds on top of #3

r? @tschneidereit -- still very much a sketch, but it can evaluate files.

@fitzgen
Copy link
Collaborator Author

fitzgen commented Sep 14, 2017

Also, it ended up being easier (mostly due to the futures_mpsc usage) to have a tokio reactor core per js task thread.

Copy link
Collaborator

@tschneidereit tschneidereit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great first draft! I have a bunch of nits, but this is very close to being mergeable.

Cargo.toml Outdated

[dependencies]
derive_is_enum_variant = "0.1.1"
error-chain = "0.10.0"
futures = "0.1.13"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well make this 0.1.15, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, didn't notice there had been new releases since I added this :-P

src/lib.rs Outdated
use std::sync::Arc;
use std::thread;

error_chain! {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it'd make sense to switch to derive-error-chain.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oo neat, I hadn't seen that before.

I think it is worth doing as a follow up.

src/lib.rs Outdated
foreign_links {
Io(::std::io::Error)
/// An IO error.
;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really the way things like this get formatted? It looks quite weird to me. I wasn't able to find other examples, and the other Rust people here also haven't seen anything similar.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rustfmt is pretty bad at dealing with things inside macros.

This is error-chain's fault: it puts the #[attrs] after the Io(::std::io::Error) part. Most crates seem to do the unsugared version:

Io(::std::io::Error) #[doc = "An IO error."]

I find this harder to read than the sugared doc comments.

Another reason to switch to derive-error-chain (and that crate's docs mention this).

}

errors {
/// Could not create a JavaScript runtime.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess these comments are needed because of #![deny(missing_docs)]? I find it somewhat unfortunate that they don't add any information whatsoever. No, I don't have any suggestions for improving them, but would like to see them removed if possible.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is very nice to have when reading the auto-generated docs rather than the source.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I hadn't considered that.

src/lib.rs Outdated
/// loop.
///
/// The given `main` JavaScript file will be evaluated as the main task.
pub fn new<P>(main: P) -> Options
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move the main arg to a new builder method, e.g. file? We'll want to support directly executing scripts from strings, and creating JS tasks without any initial script to execute. The latter should probably be the default behavior if file isn't used. For now, let's just have Starling::run panic if no file was provided.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was imagining the default file would be repl.js which drumroll implements a read-eval-print-loop.

And that the explicit_file.unwrap_or(repl_js_file) bits would be in src/bin/starling.rs, not the builder.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh, I like the idea of implementing a repl that way!

I still think that we need to have the ability to create a task that just initializes a JS runtime without any source, or that takes a string buffer as the source to evaluate. However, we can always change all this later, so let's leave it as-is for now.

src/lib.rs Outdated
&self.sync_io_pool
}

/// Get a handle to the thread pool for performing CPU bound background
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not call these "background tasks": we want to largely eliminate the notion of a main thread after all. Just "task" seems fine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CPU bound native tasks?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that works

src/lib.rs Outdated
}

/// Send a message to the starling main thread synchronously.
pub fn send_sync(&self, msg: StarlingMessage) -> Result<()> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the ability to send sync messages? I'd at least try to get away without it as long as possible. The error message below looks like it could be sent asynchronously?

src/task.rs Outdated
//!
//! Tasks are **lightweight**. In order to facilitate let-it-fail error handling
//! coupled with supervision hierarchies, idle tasks have little memory
//! overhead, and near no time overhead.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize that much of this introductory comment is aspirational right now, but this part seems somewhat farther out than the rest in that it depends on SpiderMonkey stuff. Specifically, at the very least bug 1323066 needs to be done. Perhaps extend the comment to be explicit about that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing.

src/task.rs Outdated
use js::rust::Runtime as JsRuntime;
use std::fmt;
use std::os;
// use std::panic;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove this

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, woops :-P

js_file: path::PathBuf,
) -> Result<(TaskHandle, thread::JoinHandle<()>)> {
let (send_handle, recv_handle) = oneshot::channel();
let starling2 = starling.clone();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason this cannot be inlined in the create_main call directly? (Mainly asking because I dislike the name.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to separate the concepts of spawning a thread and creating a task, since we intend to have them be different things down the line.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't fully understand why that needs the starling2 local, but given that this is very much a nit, I also don't feel I have to :)

Copy link
Collaborator Author

@fitzgen fitzgen Sep 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I didn't realize you were specifically referring to starling2 -- my reply was about spawn_main vs create_main. This is because the first starling gets moved into the thread, and StarlingHandle is not Copy so we have to explicitly clone it into a new variable.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, all I meant was to not have this local and do starling.clone() inline in the function call. Clearly this isn't in any way important, though.

Copy link
Collaborator

@tschneidereit tschneidereit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\o/

Cargo.toml Outdated
@@ -1,13 +1,34 @@
[package]
authors = ["Nick Fitzgerald <[email protected]>"]
authors = ["The Starling Project Developers"]
description = "The project that will henceforth be known as `starling`."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to mention this earlier: let's change this to "The Starling JS runtime". Not an ideal description, but I can't come up with anything better that's also concise right now. Proposals welcome!

src/lib.rs Outdated
@@ -1,21 +1,386 @@
//! The project that will henceforth be known as `starling`.

//! The project that will henceforth be known as Starling.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here.

This commit sets up the infrastructure such that we can evaluate a JS file and
exit zero or non-zero if the JS evals OK or throws an exception respectively.
@fitzgen fitzgen merged commit 9ffa24a into starlingjs:master Sep 18, 2017
@fitzgen fitzgen deleted the tasks branch September 18, 2017 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants