Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:97681 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 80740 invoked from network); 11 Jan 2017 14:09:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Jan 2017 14:09:38 -0000 Authentication-Results: pb1.pair.com smtp.mail=bobwei9@hotmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=bobwei9@hotmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain hotmail.com designates 65.55.116.26 as permitted sender) X-PHP-List-Original-Sender: bobwei9@hotmail.com X-Host-Fingerprint: 65.55.116.26 blu004-omc1s15.hotmail.com Received: from [65.55.116.26] ([65.55.116.26:57524] helo=BLU004-OMC1S15.hotmail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EB/DE-55699-D9C36785 for ; Wed, 11 Jan 2017 09:09:34 -0500 Received: from BLU436-SMTP55 ([65.55.116.9]) by BLU004-OMC1S15.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.23008); Wed, 11 Jan 2017 06:09:30 -0800 X-TMN: [QCUpOXSMsaG/9r7uasHCPmOzafrZiYYF] X-Originating-Email: [bobwei9@hotmail.com] Message-ID: Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 (Mac OS X Mail 10.1 \(3251\)) In-Reply-To: Date: Wed, 11 Jan 2017 15:09:25 +0100 CC: PHP internals list , Dmitry Stogov Content-Transfer-Encoding: quoted-printable References: To: Nikita Nefedov X-Mailer: Apple Mail (2.3251) X-OriginalArrivalTime: 11 Jan 2017 14:09:28.0297 (UTC) FILETIME=[524B2D90:01D26C14] Subject: Re: [PHP-DEV] Change in type-hint representation From: bobwei9@hotmail.com (Bob Weinand) > Am 11.01.2017 um 14:35 schrieb Nikita Nefedov : >=20 > On Wed, 11 Jan 2017 15:07:39 +0300, Dmitry Stogov = wrote: >=20 >> Hi, >>=20 >>=20 >> I propose to introduce a unified type representation (zend_type). >>=20 >> Now it's going to be used for typing of arguments and return values. >>=20 >> Later we should use it for properties and other things. >>=20 >>=20 >> https://gist.github.com/dstogov/1b25079856afccf0d69f77d499cb0ab1 >>=20 >>=20 >> The main changes are in zend_types.h and zend_compile.h, the rest is = just an adoption for new type representation. >>=20 >> I don't think we need RFC, because this is just an internal change = that doesn't change behavior. >>=20 >>=20 >> I got the idea working on typed properties together with Bob and Joe. >>=20 >> = https://github.com/php/php-src/compare/master...bwoebi:typed_ref_propertie= s >>=20 >> I think it would be better to introduce zend_type and then continue = work on typed properties. >>=20 >>=20 >> Any comments? >>=20 >>=20 >> Thanks. Dmitry. >>=20 >>=20 >=20 > Hey Dmitry, >=20 > Having worked on callable prototypes I'd say unifying PHP types in = Zend > is something we urgently need for PHP to continue evolving. >=20 > I'm not sure if PHP have ever been compatible with less-than-32bit > archs but if it was I think it should be said that this would break > such compatibility though. PHP itself uses more than 2^16 bytes of memory=E2=80=A6 And we anyway = have some code assuming that sizeof(void *) is a power of two. Hence = we'll anyway need at least 32 bit. > It would be great if there were some comment in the code near = zend_type > declaration where you'd explain how it is used and how additional > data is being added to the pointer. That's what the ZEND_TYPE_ENCODE_*() macros are for? > Is there any use of ZEND_TYPE_CE() macro? It seems to be forgotten = there? Not necessarily in this patch, but in typed_ref_property branch = reference types use the CE directly. > If I understood this correctly, the layout of zend_type is as follows: >=20 > [xxxx xxxx xxxx xxxx] xxxx xxxx xxxx xxy0 - for IS_OBJECT type hint > where the `xxxx`s are a (zend_string *) pointer and `y` designates > an allow_null flag >=20 > [xxxx xxxx xxxx xxxx] xxxx xxxx xxxx xxy1 - for all other type hints > where the `xxxx`s are a IS_CALLABLE, _IS_BOOL, IS_LONG, IS_DOUBLE, > IS_STRING or IS_ARRAY correct. > Do we decide here that IS_REF modifier should belong to the concrete > usages of the type (e.g. referentiality is a property of a variable > and not of a type)? > I'm not sure this if is a right decision or not but I feel like this > question should be raised. It is usually the opposite in other = languages. We nowhere user-facing consider references to be a separate type, just = internally for the zval representation (which was is_ref in PHP 5) - and = as such being a reference is a property of the variable. > How would you plan to extend this further? Let's say at some point we > will have callable prototypes or generic classes: we will need to = encode > somehow this type into zend_type: `callable(A)` or `A`. > Even right now it might be useful (as you suggest with ZEND_TYPE_CE) > to store a (zend_class_entry *) instead of (zend_string *) when > it is known to us in the zend_type. > Seems like without extending zend_type to the size of two pointers > it almost isn't doable :\ > Or, it could be made that zend_type, when it's not a simple type hint, > would point to the `zend_type_complex` which would store a > zend_class_entry pointer (or not, if it's for callable) and an array > of type specifiers. But that introduces another indirection. zend_type is just a typedef. If needed in future we may define it to = occupy 2 * sizeof(void *) or such, just as we'll need it. The goal of the patch is making type encoding transparent and handleable = in a single place. The current way of adding a new class of types usually was adding a new = element to the relevant structs or similar hacks=E2=80=A6 Bob > Anyway thanks for polishing this part, we definitely need zend_type in = some form. >=20 > --=20 > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >=20 >=20