Stas, you have to look into "master" branch code.

In most cases we avoid IS_UNDEF checks, verifying the most probable expected 
types first.

ZEND_VM_HANDLER(1, ZEND_ADD, CONST|TMPVAR|CV, CONST|TMPVAR|CV)
{
        USE_OPLINE
        zend_free_op free_op1, free_op2;
        zval *op1, *op2, *result;

        op1 = GET_OP1_ZVAL_PTR_UNDEF(BP_VAR_R);
        op2 = GET_OP2_ZVAL_PTR_UNDEF(BP_VAR_R);
        if (EXPECTED(Z_TYPE_INFO_P(op1) == IS_LONG)) {
                if (EXPECTED(Z_TYPE_INFO_P(op2) == IS_LONG)) {
                        result = EX_VAR(opline->result.var);
                        fast_long_add_function(result, op1, op2);
                        ZEND_VM_NEXT_OPCODE();

We also have specialized handlers that don't check for types at all (they are 
used, if we know types at optimization time).

ZEND_VM_TYPE_SPEC_HANDLER(ZEND_ADD, (res_info == MAY_BE_LONG && op1_info == 
MAY_BE_LONG && op2_info == MAY_BE_LONG), ZEND_ADD_LONG_NO_OVERFLOW, 
CONST|TMPVARCV, CONST|TMPVARCV, SPEC(NO_CONST_CONST,COMMUTATIVE))
{
        USE_OPLINE
        zval *op1, *op2, *result;

        op1 = GET_OP1_ZVAL_PTR_UNDEF(BP_VAR_R);
        op2 = GET_OP2_ZVAL_PTR_UNDEF(BP_VAR_R);
        result = EX_VAR(opline->result.var);
        ZVAL_LONG(result, Z_LVAL_P(op1) + Z_LVAL_P(op2));
        ZEND_VM_NEXT_OPCODE();
}

The second technique won't work for typed properties if they might be turned 
into IS_UNDEF. 

Thanks. Dmitry. 

________________________________________
From: Stanislav Malyshev <smalys...@gmail.com>
Sent: Thursday, April 14, 2016 20:26
To: Dmitry Stogov; Joe Watkins
Cc: internals; Zeev Suraski; Nikita Popov
Subject: Re: [PHP-DEV] Re: Typed properties patch

Hi!

> I didn't understand.
> Of course we keep a class definition, where the type of property "$a" -
> IS_LONG, but the actual value of "$a" may become IS_UNDEF.

What I'm saying is maybe it's fine.

> In PHP-7 we check for IS_LONG without type hint.
> With type hint and ability to unset(), we will have to check for IS_LONG
> anyway.

Well, we'd have to check for IS_UNDEF, but we won't have to choose
between IS_LONG, IS_OBJECT and IS_RESOURCE.

> So type hinting won't improve reading performance, but writing is going
> to be slower, because we have to perform type check.
> So even theoretically this approach couldn't make any improvement.

Maybe I misunderstand what performance improvements there are. Do we do
different things when reading a variable depending on type? I thought
it's for *operations* with variables, but for just reading them it
doesn't matter. For operations, we could have instead of function
handling all types just function handling IS_LONG and a small check for
UNDEF inside.

I think it is mych better than a weird concept of non-unsettable variable.
--
Stas Malyshev
smalys...@gmail.com

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to