From peter@|@ng|e|der @end|ng |rom gm@||@com  Sat May 11 17:03:07 2024
From: peter@|@ng|e|der @end|ng |rom gm@||@com (Peter Langfelder)
Date: Sat, 11 May 2024 23:03:07 +0800
Subject: [Rd] 
 [External] R hang/bug with circular references and promises
In-Reply-To: <d0dc027e-b579-ba5b-ec62-d1bd52fbf47f@uiowa.edu>
References: <CAPLMX9EyfB7cLgu89WPT_RFeuC1BDPYcZ81jR2q1aaDPVtnkEw@mail.gmail.com>
 <d0dc027e-b579-ba5b-ec62-d1bd52fbf47f@uiowa.edu>
Message-ID: <CA+hbrhVPoFR8tLuhS60oXW_OhWW76YxhnD0VLSZaAi4yVDgWhA@mail.gmail.com>

On Sat, May 11, 2024 at 9:34?AM luke-tierney--- via R-devel
<r-devel at r-project.org> wrote:
>
> On Sat, 11 May 2024, Travers Ching wrote:
>
> > The following code snippet causes R to hang. This example might be a
> > bit contrived as I was experimenting and trying to understand
> > promises, but uses only base R.
>
> This has nothing to do with promises. You created a cycle in the
> environment chain. A simpler variant:
>
> e <- new.env()
> parent.env(e) <- e
> get("x", e)
>
> This will hang and is not interruptable -- loops searching up
> environment chains are too speed-critical to check for interrupts.  It
> is, however, pretty easy to check whether the parent change would
> create a cycle and throw an error if it would. Need to think a bit
> about exactly where the check should go.

FWIW, the help for parent.env already explicitly warns against using
parent.env <-:

The replacement function ?parent.env<-? is extremely dangerous as
     it can be used to destructively change environments in ways that
     violate assumptions made by the internal C code.  It may be
     removed in the near future.

Peter



[Rd] [External] R hang/bug with circular references and promises
Peter Langfelder