From: Andy Wingo <wingo@igalia.com>
To: Simon Tournier <zimon.toutoune@gmail.com>
Cc: "Guix Devel" <guix-devel@gnu.org>, "Ludovic Courtès" <ludo@gnu.org>
Subject: Re: Guile CSE elimination of record accessor?
Date: Tue, 30 Apr 2024 16:43:38 +0200 [thread overview]
Message-ID: <87zftanc6d.fsf@igalia.com> (raw)
In-Reply-To: <877cgig2j7.fsf@gmail.com> (Simon Tournier's message of "Sat, 27 Apr 2024 19:04:44 +0200")
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
next prev parent reply other threads:[~2024-04-30 14:44 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-27 17:04 Guile CSE elimination of record accessor? Simon Tournier
2024-04-30 14:43 ` Andy Wingo [this message]
2024-05-03 18:08 ` Simon Tournier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87zftanc6d.fsf@igalia.com \
--to=wingo@igalia.com \
--cc=guix-devel@gnu.org \
--cc=ludo@gnu.org \
--cc=zimon.toutoune@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.