Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125057 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 A96E51A00BD for ; Mon, 19 Aug 2024 23:38:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1724110803; bh=BYK9lDH9iUphf3aGKIUfVyClE3jnCJZOBEhyW/0UhBM=; h=Date:From:To:In-Reply-To:References:Subject:From; b=FVyxrLUmp33ml7b81kcaC6IJfZVNHKSmsqrXZPOAVEAoER26mXW3skUUd+5fuj2lF oL9jrDEl1LlQ+Egie0+qrGRBaJ7ekZDmDbhI9TeB8UKj7N9WoXxhdk1f+At1NaC8yK I7Flr9JUqTo/9yFmG/7eSRLmly7K1ZjvAuRmyLPt3nvsBzI7dlO1syFak/unoQFBlB TYrel9zWiionArcJSK4rZOLrQ0y2NQocD/W6UkCYU3OgiY7JYjRDFMeFod6W9NRjOP Hdpb7LxVFVT7Hq0OVU4QVuE+G/EfncbiAbmEFy7MtxbXivINi3oNAPEKlm1Vp5C/rx tQgdX4N+n9JmA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B8BFD180042 for ; Mon, 19 Aug 2024 23:40:02 +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,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fhigh7-smtp.messagingengine.com (fhigh7-smtp.messagingengine.com [103.168.172.158]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 19 Aug 2024 23:40:01 +0000 (UTC) Received: from phl-compute-03.internal (phl-compute-03.nyi.internal [10.202.2.43]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 814DC1150BCB for ; Mon, 19 Aug 2024 19:38:12 -0400 (EDT) Received: from phl-imap-09 ([10.202.2.99]) by phl-compute-03.internal (MEProxy); Mon, 19 Aug 2024 19:38:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc: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=fm2; t=1724110692; x=1724197092; bh=tDRwoyTJZD p9qjmgWZm/uw4fHBCQ5h369HmFtEFGv5w=; b=UFT9TAXvJJWRWIMZRBNiNMtYdj 9A1dkNETPcMUPKPv1ltkuAWHugLwZ75vhT71geu0bfiYO3J/r8HiyIE9RuiJ2UYi O9B9Gh6E+TGz28rmH1UlkQr3zLTor6IAjwAPhWbbSNfQiRD3+hwdCb/aJ5vwUZde RTL68Hq/XNmu3XI5rnbIZl7ZkgiBn2Pshw2adbwIcYGGIeEheVTzfOoyM91TjWXX H8Io7r/l4vY8p5YahAehBHQ/NKrwrMq5zdKGKVqQiVXUZmUA49Mp2+aoCdKhdRrk q1KhM9WEsMd+7eF01Vnfs4OeL4ogI4FBxbj9LiMA81lt8sAIRZ3bhB709nQw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=1724110692; x=1724197092; bh=tDRwoyTJZDp9qjmgWZm/uw4fHBCQ 5h369HmFtEFGv5w=; b=P7j5q6d6qxShgG9Ev5bWrfBW26LnKnbOxtUjuVpLBE73 EC/IRnBz2ZhrMThiD3UdJAnMT1CID8qeDr9RqQ8adr2YTlDO5HzuBk70AL57AvtD e8VSlRgMjCVpU9HOv9HX0jraQDkt9u3AOZi+KBTTc9oonuF+1QWESeMwm+UrpXAn 8zNVuPu+3JoSAsSuUvxXm8+iPPDz5h+Xh+YOOhg4WOoxJzLe91ma1aerhrUDu5+n JcXD9P0qusdEfc0oa2NIMQAkuJqrBCjYg68clJS1/4g+rat3voHfDz+JwHH7Dndf FPibn9XFULOnlnA6c7B4iYDXH4Axn5X4qAxeUf2JsA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduhedgvdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefoggffhf fvkfgjfhfutgesrgdtreerredtjeenucfhrhhomhepfdftohgsucfnrghnuggvrhhsfdcu oehrohgssegsohhtthhlvggurdgtohguvghsqeenucggtffrrghtthgvrhhnpeektdefve ekueefvdevffeitdeludeiffdvleeljeeluedulefhveegkedviefhueenucffohhmrghi nhepthhhvghphhhprdhfohhunhgurghtihhonhenucevlhhushhtvghrufhiiigvpedtne curfgrrhgrmhepmhgrihhlfhhrohhmpehrohgssegsohhtthhlvggurdgtohguvghspdhn sggprhgtphhtthhopedupdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehinhhtvg hrnhgrlhhssehlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 44CF915A005E; Mon, 19 Aug 2024 19:38:12 -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: Tue, 20 Aug 2024 01:37:49 +0200 To: internals@lists.php.net Message-ID: In-Reply-To: <1b59392a-68cb-36eb-0fef-977ac7113520@php.net> References: <1b59392a-68cb-36eb-0fef-977ac7113520@php.net> Subject: Re: [PHP-DEV] State of Generics and Collections Content-Type: multipart/alternative; boundary=647d3cdb0a4f49628fec2e627e45291e From: rob@bottled.codes ("Rob Landers") --647d3cdb0a4f49628fec2e627e45291e Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Mon, Aug 19, 2024, at 19:08, Derick Rethans wrote: > Hi! >=20 > Arnaud, Larry, and I have been working on an article describing the=20 > state of generics and collections, and related "experiments". >=20 > You can find this article on the PHP Foundation's Blog: > https://thephp.foundation/blog/2024/08/19/state-of-generics-and-collec= tions/ >=20 > cheers, > Derick >=20 As an experiment, awhile ago, I went a different route for reified gener= ics by 'hacking' type aliases (which I was also experimenting with). Suc= h that a generic becomes compiled into a concrete implementation with a = dangling type alias: class Box { function __construct(T $thing) {} } is essentially compiled to class Box { use alias __Box_T =3D> ???; function __construct(__Box_T $thing) {} } This just gets a T type alias (empty-ish, with a mangled name) that gets= filled in during runtime (every instance gets its own type alias table,= and uses that along with the file alias table). There shouldn't be any = performance impact this way (or at least, as bad as using type aliases, = in general; which is also an oft-requested feature). Thus, when you create a new Box it just fills in that type alias fo= r T as int. Nesting still works too Box> is just an int type al= ias on the inner Box and the outer Box alias is just Box. Type-checking = basically works just like it does today (IIRC, Box literally got st= ored as "Box" for fast checking), and reflection just looks up the = type aliases and unmangles them -- though I know for certain I never fin= ished reflection and got bogged down in GC shenanigans. There were probably some serious cons in that approach, but I ran out of= free time to investigate. If you are doing experiments, it is probably = worth looking into. FYI though, people seemed really turned off by file-level type aliases (= at least exposed to user-land, so I never actually pursued it). =E2=80=94 Rob --647d3cdb0a4f49628fec2e627e45291e Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Mon, Au= g 19, 2024, at 19:08, Derick Rethans wrote:
Hi!

Arnaud= , Larry, and I have been working on an article describing the 
<= /div>
state of generics and collections, and related "experiments".<= br>

You can find this article on the PHP Founda= tion's Blog:

<= /div>
cheers,
Derick


As an experiment, awhile ago, I went a diff= erent route for reified generics by 'hacking' type aliases (which I was = also experimenting with). Such that a generic becomes compiled into a co= ncrete implementation with a dangling type alias:

class Box<T> {
  function __construct(T = $thing) {}
}

is essentially c= ompiled to

class Box {
 = use alias __Box_T =3D> ???;

  func= tion __construct(__Box_T $thing) {}
}

This just gets a T type alias (empty-ish, with a mangled name) = that gets filled in during runtime (every instance gets its own type ali= as table, and uses that along with the file alias table). There shouldn'= t be any performance impact this way (or at least, as bad as using type = aliases, in general; which is also an oft-requested feature).
<= div>
Thus, when you create a new Box<int> it just fi= lls in that type alias for T as int. Nesting still works too Box<Box&= lt;int>> is just an int type alias on the inner Box and the outer = Box alias is just Box. Type-checking basically works just like it does t= oday (IIRC, Box<int> literally got stored as "Box<int>" for = fast checking), and reflection just looks up the type aliases and unmang= les them -- though I know for certain I never finished reflection and go= t bogged down in GC shenanigans.

There were= probably some serious cons in that approach, but I ran out of free time= to investigate. If you are doing experiments, it is probably worth look= ing into.

FYI though, people seemed really turn= ed off by file-level type aliases (at least exposed to user-land, so I n= ever actually pursued it).

=E2=80=94 Rob




=

--647d3cdb0a4f49628fec2e627e45291e--