Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107693 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 68566 invoked from network); 25 Oct 2019 12:35:53 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 25 Oct 2019 12:35:53 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 457672C88D3 for ; Fri, 25 Oct 2019 03:22:31 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp3.php.net X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: X-Spam-Virus: No Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp3.php.net (Postfix) with ESMTPS for ; Fri, 25 Oct 2019 03:22:30 -0700 (PDT) Received: by mail-lj1-x232.google.com with SMTP id y3so2089426ljj.6 for ; Fri, 25 Oct 2019 03:22:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=dHJZpWja8SYlBgkY/S/SPdY4X1gl5XT0RJJAc9sA6J4=; b=Mt8oWj6WTbg41xnEP4ASVcDQuf7Ug1tW+bsi2f3Ksf3LNwfpRJ0hh30heev98QNddd cpuuTtMMhs8erkY8p6vSvVqCxIK2VTC2j/pVoJyBIYqNWiuZ0EnIX1XB8MCz8Zrbe0jM 5yW6VvTF7mfeJasyV0mg+zDn/NlFQaNmMO8x2+hpMLdGRtQHcMuOdnARhXz6n8kUDcyH sSvm2vuC0XS83t7Z+RSaQo4o93LC/H78zKhch4vPTbHGEhJpm0BmSfg3TRsU20l3Cvid sP/G40hg6zTwXU9qFJAQpe6EQZynMwtwd/O4o7EBPI26tVplJVdTKhJJUJhdxN15oyao lqMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=dHJZpWja8SYlBgkY/S/SPdY4X1gl5XT0RJJAc9sA6J4=; b=lEfQu14Dm27NFYwfxPHfw48AXXltLZqwFyxVyQqx+6DmoLSkOURGmm6ZUW/3OpdtYE 4U9cRL11NjF1A/UKCTlI/O13Ppw/Xah5R6MwnE1z5pxhOkc7p/IjXzH02QauraVkLJIl qYaivIzlxpQVi0VtTGnGSgwTmO9jJFAR/fS+MqU2aGC1u2929yQ+2YbvJF0mdCDgN12F AVg5SinDgIpTQUUB20R/BZDl3B6aASYWE7Lr15g83XztrkJjN6wBFrF3vLWNl9FWi/Cc povLgHHFQXoKDXCgUQD98d2qHmgy4QCMMaIbCOSY5TVtpVPbWAOLdLtzLIjpEuDjSLtC Va8Q== X-Gm-Message-State: APjAAAXO58IDC8kKbnHZsQnriUNhiK/x81U9eW2dxfUr7z6RXA2oxdj0 HcGULGn/ZLobLOhr8i1PvseReSqifDqZmmsMXqk= X-Google-Smtp-Source: APXvYqw0vTRdGb3MhDPINnnmNBKBI3EvLAshtd2Cti26ufp+D00igBqFI4rR314UFymsmBqD3W5BwdpH4ZnwfIGHqVU= X-Received: by 2002:a05:651c:1124:: with SMTP id e4mr1271816ljo.52.1571998949138; Fri, 25 Oct 2019 03:22:29 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 25 Oct 2019 12:22:12 +0200 Message-ID: To: Dmitry Stogov Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000f363f10595b9862c" X-Envelope-From: Subject: Re: [PHP-DEV] Re: [RFC] Union Types v2 From: nikita.ppv@gmail.com (Nikita Popov) --000000000000f363f10595b9862c Content-Type: text/plain; charset="UTF-8" On Wed, Oct 23, 2019 at 5:42 PM Dmitry Stogov wrote: > Hi Nikita, > > I checked the Union Type implementation, and it more or less good. I mean, > it implements the RFC in almost the best way. > However, as I don't like the RFC itself. Especially, unions of multiple > classes and interference with type variance, I'll vote against this. > > Actually, I think PHP already took wrong direction implementing "typed > references" and "type variance". > Introducing more "typing", we suggest using it, but this "typing" comes > with a huge cost of run-time checks. > From 10% (scalar type hint of argument) to 3 times (typed reference > assignment) performance degradation. > Anyone may rerun my benchmarks > https://gist.github.com/dstogov/fb32023e8dd55e58312ae0e5029556a9 > > Thanks. Dmitry. > For reference, here are the results I get with/without JIT: https://gist.github.com/nikic/2a2d363fffaa3aeb251da976f0edbc33 I think that union types don't really change much in terms of the performance calculus of type checking, because type checking is equally fast (or slow) for a single scalar type, and 5 different scalar types: they are all handled in a single bit check. The only case that is indeed somewhat slow is if multiple class types are used in the union, because we actually have to check each one until we find a match. I do hope that having unions with a large number of classes will not be common. Generally, this area could use some more optimization from the implementation side. I spent a bit of time yesterday optimizing how we perform instanceof checks (the implementation was quite inefficient, especially for interfaces), which had a large positive impact on class type checks. There's more low hanging fruit like this, for example verify_return_type has no JIT implementation yet (which is why with JIT simple arg type checks have nearly zero overhead, while return type checks have a large overhead). Assignments to typed properties are also badly optimized, because everything is punted to the slow path, while we should be able to handle the simple cases with just one extra bit check, without going through the complex implementation that deals with things like weak typing coercions. I do think that performance considerations are important when it comes to new typing features (which is why, for example, we have categorically rejected a "typed arrays" implementation that has to check all array elements), but don't see union types are particular problematic in that regard, beyond what we already have. Nikita ------------------------------ > *From:* Dmitry Stogov > *Sent:* Tuesday, October 22, 2019 15:38 > *To:* Nikita Popov ; PHP internals < > internals@lists.php.net> > *Subject:* Re: [PHP-DEV] Re: [RFC] Union Types v2 > > Hi Nikita, > > Can you please give me one/two days, before starting the voting, for > implementation review (at least until October 25), > > Thanks. Dmitry. > > ------------------------------ > *From:* Nikita Popov > *Sent:* Tuesday, October 22, 2019 12:36 > *To:* PHP internals > *Subject:* [PHP-DEV] Re: [RFC] Union Types v2 > > On Wed, Sep 4, 2019 at 10:26 AM Nikita Popov wrote: > > > Hi internals, > > > > I'd like to start the discussion on union types again, with a new > proposal: > > > > Pull Request: https://github.com/php/php-rfcs/pull/1 > > Rendered Proposal: > > > https://github.com/nikic/php-rfcs/blob/union-types/rfcs/0000-union-types-v2.md > > > > As an experiment, I'm submitting this RFC as a GitHub pull request, to > > evaluate whether this might be a better medium for RFC proposals in the > > future. It would be great if we could keep the discussion to the GitHub > > pull request for the purpose of this experiment (keep in mind that you > can > > also create comments on specific lines in the proposal, not just the > > overall discussion thread!) Of course, you can also reply to this mail > > instead. The final vote will be held in the wiki as usual. > > > > Relatively to the previous proposal by Bob&Levi ( > > https://wiki.php.net/rfc/union_types), I think the main differences in > > this proposal are: > > * Updated to specify interaction with new language features, like full > > variance and property types. > > * Updated for the use of the ?Type syntax rather than the Type|null > > syntax. > > * Only supports "false" as a pseudo-type, not "true". > > * Slightly simplified semantics for the coercive typing mode. > > > > Regards, > > Nikita > > > > An implementation of this proposal is now available at > https://github.com/php/php-src/pull/4838. As the implementation didn't > turn > up any new issues, I think it's time to move this RFC forward to voting. > > Nikita > > > CAUTION: This email originated from outside of the organization. Do not > click on links or open attachments unless you recognize the sender and know > the content is safe. > --000000000000f363f10595b9862c--