Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125059 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 7BE281ADA95 for ; Tue, 20 Aug 2024 00:44:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1724114796; bh=grad5RwN5GVFPhMZZagmWoZw1wAV7dnkAjHyUpuF8zg=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=bGhLBF+eAdAdOeukdSvRMRjg65SZmHiPTt40xvk+c0EOblS6rwgt049FAUi+as8XH mdR7en3awXdH8LufdsNcfnqIsFuj8uESBqkcPBILXvYFqtqK5jAGeIkxBx3/s/A62X 63vLpYVSLij7VJ4Ub50WK9+U2WgmSv9CwP3pgmaGnPkmS80ekwW/7afL9DrlpS1SY0 mfZWBfLMGdHdq651GhdZW/vSYvTl6VLSdRBNBZ0hFSZ6CaPNp11+s0iafXEv9G8DDh 5rJpu9JAZBweMhwMFMfWT15i5Lw7Z7alddKd2uAoAidhp9ICtAY4QpBOHW++5uDjr6 bY6MfcjH4uCVw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B02851801D4 for ; Tue, 20 Aug 2024 00:46:34 +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=BAYES_50,DKIM_SIGNED, DKIM_VALID,DMARC_MISSING,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-yb1-f176.google.com (mail-yb1-f176.google.com [209.85.219.176]) (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 ; Tue, 20 Aug 2024 00:46:32 +0000 (UTC) Received: by mail-yb1-f176.google.com with SMTP id 3f1490d57ef6-e0e76380433so5086402276.2 for ; Mon, 19 Aug 2024 17:44:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20230601.gappssmtp.com; s=20230601; t=1724114681; x=1724719481; darn=lists.php.net; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=f08sajT7bf4G2yx1DiUm7U6BWjTZ8/LzZIRfZz+Llc8=; b=dkMABzB8Y0iQYM+cPddaint2Lt5/0fyholcMjBW6F9/ZFR/3uqDXw3AsV48a/lJ5aK sFFD96KPLODdaj7MT3qrzhtstADsGqL9SFQus+wAnoDVS6s3RKt4Od7UnWG325ZhkKV+ UCT0P/qD/2MBH4WyjLAF/ZcHEtJKvV+5ZFFUVmPmCI8UilWCg4r5oHb72vM5QOexIk3B TaBBau8dPZjnhd3dby/3Ca7FU487wxbA6HB7N9CfBS8CQ+jluvSYvxDFzZfG/jUvFwC6 CAEz9Uw4DOObIqrLqb4IXBzAscozZi9VwE5aXyhhpdFbv0xbUil6GwmYmW3x4KU7Y/4H CsJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724114681; x=1724719481; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=f08sajT7bf4G2yx1DiUm7U6BWjTZ8/LzZIRfZz+Llc8=; b=uiU8HlQieS0A2CyCZyB0GRoLtLDbhH0ksjqUvyd5kUI+BD6dnvYDfa9YJqM18ADl3b EH+IwhPKO7ssDIh84frBXBGVFnlfB07EpIfbGeJZ90aa/8JJA9shmMKlYfB1r0YlCXtK 4H2qoi1aLy/fO4c/qNWGWstSWWTR5aTUP/g+X8N1BQOPRcC1IX4jVR388Szcsh3202jJ JuUJ6DNEDJpSqQECk+SZNkk7RtLhcbSE8jK5CKm/i3xBFrk5apMA6hwsdPL1crb0CIYm DW24PTDGwTgX6Z2aANZZPZi4c5w3QdNrJ751h0wF0PGWvrMbkFBLbeXtSPP5LUFgxJAX MgJA== X-Gm-Message-State: AOJu0YwE6BwkOIsBb61FriffTLtiL9oYyeb/8YrjXBEd1RG4byI3qnma 72oMzypisgvdlLceVBO5rvMZHLhUjGTf1UuAXNC7IUtemuJzvAFLgpCc0nWoKSod4AM/Gby8qJk ofjM= X-Google-Smtp-Source: AGHT+IECpvTKywKQqBroJ/DeTJKbDjksSoCpYwNfQKBq93czGVFWde3MmUiKO0kW8Sn1n40eAuI0rA== X-Received: by 2002:a05:690c:690f:b0:6b1:2825:a3cf with SMTP id 00721157ae682-6b1ba5f78dcmr153728297b3.10.1724114680752; Mon, 19 Aug 2024 17:44:40 -0700 (PDT) Received: from smtpclient.apple (c-98-252-216-111.hsd1.ga.comcast.net. [98.252.216.111]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6af9e1d9e31sm17389087b3.143.2024.08.19.17.44.40 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Aug 2024 17:44:40 -0700 (PDT) Message-ID: <44AE8AF8-B094-461C-8A49-65A86484FE65@newclarity.net> Content-Type: multipart/alternative; boundary="Apple-Mail=_352E7439-E027-4941-89EF-43A971EB2546" Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.8\)) Subject: Re: [PHP-DEV] State of Generics and Collections Date: Mon, 19 Aug 2024 20:44:40 -0400 In-Reply-To: Cc: internals@lists.php.net To: Rob Landers References: <1b59392a-68cb-36eb-0fef-977ac7113520@php.net> X-Mailer: Apple Mail (2.3696.120.41.1.8) From: mike@newclarity.net (Mike Schinkel) --Apple-Mail=_352E7439-E027-4941-89EF-43A971EB2546 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > On Aug 19, 2024, at 7:37 PM, Rob Landers wrote: > As an experiment, awhile ago, I went a different route for reified = generics by 'hacking' type aliases (which I was also experimenting = with). Such that a generic becomes compiled into a concrete = implementation with a dangling type alias: >=20 > class Box { > function __construct(T $thing) {} > } >=20 > is essentially compiled to >=20 > class Box { > use alias __Box_T =3D> ???; >=20 > function __construct(__Box_T $thing) {} > } >=20 > 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). =46rom what I understand this is essentially how Go implements Generics. = So +1 for considering this approach. > FYI though, people seemed really turned off by file-level type aliases = (at least exposed to user-land, so I never actually pursued it). Shame. Type aliases are super useful in practice in other languages, = with many used for single-file scope in my experience. -Mike= --Apple-Mail=_352E7439-E027-4941-89EF-43A971EB2546 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii
On = Aug 19, 2024, at 7:37 PM, Rob Landers <rob@bottled.codes> = wrote:
As an experiment, awhile ago, I went = a different route for reified generics by 'hacking' type aliases (which = I was also experimenting with). Such that a generic becomes compiled = into a concrete implementation with a dangling type alias:

class Box<T> {
  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).

=46rom= what I understand this is essentially how Go implements Generics. =  So +1 for considering this approach.

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

Shame. Type = aliases are super useful in practice in other languages, with many used = for single-file scope in my experience.

-Mike
= --Apple-Mail=_352E7439-E027-4941-89EF-43A971EB2546--