Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110125 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 8314 invoked from network); 11 May 2020 10:58:20 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 May 2020 10:58:20 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B90641804C9 for ; Mon, 11 May 2020 02:34:41 -0700 (PDT) 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 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-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 11 May 2020 02:34:41 -0700 (PDT) Received: by mail-lj1-f180.google.com with SMTP id l19so8698582lje.10 for ; Mon, 11 May 2020 02:34:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=++lhqTOCu8sq9560W/+1/fYyx/HnuISKMtaVKmGCIV8=; b=ZFVoPefPX9v77wwjDtBqXG7l3E5ShGxhi36P2HE7Coc3pqrDyanuXI7ykFwu6Qgmpe nt/a1Y1Tb58Jo0e+gkpILPL1dFjL9Awa4eDyaffteiIqm8uBSBo5gh2fXWELvbsRph0V FsRoEpHimgkmVHmtoWr6KVwiBxt5cADC93xRcHNe6o6JtoAdznhkdFM8DdhDa9lWvrY3 jIl37paQgy/H9shQdqi2y5wkql7Jlg0Gdf4cHw/LhobUb+Ag1jwGLc5FbDJsjn1UU/CH 6sBWtWILVU1mH/Obzm7AeZTUYm45LQsOUaqTloWwUgsWtbPvFS0ktlEFbHa/fzHZeZHc BILw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=++lhqTOCu8sq9560W/+1/fYyx/HnuISKMtaVKmGCIV8=; b=K7SCzb7i4acwACRpj/EJ9rkWw5LBvW+ohbxxgn169wkjv+NuB67+g63TPBTSxW0K4i kRwiADAHiNMtYf1nPUdY7ZquRIpHLAgyvedXPvIvP3JPM5EbFlbFp/ik++cf+5CVRtLY sG2uEk50sZJ+0xrXDiFBlIE73hboHDGp2IkpxSAJ6tujzEgduPs2dRAa2FaQFn2IKb9W IQY1/ruMswkV0Pcv3iFumQ/PLonfYOIRPyfPytWZ3K15nR5bzvBTx6ztb4H3V2RjCCtC M+nsiJquK2tPj3OLMSGNmFI2a+CWQcbNbGxxMUjfWPbVx1hCYMwYluxLZYpIEAz0R46D ofcg== X-Gm-Message-State: AOAM531RHvfbWvnHuGUXbu0VQwkmu1nXeh2NZKhzNVhNHZsrGps1sTOW BxrLP/FIABsV/kdGgaRH3GEKPUJsYpc3HpDxRi9F09Blp7o= X-Google-Smtp-Source: ABdhPJzdof1BXqRJnwiRz0H19utE6TA3NIubyMFmUNXfa8NlniIOIL8aIoeI1KiGT8aJ91cZS9/TkgO2JQ+H/Pcg+zU= X-Received: by 2002:a2e:8884:: with SMTP id k4mr9870133lji.267.1589189678830; Mon, 11 May 2020 02:34:38 -0700 (PDT) MIME-Version: 1.0 References: <171dee3baf3.bef5753260554.3262181919550021853@manuelcanga.dev> <171e05b4ced.1041f31b5124598.4028595156690203917@manuelcanga.dev> <10faa29f-f08f-a73e-b76d-683f5abbee86@gmail.com> <171f30b0df0.102b810be444185.2462173785894899100@manuelcanga.dev> In-Reply-To: <171f30b0df0.102b810be444185.2462173785894899100@manuelcanga.dev> Date: Mon, 11 May 2020 11:34:22 +0200 Message-ID: To: Manuel Canga Cc: Rowan Tommins , internals Content-Type: multipart/alternative; boundary="00000000000049964605a55c0e89" Subject: Re: [PHP-DEV] [RFC] Keep type of reference params From: nikita.ppv@gmail.com (Nikita Popov) --00000000000049964605a55c0e89 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, May 8, 2020 at 8:49 AM Manuel Canga wrote: > > > > > ---- En lun, 04 may 2020 19:33:51 +0200 Rowan Tommins < > rowan.collins@gmail.com> escribi=C3=B3 ---- > > On 04/05/2020 16:43, Manuel Canga wrote: > > > I think I=E2=80=99d be positive of adding `inout` keyword in order t= o: > > > > > > - Check type of out is equal to type of param( like example of my > first email ). > > > - Avoid modifying caller var value when the function throws an > exception > > > > > > Another huge advantage of adding inout parameters is that we could mak= e > > it mandatory to mark at the call-site, and get the advantages of this > > RFC with less of the compatibility hassle of changing the way > references > > work: https://wiki.php.net/rfc/explicit_send_by_ref > > > > We'd still need to figure out how to smoothly transition built-in > > functions to use inout rather than by-ref parameters; but then we > > already have magic "prefer-ref" in internal functions, so maybe we > could > > come up with some kind of "prefer-inout". > > > > > Hi, Rowan. That's a good point. > > If nobody objects to this RFC, could someone give me(manuelcanga user ) > karma in order to create wiki page ?. > I'm finding it hard to follow what is actually being proposed here at this point (as many different ideas seems to be discussed at the same time). I've granted you RFC karma on the wiki in case you want to write down something. As other's have mentioned, this is not a simple topic from the implementation side, so it's good to have a firm idea of how things would work on a technical level. If you want to pursue the "inout" idea, I would recommend reading through https://externals.io/message/101254 in its entirety, because there is quite a bit of inout related discussion in there. My current assessment is that I do not see any way to implement inout in a way that both does not use references and has acceptable performance. (Implementing inout on top of references is possible, but has impact on its behavior, e.g. the fact that the reference will be initialized to null by default, even if the function throws.) One of the core problems is that any naive approach to inout (i.e. literally implementing it as a read before the call and a write after the call) will necessitate a copy of the modified value, precluding rc=3D1 cow avoidance. Implementing array_push() as an inout operation would copy the array every time a value is pushed. Maybe this is actually a fundamental implementation-independent property of inout, if it has the semantics that the original value is not changed on exception (a copy would be necessary in case code later in the function throws.) Regards, Nikita --00000000000049964605a55c0e89--