Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126566 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 5B9231A00BC for ; Tue, 4 Mar 2025 22:22:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1741126809; bh=zl59qN8zVk+FIyaFL8NpKWMs06xOX69IO1Xpuxw8Ufs=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=ZBezDjpvCCwVIkTJTs/6DkpGeUbt3J98fCSMhD0GOryFIDGK39kj2QFujOOHdqwbC mUdxYkjGKtSQyjHw2iXJyrsOMTdoU4OqeaLfLycXkfIG6McLZNouXuzCnWiPt4j9ID cBSpZhlKW2QGpoNK21PtgiEAvxjXEruOvMj1WgvjaZZeCsQyrl/xGa7dFwUXWrXixH 43pvqE5u4iAZwDlPMOzt3Ua2Li2yxVgq0OAPdTOlQBxkF6rL744KwglmpivwUkpHK3 wWQS9X3UgMLU72m2TozjdSophiz/fwn5DwpHWsg+/xklkaVze/sw54oYy5qzCOCXQm +d3LuiXGZlmJA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 275C618005B for ; Tue, 4 Mar 2025 22:20:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-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,DMARC_PASS,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 4 Mar 2025 22:20:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1741126963; bh=lM0UsJUfn1YpLBjw1GoHUV/q5fCPp+5gSBASt2STb5k=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type:from:to:cc:subject:message-id; b=Vpx9ntk3G9etvC5ZiWxBTcZuBmRME1yMyC5SEd69eoyTIqyvmp3uZsq0zlrWnd0a5 y7lOgyINznQLjjd334ronJUUjv4pDu98JJiw+13jm8hICvfB0fMNZ+d4pry5qQPK9C GYGT7K+XXuixqVkp4Dvlql5AvcgMBwfIVCtbELre8jIDrIDzyK85a3+fzthfKl0kn+ /loOLVapYoPeHklu5h9VTGhrAzbp4iheJ6L9wtRp/XeExDxobmhmE0LLxzhnNhcYKR yttqpeQgNCb0gPgl000jlisjmoqVa0p1IcSRMUcUbzPg0D6nIobUEHNZ0wW10OOT29 4Cc4zZKBhN1SA== Message-ID: Date: Tue, 4 Mar 2025 23:22:42 +0100 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Subject: Re: [PHP-DEV] Re: RFC: Marking return values as important (#[\NoDiscard]) To: =?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?= Cc: "Marc B." , Volker Dusch , php internals References: <55b798d4-dcd7-4d81-852b-b78294cdc39d@email.android.com> <1a980468-c5f3-485b-9e8b-8c97d6ac4802@bastelstu.be> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=C3=BCsterhus?=) Hi On 3/4/25 23:08, Alexandru Pătrănescu wrote: > Just asking, as my engine knowledge is a bit limited, > Wouldn't it be possible that when OPcache would optimize away the unused > variable assigned to a function, it could detect that that function have > the NoDiscard attribute and also remove the attribute effect (warning > triggering). Not with how the implementation currently works: It's checking whether or not the FCALL opcode’s result is used or not. If the assignment is removed, the FCALL result will be unused. > Or identify that the function has the NoDiscard attribute and based on that > do not optimize away the variable? First things first: It's not a super important optimization to have, the assignment to a variable is one of the cheaper operations - and given that OPcache needs to know about the function it's also pretty limited in application. Of course you can also always just remove the assignment yourself (or ask your favorite IDE or static analyzer to point it out for you). That said: Checking for the attribute and performing the optimization is likely possible, though likely of limited cost/benefit. In any case that would be an implementation detail that does not change observable behavior. The RFC defines that `(void)` or alternatively `$_` will be the solution that guarantees that the warning will be suppressed (which will then also be part of the documentation), how exactly that will work internally is something that can and will change when refactoring and evolving the engine and OPcache. Best regards Tim Düsterhus