guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Guile CSE elimination of record accessor?


From: Andy Wingo
Subject: Re: Guile CSE elimination of record accessor?
Date: Tue, 30 Apr 2024 16:43:38 +0200
User-agent: Gnus/5.13 (Gnus v5.13)

Hi :)

On Sat 27 Apr 2024 19:04, Simon Tournier <zimon.toutoune@gmail.com> writes:

> In Guile module (ice-9 vlist), one reads:
>
> ;; Asserting that something is a vlist is actually a win if your next
> ;; step is to call record accessors, because that causes CSE to
> ;; eliminate the type checks in those accessors.
> ;;
> (define-inlinable (assert-vlist val)
>   (unless (vlist? val)
>     (throw 'wrong-type-arg
>            #f
>            "Not a vlist: ~S"
>            (list val)
>            (list val))))
>
> [...]
>
> (define (vlist-head vlist)
>   "Return the head of VLIST."
>   (assert-vlist vlist)
>   (let ((base   (vlist-base vlist))
>         (offset (vlist-offset vlist)))
>     (block-ref (block-content base) offset)))
>
>
> Other said, the argument ’vlist’ is “type-checked” with ’assert-vlist’
> and thus that is exploited by Guile compiler, if I understand correctly
> the comment.
>
> The first question is: is it still correct?  Because this module had
> been implemented before many Guile compiler improvements.

No, the comment is incorrect.  The type check on whatever accessor is
called first (unspecified in scheme; probably we should just bite the
bullet and do predictable left-to-right semantics, as racket does) will
dominate the rest and eliminate those checks.  The assert-type is
unnecessary.

To see this, do ,optimize-cps at the repl, and count the number of
e.g. struct? checks with and without the assert-vlist.  There is only
one, either way.  (A type check is a heap-object? check, then struct?,
then get the vtable, then check against the global variable <vlist>.
All of these duplicates get eliminated.)

> PS: Raining day and weird pastime… diving into Guile source code. ;-)

:)

Cheers

Andy



reply via email to

[Prev in Thread] Current Thread [Next in Thread]