Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125061 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 D00EA1A00BD for ; Tue, 20 Aug 2024 01:53:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1724118921; bh=pjFF0H4G/XNJf7mVCUlWz8M8jRLNsW/9PmSppk5T9FI=; h=Date:Subject:To:References:From:In-Reply-To:From; b=dD5XeKKclEOjlAz4YWzKV5d/woW2swzfPoJmYqdapjG+KRGzYhQaRyF/OYwdGXVot 53Fx21ZwGoFVtjI/j0QFLitd6dZot0v+F7JDGu0DUvghO8QLzSLYufFOlPA4H+1pA8 O3bkJAJZ82t4Y9QHhmWwaP/eV+Qjo2BsTzphEw1LIEsC3DIj4Tt6TyAXg9bGvcG2/S nroFzKUaOHNmMWMNfheWFDjC4wDNdcTDUTvOl9n8gW1ShAnpdZtoZS9ftEs32wIGNr DTJjKsJQXBwHi5ZgweglWB4kG5HJLjq2d2vVWkPZNUkfDrUj7SZG+CcqaJy5+VKBFi 3BbmEPHxNiwlg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 85393180062 for ; Tue, 20 Aug 2024 01:55:20 +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.8 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_50, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05olkn2018.outbound.protection.outlook.com [40.92.91.18]) (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 ; Tue, 20 Aug 2024 01:55:19 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ThrQDDLad7CFXKSOOJMm73b4m1mj5sZOKdvuLreZN4rk5DlJbo1GD1haVeC9orfOSe4AyptnE9FMS1jm787etu4eioTpnETaNGGbNDwGkX7yRIdsNXCcYbzqDwJ2agcCfuKpdTPVjDEvBnNSLrVc+isVr65fExg/fLuGw0qrmtlxqKaOmFJQAwJYBb5NuRPK4NrZSI5roBj7W8GtGOTx3H6JdME006aTN1KRgVq6YpFwPLh9lGceJp/395IVHjSM2a6iA4vbvwc9j9zMBa81JkjxEvEe0Kcyo9OJ3J3GfUgX0CYdHnNImDSJwIU/D9FyMfx2Ovv0sUNwsIvXkUziJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=LMoi1+y8/c/5Ei2EgNYH6jwB7WKTgR3MJ8WANebM58E=; b=mopvbmhDFbCCx6bqKkUs7sGY/IfLW37IjsuyrmWQVpinygf9q3yNubQQqOXSaacRFrw7PK1LCv4OIkOca7WB16Je3BgFewKXRu5tDvAdnbrc76K1DKgiL0y0H55ZNRQh86njH/6rm8c4TQm6Ls8YranLPFNcmid7D6RuIcXQAmb87ddVuy4pBsNL+HBGQR1YmT77Gkj3DNASJU6KW4dLj0V+MLEDNHowsN9hKSGPtRiaS2Xhn8YF+8VoGmF7W0ihO2f25Jh4pomyFrIymR9m77XhDlOwFrJoq5Wm2zMjYc1EkY+9icf55BttT5InSzt1C5fgAab+Xbf2Trv7Hw/uyQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LMoi1+y8/c/5Ei2EgNYH6jwB7WKTgR3MJ8WANebM58E=; b=GRsybNcBEJtC0yX1OVBa6HPJ9uTIJDa3VSF8KUuVSkoftDbOlzpuw+MTrpW3kTJPAzQjg6SZipGLG1P9oLy4PUoBdf4DCXYVDpF5jkS8RR+PRD2Qh4rRwwXzt32y/GugyAYj2YhKOkR6PkAXBnEcmZhOEqtl3i0pAOfjChoIvBbgCwxqWeycwU0dbdpTP+opHyCnYr6gKLAKKLlfjR1JXNSVosDR9LJXBwmi0DtIYTBegYdNEjKOW9E2Q3C8/v0NrNk7nxo5LHOUKWLdPDmijZoCB+na9YSKC8XJCKvBtAUje5nkBLKHdXMXdtE99hHt7emiDfms79BWAfEEOCkFbw== Received: from AM8P250MB0170.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:321::21) by AS4P250MB0534.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:4b9::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.21; Tue, 20 Aug 2024 01:53:25 +0000 Received: from AM8P250MB0170.EURP250.PROD.OUTLOOK.COM ([fe80::651e:bbd2:b18a:80ff]) by AM8P250MB0170.EURP250.PROD.OUTLOOK.COM ([fe80::651e:bbd2:b18a:80ff%6]) with mapi id 15.20.7875.019; Tue, 20 Aug 2024 01:53:25 +0000 Content-Type: multipart/alternative; boundary="------------CHTHbj0HVCd0JoaOfHbBJ4oI" Message-ID: Date: Tue, 20 Aug 2024 03:53:22 +0200 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] State of Generics and Collections To: Larry Garfield , php internals References: <1b59392a-68cb-36eb-0fef-977ac7113520@php.net> Content-Language: en-US In-Reply-To: X-TMN: [2tLul+JOwKZuYP0jKlzTS1Pj7Pg2QREh/GGJS1JLGE+t9aiXwf5OB0umEBAhscFf] X-ClientProxiedBy: BLAPR03CA0054.namprd03.prod.outlook.com (2603:10b6:208:32d::29) To AM8P250MB0170.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:321::21) X-Microsoft-Original-Message-ID: Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM8P250MB0170:EE_|AS4P250MB0534:EE_ X-MS-Office365-Filtering-Correlation-Id: 9f77cd6e-fa13-4d08-600a-08dcc0bae0fc X-Microsoft-Antispam: BCL:0;ARA:14566002|15080799003|9400799024|5072599009|8060799006|19110799003|12050799009|461199028|1602099012|4302099013|440099028|3412199025; X-Microsoft-Antispam-Message-Info: IimtFgFn0GPEGffW+cvk+OREMO5i+cIpFoUFTXPqafxdNBgNeFLWDMMP/r4E/UMoTGCnVWlTHbA47LL1NliFZaeGNu6u/2jDoykvhL9hNdH+hkCFXrF2BOdc8nsc6mQz+9kcy/uCLa/R7fD8kWbo+z/tChqkAq0Vh44xfJkEfBCzCPSvwnddzNLQ1+ZskB85JtpYncc0Ee8ab8B50KfzwQvyKl+dgFy1F6ITVFnvpP/Liiiam4Pt1AbKCA20n1njjxYlDpTJ050Ele7sWJvsj4sBpzvSjC2IBk9/AtjVolVHxZGa+d0deyr/sTHZQLkeEJp38PhjADBm2qsrMoA2/STSI47bGFf2H+aIsCkdVTmWUc7ULuvVG7pBYCAYGWpyOIDRMZ+QFzIsaXYTpBxHTAVbBEUq8B6+IRpArtoI5JeGX7HcEmPkT3UgVlQOSwRV3V9dvRZ+j09AXfvFtHWnaOCCpl4tZeR5qLvv9ylfe7Td3kK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=?utf-8?B?RWt6aG03TlhGS2hORHIzaHBPcFNRcmZwVHc2bnlielVsRkN0NEhDK0pDK2ly?= =?utf-8?B?RXFERVh4YUFvdWlDWmxvTGVjNWQzc2pNUEdvRDFHQjdlc1h5c1JkK1I1S2U1?= =?utf-8?B?dlc3WjEvcG9VTktwaWVFTUI2VnlQMDlMOTdXM25zcEk1WUpocmNubEZJSFBk?= =?utf-8?B?d1ptZ1ZqcmNkY3VSWDA0a3cwZXR5KzRGMmJ5SVcweFFPOWV1NEFkWlVQL21P?= =?utf-8?B?cDliYXFiZ2tRSmVZMDJudFFNV082aThsbjVsRWtUVmtndWNocm8rUGlCbmdX?= =?utf-8?B?VEFSN2JhTyswTXV3aXRWVUxrNFdHU0FJc050ZmFFMEpCTGVhNEpvNUNYdWdz?= =?utf-8?Q?Z+ebdheYf2L0tbC62k=3D?= X-OriginatorOrg: sct-15-20-7784-11-msonline-outlook-95b76.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 9f77cd6e-fa13-4d08-600a-08dcc0bae0fc X-MS-Exchange-CrossTenant-AuthSource: AM8P250MB0170.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Aug 2024 01:53:25.4701 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS4P250MB0534 From: bobwei9@hotmail.com (Bob Weinand) --------------CHTHbj0HVCd0JoaOfHbBJ4oI Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 20.8.2024 03:31:05, Larry Garfield wrote: > On Mon, Aug 19, 2024, at 5:16 PM, Bob Weinand wrote: > >> Regarding the Collections PR, I personally really don't like it: >> >> • It implements something which would be trivial if we had reified >> generics. If this ever gets merged, and generics happen later, it would >> be probably outdated and quirkiness the language has to carry around. >> • It's not powerful. But rather a quite limited implementation. No >> overrides of the built-in methods possible. No custom operations ("I >> want a dict where a specific property on the key is the actual unique >> key", "I want a custom callback be executed for each modification"). >> It's okay as a PoC, but far from a complete enough implementation. > I think we weren't that clear on that section, then. The intent is that dedicated collection classes are, well, classes. They can contain additional methods, and probably can override the parent methods; though the latter may have some trickiness if trying to access the internal data structure, which may or may not look array-ish. (That's why it's just a PoC and we're asking for feedback if it's worth trying to investigate further.) I assumed so, as said "okay as a PoC" :-) >> • It's a very specialized structure/syntax, not extensible for >> userland at all. Some functionality like generic traits, where you'd >> actually monomorphize the contained methods would be much more >> flexible. E.g. class Articles { use Sequence
; }. Much less >> specialized syntax, much more extensible. And generic traits would be >> doable, regardless of the rest of the generics investigation. >> In fact, generic traits (essentially statically replacing the generic >> arguments at link-time) would be an useful feature which would remain >> useful even if we had fully reified generics. >> I recognize that some functionality will need support of internal >> zend_object_handlers. But that's not a blocker, we might provide some >> default internal traits with PHP, enabling the internal class handlers. >> So to summarize, I would not continue on that path, but really invest >> into monomorphizable generic traits instead. > Interesting. I have no idea why Arnaud has mainly been investigating reified generics rather than monomorphized, but a monomorphized trait has potential, I suppose. That naturally leads to the question of whether monomorphized interfaces would be possible, and I have no idea there. (I still hold out hope that Levi will take another swing at interface-default-methods.) > > Though this still wouldn't be a path to full generics, as you couldn't declare the inner type of an object at creation time, only code time. Still, it sounds like an area worth considering. > > --Larry Garfield Nikita did the investigation into monomorphized generics a long time ago (https://github.com/PHPGenerics/php-generics-rfc/issues/44). So it was mostly concluded that reified generics would be the way to go. The primary issue Arnauld is currently investigating, is propagation of generic information via runtime behaviour, inference etc. It would be solving large amounts of problems if you'd have to fully specify the specific instance of a generic every time you instantiate one. But PHP is at heart a dynamic language where typing is generally opt-in (also when constructing new objects of generic classes for example). And we want to avoid "new List, WeakReference>>()"-style nesting where not necessary. "Monomorphization of interfaces" does not really make a lot of sense as a concept. Ultimately in an interface, all you do is providing information for classes to type check against, which happens at link time, once. (Unless you mean interface-default-methods, but that would just be an implicitly implemented trait implementation wise, really.) But sure, generic interfaces and monomorphized generic traits are perfectly implementable today. In fact, I'd definitely suggest we'd start out by implementing these, orthogonally from actual class generics. Bob --------------CHTHbj0HVCd0JoaOfHbBJ4oI Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 20.8.2024 03:31:05, Larry Garfield wrote:
On Mon, Aug 19, 2024, at 5:16 PM, Bob Weinand wrote:

