Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120104 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 7082 invoked from network); 21 Apr 2023 14:54:35 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 21 Apr 2023 14:54:35 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0A5901804DF for ; Fri, 21 Apr 2023 07:54:34 -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,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS24940 176.9.0.0/16 X-Spam-Virus: No X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 21 Apr 2023 07:54:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1682088871; bh=bUYex0nesYCjcNiUB8kkKdOBTdGUanCY0oOCjZP6vhQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type:from:to:cc:subject:message-id; b=ojg9bVeioMCLPQA6CGu3yLX1j9AJ7Tc0WUOckCx/sYu/yX8NQW6C46fny4671uDL0 8x3I+XLhXFraAHcNSHnp6PLa5jnfWOw0fOCliVdAz/YrTe3i8FZ0txGAuiDhqa20D8 SXGfVAp1dC6aLOBiB4SgH6blemo3ZK4jH7cHUWsalEHLD+EDyCQMRLTev+KC6XRMVF nXD5Z2w29npUriOgqyMbPlsxH7cQ0k7K0159svPNXT0kIN2ox3y/4Lw0vIGZ+QBzRB ps28RCeK9jQl/VVc6s99Dk6D5KDYN+D9pAPM2o7BxTFE4gil3OZoOC2sTgWQ75QjER UYbPwswn7zIvQ== Message-ID: Date: Fri, 21 Apr 2023 16:54:30 +0200 MIME-Version: 1.0 To: Deleu , Robert Landers Cc: PHP internals References: Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Expansion of PHP Symbols? From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=c3=bcsterhus?=) Hi On 4/21/23 12:49, Deleu wrote: > What is fundamentally different about Type Alias as opposed to something > like Enums that was recently introduced? Type aliases might include an unbounded number of types and are … aliases, which based on [1] is a major issue. To my understanding, PHP currently assumes that no object of a non-existent type can exist, thus is able to short-circuit checks like: $foo instanceof Bar; // If Bar does not exist, // $foo cannot be Bar by definition. However this might be violated if such type aliases exist, as Bar could be an alias to a type that actually exists. Bar could probably even be an alias to another alias: type Bar = Baz|Quux type Baz = Foo So to check if `$foo instanceof Bar` in this case, the engine would need to load Bar, Baz, Quux and Foo in order to determine if $foo is any of these. If folks also want intersection types in there, which they likely want, this gets complicated quickly, because nested type definitions would not necessarily be in DNF and thus expensive to check. Consider: type Foo = Bar&Baz; type Bar = Quux|Asdf; type Baz = Apple|Banana Then `type Foo = (Quux|Asdf)&(Apple|Banana);` which is not in DNF and explodes into this type when written in DNF: `type Foo = (Quux&Apple)|(Quux&Banana)|(Asdf&Apple)|(Asdf&Banana)`. So you'd likely have to eagerly load all pieces of the definition and normalize it, whereas to my understanding currently many type checks can happen more lazily. The normalization in itself can be expensive as shown with the combinatorial explosion above. Disclaimer though: I'm just parroting what smarter people than me have said before and also drawing my own conclusions from my understanding of what they said. Best regards Tim Düsterhus [1] https://chat.stackoverflow.com/transcript/message/55310273#55310273