Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70268 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 69307 invoked from network); 21 Nov 2013 20:05:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Nov 2013 20:05:56 -0000 Authentication-Results: pb1.pair.com header.from=tyra3l@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tyra3l@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.54 as permitted sender) X-PHP-List-Original-Sender: tyra3l@gmail.com X-Host-Fingerprint: 209.85.216.54 mail-qa0-f54.google.com Received: from [209.85.216.54] ([209.85.216.54:42910] helo=mail-qa0-f54.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7A/B5-36839-3A76E825 for ; Thu, 21 Nov 2013 15:05:55 -0500 Received: by mail-qa0-f54.google.com with SMTP id f11so4372558qae.20 for ; Thu, 21 Nov 2013 12:05:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=iq2HnXKqD6V7mS5yjxR59ote4TYesjs5X4baxY8f/l0=; b=i7rEppDeSu1xeaePXBXcDDkhqN2a8uAdIv5HJrtJQXhhT5+T8mK/gGaRswHWRtZ8fA T6QtSJYfXVgk7z/BY8DVArxWFIOI/pN3Uu5lhJnrQcOmvUgOblmAOCwmSIOp0EsyVPTK NHSv8E37P+bCVs6abEyVeVvmGL4yW5PvM64CDQJE4ZBO4v7hH840huc1iDxMKMKusu5/ h47IbNfi8zbPEtpm03vU4f7BABY5JKuk8Jv/tIs40+VMSSZzGXTpwNjLJdMJNncfKW7I kHwNxymneTu2fzNicfqEz23uNpI88stxsQXwOFrEJDEkM4A6EVmmEXnC2LnB45/LX+4j zVnw== MIME-Version: 1.0 X-Received: by 10.49.127.101 with SMTP id nf5mr14681554qeb.61.1385064352458; Thu, 21 Nov 2013 12:05:52 -0800 (PST) Received: by 10.140.37.201 with HTTP; Thu, 21 Nov 2013 12:05:52 -0800 (PST) Received: by 10.140.37.201 with HTTP; Thu, 21 Nov 2013 12:05:52 -0800 (PST) In-Reply-To: <528CE64A.1020303@gmail.com> References: <528CE64A.1020303@gmail.com> Date: Thu, 21 Nov 2013 21:05:52 +0100 Message-ID: To: Terry Ellison Cc: PHP Internals , Joe Watkins Content-Type: multipart/alternative; boundary=047d7b6dc0bcb82c7704ebb56ca7 Subject: Re: [PHP-DEV] Comments on non-unique naming convention for closures From: tyra3l@gmail.com (Ferenc Kovacs) --047d7b6dc0bcb82c7704ebb56ca7 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 2013.11.20. 17:42, "Terry Ellison" ezt =C3=ADrta: > > The following bugs relate to this discussion: > > #64291 Indeterminate GC of evaled lambda function resources > #65915 Inconsistent results with require return value > > I don't want to discuss these or the specific fixes here, since I can work up a fix and discuss them in the bugrep. However, > my one-sentence Q is "should we replace the naming convention for closures with a truly unique one?" What I would like is some feedback / guidance / discussion on the general architectural issue which underlies the reasons for these bugs occuring in the first place. > > * The associated closure functions are compiled during the INCLUDE_OR_EVAL opcode that included / eval'ed the originating PHP source, and are named according to the convention "\0{closure}$name$addr" where the name is the resolved filename of the source where the function was defined and the addr is the absolute address of the function definition within the memory resident copy of the source during the compilation process. The compilation creates an entry in the GC(function_table) for this function > > * Closure objects are instantiated during the execution ZEND_DECLARE_LAMBDA_FUNCTION opcode at runtime. This handler invokes the built-in CTOR for the closure bind the corresponding function, > > * Closure objects are destroyed by the closure DTOR in line with the usual PHP scoping rules. > > * There is no specific deletion function for the GC(function_table) entries other than normal request rundown, because the compiler and RTS can't safely determine if a closure function will no longer be required for further closure, e.g. > > for ($array as $i) { > $f =3D function($x) { ... }; > ... > } > > * The "\0{closure}$name$addr" scheme does provide a sort of dirty reuse in that if another function is compiled with the same filename and at the same source address (which can happen for logically different variables due to storage reuse), then the current implementation simply overwrites the earlier function definition. Though the rationale for this isn't documented, I assume that this is because it is _usually_ safe to assume that the earlier copy is no longer required. However, it is possible to construct cases where this assumption is false -- especially as is the case of OPcached functions where the name can persist for the life of the SMA rather than just one request. > > What I am suggesting is that this convention should be changed for something like "\0{closure}$name$ctime$index" or even just "\0{closure}$uuid" using the standard UUID algo. Reactions? Comments? > > The only side effect that I can see is that in circumstances where the overwrite *does* replace stale functions then the function DTOR will no longer be taking place leading a growth in the function table with the associated memory overhead. > > Thanks for any feedback > Terry > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > Bumping the thread and ccing Joe as we were having a similar discussion about the internal naming of the inner classes proposed by him. --047d7b6dc0bcb82c7704ebb56ca7--