Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116947 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 52614 invoked from network); 28 Jan 2022 21:58:33 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 28 Jan 2022 21:58:33 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E14001804BA for ; Fri, 28 Jan 2022 15:11:52 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.2 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS 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-yb1-f178.google.com (mail-yb1-f178.google.com [209.85.219.178]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 28 Jan 2022 15:11:52 -0800 (PST) Received: by mail-yb1-f178.google.com with SMTP id j2so9711974ybu.0 for ; Fri, 28 Jan 2022 15:11:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:from:date:message-id:subject:to; bh=rdh7P1bFdG0leP9zV5PEXgmuHgYzzCRos5IEHiYH+d8=; b=GFyJQaQtA+vUT0Xg5+YrLkIK17RYCoxHvfzOQ74mISaP3KU4kzUrNS96CJ9MH67tDg HhPGDh/nKkw6PzVdvS1OLIVlq7fIzVZX29V67Kdi0x193LCz1gDizklNjva8kWXreSS8 18+9OBTzcGaVYT7XuYNMYSd1eG7W40xQMLFt61Ndz3mODf2e1T1ySCXnkJwfnhVX4ROQ cF0Hl4KRueEtwXTgOtCASMp0OIbXtcd0WOJ/6XKpeRSLutkgZnK7JVEizhJUlBKSzBSC 7bYtxwCT0pIO2hvtwD7IJa23AytQ/yC4Q5lxXI8dVURLXnkuKMcTi1X6YbJUxsp87cjY 9Etg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=rdh7P1bFdG0leP9zV5PEXgmuHgYzzCRos5IEHiYH+d8=; b=DHgg5I0glbVEzxpiITGpDKoAu4uiegAW3SVFBhmeYoHCMs61/nlGEuOZNIc9UEInSj VgQ0w/bt5HN08Lxke+D+suCQgYaPrRy1p1FCrHBnAmpPlROzdo5W1a/4EQ8HkLEb53uC BlSJrwC0sxh+WCrtrc/QSwH3GAyTwB0CyP2AsO3jynzWt67L0fLSde56cdFm0pELOHjW hAyK9MuSITt7yb9aE0iFa+XGHRxkFk391OPDampj/gAxQaaWWQeObJ4F0PACF61Q9aHp VqDfB4g/CBFuw8TecV1ZQ7rzjipZoGXoqEvxAhPaDFP/XsZi0i1hg17U9mNSUy9yC8ue by5g== X-Gm-Message-State: AOAM530O5IVzIB4Z2dcUsyDr83+LrRBwfHiZwIu4NvIoPcKSjOSGyYKR UrvcqaM0esgLzP9kMIX5fDo38rO76eqMBT/yfu4iHPN64pU= X-Google-Smtp-Source: ABdhPJxnOnwFCA7yDWFvsP7J+j/9ssXH9UPhRFez9RRVJD8beAb0gMDsERyXks4LHTmzBKaxNL2VitXBRlwZYuQoft8= X-Received: by 2002:a25:3c8:: with SMTP id 191mr16828544ybd.204.1643411511570; Fri, 28 Jan 2022 15:11:51 -0800 (PST) MIME-Version: 1.0 Date: Fri, 28 Jan 2022 15:11:40 -0800 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="0000000000005df6b705d6ac8f86" Subject: Handler(s) and priority for == and != opcodes From: jordan.ledoux@gmail.com (Jordan LeDoux) --0000000000005df6b705d6ac8f86 Content-Type: text/plain; charset="UTF-8" Hello internals, Following the rejection of the operator overloads RFC I have looked at bringing some mathematical improvements to PHP in extensions instead. As part of this, there is one truly blocking issue: The opcodes for == and != are handled by the compare handler. On zend_class_entry, extensions can define a handler for do_operation which allows them to overload operators. As I described in the op overloads RFC, this is something that extensions and C code can fully accomplish, it's just restricted for userland code. However, currently the following operators are handled by the compare handler instead: >, >=, ==, !=, <=, <, <=>, <> The reason this is a problem is that in mathematics (and presumably other domains), it is possible for something to be *equatable* but not *sortable*. For example, consider the following: `2 + 1i == 2 + 1i` This should return true. However: `2 + 1i >= 2 + 1i` This should either return false or throw an exception or error. Complex numbers are *not* comparable, but they *can* be equal or not equal. To accomplish this, the zend_class_entry handlers *must* provide a way for the ==, !=, and <> opcodes to be handled separately if desired. I discussed this issue briefly with nikic, joe, and cmb. Both nikic and cmb expressed understanding of the issue and a tentative understanding of the value of this change, while joe didn't provide any negative feedback. I'd like to alter the VM and possibly zend_class_entry in order to accomplish this. This can be done in a BC compliant way, meaning that it's an internal engine change that doesn't require an RFC. However chris brought up the point that this could be accomplished by *either* sending the relevant opcodes to the do_operation handler or to a brand new handler. The PR for the first option (sending it to do_operation) can be viewed here: https://github.com/php/php-src/pull/7973 I'd like to gather feedback on whether it's more appropriate to send this to the do_operation handler or to create a new handler. Jordan --0000000000005df6b705d6ac8f86--