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

refactor(core): Move Deno.core bindings to ops #14793

Merged
merged 13 commits into from
Jun 7, 2022

Conversation

nayeemrmn
Copy link
Collaborator

@nayeemrmn nayeemrmn commented Jun 3, 2022

Move most Deno.core bindings which are defined in Rust to ops e.g. Deno.core.encode(foo) -> Deno.core.opSync("op_encode", foo) using #[op(v8)]. Ref #14574, #14582. One more change to the macro was required to avoid late-bound lifetime parameters when returning a value with a lifetime compatible based on scope's.

The following which are used in std are preserved as wrappers in 01_core.js, we should deprecate this syntax and update them to ops:

  • Deno.core.setMacrotaskCallback()
  • Deno.core.setNextTickCallback()
  • Deno.core.runMicrotasks()
  • Deno.core.hasTickScheduled()
  • Deno.core.setHasTickScheduled()
  • Deno.core.evalContext()
  • Deno.core.encode()

Copy link
Contributor

@AaronO AaronO left a comment

Choose a reason for hiding this comment

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

Great work overall, pretty much what I had in mind following #14582

However I would suggest the following changes for this first pass:

  1. Scope changes to core/, have outside callers still use Deno.core.foo() by adding light wrappers in 01_core.js.
  2. Keep the "v8 ops" separate from the other "regular ops", e.g: in an ops_v8.rs or ops_builtin_v8.rs or just in bindings for now

@nayeemrmn
Copy link
Collaborator Author

nayeemrmn commented Jun 3, 2022

  1. Scope changes to core/, have outside callers still use Deno.core.foo() by adding light wrappers in 01_core.js.

Okay, I added wrappers for the ones used in std but it's fairer to do it with all of them after all :-) I think in a couple of versions we should remove all of those basic wrappers, including existing Deno.core.read() etc. in favour of the ops.

@AaronO
Copy link
Contributor

AaronO commented Jun 3, 2022

  1. Scope changes to core/, have outside callers still use Deno.core.foo() by adding light wrappers in 01_core.js.

Okay, I added wrappers for the ones used in std but it's fairer to do it with all of them after all :-) I think in a couple of versions we should remove all of those basic wrappers, including existing Deno.core.read() etc. in favour of the ops.

Both opSync and opAsync will likely disappear soon, and so ops might be called as Deno.core.ops.op_foo or Deno.ops.op_foo or Deno.ops.foo

Copy link
Member

@littledivy littledivy left a comment

Choose a reason for hiding this comment

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

great stuff

ops/lib.rs Show resolved Hide resolved
core/ops_builtin_v8.rs Show resolved Hide resolved
core/runtime.rs Outdated Show resolved Hide resolved
@@ -1,4 +1,5 @@
[WILDCARD]error: Uncaught Error: foo
Warning Couldn't format source line: Column 31 is out of bounds (source may have changed at runtime)
at file:https:///[WILDCARD]/eval_context_conflicting_source.ts:1:31
at [WILDCARD]
Copy link
Member

Choose a reason for hiding this comment

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

What's changed here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There's a new stack frame for opSync

@@ -205,7 +205,7 @@
const transferables = [];
const hostObjects = [];
const arrayBufferIdsInTransferables = [];
const transferedArrayBuffers = [];
Copy link
Member

Choose a reason for hiding this comment

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

These are technically unrelated, but thanks for fixing it

@bartlomieju
Copy link
Member

Blocked by update after #14604 was merged

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

LGTM, I'll wait for one more approval before landing

@AaronO AaronO merged commit 9385a91 into denoland:main Jun 7, 2022
@nayeemrmn nayeemrmn deleted the core-bindings-to-ops branch June 7, 2022 09:52
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.

None yet

4 participants