Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125175 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 503DB1A00EA for ; Fri, 23 Aug 2024 21:57:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1724450362; bh=BAJm8tAUKxv/AX2QRQWYXDZy68fGyPJ6Jl84e9/y5Iw=; h=References:In-Reply-To:From:Date:Subject:To:From; b=moMS7ePU5qYEw6mub2Bv6eHl9V4mFhzVtu8shyyJTBSUP8HtHXgXsBArw90OgEaWK re0F478sJk98Is9eHp1KmJLLLUN7avugKAFMuCN2aEkdBrQ4FmDuvcB3NKGyd5wjFx 51WL0sNllM5FoO8vETwxTkwigkBwTSv8HyA5laKKFS9noQ/6CwiB9Ph+cGR8unAHhs Zegy9/y67HaYo653LdEwqwU/eZMr/ANnRCAQjO9h/cppnHoPPePdOqgXX9188ysHqh XCu2FJC11t1dsIprhPXnCuQIAT41x91XgMVRpc0SkwuXxfSaXbf3CmCPnbT9YSSwiQ 6EzLlxw4+TK8w== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5F270181213 for ; Fri, 23 Aug 2024 21:59: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.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-oo1-f44.google.com (mail-oo1-f44.google.com [209.85.161.44]) (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 ; Fri, 23 Aug 2024 21:59:16 +0000 (UTC) Received: by mail-oo1-f44.google.com with SMTP id 006d021491bc7-5dc93fa5639so1793160eaf.1 for ; Fri, 23 Aug 2024 14:57:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724450244; x=1725055044; darn=lists.php.net; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=BAJm8tAUKxv/AX2QRQWYXDZy68fGyPJ6Jl84e9/y5Iw=; b=RbK0S9NA4KMdMMm7+xtXI18Ro0yTMMM7u8FzDdzU8VqbFYWoOv9YCf1OrSUG+7EAZ6 Ec1s7TelHemXqBXmeQ219DvneyBI6OWlnU+Lw+ofguOgNwAc6QZHchhd3oRrrqyWO7xK +d6TydiPkwKfkHIjbd+K+597GluvVfOwDV/tep3HpW+CJxvhtUMBrXwXX9PxBIMv/oTM kLao/YFA/DoAWK3OrzS6GHZAp9kmm4/QgNr82UrLWCIW+abt1ThTf51Nu8nj8L+myqpm C+MGWEWYlUc8qJu8ywlTAxQhZ8zbPd2FVnicJtK/Lqa9n9BPhoQ/ZxFs86s0K1y/UK20 /bdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724450244; x=1725055044; h=content-transfer-encoding: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=BAJm8tAUKxv/AX2QRQWYXDZy68fGyPJ6Jl84e9/y5Iw=; b=DkRlH65mm54a0Hdk8cK1Wo8hTu9egfs0XFD3e4FRfpUMaey8U7zb/O5aCvCebZhCXs j5gWScAB44bT1lRW0e96GePnSJQT1zLnOQSdN+b/lzxcUY62IRKYX5wpzUJppK07ZXmI 6QYq/Nb1Cf+6r1HUzlwDfuBwuh5iGHQeBxRGy+3BE7c0U3oPOaUDih8YytjnEabJP4ci gmlxrqlakOU89kNCthu1uS2QtpFW7sfqUrReW2Zgn5hEGp5EVod1UxdZvou8Xr1weDMW Ht1p3yVkdBMn0vsp+fkJT/vcqaWXBBeQZnUfjoWpHMWL48ZYM0yWDthKCTmHCZ7Lbwro OtmA== X-Gm-Message-State: AOJu0YyOwO1Unuq+2S79IPITtTVTUyongp8MWOAS3D/ljxa+ew4MAXjo 5yxnD5bUv/ZckzgHt8omjp8MuqeCnMHsdRe3EtFP2qXcQZiiYzxCS3/aKkP2/TcfW6Pxsuca7nX OB4sF7RAqYlCEHzam3ZghJsuLzHUH9VpysW0irQ== X-Google-Smtp-Source: AGHT+IFD7PhLtwp2K55KunkxKxDWjlY8bF5QhScL55prrINFqEh64/+uVRljVX1op4ZxoDdT9sbDFegFC7+yyWekvTM= X-Received: by 2002:a05:6358:57a3:b0:1ac:f109:e248 with SMTP id e5c5f4694b2df-1b5c3a458a8mr385404655d.2.1724450243920; Fri, 23 Aug 2024 14:57:23 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <21D6F160-5EAE-44FA-907B-E1DAAC1B8D75@rwec.co.uk> <53BD062A-4D7F-4E5D-852E-6D27641213A8@koalephant.com> <7607FD64-5572-466E-9866-63C2536B2A09@koalephant.com> <0d269a38-28fe-494c-a903-50022e09f27b@app.fastmail.com> <63DAE337-B117-4380-8735-186DC30FE0B7@rwec.co.uk> <977227E3-8793-4FB1-B572-B75D27C06ED5@rwec.co.uk> In-Reply-To: <977227E3-8793-4FB1-B572-B75D27C06ED5@rwec.co.uk> Date: Fri, 23 Aug 2024 23:57:12 +0200 Message-ID: Subject: Re: [PHP-DEV] [Concept] Flip relative function lookup order (global, then local) To: PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: tovilo.ilija@gmail.com (Ilija Tovilo) On Fri, Aug 23, 2024 at 9:41=E2=80=AFPM Rowan Tommins [IMSoP] wrote: > > On 23 August 2024 18:32:41 BST, Ilija Tovilo wro= te: > >IMO, 1. is too drastic. As people have mentioned, there are tools to > >automate disambiguation. But unless we gain some other benefit from > >dropping the lookup entirely, why do it? > > I can think of a few disadvantages of "global first": > > - Fewer code bases will be affected, but working out which ones is harder= . The easiest migration will probably be to make sure all calls to namespac= ed functions are fully qualified, as though it was "global only". To talk about more concrete numbers, I now also analyzed how many relative calls to local functions there are in the top 1000 composer packages. https://gist.github.com/iluuu1994/9d4bbbcd5f378d221851efa4e82b1f63 There were 4229 calls to local functions that were statically visible. Of those, 1534 came from thecodingmachine/safe, which I'm excluding again for a fair comparison. The remaining 2695 calls were split across 210 files and 27 repositories, which is less than I expected. The calls that need to be fixed by swapping the lookup order are a subset of these calls, namely only the ones also clashing with some global function. Hence, the process of identifying them doesn't seem fundamentally different. Whether the above are "few enough" to justify the BC break, I don't know. > - The engine won't be able to optimise calls where the name exists locall= y but not globally, because a userland global function could be defined at = any time. When relying on the lookup, the lookup will be slower. But if the hypothesis is that there are few people relying on this in the first place, it shouldn't be an issue. It's also worth noting that many of the optimizations don't apply anyway, because the global function is also unknown and hence a user function, with an unknown signature. > - Unlike with the current way around, there's unlikely to be a use case f= or shadowing a namespaced name with a global one; it will just be a gotcha = that trips people up occasionally. Indeed. But this is a downside of both these approaches. > None of these seem like showstoppers to me, but since we can so easily go= one step further to "global only", and avoid them, why wouldn't we? > > Your answer to that seems to be that you think "global only" is a bigger = BC break, but I wonder how much difference it really makes. As in, how many= codebases are using unqualified calls to reference a namespaced function, = but *not* shadowing a global name? I hope this provides some additional insight. Looking at the analysis, I'm not completely opposed to your approach. There are some open questions. For example, how do we handle functions declared and called in the same file? namespace Foo; function bar() {} bar(); Without a local fallback, it seems odd for this call to fail. An option might be to auto-use Foo\bar when it is declared, although that will require a separate pass over the top functions so that functions don't become order-dependent. Ilija