Constructors, excessive consing, R7RS Large Daphne Preston-Kendal (21 Nov 2024 20:34 UTC)
Re: Constructors, excessive consing, R7RS Large Arthur A. Gleckler (21 Nov 2024 20:42 UTC)
Re: Constructors, excessive consing, R7RS Large Marc Nieper-Wißkirchen (21 Nov 2024 21:29 UTC)
Re: Constructors, excessive consing, R7RS Large Marc Nieper-Wißkirchen (22 Nov 2024 08:08 UTC)
Re: Constructors, excessive consing, R7RS Large Daphne Preston-Kendal (14 Jan 2025 16:52 UTC)
Re: Constructors, excessive consing, R7RS Large Marc Nieper-Wißkirchen (14 Jan 2025 17:05 UTC)

Re: Constructors, excessive consing, R7RS Large Daphne Preston-Kendal 14 Jan 2025 16:52 UTC

On 22 Nov 2024, at 08:08, Marc Nieper-Wißkirchen <xxxxxx@gmail.com> wrote:

> Chez Scheme's optimiser is not able to remove the temporary heap
> allocation in the following example, although it is able to inline the
> procedures.

With the following example, cp0 does remove the intermediate allocation:

(library (a-b)
  (export my-make-b make-a a-x b-y)
  (import (rnrs))
  (define-record-type a (fields (immutable x)))
  (define-record-type b (fields (mutable y)) (parent a))
  (define (my-make-b an-a y)
    (make-b (a-x an-a) y)))

(my-make-b (make-a 4) 5)

If the b-y field is declared immutable, it will also instantiate the record instance during cp0.

If the a-x field is declared mutable, then you have a problem.

> The average Scheme implementation will likely do even fewer optimisations.

This is probably correct. (Guile, for example, can’t do this – at least when the R6RS d-r-t is used, like here. Verified with the above example code and the ,optimize and ,disassemble REPL commands.)

Daphne