Re: SRFI 254, as written, is incompatible with generational gc Marc Nieper-Wißkirchen 04 Dec 2026 14:27 UTC

The SRFI 254 term "moved" is a semantic notion.  It does not mean that
the GC has to relocate an object physically.  When an object of your
vector moves, the vector itself counts as moved even if its address
stays the same.

The reference implementation (built on Chez) can already handle
arbitrarily long chains of such references, and Chez has a
generational garbage collector.

P.S.: In order for the sample implementation to be implementable on
top of what Chez exports, the transport guardian notifications are
more conservative than they need to be in a native implementation.
I'll describe a more selective native implementation in a later post.

P.P.S.: By returning to SRFI 254, I found an unrelated bug in the
sample implementation. The bug was introduced by a later change of the
spec without updating the sample implementation accordingly.

Arthur, can you apply the following patch to the sample implementation?

diff --git a/lib/srfi/:254.sls b/lib/srfi/:254.sls
index b2fd7e6..0a468d4 100755
--- a/lib/srfi/:254.sls
+++ b/lib/srfi/:254.sls
@@ -147,7 +147,6 @@
     [(bwp-object? (car m))
      (f (g))]
     [else
-     (g m)
      (car m)])))])
          5 $transport-cell-guardian))))

diff --git a/tests.sps b/tests.sps
index c99e614..5d3ec0f 100644
--- a/tests.sps
+++ b/tests.sps
@@ -28,6 +28,7 @@

 (import
   (rnrs)
+  (only (chezscheme) collect collect-maximum-generation)
   (srfi :254))

 (define k1 (vector #f))
@@ -37,3 +38,14 @@
 (assert (eqv? (ephemeron-ref e1 k1) 'foo))
 (assert (eqv? (ephemeron-ref e1 (vector #f) 'bar) 'bar))
 (assert (not (ephemeron-ref e1 (vector #f))))
+
+;; Retrieving a transport cell removes it from its guardian.
+(let* ([guardian (make-transport-cell-guardian)]
+       [key (vector #f)]
+       [cell (guardian key 'foo)])
+  (collect (collect-maximum-generation))
+  (assert (eq? (guardian) cell))
+  (collect (collect-maximum-generation))
+  (assert (not (guardian)))
+  (reference-barrier cell)
+  (reference-barrier key))

Am Do., 3. Dez. 2026 um 23:24 Uhr schrieb Will Clinger <xxxxxx@larcenists.org>:
>
> Please disregard the program shown in my previous message,
> because it only pretended to demonstrate the problem.  Here
> is a program that actually demonstrates the problem.
>
> Will
>
>
> #!larceny
>
> ;;; SRFI 254 says the following:
> ;;;
> ;;;     This SRFI further stipulates that locations and sequences of
> ;;;     locations can be kept alive in the course of a computation.
> ;;;
> ;;;     Finally, it stipulates that objects may be moved in the
> ;;;     course of a computation with the following restrictions:
> ;;;
> ;;;         1. If an object obj1 is moved, every object obj2 such
> ;;;            that eq? returns #t when applied to obj1 and obj2 is
> ;;;            moved as well.
> ;;;
> ;;;         2. If an object obj1 denotes a location holding an
> ;;;            object obj2 that is moved, the object obj1 is moved
> ;;;            as well.
> ;;;
> ;;; To my knowledge, none of the generational garbage collectors
> ;;; that are currently being used by implementations of Scheme
> ;;; are able to guarantee that second stipulation will hold.
> ;;;
> ;;; The follow R7RS top-level program illustrates that failure
> ;;; in Larceny.  It should not be terribly hard to port this
> ;;; demonstration to show the same kind of failure in other
> ;;; implementations of Scheme.
>
> (import (scheme base)
>         (scheme write)
>         (scheme process-context)
>         (srfi 176)            ; for version-alist
>         (primitives collect
>                     .internal:machine-address))
>
> ;;; Which of Larceny's three garbage collectors are we using?
>
> (define gc-technology
>   (cadr (assq 'larceny.gc (version-alist))))
>
> (display "\nThe current garbage collection technology is: ")
> (write gc-technology)
> (newline)
> (newline)
>
> (if (not (eq? gc-technology 'generational))
>     ;; The (collect 0 'promote) command is a very low-level command
>     ;; that works only with Larceny's conventional younger-first
>     ;; generational collector.
>     (begin (display gc-technology-message)
>            (exit)))
>
> (define gc-technology-message
>   "This Larceny-specific program works only with Larceny's
> conventional younger-first garbage collector.
> Please try again, using that generational collector.\n")
>
> (define stipulation-2-failure-message
>   "\nVector v did not move when its element 0 moved, which reveals
>    a failure of SRFI 254's second numbered stipulation.\n")
>
> (let* ((v (make-vector 1 0))
>        (original-address-of-v (.internal:machine-address v)))
>
>   ;; force the generational garbage collector to move v
>   ;; into an older generation
>
>   (collect 0 'promote)
>
>   (let* ((second-address-of-v (.internal:machine-address v))
>          (x (list 'some-object))
>          (original-address-of-x (.internal:machine-address x)))
>
>     ;; store x in element 0 of v
>
>     (vector-set! v 0 x)
>
>     (let ((second-address-of-x (.internal:machine-address x)))
>
>       ;; force the generational garbage collector to move x
>
>       (collect 0 'promote)
>
>       (let* ((last-address-of-v (.internal:machine-address v))
>              (last-address-of-x (.internal:machine-address x)))
>
>         (display "Original address of v: ")
>         (write original-address-of-v)
>         (newline)
>         (display "Second address of v:   ")
>         (write second-address-of-v)
>         (newline)
>         (display "Original address of x: ")
>         (write original-address-of-x)
>         (newline)
>         (display "Second address of x:   ")
>         (write second-address-of-x)
>         (newline)
>         (display "Last address of x:     ")
>         (write last-address-of-x)
>         (newline)
>         (display "Last address of v:     ")
>         (write last-address-of-v)
>         (newline)
>
>         (if (and (not (= original-address-of-x
>                          last-address-of-x))
>                  (= second-address-of-v
>                     last-address-of-v))
>             (display stipulation-2-failure-message))))))
>