Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121371 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 7816 invoked from network); 18 Oct 2023 07:13:59 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Oct 2023 07:13:59 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 37CE1180504 for ; Wed, 18 Oct 2023 00:13:59 -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_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-il1-f176.google.com (mail-il1-f176.google.com [209.85.166.176]) (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, 18 Oct 2023 00:13:58 -0700 (PDT) Received: by mail-il1-f176.google.com with SMTP id e9e14a558f8ab-3576121362eso21855085ab.1 for ; Wed, 18 Oct 2023 00:13:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697613238; x=1698218038; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Cysp9GlSsubkJj7pKtOK0r/TTl3iypquDUp0ZyH0ycQ=; b=cgEX8+uarq9r8u8gxvykz1KGxqe0TBysfdGM3WtgyjYzK0Dq/x6bxYMSHI7haVUybm zRoeTu7pHayWKH0NxXA7zCiRAtBpCxrMWb29y9wulyfYd7zWzvhAhGSYgAo5+7pCnU5N LRNIEWcouFrJDWZvnh/3FHco2b8M4jQBLLfCnIUAPWfwna6t4e/8Oj9urNtw7WetPHJU eK5U5jdp9vGDBfafMXsANfDAwBhi0RnLj1N2tSVavlENrFT2wu7Tr6wp9yTcN0tUbQIZ oZ9Iru6X8fjPez8xN86xRQQwinywgt79ER9RYI+VOC6rAvoML+3+T/Mti+Wqg9kIk8E3 H12g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697613238; x=1698218038; h=content-transfer-encoding:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Cysp9GlSsubkJj7pKtOK0r/TTl3iypquDUp0ZyH0ycQ=; b=gOrrLOw+PaA5CAhaxk4/afd5u/z0tHURV59UEVJlnhRj5xrnPrr71IdPwVAuadXynA ndEIr3Mxj13TMz27BGlDvY0e2uGF6Mo/KMH4GMSL9qJ1dvhOIKG1Ne0ulY4rb2oeIHtP 1RfqqZtjrqu9+09qUfKX+DgaGi5NbWgLd9ToEgxlOlVNoRS5wPsxqvWWz9kBR9x5A2dZ 5iMwTIEVWErmOQ7wUos57DuBkYQvdmzC5UBvEbEI2BSvL4eciHzeVYKUPvB8tdUshRJA SuOZoqeQl57G7dSJ8Tq4SAgV0ifjLPzEH2c1XF9qZnxy1KSqmSGc1OUJt/j0mhZ0Vs4p v1PA== X-Gm-Message-State: AOJu0YwBxg+nXNGybs/BoRlQHb+YJ4R1mByD7YUuzMS//PElELu8HURP zbcHjEARRvLpb3rFl+CN5fVTeCrXl7DxEbY8V6o= X-Google-Smtp-Source: AGHT+IGN198iggQp3938QrP60I4JwfYKoaIRqOH/u5L2edJ9nn8GZNwNFqro0f94lZwq49/Izhr8YxO29RtoHwDiZ6M= X-Received: by 2002:a05:6e02:1d1a:b0:357:54d8:94f6 with SMTP id i26-20020a056e021d1a00b0035754d894f6mr5424131ila.3.1697613237901; Wed, 18 Oct 2023 00:13:57 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a05:6e04:2109:b0:2ed:1ae2:83ac with HTTP; Wed, 18 Oct 2023 00:13:57 -0700 (PDT) In-Reply-To: <9d5388fa-a5a5-4fa5-81ff-16f6670f80b6@gmail.com> References: <9d5388fa-a5a5-4fa5-81ff-16f6670f80b6@gmail.com> Date: Wed, 18 Oct 2023 09:13:57 +0200 Message-ID: To: Rowan Tommins Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Previous discussions about generics syntax only? From: olleharstedt@gmail.com (=?UTF-8?Q?Olle_H=C3=A4rstedt?=) 2023-10-17 21:39 GMT+02:00, Rowan Tommins : > On 16/10/2023 15:08, Olle H=C3=A4rstedt wrote: >> Hello internals, >> >> Was there a previous discussion about the pros/cons of adding only the >> syntax needed for generics, but not the functionality? So static >> analyzers could use it, instead of docblocks. I looked at externals.io >> but couldn't find anything specific. > > > Hi Olle, > > Since I haven't seen it expressed quite this way in the previous > discussion, I'd like to highlight what I think is a major downside to > this approach, at least as commonly proposed: > > Using the same syntax for type information that is guaranteed to be true > (existing run-time checks) and type information that is "advisory only" > (new checks for optional static analysis) means users can no longer have > confidence in that type information. > > This is one of the interesting things about the compromise over scalar > types - if you see a declaration "function foo(int $bar) { ... }", you > *know* that $bar will be an int at the start of every invocation of that > function, regardless of which mode the calling code uses. I think adding > exceptions to that certainty would be a bad direction for the language. > > On the other hand, I can see a "third way": if the problem with current > static analysis conventions is that they have to be parsed out of a > string-based docblock, we can provide *dedicated* syntax, without > unifying it with the standard type syntax. For instance, some of the > earlier discussions around introducing attributes suggested reflection > expose the AST of the attributes arguments, rather than the resolved > expressions, allowing them to act a bit like Rust's "hygienic macros". > If that was added as an optional mode, you might be able to do something > like this: > > #[RawAttribute] > class GenericType { > public function __construct(AST\Node $typeInfo) { ... } > } > > function foo(#[GenericType(int|float)] array $foo) { > // array is the type guaranteed by the language > // static analysis libraries can get the GenericType attribute from > reflection and receive an AST representing the type constraint int|float > } Not sure readability is improved here compared to existing @template annotations. ;) Olle