-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
[WIP] Move fs ops to standalone crate. #2840
Conversation
511d14d
to
169ac02
Compare
Is it possible to get the typescript side of the ops in there too? |
cba256c
to
397174f
Compare
I feel like a nicer API on the ts side would be:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a lot of churn in this diff, which makes reviewing it challenging.
Anyway, I read through and added some comments.
One question: I don't understand why op registering is required at the ts level?
Once an op is registered in rust (namespace, opName) why isn't looking up the opId sufficient to send?
use crate::state::ThreadSafeState; | ||
use crate::tokio_util; | ||
use deno::*; | ||
|
||
// Cache |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These comments are unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 They seemed helpful before I reduced the amount of code for each op.
let import_maps = vec![ | ||
deno_ops_fs_bundle::get_import_map(), | ||
deno_bundle_util::get_import_map(), | ||
deno_dispatch_json_bundle::get_import_map(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really understand the purpose/necessity of this import map stuff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should't be necessary for deno cli, but I'm trying to keep deno core embedding in mind here.
No matter where the source for deno_ops_fs_bundle
is in relation to the project it's being used in, if I include the import maps deno_ops_fs
will always resolve to the absolute path to the library entry point.
) { | ||
ops[this.opNamespace][this.opName] = (id?: number): void => { | ||
this.opId = id; | ||
if (id !== undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should throw if id === undefined
(not sure if that case is possible).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
undefined
is used to signal a "reset" to listeners, since I can't really unsetAsyncHandler
currently we just ignore. The only time a "reset" happens is when you call Isolate::set_dispatcher_registry
(only when creating a new worker in our case). setAsyncHandler
has no way to "correctly" handle a opId
value that isn't a number, thus passing undefined
will throw a error.
export let OP_START: OpId; | ||
opNamespace.start = (id: MaybeOpId): void => { | ||
OP_START = id!; | ||
core.setAsyncHandler(id!, json.asyncMsgFromRust); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This API is strange...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm using a class based API like the one you suggested in all new implementations. Consider this depreciated.
import { JsonOp } from "deno_dispatch_json"; | ||
import { opNamespace } from "./namespace.ts"; | ||
|
||
const OP_CHOWN = new JsonOp(opNamespace, "chown"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The opNamespace (which is always "builtin" seems uncessary), maybe export a function that wraps this:
const OP_CHOWN = builtinOp("chown")
// which also allows (if one op in the file)
const { sendSync, sendAsync } = builtinOp("chown")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to make opNamespace
configurable. If I wanted to include multiple versions/instances of the same ops in a project I should be able to.
4b3f6d9
to
2c6d6c6
Compare
It's not you can just as easily use |
But couldn't that lookup be moved into the class constructor? Then it's only done once and avoids the accessor. On the ts side it's more "lookup" than "register"? Perhaps I'm just not following, I'll reread. This is an exciting change, looking forward to it. |
Yes, sort of.
Read/get performs a direct lookup(returns whatever value is available at the time):
The api uses a fancy set accessor to register "listener" functions that will be informed as soon as a op is registered on the rust side. https://github.com/afinch7/deno/blob/dbe541f37baa9d910989402ef5fb815e257fdbff/core/core_lib.js#L242-L274 Basically
is equivalent to something like this
This seems unnecessary, but accessors are slow and we don't want to expose things directly to avoid tampering.
The op ids we need only exist at runtime, so preforming a direct lookup during snapshot creation would just give us a inaccurate or |
2c6d6c6
to
9ee33c7
Compare
I agree with the premiss of this PR but +3000 LoC is unreasonably large when there is no new functionality being added... We need to find a way to do this in smaller pieces and less verbosely. If anything this PR should be removing code, not adding more. |
depends on #2785
part of #2180
soft depends on switch to cargo for builds and snapshot gen refactors
Primary reasons for moving ops to standalone crates:
Main goals in this PR:
TODOs:
This also removes
Deno.platform
.