Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110984 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 22741 invoked from network); 13 Jul 2020 22:40:12 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 Jul 2020 22:40:12 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 592FA180539 for ; Mon, 13 Jul 2020 14:32:29 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-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,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=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (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 ; Mon, 13 Jul 2020 14:32:28 -0700 (PDT) Received: by mail-ej1-f52.google.com with SMTP id dr13so19117490ejc.3 for ; Mon, 13 Jul 2020 14:32:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=eOxh19N1FJ4Qoe+3DiHzCvIqvryVLSav6Z7hSKFzzDU=; b=luR3pYEa9UGb2dhCCEWzb45+vrg0Gh9LZCIsaJnXOrF7XTi9cBqlkYOHak97U5tMMd Ye2Si3PEfuGJntcbGGgZeva+8iVT8XWuQsB1urQVTyqqobc6OP4aGOVXc80daFs1DW80 a4eKwgkSvsAoUF6Yg8Y2POIG6GmTHe9QypxMAA07EdHpSxx56S4b83NfY+5KHccpDvI0 17lzizHYczY+7Cvlb7cvOIHgieh86yJjHdPk+PK2UYpSoPY5/J8+2DxJu6QZ/q0GDjH9 PLsN0VxGymOeXvRJiJ5uWHrE8758QRUW5V4oATiR/dHRRjdHJllLJxfevu4lFg+f7Zz7 MhFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=eOxh19N1FJ4Qoe+3DiHzCvIqvryVLSav6Z7hSKFzzDU=; b=ZjxOuoqEG2ksqrOCrtKmFoZMhZasE3GvAoqk0gznUIgEXXZN/Wh7HpD0AVaBhKJGVk mqQ447SRUd+a36c4d7WFdq81WHqXmSCZCDqB4a1j53zK6Zy+90ibFtwIqtgplgWFyR59 wYwaOLjsjiCHPMUMbIqtYDknsK9neVasxJ8WKZpIGtUdNxhEe5AhADL1laM9dhcfusHw lVOWocoNAlQPtS3JBK28gRINyepolu24P30wmw9Ti3WcLp/VnIbvURwWBQb9qNy+qRjb booWv3xHuv5CATsRjS+Lh0fq0JGm+9txPB7dS5PNZgVlayOaQFZrEeJxV7DrtY/bCLQ+ gZgw== X-Gm-Message-State: AOAM533u6Gnqxkx8Uta+/DdPjpE5sTvH7uPrLHximWQ9L8757LNgZO1c vgfM+0LUNuSegUQt+SwZezfRwCz9u67jYcdZMOc= X-Google-Smtp-Source: ABdhPJxaEwf++BS4MptvYf0CF9k7LXniQLQzdC/tq+3k8Jk1BE/XTdx+JRzumKOA85H1gnwp2pvCiEgZC1p9VCFzPFI= X-Received: by 2002:a17:906:e2ca:: with SMTP id gr10mr1580408ejb.81.1594675944720; Mon, 13 Jul 2020 14:32:24 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a54:3091:0:0:0:0:0 with HTTP; Mon, 13 Jul 2020 14:32:24 -0700 (PDT) In-Reply-To: References: <1e39fdcb-16d2-42c3-95cf-507f7b647b50@www.fastmail.com> <3bfb89c5-c8fd-4587-8c1f-8b7bbbaca692@www.fastmail.com> Date: Mon, 13 Jul 2020 21:32:24 +0000 Message-ID: To: Rowan Tommins Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Possible RFC: UniqueInterface that throws exception at refcount > 1 From: olleharstedt@gmail.com (=?UTF-8?Q?Olle_H=C3=A4rstedt?=) 2020-07-11 23:24 GMT, Rowan Tommins : > On 11 July 2020 22:47:21 BST, "Olle H=C3=A4rstedt" > wrote: >>You're misunderstanding. :) Yes, it should be shared, but not with the >>same access level as the owner. If a dependent class closes the >>connection it will cause spooky-action-at-a-distance somewhere else in >>the program. > > > I think that particular example is solved adequately by destructors: if y= ou > know you hold the last reference to an object, you can unset() that > reference and the destructor will fire. > > You'd only need the ability to "unfreeze" an object if you were going to > mutate it and then carry on using it. > > >> Sorry, it's related to refcount as ownership checking > > > I still don't think those concepts map well. If you store two references = to > an object in an array, and then unset one of them at random, does it make > sense to say the remaining reference "owns" that value, because the objec= t > now has a refcount of one? Well, yes, to do it properly you'd have to make sure the owner remains in scope longer than the borrower. Otherwise you're "leaking" ownership. :) > As I understand it, ownership in Rust implies not just the *right* to fre= e > something, but the *obligation* to do so. That only works if ownership is > explicitly assigned, rather than being a side effect of other references > being released. That's due to move semantics. You can have benefit of ownership and uniqueness without having move. > Thinking about destructors, a better description of how PHP currently wor= ks > might be that the owner of an object is the object itself, and the refcou= nt > is a count of how many times it has been borrowed. So once the constructo= r > completes, all we can say is that there is at least one "borrowed" refere= nce > somewhere in the code; once that stops being true, the "owner" is notifie= d, > and runs the code in the destructor. > > > You could create a wrapper object and have a way to check that its > destructor had been called - anything from setting a global variable to > holding a WeakRef and calling its valid() method - but if something *does= * > hold onto a reference, there's not much you can do about it. > > I can't think of a scenario where the code that wants to "own" the object > wouldn't end up equivalent to either full immutability (don't mutate it > after initialisation because you can't guarantee yours is the only > reference) or an optimised copy-on-write (mutate if you happen to have th= e > last reference, otherwise clone). It would be better for the language to > implement those in a user-friendly way than exposing the implementation > details of refcounting. Yeah, I guess. :( In the end I need uniqueness (non-aliasing) to finish my series of patches about typestate and type-safe builders to Psalm, but I guess I can live without any runtime representation of this, or just suffer the hack I already did with zval dump. Thanks for the feedback! > Regards, > > > -- > Rowan Tommins > [IMSoP] > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > >