Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112480 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 73457 invoked from network); 10 Dec 2020 00:54:56 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 10 Dec 2020 00:54:56 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7A5A21804D8 for ; Wed, 9 Dec 2020 16:24:28 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 9 Dec 2020 16:24:27 -0800 (PST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 4F34A5C0135 for ; Wed, 9 Dec 2020 19:24:27 -0500 (EST) Received: from imap26 ([10.202.2.76]) by compute4.internal (MEProxy); Wed, 09 Dec 2020 19:24:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=9bi8my j2y+3lSrZu/QerCBjPIV778Z7ea6yB7OqvkQo=; b=aXcAmWPxjuHgBvFUKi8xxo IhGmUVIrnYNXYveOp3lYSkOgr1V9SGFWZxu9Q10skP7GhfQwWAr2wseN6Ld4s43Z UzuV0kUi3UQ+y1FKDHZ1Ia4cmyHSRIkS2LRA+cj3zMZyc0eHKQC1CvSU5tVBNttP d/Y29aF+P5t90YU42GYdVALhkU0d6UDhHtZtplorhIHQtl5ugWfs+ZkN+jSjULeW tE3oFgZiqKuRN82yYB0XAEVowCG4Cn0hv3JA0HKbM18Wsn5p/OJvZkEglbHWjJrq vkaiUgMjlDM9BopkehLN7mNwZc1Rft4x8KYHUIrVJGev/S/D3xEZL2GP+jNWUupw == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudejledgvddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucggtffrrghtthgvrhhnpeeglefgkeduiedvvdetffeujefftdfhjeeiveehgfff keduveektddvledvvdfffeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id C3EDB14200A2; Wed, 9 Dec 2020 19:24:26 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.3.0-622-g4a97c0b-fm-20201115.001-g4a97c0b3 Mime-Version: 1.0 Message-ID: <11d829df-7e61-497d-bfd6-0f74045928ab@www.fastmail.com> In-Reply-To: References: <1150805a-44b0-af7e-d54b-6082fd23a63e@gmail.com> Date: Wed, 09 Dec 2020 18:23:57 -0600 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] [RFC] Enumerations From: larry@garfieldtech.com ("Larry Garfield") On Wed, Dec 9, 2020, at 2:03 PM, Mike Schinkel wrote: > > Unless I'm missing something, trying to define "idempotence" or "pure functions" any more strictly than that would surely be a massive project in itself - for a start, you'd need a whitelist of all built-in operations which were side-effect free (i.e. no file writes, configuration changes, output, etc, etc). > > I do not believe it should be a massive project. I believe it could be > implemented with a simple map that takes a hash of the input parameters > and maps to their return value. For idempotency this value should be > calculated the first time the method is called. > > After the first call every subsequent call would hash the input > parameters, lookup the pre-calculated value from the map, and the just > return it without re-executing any code in the method except for the > return statement (I am considering of the desire to set a breakpoint in > XDEBUG on return for all accesses, not just the first.) > > The one potential concern is if the number of potential input > permutations is large it could eat a lot of memory if the app actually > used a lot of them. But then that is true on any use of memory in PHP, > so if it became a problem for a developer I think it should be on them > to rearchitect their solution to avoid using too much memory. > > This is an important question to answer *now* because IF the answer to > idempotency is "no" then restricting it a later to be idempotent would > require accepting a BC break. But if the answer is YES, the > restriction could always be relaxed in a future version if that ever > made sense. > > -Mike What you're describing is memoization. Memoization is only safe on idempotent functions. Please do not confuse the two terms, as they mean very different things. However, as long as global variables exist in the language and there are file IO operations defined, we cannot guarantee that a given method is idempotent and thus safely memoizable. Saying "well this function/method really should be idempotent if you're doing it right" (even when correct) is insufficient justification for blindly memoizing it. That's true regardless of whether or not the method in question is on an enum. Having a way for developers to flag a function as safe to memoize would be helpful, but is a completely different topic from Enums. Forbidding enum-bound state is as close to guaranteed idempotence as PHP allows, which is what the current RFC does. --Larry Garfield