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

limit allocation to innermost Scope #2

Closed
dherman opened this issue Sep 24, 2015 · 3 comments
Closed

limit allocation to innermost Scope #2

dherman opened this issue Sep 24, 2015 · 3 comments

Comments

@dherman
Copy link
Collaborator

dherman commented Sep 24, 2015

Since V8 actually allocates handles using the current isolate's innermost HandleScope, but the Rust types do not statically prevent attempting to allocate a handle connected to an outer Scope, dynamically track the linked list of Scopes and disallow allocation to a Scope that is not the current innermost one.

This seems unfortunate for performance, but I'm not sure if there's a faster way. Ideally we'd prevent it statically.

@Qard
Copy link

Qard commented Sep 24, 2015

You could hack it with macros.

Rather than:

pub extern fn make_an_array(call: &mut Call) {
  let result = Scope::run(|scope| {
    let mut array = scope.array(3);
    array.set(0, scope.integer(17));
    array.set(1, scope.integer(42));
    array.set(2, scope.integer(1999));
    call.set_return(array);
  });
}

you could have something like:

pub extern fn make_an_array(call: &mut Call) {
  let result = scope_run!({
    let mut array = v8_array!(3);
    array.set(0, v8_integer!(17));
    array.set(1, v8_integer!(42));
    array.set(2, v8_integer!(1999));
    call.set_return(array);
  });
}

I feel dirty just thinking about it.

@dherman
Copy link
Collaborator Author

dherman commented Oct 7, 2015

I had another hacky idea but I think it's too painful to use: if we could exploit the borrowing rules that prevent multiple simultaneous borrows when one is mutable, maybe we could somehow force the client into a mutable borrow when nesting so that no other borrowing is legal for that duration. I'm not sure if this would work, but the problem is it means you have to declare all scope variables with mut when they're going to be nested, which would just be hacky and ugly.

dherman pushed a commit that referenced this issue Oct 7, 2015
@dherman
Copy link
Collaborator Author

dherman commented Oct 7, 2015

Fixed in 3c596a0

@dherman dherman closed this as completed Oct 7, 2015
alshdavid added a commit to alshdavid-forks/neon that referenced this issue Jun 22, 2024
# This is the 1st commit message:

get_uv

# This is the commit message neon-bindings#2:

added AsyncContext and cx.spawn_async

# This is the commit message neon-bindings#3:

added async function registration

# This is the commit message neon-bindings#4:

tidy

# This is the commit message neon-bindings#5:

comments

# This is the commit message neon-bindings#6:

using futures

# This is the commit message neon-bindings#7:

using futures

# This is the commit message neon-bindings#8:

vendored libuv

# This is the commit message neon-bindings#9:

Incorrect settings
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

No branches or pull requests

2 participants