Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121559 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 64770 invoked from network); 2 Nov 2023 22:59:46 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 2 Nov 2023 22:59:46 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A79AF1804D0 for ; Thu, 2 Nov 2023 15:59: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,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,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: AS2639 136.143.188.0/23 X-Spam-Virus: No X-Envelope-From: Received: from sender4-of-o50.zoho.com (sender4-of-o50.zoho.com [136.143.188.50]) (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 ; Thu, 2 Nov 2023 15:59:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698965979; cv=none; d=zohomail.com; s=zohoarc; b=PfHDFaiAHHv3RMNgUibaAx9Fqu5TILqZPzBRI6E6itEDLJzSG3Og9EH626EmPxYHFeivDk4ylRkj6UvDbmKfrMQB9wAibppDE3UqO4ed/iMULrqx1G5eZgjLADROTvbiaYkCEe7DZpO3Lb22JR8OY0IcyvrTIQkE1kD6J40IVHo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698965979; h=Content-Type:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=7QuX4FMyYX7fMFt5t+O875UphWPf/yiQ13AiFUwfZDM=; b=Fh44G23nAA1jw+SE2BchZxgKs9Fm4aoFGErJKNvp4u9Qyui+faQ5070nwO6lc+VUi5FE+DUyqCcfHDO+nVjRdARMtEa8W3k+svewxom71qvgVxMfk0tcLw+tMqZEfIdeJpP42fdPkuNsvtwIIk701rUc+IX9nze2g5FkkO7+tbI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=daniil.it; spf=pass smtp.mailfrom=daniil@daniil.it; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1698965979; s=daniil; d=daniil.it; i=daniil@daniil.it; h=Date:Date:From:From:To:To:Message-ID:In-Reply-To:References:Subject:Subject:MIME-Version:Content-Type:Message-Id:Reply-To:Cc; bh=7QuX4FMyYX7fMFt5t+O875UphWPf/yiQ13AiFUwfZDM=; b=eVnEsSuHLw2O4NwuljSZWmpULTJrk04f1mvv8Zl4MX0b5E7ID5/xQc7lnS2XzwtG QnNexY9jXCeK83AiaKG3Ab8l8fd5ygjL4UD3eQ0//0nDNPIbmjo7ObDf1t8A/v3D9sw k6glgcA6r1oMo2J94hnwtHxlo8G/dsvN1tLaYWY8= Received: from dummy.faircode.eu (128.116.205.77 [128.116.205.77]) by mx.zohomail.com with SMTPS id 1698965977785188.86772173546728; Thu, 2 Nov 2023 15:59:37 -0700 (PDT) Date: Thu, 2 Nov 2023 23:59:36 +0100 (GMT+01:00) To: internals@lists.php.net Message-ID: In-Reply-To: References: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_33_75548869.1698965976250" X-Correlation-ID: X-ZohoMailClient: External Subject: Re: [PHP-DEV] Previous discussions about generics syntax only? From: daniil@daniil.it ------=_Part_33_75548869.1698965976250 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Hi all, Perhaps chiming into the conversation a bit too late, but I would personally like to say that I *really* do not like the idea of attribute-like, unvalidated generics syntax. As a maintainer of Psalm and an active user of it both personally and at work, I absolutely *adore* the typesafety and ergonomics generics can provide, but all benefits are nullified if generics are not not actually typechecked. Generics can be typechecked by: - The language itself, which *requires* all types to be correct - Oe by a static analysis tool which is specifically added to a given project for the purpose of typechecking generics: in this case, we can consider to be using a superset of PHP which similarly *requires* the static analysis to pass in order to "compile" the source code (I.e. if the Psalm pipelines are red, deployment is blocked). Generics whose syntax is fully provided by the language, but then can only be *optionally* typechecked by installing third party unofficial tools are not, in my opinion, an improvement over the status quo. Now, after reading this thread I was actually inspired to implement runtime typechecked generics in PHP itself, and https://github.com/nicelocal/php-src/tree/generics is the single-evening result of that: it features generics support in the parser, and some initial, partially committed runtime validation. However, I paused the effort for the reasons listed in https://github.com/php/php-src/pull/8752: runtime generics typechecks are (needlessly) expensive. The much better approach, one that I intend to maybe give a shot at this Christmas, is to add static analysis functionality to PHP itself (i.e. turn it into a truly statically typed language). I have a hunch it may be easy enough to do by hooking into the type inference functionality provided by opcache, and throw compile-time exceptions instead of silently inserting runtime typechecks. This functionality may be initially enabled through a declare(static_types=1); statement, and might actually also help find bugs in the type inference functionality which causes JIT bugs. Personally I'm super excited for the possibility of introducing static typechecking in PHP itself, partially because it also allows to easily and cheaply implement generics. Regards, Daniil Gentili ------=_Part_33_75548869.1698965976250--