Regarding the Collections PR, I personally really don't like it:

 • It implements something which would be trivial if we had reified 
generics. If this ever gets merged, and generics happen later, it would 
be probably outdated and quirkiness the language has to carry around.
 • It's not powerful. But rather a quite limited implementation. No 
overrides of the built-in methods possible. No custom operations ("I 
want a dict where a specific property on the key is the actual unique 
key", "I want a custom callback be executed for each modification"). 
It's okay as a PoC, but far from a complete enough implementation.
I think we weren't that clear on that section, then.  The intent is that dedicated collection classes are, well, classes.  They can contain additional methods, and probably can override the parent methods; though the latter may have some trickiness if trying to access the internal data structure, which may or may not look array-ish.  (That's why it's just a PoC and we're asking for feedback if it's worth trying to investigate further.)
I assumed so, as said "okay as a PoC" :-)
 • It's a very specialized structure/syntax, not extensible for 
userland at all. Some functionality like generic traits, where you'd 
actually monomorphize the contained methods would be much more 
flexible. E.g. class Articles { use Sequence<Article>; }. Much less 
specialized syntax, much more extensible. And generic traits would be 
doable, regardless of the rest of the generics investigation.
In fact, generic traits (essentially statically replacing the generic 
arguments at link-time) would be an useful feature which would remain 
useful even if we had fully reified generics.
I recognize that some functionality will need support of internal 
zend_object_handlers. But that's not a blocker, we might provide some 
default internal traits with PHP, enabling the internal class handlers.
So to summarize, I would not continue on that path, but really invest 
into monomorphizable generic traits instead.
Interesting.  I have no idea why Arnaud has mainly been investigating reified generics rather than monomorphized, but a monomorphized trait has potential, I suppose.  That naturally leads to the question of whether monomorphized interfaces would be possible, and I have no idea there.  (I still hold out hope that Levi will take another swing at interface-default-methods.)

