Coder Social home page Coder Social logo

Comments (7)

piscisaureus avatar piscisaureus commented on August 20, 2024

I was under the impression that eliding the lifetimes would mean they'd all be inferred to the same lifetime. But I guess I was wrong about that...

Can you share a snippet of code that compiles but shouldn't? Then I can add a trybuild test for that.

from rusty_v8.

Protryon avatar Protryon commented on August 20, 2024

@piscisaureus I added a test in theory that should be affected, basically anything that interacts between scope, arguments, and return_value without some implicit cast happening (i.e. like with ReturnValue::set).

The example included in my commit actually doesn't quite cover it now that I look, see below:

fn fn_callback_lifetimes_proxy<'sc>(scope: &mut impl v8::ToLocal<'sc>, arg: v8::Local<'sc, v8::Value>) -> v8::Local<'sc, v8::Value> {
  v8::String::new(scope, "Hello lifetimed callback!").unwrap().into()
}

fn fn_callback_lifetimes(
  scope: v8::FunctionCallbackScope,
  args: v8::FunctionCallbackArguments,
  mut rv: v8::ReturnValue,
) {
  rv.set(fn_callback_lifetimes_proxy(scope, args.get(0)));
}

That should fail to compile because args.get(0) will have a lifetime equal to the lifetime of this callback, but not equivalent to that of the callback scope, which is asserted by fn_callback_lifetimes_proxy.

By the way, I pushed up another commit to my fork that fixes this issue further by keeping scope lifetimes fully attached to FunctionCallbackArguments and ReturnValue. This is a greatly breaking change though, as it more or less breaks using closures as a callback.

A more elegant way forward might be to not track lifetimes explicitly with FunctionCallbackArguments and ReturnValue, but to require a scope to be passed in like other places to provide that lifetime. At this point I'm just hacking stuff together to get my own project working, so I didn't drop that in my fork.

from rusty_v8.

Protryon avatar Protryon commented on August 20, 2024

I have confirmed that my own fix has solved this issue for the project I'm working on. Previously I had been transmuting the lifetimes to avoid the issue...

from rusty_v8.

Protryon avatar Protryon commented on August 20, 2024

@piscisaureus See https://doc.rust-lang.org/nomicon/lifetime-elision.html

from rusty_v8.

piscisaureus avatar piscisaureus commented on August 20, 2024

@Protryon

The example included in my commit actually doesn't quite cover it now that I look, see below:

fn fn_callback_lifetimes_proxy<'sc>(scope: &mut impl v8::ToLocal<'sc>, arg: v8::Local<'sc, v8::Value>) -> v8::Local<'sc, v8::Value> {
  v8::String::new(scope, "Hello lifetimed callback!").unwrap().into()
}

fn fn_callback_lifetimes(
  scope: v8::FunctionCallbackScope,
  args: v8::FunctionCallbackArguments,
  mut rv: v8::ReturnValue,
) {
  rv.set(fn_callback_lifetimes_proxy(scope, args.get(0)));
}

That should fail to compile because args.get(0) will have a lifetime equal to the lifetime of this callback, but not equivalent to that of the callback scope, which is asserted by fn_callback_lifetimes_proxy.

So, with all due respect, I think the above example is perfectly safe and therefore it should compile.
What am I missing?

from rusty_v8.

piscisaureus avatar piscisaureus commented on August 20, 2024

@piscisaureus See https://doc.rust-lang.org/nomicon/lifetime-elision.html

Thanks. "Each elided lifetime in input position becomes a distinct lifetime parameter." 🤦🏻‍♂️

from rusty_v8.

devsnek avatar devsnek commented on August 20, 2024

Seems like these types all have explicit lifetimes on them now.

from rusty_v8.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.