Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121362 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 68259 invoked from network); 17 Oct 2023 19:39:58 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 Oct 2023 19:39:58 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4DF0B1804B0 for ; Tue, 17 Oct 2023 12:39:57 -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-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 ; Tue, 17 Oct 2023 12:39:56 -0700 (PDT) Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-4065f29e933so63128285e9.1 for ; Tue, 17 Oct 2023 12:39:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697571595; x=1698176395; darn=lists.php.net; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=SPhGNEyex3RzmVCbeI3EbhUozyKtzzIZgToYjQBjxXY=; b=Sb1mT6WnUUfPCmT5eJm71jr3pO6M/+cDyLm7diKh2eHs24CnMyG7UET4ka6XE0e01x wR4ZVWqQttECooSU3SJ2yYFArwoDvlRSWtIIGslrb3C58+vkBdYetL98W56cXE7KfYWq 1s1c3zmSeWIai2rSUH8Kiw/wl+ZUc2pM614Wx2y7pKjnO2IlNBo48EFBF9Xsoq4f/I3r OaPJywNSi6YYPVoGT/SXpu1xT3xATkWIzJeTQDEre2njwMAY8HvWiex2HqGJJe0D2k+q FUDrHKNQKDlziEfUC5spquVig3BtDIibzDpVL/fX1xh/HPIXjJFF08XjmteIGZZzQ8hi ojuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697571595; x=1698176395; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SPhGNEyex3RzmVCbeI3EbhUozyKtzzIZgToYjQBjxXY=; b=D3DXB+THsm3WX9ADlPu9hDkQBxhzuBb8AWivx08V6PqgxRjLkKTUWwQFJReqTUMewR XvdIrxT8ghEPsUIWx0fbVHHw+Z+Tkr6TWgH9k80QLXDnNaIKE06N1igfn/HlLNgWVRE9 uxFsVpVg1ENcjivjuhDwMFN2lcS6XAMuLPDyzWPYAUWvr7J0XSQY1vn04zbLRsBrp7nn JVE9fVVxG4hQTZ7oTe1bghlJbpwlr4HQXE70Y3rWxe1KhXPvesNTMyX+K9vmunSz9FKA 2ABJM4+hJTAFEY5e2nwISmJPsbSVPS/eFMh5Q8Z45swLVibF1SMHN+KEoE4U4t2GxYpe zMHQ== X-Gm-Message-State: AOJu0YxHXMMwcVf1aYcIE2puMITsPiXbiPGKWO4Duku6WxzP15ASfLUn TeZE14Gkh9G5R3dfm1vXt0Wj9nOzJug= X-Google-Smtp-Source: AGHT+IFEJvJb3PGpjM2A8nDiTJZwzOgeffvMUOJqSo/z6jAAIJZ0icOPBrmk3mEXdrG/Vy6jXJqbHg== X-Received: by 2002:a5d:5547:0:b0:32d:cd02:d4f3 with SMTP id g7-20020a5d5547000000b0032dcd02d4f3mr421265wrw.40.1697571595311; Tue, 17 Oct 2023 12:39:55 -0700 (PDT) Received: from [192.168.0.22] (cpc83311-brig21-2-0-cust191.3-3.cable.virginm.net. [86.20.40.192]) by smtp.googlemail.com with ESMTPSA id b16-20020adfee90000000b0032d87b13240sm435199wro.73.2023.10.17.12.39.54 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 17 Oct 2023 12:39:54 -0700 (PDT) Message-ID: <9d5388fa-a5a5-4fa5-81ff-16f6670f80b6@gmail.com> Date: Tue, 17 Oct 2023 20:39:52 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: internals@lists.php.net References: Content-Language: en-GB In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Previous discussions about generics syntax only? From: rowan.collins@gmail.com (Rowan Tommins) On 16/10/2023 15:08, Olle Härstedt 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 } The actual attributes could either be built-in, making them official parts of the language, or managed in a library that static analysers co-operate on, making them standardised but more agile. Regards, -- Rowan Tommins [IMSoP]