Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125069 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 486FA1A00BD for ; Tue, 20 Aug 2024 13:01:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1724159011; bh=cVseVGUvyYvh02gqx/85JBOyL3S9G4nZHIYj6qOX2UQ=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=DxblER5FiUvwRTcw1SbXcGVy9zTctZImggn3dtq4ja1PX9BL4nFcDqMTx6SFG12Sf yxt6aj2ydlQAPUaXeZlttM86ZJbk7nQec4WvKHTjv/rDKYvIg7gF5Wgw8C1zV2tjzH C2BUtlgF+9yw1EiLq5nfnDKaA6+tj+J2pkIjQyY2acjK1S5InSbQwwXayAAKCZvoXg HMRQ9BzSplIYBfFc9ixWhBoCob2GdcvM6pFyUD1GHXgNASDjujKsoyjO0y23io1nRF IN9BuRpOYbOVH+Akq79Y7py1YVL65a51WM4lwnQIKX6epu+5B2msumHRyLEeFrP9os BjcFMoLh7LAiQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D72B118006D for ; Tue, 20 Aug 2024 13:03:30 +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=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (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, 20 Aug 2024 13:03:30 +0000 (UTC) Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a7aa4ca9d72so713922266b.0 for ; Tue, 20 Aug 2024 06:01:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724158900; x=1724763700; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=iO+APi834d/TUFmqsEVtRX1J4GwRNHsdS5jJQ9lDiG4=; b=VQEJpzNOoQKAB1rKnQ8qAQMCyYn44BueIsXH9Tu8MNkb3ajdAhB46ITJAvIpZsehg1 eQeQK5iX7sW5Elsa4ItbSA2zVqu1/hjWqg9FXRGSpnXOfSIVusdmih28l6n8aWIdmRYN bSToMOzeyMuSJsJvRrc0BBvv50n5Dg/jv9tWSS2oH0brRdPqUwQNqp1lF4Ncyk84BHPJ 1M91MQES6pkhfdO5usvo4W8neq9zK9G10zBMkBkVWfnvb3CJdLznVppBfrphIahBSuYh GGYBLyIZFxDNUtcboar0BvILu7tUdn8etiSzBNoOXlFIrBr3Uj4xiHRT+T9tghbwuMKW f+gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724158900; x=1724763700; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iO+APi834d/TUFmqsEVtRX1J4GwRNHsdS5jJQ9lDiG4=; b=inN9kEnwqgSp0jkVHWSsEAuU0uG/geiMxoRKCaEieAID9IcMj5BNj5oM5KLoFTHisq 5sURUS2e3gb+q1u9c8t3en9dfAm8bwZa1bf4/wGOZ7eP2NkQPgLEAJiKBJ/oObYG1pXm AqLRb1vPOJst2NOMJ3bQUqKZqhuX6h20/fD8sNU/RfpZbTISNrQjsfnThzckoD7wnUme FYCPRQDGvHQNSjCSqGaErS2e+N2xKe+S11T0tZYPsqo3qpvHCtwYFL6Cnlc5c13LSkI9 IjYFLBXff/vNlxjLEAFqKknFcCTFLIcf7TjtKSISa33zjna/H8oRhE4caTDicLmlCJjQ 8bTg== X-Forwarded-Encrypted: i=1; AJvYcCUnaCG6IFu3GqS8MV+lTTJ5cdpg4up50IpOohIoRwLYQPkxDGlktwfbvfM+a9C8od1K0jmjDD9P5QA=@lists.php.net X-Gm-Message-State: AOJu0YzK8ux99wQRFyOGk6MTeB62NiC+RlSYI6VCB+fzy+jsup52BR8G KmwAHWuR36x7nLIl42aG+S2X3mmGndkH0t+DZH83zVH3iA1dXXvcaRb3OnZvEbTG14F6A8yrcPh lQQ9oyV7f9/ncZh1XprB8EtYyryI= X-Google-Smtp-Source: AGHT+IE8i1rzrIIF5t79rQ14UPzu/N3xYWnU/ugdvNKb8xTXAKfQ/mWO+VKpsbD4LL5Y/LfJPLekfxoXlnKCyh5cBqM= X-Received: by 2002:a17:907:944a:b0:a77:abe5:5f47 with SMTP id a640c23a62f3a-a8392a4971amr886206666b.63.1724158899465; Tue, 20 Aug 2024 06:01:39 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <1b59392a-68cb-36eb-0fef-977ac7113520@php.net> In-Reply-To: Date: Tue, 20 Aug 2024 15:01:28 +0200 Message-ID: Subject: Re: [PHP-DEV] State of Generics and Collections To: Bob Weinand Cc: Derick Rethans , PHP Developers Mailing List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: arnaud.lb@gmail.com (Arnaud Le Blanc) Hi Bob, On Tue, Aug 20, 2024 at 12:18=E2=80=AFAM Bob Weinand = wrote: > The fluid Arrays section says "A PoC has been implemented, but the perfor= mance impact is still uncertain". Where may I find that PoC for my curiosit= y? I'm imagining the implementation of the array types as a counted collect= ion of types of the entries. But without the PoC I may only guess. I may publish the PoC at some point, but in the meantime here is a short description of how it's implemented: - The zend_array has a zend_type member representing the type of its elemen= ts - Everytime we add or update a member, we union its type with the array type. For simple types it's just a |=3D operation. For arrays with a single class it's also simple. For complex types it's more expensive currently, but it may be possible to cache transitions to make this cheaper. - Updating the array type on deletes requires to either maintain a counter of every type, or to re-compute the type entirely everytime. Both are probably too expensive. Instead, we don't update the type on deletes, but we re-compute the type entirely when a type check fails. This is based on two hypotheses: 1. A delete rarely changes an array's type in practice, and 2. Type checks rarely fail - References are treated as mixed, so adding a reference to an array or taking a reference to an element changes its type to mixed. Passing an array to a more specific array will cause a re-compute, which also de-refs every reference. - Updating a nested element requires updating the type of every parent > It also says "Another issue is that [...] typed properties may not be pos= sible.". Why would that be the case? Essentially a typed property would jus= t be a static array, which you describe in the section right below. It becomes complicated when arrays contain references or nested arrays. Type constraints must be propagated to nested arrays, but also removed when an array is not reachable via a typed property anymore. E.g. class C { public array> $prop; } $a =3D &$c->prop[0]; $a[] =3D 'string'; // must be an error unset($c->prop[0]); $a[] =3D 'string'; // must be accepted $b =3D &$c->prop[1]; $b[] =3D 'string'; // must be an error $c->prop =3D []; $a[] =3D 'string'; // must be accepted I don't remember all the possible cases, but I didn't find a way to support this that didn't involve recursively scanning an array at some point. IIRC, without references it's less of an issue, so a possible way forward would be to forbid references to members of typed properties. Unfortunately this breaks pass-by-reference, e.g. `sort($c->prop)`. out/inout parameters may be part of a solution, but with more array separations than pass-by-ref. Best Regards, Arnaud