Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125170 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 4B2141A00BD for ; Fri, 23 Aug 2024 21:06:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1724447313; bh=3EmKWnpV1s1H2cYNZoO9dPQeTy0jBOkDQalGMnKAMXs=; h=Date:From:To:In-Reply-To:References:Subject:From; b=I4v2C+GfyvlluvNdK9Cwp0bh5mbErKcqiXR/icLpNtQ9DwuAG0QFV8W87Xi3bb8QQ /xDIZXR3ZP7JvJpEz7tnUsqLM0UOIrKw6wFJah3+vl51GnczrQQ6kSACQOUUKP+qVd h7/qDeD8N9Gb1mC52nCbk572J03ql/8n6OEGAZhlG7y8IcQ1KZ7fUX3cgPP+JHcjQR 1+hEeliu33FEHfUwHkbiGyFNHLts8D7s2PUJj7OqHmGNgSDHL3tJB+ggVRDjJ8ontt +o6iHfSON84O1VLOlkR28JXrDQUlKCg2xB86GtcBaQLRwXXqwhdCm2h4fzRjsNUS+4 XEwTy4MwNTepw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4FCE9180658 for ; Fri, 23 Aug 2024 21:08:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 23 Aug 2024 21:08:31 +0000 (UTC) Received: from phl-compute-03.internal (phl-compute-03.nyi.internal [10.202.2.43]) by mailfout.nyi.internal (Postfix) with ESMTP id 272A513904B5 for ; Fri, 23 Aug 2024 17:06:40 -0400 (EDT) Received: from phl-imap-06 ([10.202.2.83]) by phl-compute-03.internal (MEProxy); Fri, 23 Aug 2024 17:06:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to; s=fm1; t=1724447200; x=1724533600; bh=itGCEzj1Q5tAZPpTWkhQh YCwFQCTkCq4mUkh8YG+yFY=; b=HZBUouMhJA0ZK1PMXC2jWl0uMUz2s/qqCsc1P htklpmtxGYS2LRvuye1MT1dhcX3FzvWlGSA06cJG43Z/86wdimbW2NLHym/t5s+p 1qVxvBg9RDSOBYQy8CYV5AD2stj93dEi3GhAsOzqPVwfyhDQBHbR1Rnl4ltifbFH LnNhbzgUsdi4rBgA1YFEEXW57JmY0HuAHtUrpD34HPVJBLjL78ELKG3PLde5Up7S hpxhl4nyi5c242XznG3KlpFApn+uQ1n2uBcHKo9QL6rQBKlD6dOz59BMeTn4qVyC 1JNAgnEa5YwmZ7PJAMIomoE3UNrEXyglJqxVsS5PwOFhhYn/A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1724447200; x= 1724533600; bh=itGCEzj1Q5tAZPpTWkhQhYCwFQCTkCq4mUkh8YG+yFY=; b=k wRax6lVsdneHElHgzE+5PrbS1FCoMYiSPqyV6tywT+pgfpEan3ojlZ7pVvuGDpqB oYx4jMvtSwxVWR1NSKNMTWud/+F0uPMVVOvm2kAsLDW7qh8UKjwpdGabv0H25cjb lR/pBC2lKuqGf8ihRMkBGvv3gt/6C7HtSHJcEi+sLmFyWfkMEnQOgbMpGtYzUyhB sTZn7iYpPD2SswYQgzTAw7993ZgGJ/EL+DhppzXobW1+AdXv/j1rYMg31tuRauaf ZvJMmbGAiInT9cbTw8PXBCXVRoJ3H9hv7WbUWPG9h/YsbxltiwQ+CP6/LWyS+/Tz iHwWSgmRiDPOzToLMQ4ag== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddvvddgudehiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenogfuuhhsphgvtghtffhomhgrihhnucdlgeelmdenucfjughr pefoggffhffvkfgjfhfutgfgsehtqhertdertdejnecuhfhrohhmpedfnfgrrhhrhicuif grrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomheqnecu ggftrfgrthhtvghrnhepheffvdetjeetvdfhtefgteehfeejieetheefhfehgfehkeetff etueejjeejgffgnecuffhomhgrihhnpeefvheglhdrohhrghenucevlhhushhtvghrufhi iigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlug htvggthhdrtghomhdpnhgspghrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhr tghpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id D816D29C0064; Fri, 23 Aug 2024 17:06:39 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Fri, 23 Aug 2024 16:06:18 -0500 To: "php internals" Message-ID: <7c617909-c019-4a3d-bee9-8e4b0f949acf@app.fastmail.com> In-Reply-To: References: <1b59392a-68cb-36eb-0fef-977ac7113520@php.net> Subject: Re: [PHP-DEV] State of Generics and Collections Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: larry@garfieldtech.com ("Larry Garfield") On Fri, Aug 23, 2024, at 1:38 PM, Rob Landers wrote: > On Fri, Aug 23, 2024, at 20:27, Bruce Weirdan wrote: >> On Fri, Aug 23, 2024 at 4:27=E2=80=AFPM Larry Garfield wrote: >>> Moving those definitions to attributes is certainly possible, though= AFAIK both the PHPStan and Psalm devs have expressed zero interest in i= t. >>> Part of the challenge is that such an approach will either still inv= olve string parsing, >>=20 >> That's not really a challenge and would help somewhat with the curren= t status quo where we have to guess where the type ends and the textual = part of the comment begins. But it gets ugly for any type that has to in= clude quotes (literal strings, array keys, etc). Technically one can use= nowdocs, but it's not much better: https://3v4l.org/4hpte >> =20 >>> or will involve a lot of deeply nested attribute classes.=20 >>=20 >> Yeah, that would look like Lisp's S-exprs, but much worse - which, in= my opinion, would harm adoption. >>=20 >> All in all, in my opinion attribute-based solutions are less ergonomi= c than what we already have now in docblocks. >>=20 >> -- >> Best regards, >> Bruce Weirdan mailto:weirda= n@gmail.com > > Thank you Larry for expressing some of the problems. Is there any=20 > reason nesting has to be supported out of the gate? Think about type=20 > hints. It started with some basic functionality and then grew over=20 > time. There is no reason we have to have a new kitchen sink, oven,=20 > dishwasher and stove when all we want is a new refrigerator.=20 > > =E2=80=94 Rob While I understand the temptation to "just do part of it", which comes u= p very often, I must reiterate once again that can backfire badly. That= is only sensible when: 1. There's a very clear picture to get from A->Z. 2. The implementation of C and D cannot interfere with the design or imp= lementation of J or K. 3. The steps along the way offer clear self-contained benefits, such tha= t if nothing else happens, it's still a "complete" system and a win. 4. The part being put off to later isn't just putting off the "hard part= ". In practice, the level at which you get all four is quite coarse, much c= oarser than it seems most people on this list think. Examples of where we have done that: * Enums. The initial Enum RFC is part one of at least 3 steps. Step 2 = is pattern matching, Step 3 is ADTs/tagged unions. Those are still comi= ng, but all three were spec'ed out in advance (1), we're fairly confiden= t that the enum design will play nice with tagged unions (2), and enums = step 1 has very clearly been hugely positive for the language (3, 4). * Property hooks and aviz. These were designed together. They were ori= ginally a single planning document, way back in Nikita's original RFC. = After effectively doing all the design work of both together, we split u= p the implementations to make them easier. Hooks was still a large RFC,= but that was after we split things up. That meant we had a clear pictu= re of how the two would fit together (1, 2), either RFC on its own would= have been beneficial to the language even if they're better together (2= , 3), and both were substantial tasks in themselves (4). * Gina's ongoing campaign to make PHP's type juggling have some passing = resemblance to logic. With generics, the syntax isn't the hard part. The hard part is type in= ference, or accepting that generic-using code will just be extraordinari= ly verbose and clumsy. There is (as I understand from Arnaud, who again= can correct me if I'm wrong) not a huge amount of difference in effort = between supporting only Foo and supporting Foo>. The nest= ing isn't the hard part. The hard part is not having to type Foo 4= times across 2 files every time you do something with generics. If tha= t can be resolved satisfactorily (and performantly), then the road map t= o reified generics is reasonably visible. So for any intermediate generics implementation, it would need to have a= very clear picture to get from that initial state to the final state (w= ithout the landmines that something like readonly gave us), we'd need to= be confident we're not adding any landmines, each step would need to be= useful in its own right, and it would have to be breaking up the "hard = work" into reasonable chunks, not just punting the hard work for later. Leaving out nested generics doesn't achieve those. This is also why the dedicated collections work that Derick and I were l= ooking into has been on pause, because adding a dedicated collections sy= ntax, and then getting full reified generics later, would lead to a very= ugly mess of inconsistency. Better to wait and try to get full generic= s first, or confirm once and for all that it's impossible. Strategies that MIGHT make sense in that framework, and the ones on whic= h we are specifically requesting feedback, include: * Type-erased generics, with the expectation that they would become enfo= rced at some point in the future. (Though this could lead to lots of "w= orking" code suddenly not working once the enforcement was turned on.) * No type inference. Generics are just very verbose, deal with it. Typ= e inference could, potentially, be added later. (Maybe; it's not guaran= teed that it could be done effectively, as the writeup discusses). * Only allow generics over simple types, not union/intersection types. = Unlike nested generics, union types do increase the cost of determining = compatibility considerably, so making them performant is a much bigger c= hallenge. Maybe that challenge could be punted for later? (And if late= r turns into never, or 10 years from now, is that still an acceptable en= d-state?) The acceptability of each of these strategies is what we were hoping to = determine in feedback to the writeup. --Larry Garfield