From iuke-tier@ey m@iii@g oii uiow@@edu  Sat May 11 03:34:19 2024
From: iuke-tier@ey m@iii@g oii uiow@@edu (iuke-tier@ey m@iii@g oii uiow@@edu)
Date: Fri, 10 May 2024 20:34:19 -0500 (CDT)
Subject: [Rd] 
 [External]  R hang/bug with circular references and promises
In-Reply-To: <CAPLMX9EyfB7cLgu89WPT_RFeuC1BDPYcZ81jR2q1aaDPVtnkEw@mail.gmail.com>
References: <CAPLMX9EyfB7cLgu89WPT_RFeuC1BDPYcZ81jR2q1aaDPVtnkEw@mail.gmail.com>
Message-ID: <d0dc027e-b579-ba5b-ec62-d1bd52fbf47f@uiowa.edu>

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.
>
> It looks like it is looking for "not_a_variable" recursively but since
> it doesn't exist it goes on indefinitely.
>
> x0 <- new.env()
> x1 <- new.env(parent = x0)
> parent.env(x0) <- x1
> delayedAssign("v", not_a_variable, eval.env=x1)
> delayedAssign("w", v, assign.env=x1, eval.env=x0)
> x1$w

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.

Best,

luke

>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa                  Phone:             319-335-3386
Department of Statistics and        Fax:               319-335-3017
    Actuarial Science
241 Schaeffer Hall                  email:   luke-tierney at uiowa.edu
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu/



[Rd] [External] R hang/bug with circular references and promises
iuke-tier@ey m@iii@g oii uiow@@edu