Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119487 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 41050 invoked from network); 8 Feb 2023 14:59:52 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 8 Feb 2023 14:59:52 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0DAFE18037E for ; Wed, 8 Feb 2023 06:59:52 -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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-oi1-f174.google.com (mail-oi1-f174.google.com [209.85.167.174]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 8 Feb 2023 06:59:51 -0800 (PST) Received: by mail-oi1-f174.google.com with SMTP id 20so14909266oix.5 for ; Wed, 08 Feb 2023 06:59:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=DztfEfY7mQXeTa4Tk9389B1RpoY4e/VvJxHcIxZZmss=; b=dbDIEerbBCYqPDbdKMAllG4eGX4ezXlsm7A76k8LKxZf38vKhPOyWCDjXfLk2sDAyw QThHmFwgBX9H4UyY1u/Yw4Bs8ec93Uo6vusZdFTybZW2v01SK0lvTb8gtNFTuYeAJfgB ENMGXyl50pQzHzEFa90l2dM9E9dw9wiIZ8GcpGvQVReMCw51QlHJtuWTCL+R/PELjMrO 3hnuHtIPJ1KLR3CxEIn8c+4bOpqBBd+GyGgPRuyGmz935HZZj9rgBy23hWaEFQ3+vign y4pPYtjbj5k10CxmSFUcfQRX1E8ofHzzBPuifkJQqL/bHCmnTumrew1ZJ2U0S6Wr9ZHa 07cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DztfEfY7mQXeTa4Tk9389B1RpoY4e/VvJxHcIxZZmss=; b=OmrFItcrXMP1PfZkSUl5Ph3Bk8doQaAP3C8anwQwANDB3TxkuLXbKaaw+w0BArsUdy GTJVQoBY1GvBCOTSCEfOpWRLGDh3FHzbpdA1j7KMjm928GbLmYm3PxkWn7lhhNRAkFkX xqK6PK9G76UqXLorvVp1ubox7oPNpcS5T+Cx8+EDyt7lglzuroZK3jv8+MigOqn3xD2g B3l/k/3kgJh5/wC1vMsk/fM7E58oKskKQ0py6jlny28mG5lh6xRbrjCJsPd5hKOGhXJr hgdi0vUHG7nqaSadlFE5fVJimecIF3zQ8yNG4H7Zm1QtipFfQRqzhfxGqxEq1DXAN0rO u9DA== X-Gm-Message-State: AO0yUKXxOKfnAL+L+QcPYHa3b8bD0RtSvEwUOVEauYT2G5VInIgz99lz Mnv2eS2yUtMC5CiMRMN25JJd6BWtOl9TQEJJORDh1kZyGnY= X-Google-Smtp-Source: AK7set/ZW3erAe29LfltcmXCRZzkl5sAnyGuVW8eNhHR6fbAIZoEuN/KwNLO85+qsMDfBt/4+62cDQEv44N5zHU2Bos= X-Received: by 2002:aca:bdd5:0:b0:364:46ae:5a6a with SMTP id n204-20020acabdd5000000b0036446ae5a6amr218873oif.66.1675868390763; Wed, 08 Feb 2023 06:59:50 -0800 (PST) MIME-Version: 1.0 References: <18627e9c82d.1185ba82a2669697.6762525826203739336@wendelladriel.com> <8c3fb742-4367-0e4a-b96e-142657ac902c@gmail.com> <5edaa45e-08ff-9529-3a1b-42f655a68497@gmail.com> In-Reply-To: Date: Wed, 8 Feb 2023 14:59:39 +0000 Message-ID: To: PHP Internals Content-Type: multipart/alternative; boundary="0000000000001f307a05f43184bd" Subject: Re: [PHP-DEV] RFC Proposal - Types for Inline Variables From: wendelladriel.ti@gmail.com (Wendell Adriel) --0000000000001f307a05f43184bd Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hey everyone, it's me, Wendell (that proposed this RFC in the first place). I'm just using another e-mail because my other email me@wendelladriel.com is having some issues with the PHP email lists. First of all, thanks for all the feedback so far on this proposal. I'm seeing that the implementation would be far more complex than I thought it would be. I have two questions about this: 1. Should I move forward on creating the RFC for further discussion? If so, I know that I need karma for that, I already created my Wiki account with the email wendelladriel.ti@gmail.com and username wendell_adriel. In the how-to guide says that I need to ask in this list for the needed Karma, so if you think that I should move on with this RFC can someone give me the needed karma for that? 2. It would be great to have someone else aboard with more experience in the PHP source code and the RFC process since I'm a beginner and this seems to be way more complex than I first thought. Is there anyone that wants to work with me on the RFC proposal and the implementation if this should proceed? Thanks in advance. Have an amazing day everyone. *---* *Best Regards,* *Wendell Adriel.* *Software Engineer **| Investor | Amateur Photographer | Musician | INFP* *https://wendelladriel.com * Em qua., 8 de fev. de 2023 =C3=A0s 14:40, Rowan Tommins escreveu: > On Wed, 8 Feb 2023 at 00:13, Sergii Shymko wrote: > > > I think, typed variables would be a necessary prerequisite for typed > > arrays and eventually generics. > > If my understanding is correct, the primary concern there is performanc= e > > overhead of iterating items for type checking. > > With typed variables, type checking is done at assignment and passing > > typed array around becomes lightweight. > > It would be enough to type check against a known array item type withou= t > > iterating over items. > > > > For example: > > function do_something(array $strings) { > > ... > > } > > array $names =3D ['John', 'Jane', 'Jake']; // items are type > > checked similar to variadic argument unpacking > > sort($names); > > do_something($names); // lightweight type check as for scalar types > > > > This is probably more complicated to implement than you're imagining. > > Firstly, there is a key distinction between *variables* and *values*: whe= n > you say do_something($names), the receiving code in do_something doesn't > know that the argument it was given is the variable $names, with type > array; it just receives the value ['John', 'Jane', 'Jake']. > > That leads to another distinction: the variable has a single type > *constraint* ("must always point to a value matching this type"), but the > value has multiple pieces of type *information* ("has been checked as > meeting these different constraints"). Both can also be deduced using the > relationships between types. For example: > > function do_something(array $strings) { > ... > } > function filter_non_strings(array $items): array { > ... > } > array $mixed_list =3D ['John', 42, 'Jane']; > $mixed_list =3D filter_non_strings($mixed_list); > // when calling filter_non_strings, we know that the value matches > array, so can deduce that it matches array as well > // when assigning the result back to $mixed_list, we know (from the retur= n > type check) that it matches array, so can deduce that it matches > array as well > > do_something($mixed_list); > // since the value hasn't changed since it was returned, it still matches > array, even though the variable doesn't have that constraint > > sort($mixed_list); > // for this call to succeed, we need to know that the variable is an arra= y; > we can deduce that from knowing it matches array or knowing that = it > matches array > // as a minimum, we need to assert that after modifying it by reference, = it > still matches array, as required by $mixed_list > // but do we also still know that it matches array? > > It's all probably doable, but I think it's the other way around from your > initial statement: working out how to cache type checks would be a > pre-requisite for implementing local variable types. > > Regards, > -- > Rowan Tommins > [IMSoP] > --0000000000001f307a05f43184bd--