[Development] Redesigning QML value types

Yuya Nishihara yuya at tcha.org
Wed Sep 21 17:59:13 CEST 2022


On Wed, 21 Sep 2022 14:59:08 +0200, Ulf Hermann wrote:
> If a function has type annotations, we pass its arguments and return
> value by value (if they are value types). Otherwise we pass by
> reference. Inside a function, everything is a reference.
> 
> This makes some intuitive sense: The type annotations are QML types, not
> JavaScript types. You might expect QML _value_ types to be passed by
> value. As long as the arguments and return values (or indeed the locals
> on the stack) are untyped, we're firmly in JavaScript land.

I like this idea in general in that it's explicit and backward compatible.

Following this type annotation rule, maybe we'll need to consider about
explicitly-value-typed vs JS-ish variable?

  let a: font = f  // copy f because a is value-typed?
  let b = a        // copy because a is typed, and b's type is inferred from a?
  let c = f        // ref because f is JS-ish type

And it's probably nice to provide an explicit copy/clone function (like the
proposed detach()) if untyped value isn't copied by default:

  let v1 = vec3d.explicit_copy_func();
  v1.x = whatever;  // don't wanna mutate the original vector

Regards,


More information about the Development mailing list