ZEND_ARG_TYPE_INFO usage in core?

php.internals

Sara Golemon

9 years ago
Spinning off a sub-thread: Does anyone know any particular reason why ZEND_ARG_TYPE_INFO is not (barring two windows specific functions in standard) used anywhere in core? Is it? 1. Nobody has done the grunt work since 7.0? 2. It breaks something? (should only impact reflection AIUI) 3. ??? I'd be happy to put in the grunt work on standard, hash, and intl at the very least. -Sara

Nikita Popov

9 years ago
On Sat, Apr 29, 2017 at 10:24 PM, Sara Golemon <pollita@php.net> wrote:
> Spinning off a sub-thread: Does anyone know any particular reason why > ZEND_ARG_TYPE_INFO is not (barring two windows specific functions in > standard) used anywhere in core? > > Is it? > 1. Nobody has done the grunt work since 7.0? > 2. It breaks something? (should only impact reflection AIUI) > 3. ??? > > I'd be happy to put in the grunt work on standard, hash, and intl at > the very least. > > -Sara >
There are a number of reasons why this hasn't happened yet: 1. In weak mode, arginfo type violations throw, while zpp violations warn and return NULL. As such, adding arginfo types to existing functions is a BC break. 2. For methods in particular, prior to PHP 7.2, adding arginfo types was also a BC break. This is no longer the case, as variance is now respected. 3. Arginfo types for internal functions are enforced by the runtime. Because the types are already checked by zpp, this is an unnecessary duplicate check. Additionally, type-checking for internal functions is on the slow-path (to the point there it uses a different opcode). While of course this doesn't matter for some functions, in other cases type checking / parameter parsing is the main overhead of a function (which is why fast zpp was introduced in the first place). I'm sure we do not want to have decisions on whether to add or not add arginfo for a particular function based on whether it would have a significant performance impact. The solution to these problems is simple: Stop checking arginfo types for internal functions, just use them for reflection / inheritance checks, but leave the actual type-checking to zpp. However, this doing this will also change current behavior due to point (1.), as in weak-mode some type errors that are currently throwing would be reduced to warn + null. Personally I don't have a problem with that, as I'd consider this a compatible change, and it would make type-checking for internal functions consistent. Nikita

Sara Golemon

9 years ago
On Sat, Apr 29, 2017 at 3:54 PM, Nikita Popov <nikita.ppv@gmail.com> wrote:
> 1. In weak mode, arginfo type violations throw, while zpp violations warn > and return NULL. As such, adding arginfo types to existing functions is a BC > break. > 2. For methods in particular, prior to PHP 7.2, adding arginfo types was > also a BC break. This is no longer the case, as variance is now respected. > 3. Arginfo types for internal functions are enforced by the runtime. Because > the types are already checked by zpp, this is an unnecessary duplicate > check. Additionally, type-checking for internal functions is on the > slow-path (to the point there it uses a different opcode). While of course > this doesn't matter for some functions, in other cases type checking / > parameter parsing is the main overhead of a function (which is why fast zpp > was introduced in the first place). I'm sure we do not want to have > decisions on whether to add or not add arginfo for a particular function > based on whether it would have a significant performance impact. > > The solution to these problems is simple: Stop checking arginfo types for > internal functions, just use them for reflection / inheritance checks, but > leave the actual type-checking to zpp. However, this doing this will also > change current behavior due to point (1.), as in weak-mode some type errors > that are currently throwing would be reduced to warn + null. Personally I > don't have a problem with that, as I'd consider this a compatible change, > and it would make type-checking for internal functions consistent. >
Ugh.... This is why we can't have things. I'm with you on personally being fine with not enforcing ARG_INFO hints in the runtime for internal functions (leaving it to zpp), but as you say that doesn't work due to #1. Something for 8.0, I suppose. -Sara P.S. Or to quote a common acquaintance: Who uses weak mode? Weak people, that's who.

Andrew Faulds

9 years ago
Hey Nikita, Nikita Popov wrote:
> The solution to these problems is simple: Stop checking arginfo types for > internal functions, just use them for reflection / inheritance checks, but > leave the actual type-checking to zpp.
I agree that this is the way forward. An alternative would be splitting the responsibilities of argument type checking/conversion and PHP-value-to-C-value conversion. But the latter would be slower and isn't the path of least resistance. :) Thanks!
-- Andrea Faulds https://ajf.me/