Though this still wouldn't be a path to full generics, as you couldn't declare the inner type of an object at creation time, only code time.  Still, it sounds like an area worth considering.

--Larry Garfield

Nikita did the investigation into monomorphized generics a long time ago (https://github.com/PHPGenerics/php-generics-rfc/issues/44). So it was mostly concluded that reified generics would be the way to go. The primary issue Arnauld is currently investigating, is propagation of generic information via runtime behaviour, inference etc.

It would be solving large amounts of problems if you'd have to fully specify the specific instance of a generic every time you instantiate one. But PHP is at heart a dynamic language where typing is generally opt-in (also when constructing new objects of generic classes for example). And we want to avoid "new List<Entry<Foo<Something>, WeakReference<GodObject>>>()"-style nesting where not necessary.

"Monomorphization of interfaces" does not really make a lot of sense as a concept. Ultimately in an interface, all you do is providing information for classes to type check against, which happens at link time, once. (Unless you mean interface-default-methods, but that would just be an implicitly implemented trait implementation wise, really.)

But sure, generic interfaces and monomorphized generic traits are perfectly implementable today. In fact, I'd definitely suggest we'd start out by implementing these, orthogonally from actual class generics.

Bob

--------------CHTHbj0HVCd0JoaOfHbBJ4oI--