Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108200 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 45796 invoked from network); 20 Jan 2020 02:45:05 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 20 Jan 2020 02:45:05 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0A6361804F4 for ; Sun, 19 Jan 2020 16:53:18 -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=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE 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-f181.google.com (mail-yb1-f181.google.com [209.85.219.181]) (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 ; Sun, 19 Jan 2020 16:53:16 -0800 (PST) Received: by mail-yb1-f181.google.com with SMTP id f136so8969599ybg.11 for ; Sun, 19 Jan 2020 16:53:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=ISBjq3YqFU5O0agBUUEVU+HSdartCoK3P59DMZm9SY8=; b=wkfAbSVlzbpenb9o21HmpjQXYTRPB8E3nYP9J284uQ+lXg+lDhY0iGAjHvZsu6yEuz yA/aohK8P5X8jhkmA/kvj16WluyNGLel+LYkrHvgg6YTyeV9QBygElh4QYbtPAuQtMqF K21SzDE7qTLXkrC0pEBYbqBmubbP6r8DIBJK7hxGq9kJKB98GJDCrx2VGC299bRf1Nwh IoaAjeMgutopzrKRGk0WnvG9Z2R21C2hMC/x2diORuPg261A2CPQahI/Ll6qfZE6WX93 HiGiI+QA/3I4JINVQ5lkrEwrPFXIt2KqifllDl4EUs8sF+Jx6XlklyneP40rreSo8/Up vE2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=ISBjq3YqFU5O0agBUUEVU+HSdartCoK3P59DMZm9SY8=; b=kI9Xs+9KU6UjEb6cSABspaUNVXnPPodB2lIx03RHVCCc+eHrgRn1pxvZBGAfxzbDmt I1kryN4r2eO0008W63wwpc88ePpt3TtrLioMxWivNF9O4/1fNj2lwh4uPUAa8CcyhfFE tBmdpfdRGuJcaZLTdQxPr3l2PAMTF197qyy0xyEUFcRMqyaaY+Rgqv2NH/NGKAkk+mXZ EQohNVjXYuP7NXTot9NHvZMFDQ494KO7bLugUPw16auXTlMT9jpPASxDsvupV7ns7zuN FxPXf2AKmyaBypnRoqxcWgKfWQu0i1nFvkdTK7YiIeGv3UTsHN8wI6dUwk7Zk7goDf83 C6rw== X-Gm-Message-State: APjAAAXEfvBFe7wKJ14cxsbRXkPnF/pPjCzBHO97sJfYBBIcfvSYvyS+ EtitV0cHM0lfjJgLiwdfDzShIw== X-Google-Smtp-Source: APXvYqyyEYVAzBIeeFVgmjN5LmlN/8JXswEelwHyplDqUHTMvj34kKPXelXRrvzA5qCJA4Y/DjnUag== X-Received: by 2002:a25:3241:: with SMTP id y62mr7290598yby.12.1579481593478; Sun, 19 Jan 2020 16:53:13 -0800 (PST) Received: from ?IPv6:2601:c0:c680:5cc0:1958:acb8:bd02:51b0? ([2601:c0:c680:5cc0:1958:acb8:bd02:51b0]) by smtp.gmail.com with ESMTPSA id k13sm15385005ywh.103.2020.01.19.16.53.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 19 Jan 2020 16:53:11 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) In-Reply-To: Date: Sun, 19 Jan 2020 19:53:10 -0500 Cc: PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: <5DC86728-1BBF-4DCA-8A6B-9B0B190DB99D@newclarity.net> References: To: Nikita Popov X-Mailer: Apple Mail (2.3445.104.11) Subject: Re: [PHP-DEV] Typed array properties V2 From: mike@newclarity.net (Mike Schinkel) Hi Nikita, > On Jan 18, 2020, at 5:05 AM, Nikita Popov = wrote: > Did you read through the previous discussions on this topic? > https://externals.io/message/100946 in particular comes to mind. Thanks for this link. It was very insightful. > The primary concern about the previous typed array proposal was the = O(n) > cost of type checks, which required iterating over the whole array and > checking the type of individual elements. Any new proposal in this = area > *must* address this concern. Agreed. > As far as I know, the only viable way to do that is to make the array > intrinsically typed, which means that types are validated when = elements are > inserted into the array, not when it is passed across a function = boundary. > In other words, array generics. Reading the prior discussion, there appeared to be several other = potential approaches, but none were followed to a conclusion. Of course = it devolved into bikeshedding, but I digress... One approach mentioned by Andrea Faulds was to extend the hashtable = (ref: your article[1]) and count types as assigned just like we = currently count references. So a 10,240 element array of ints could = have an internal tracker showing that the array contains type(s): ['int' = =3D> 10240]. Append a string value to the array and then the types = would be ['int' =3D> 10240, 'string' =3D> 1]. Mark Randall mentioned that this would not work if the array contained = references, but no one discussed the potential of simply disallowing = arrays with references at compile time when the arrays are typehinted, = which seems like it could solve the proverbial 80/20 scenario. Need = references in arrays? Don't typehint them. Also, Rowan Collins mentioned that checks in Go can be disabled for = runtime checking; maybe we could support an option that disables said = checking so that production sites could run w/o checks but we could run = checks in development, testing and staging. We could also have an option = to disable checking of array types above a given size of array, maybe = defaulting to 1024? Clearly both of these would be no worse than what we = have today.=20 I think this could add a major improvement to PHP all without having to = finalize the design and implementation of generics, no? Are none of these viable options? I am asking that as a legitimate = question =E2=80=94 as I am not (yet) a PHP internals developer =E2=80=94 = and not just assuming they are viable options. -Mike [1] = https://nikic.github.io/2012/03/28/Understanding-PHPs-internal-array-imple= mentation.html=20 P.S. There was also the mention by Levi Morrison that the type[] syntax = was a poor one because of ambiguity between (?int)[] or ?(int[]). I = would argue that the latter would likely occur orders of magnitude more = often than the former, so I would argue that ?int[] should interpret as = ?(int[]), and if they want (?int)[] then the developer should use = parentheses.