On 31 October 2017 17:37:17 GMT+00:00, Levi Morrison <le...@php.net> wrote:
>  - Our current infrastructure requires us to check every element of
>the array for conformance. While undesirable I believe this can be
>optimized away in the future if we care enough, and therefore not a
>show-stopper.

Do you have a mechanism in mind for "optimising this away"? I think releasing 
the feature without any optimisation will just lead to painful slowdowns when 
people use it without realising the implications.

As I said in my previous message, it seems to be a fundamental issue with PHP's 
current type declarations that they are a) runtime, and b) asserted at 
arbitrary points, not at assignment. So even if you optimise the check 
slightly, it's still a separate check every time you enter a new function, 
which puts a limit on optimisation.

The only way I've thought of to improve things is to cache the result of 
previous type checks, but this comes with all the normal challenges of caching. 
For instance, all assignments into the array would need to invalidate these 
cached checks, or check the new value against each. References would be 
particularly tricky, as they were with the property type hint proposal.

If we selectively invalidated cached checks, we'd be running specific type 
checks at every variable assignment, but not letting the user actually assert 
on those checks. At which point, should we approach from the other direction, 
and let the user declare variable types, rather than assert value types? 

This is kind of implied if we implement generics, too, since explicitly 
constructing an instance of list<int> is asking the runtime to check future 
assignments to members of that list. In effect, could declaring "int $foo = 
42;" be considered equivalent to "$foo = new checkedScalar<int>(42);"?

Regards,

-- 
Rowan Collins
[IMSoP]

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

Reply via email to