Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121567 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 15678 invoked from network); 3 Nov 2023 16:06:01 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Nov 2023 16:06:01 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C72091804D5 for ; Fri, 3 Nov 2023 09:05:58 -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_H5,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.184.0/24 X-Spam-Virus: No X-Envelope-From: Received: from sender3-of-o58.zoho.com (sender3-of-o58.zoho.com [136.143.184.58]) (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, 3 Nov 2023 09:05:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699027555; cv=none; d=zohomail.com; s=zohoarc; b=FmuDXi34P4b8116x7kx+rGZfEkuFjqrvwCVxfq/7zpgppTrC0K8WSEWydB1Eu+Lr2YLbQ56o+V+y43P/O5AKDV/dJlxLMsjTdMu0BnkM8RliGYJo4fGYmDplcf+b/hIYWewNkDtgWlfyfu8YI65tX5XJHluIAhcYusOF95SDvLs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699027555; 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=xiQUIms7DBkYFXmZaFy14TBKHF4eCfVoH2HgFaB9EMM=; b=d3sSORhlCyUOM4cmOxyErXcZCZujmhoYRup9cUAvETvx9+MEDEXaK37NAoLQ+A6k67kF2PXLWvCZO44TZeFzWWF8Mu1tZahJAJxrnOhSD8XwkfgP1a0Da/5M2wZZeTPdEBkzMblEml6k47I5hz2KgKuND6G3awJ3uYRbSvLK1rs= 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=1699027555; 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=xiQUIms7DBkYFXmZaFy14TBKHF4eCfVoH2HgFaB9EMM=; b=T91YlXoyAvBmY5lW4VPhe9a0JNRi/xrMbrI/Qcmy+2WCB8b/KWtJemE0IwSYhewt xqRC6iTo3DpgBj9ywJ8X7GTc2XhV7CKbEXi6H2yH7WeJ5snpOPTM6ajHRrtHo6NMk39 MlO13vVttEzQmeheoP37K/x8VAQ9yUXJD1HsV1fc= Received: from dummy.faircode.eu (128.116.205.77 [128.116.205.77]) by mx.zohomail.com with SMTPS id 1699027555157111.55409626259211; Fri, 3 Nov 2023 09:05:55 -0700 (PDT) Date: Fri, 3 Nov 2023 17:05:52 +0100 (GMT+01:00) To: internals@lists.php.net Message-ID: <1503e012-c445-4f37-810f-a59bc38ba8f3@daniil.it> In-Reply-To: References: <5ea314c4-f45d-4b7c-a94d-a82931eeb80b@daniil.it> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_4_193146460.1699027552818" X-Correlation-ID: <1503e012-c445-4f37-810f-a59bc38ba8f3@daniil.it> X-ZohoMailClient: External Subject: Re: [PHP-DEV] Previous discussions about generics syntax only? From: daniil@daniil.it ------=_Part_4_193146460.1699027552818 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Hi, > Doesn't that just take us back to the "generic types are only optionally checked" scenario you were trying to avoid? Of course, my idea would also require bundling and enabling opcache by default with PHP and actually requiring the preloading+compilation step in order to run any code, like for any other statically typed compiled language. I.e. no more REPL-like, open world assumptions: all referenced classes and types must be present (or autoloadable) at compile time, with no way provided to disable compile-time type checks, like for any statically typed language (of course this would be somewhat of a breaking change, PHP 9-worthy). > you've got to switch from rules for loading classes at runtime to generating a static preload list in advance. > To be reliable for static analysis, that preload list would need to be *comprehensive*, defining every symbol up front, then making a second pass of cross-file analysis. The preload list does not have to be generated manually, PHP itself could autonomously autoload all required classes at compile time (this differs from the current behavior, where autoloading is only triggered during execution of code mentioning not-yet-loaded classes). >That makes it look very much like a separate build step, rather than something integrated into the normal execution pipeline. Well yeah, but it doesn't have to be separate from the execution step, I.e. I don't see why running a script using php a.php should not be able to autoload all reachable classes during compile time instead of at runtime, I.e. because they're mentioned in typehints, not because the function using the typehint is being executed. >I've said before that this might be the way PHP should go - a native "module" concept, with full pre-compilation - but it would be quite a radical change. This is a different, unrelated matter, and it would actually be super cool to generate a single executable using function JIT, bundling both the compiled php code and php itself; I've actually already done this as an experiment with another JIT language based on dynasm, it's quite simple really. > Perhaps an alternative is to change the rules of when autoloading can be invoked, by allowing the preload script to recursively autoload every symbol it can identify, rather than waiting for the relevant code to be executed. I think this is how current offline static analysers work. Precisely. > That doesn't solve the "optional checks" problem, though, if preloading remains optional. We could produce an error if any generic/extended type was encountered without being preloaded, but that poses a dilemma for libraries: either don't use the new types, or impose a requirement for applications to use preloading. I'm not convinced there's an easy compromise here. No need to preload, just autoload at compile time like you said, and polyfill missing classes that cannot be autoloaded. Regards, Daniil Gentili. ------=_Part_4_193146460.1699027552818--