Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120107 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 25238 invoked from network); 21 Apr 2023 20:12:42 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 21 Apr 2023 20:12:42 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1D3DB1804C6 for ; Fri, 21 Apr 2023 13:12:42 -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, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) (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 ; Fri, 21 Apr 2023 13:12:41 -0700 (PDT) Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-24735727c83so1817027a91.3 for ; Fri, 21 Apr 2023 13:12:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682107960; x=1684699960; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=5DZy1FQywZ26dDGXfUhJnJF8D6CN6qAO+BS5XEdyxpM=; b=GwFF+sRbhI0T7uwnOA6xJlJbb0+WUZ59TNcYy58QoYmw4pzoRtIsaTt8X0/+iRx6Q9 BLptBPdWI5cVGio99dvP/YcNz0e1zK+C0BPtOYCMBGe3DOiVE/hgje6X1xT3seJGnFcr dienRnpy3J0AUIJpbKxyvRlX42fUzO2m9s6vwaeMABiSjvjlHNMeer4A49gvBcPBpkqS ikhRsRXXNsndj84jNwPzPCQR1NLYeUZ66dFFmT60ZSGfjAM2tC/IelbtHH4pu/OyWJog XRr00n4TyECX6jedgJM4Qx6/G4Pqq8xUgNHxbyZ7wwKOKXFMvsU5BNoU0zuNndnVTYJN 3U4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682107960; x=1684699960; 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=5DZy1FQywZ26dDGXfUhJnJF8D6CN6qAO+BS5XEdyxpM=; b=aCIsokSva3mubAGlj8sVGnBJCwOK3rplgD8hx+y67WlSTSYhS45T1qb48lMB+iVugO ezb8kvr5Uf3S0DBqkf4k7SNpuxY2yV8YIHIk9kwMtWeFuusx22L7acj5PgnTOLiJzG7R 9HFGmSnipQ6i6lMTP0PZnA68TxeGx0kpRkhl7ut+oihRDeS/Lzk5G9Dzv/79sM/pLCqp i5cvWa+xoV137KNuoy+4r50UbzmRbT09PgXa2ixZ1dL7yQ1j1O5CBipjRLX6+o36V7Jy P0xv3VnIV4ldmonqk90Lo+Ly0reXkQzPYAv6PPI/LiTZhhvozFo2++sXVzm/zmHQTM09 uraA== X-Gm-Message-State: AAQBX9eZzrqIwT3+76BibceY6j3fERVLasru+Gs2iMa4oDeNxVIDbB7e e+07wiJgpfnvjmbVG/jhVghhm9UT9KYlbo2TMemnJ3rQ1IQ= X-Google-Smtp-Source: AKy350ZhG4hiLcIkg2dYGHYMKaS3FKeLuNoRlMEJR3miO7IV1nnEn2WrRtXESni5rD2qDwmrdh8nN01Yo/5QWPAho2s= X-Received: by 2002:a17:90a:ca90:b0:23f:b177:9082 with SMTP id y16-20020a17090aca9000b0023fb1779082mr5499314pjt.49.1682107960094; Fri, 21 Apr 2023 13:12:40 -0700 (PDT) MIME-Version: 1.0 References: <6581c252-75c9-889d-75d2-eff5220216c2@gmail.com> In-Reply-To: Date: Fri, 21 Apr 2023 22:12:29 +0200 Message-ID: To: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] Expansion of PHP Symbols? From: tovilo.ilija@gmail.com (Ilija Tovilo) Hi Deleu > From Rob's email (https://externals.io/message/120094#120097), the argument > against a simple "use" statement seems quite natural. I certainly don't > want to redefine "use int|float as Number" in every PHP file I work with, > so naturally we would go back to type alias definition, symbol registration > and autoloading. So I guess my final question is: what is fundamentally > different about Type Alias when compared to interfaces, classes, enums that > make this controversial? I don't think autoloading is the fundamental issue with type aliases, nor are the symbol tables. Enums live in the class symbol table, as they are just classes. Type aliases don't need most things classes need, but they could live there too with a discriminator flag if we're ready to waste that space for "convenience" of not rewriting all accesses to the class table. I believe the bigger issue is typing itself. There are multiple complications. * Currently, any name that is not a known named type is considered a class type. With type aliases this assumption is no longer correct, which may require many changes in the engine (and in the optimizer). * Combinations of union and intersection types are limited at the moment (Foo|Bar, Foo&Bar, (Foo&Bar)|Baz). With type aliases we can nest types indirectly to create new combinations that were previously disallowed on a syntax level. We'll either have to handle these correctly (which from what I understand is quite complicated) or disallow them at runtime. * Type variance may be challenging. E.g. do we allow substituting a type alias with its concrete types and vice versa? What about substituting two equivalent typealiases? There are infinite combinations. * For runtime type checking itself we would need to compare the value against the concrete types instead of the typealias, thus complicating and slowing down the type check. All of those could be solved (to some extent) by substituting the typealias with the concrete types as early as possible and reusing the existing type system. This is the approach I've tried some years ago: https://github.com/php/php-src/compare/master...iluuu1994:php-src:typealias The main issue with this approach is that classes/functions are generally immutable (with OPcache) because we want to store them in shared memory where all processes can access them. We have mechanisms to make *parts* of the class/function mutable per request but adjusting this for all types might once again require many code changes. Furthermore, every type (with a typealias, at least) would require copying to process space to substitute the typealiases with the concrete type, for every request. This might or might not be significant, it's hard to tell without measuring. But the main reason why I stopped working on this was, what do we use it for? Right now the main use cases are union and intersection types which are fairly limited or short in my personal PHP code. A reasonable use case might be closure types. However, I have become increasingly sceptical whether runtime types for closures are the direction we should take, as 1. they may be slow, hard to implement or both and 2. most code doesn't *want* to add closures types that could be inferred in most other typed languages. This e-mail is not too structured and not exhaustive, let me know if you have any more questions. Ilija