Skip to content
Menu
Open World News Open World News
  • Privacy Policy
Open World News Open World News

Andy Wingo: a whiff of whiffle

Posted on November 17, 2023 by Michael G

Author:
Source

A couple nights ago I wrote about a superfluous Scheme
implementation

and promised to move on from sheepishly justifying my egregious behavior in
my next note, and finally mention some results from this experiment.
Well, no: I am back on my bullshit. Tonight I write about a couple of
implementation details that discerning readers may find of interest:
value representation, the tail call issue, and the standard library.

what is a value?

As a Lisp, Scheme is one of the early “dynamically typed” languages.
These days when you say “type”, people immediately think propositions
as
types
,
mechanized proof of program properties, and so on. But “type”
has another denotation which is all about values and almost not at all
about terms: one might say that
vector-ref has a type, but
it’s not part of a proof; it’s just that if you try to vector-ref a
pair instead of a vector, you get a run-time error. You can imagine
values as being associated with type tags: annotations that can be
inspected at run-time for, for example, the sort of error that
vector-ref will throw if you call it on a pair.

Scheme systems usually have a finite set of type tags: there are
fixnums, booleans, strings, pairs, symbols, and such, and they all have
their own tag. Even a Scheme system that provides facilities for
defining new disjoint types (define-record-type et al) will implement these via a secondary type tag layer: for example that all record
instances are have the same primary tag, and that you have to retrieve
their record type descriptor to discriminate instances of different
record types.

Anyway. In Whiffle there are immediate types and heap types. All values
have a low-bit tag which is zero for heap objects and nonzero for
immediates. For heap objects, the first word of the heap object has
tagging in the low byte as well. The 3-bit heap tag for pairs is chosen so that
pairs can just be two words, with no header
word
.
There is another 3-bit heap tag for forwarded objects, which is used but the
GC when evacuating a value. Other objects put their heap tags in the low 8
bits of the first word
.
Additionally there is a “busy” tag word value, used to prevent races
when evacuating from multiple threads.

Finally, for generational collection of objects that can be “large” —
the definition of large depends on the collector implementation, and is
not nicely documented, but is more than, like, 256 bytes — anyway these
objects might need to have space for a “remembered” bit in the object
themselves. This is not the case for pairs but is the case for, say,
vectors: even though they are prolly smol, they might not be, and they
need space for a remembered bit in the header.

tail calls

When I started Whiffle, I thought, let’s just compile each Scheme
function to a C function. Since all functions have the same type, clang and gcc will have
no problem turning any tail call into a proper tail call.

This intuition was right and wrong: at optimization level -O2, this
works great. We don’t even do any kind of loop recognition /
contification: loop iterations are tail calls and all is fine. (Not the
most optimal implementation technique, but the assumption is that for
our test cases, GC costs will dominate.)

However, when something goes wrong, I will need to debug the program to
see what’s up, and so you might think to compile at -O0 or -Og. In
that case, somehow gcc does not compile to tail calls. One time while
debugging a program I was flummoxed at a segfault during the call
instruction; turns out it was just stack overflow, and the call was
trying to write the return address into an unmapped page. For clang, I
could use the musttail
attribute
;
perhaps I should, to allow myself to debug properly.

Not being able to debug at -O0 with gcc is annoying. I feel like if GNU were an actual thing, we would have had the equivalent of a musttail attribute 20 years ago already. But it’s not, and we still don’t.

stdlib

So Whiffle makes C, and that C uses some primitives defined as inline
functions
.
Whiffle actually lexically embeds user Scheme
code

with a
prelude,
having exposed a set of
primitives

to that prelude and to user code. The assumption is that the compiler
will open-code all primitives, so that the conceit of providing a
primitive from the Guile compilation host to the Whiffle guest magically
works out, and that any reference to a free variable is an error. This
works well enough, and it’s similar to what we currently do in
Hoot

as well.

This is a quick and dirty strategy but it does let us grow the
language
to something
worth using. I think I’ll come back to this local maximum later if I
manage to write about what Hoot does with modules.

coda

So, that’s Whiffle: the Guile compiler front-end for Scheme, applied to
an expression that prepends a user’s program with a prelude, in a
lexical context of a limited set of primitives, compiling to very simple
C, in which tail calls are just return f(...), relying on the C
compiler to inline and optimize and all that.

Perhaps next up: some results on using Whiffle to test Whippet. Until
then, good night!

Read more

Related Posts:

  • Andy Wingo: a world to win: webassembly for the rest of us
    Andy Wingo: a world to win: webassembly for the rest of us
  • Specbee: The Ultimate Guide to Jumpstart your Drupal Contribution Journey
    Specbee: The Ultimate Guide to Jumpstart your Drupal…
  • Palantir: DrupalCon Pittsburgh Preview
    Palantir: DrupalCon Pittsburgh Preview
  • Andy Wingo: approaching cps soup
    Andy Wingo: approaching cps soup
  • GNU Guix: Dissecting Guix, Part 2: The Store Monad
    GNU Guix: Dissecting Guix, Part 2: The Store Monad
  • GNU Guix: Guix User and Contributor Survey 2024: The Results (part 1)
    GNU Guix: Guix User and Contributor Survey 2024: The…

Recent Posts

  • [TUT] LoRa & LoRaWAN – MikroTik wAP LR8 kit mit The Things Network verbinden [4K | DE]
  • Mercado aguarda Powell e olha Trump, dados e Haddad | MINUTO TOURO DE OURO – 11/02/25
  • Dan Levy Gets Candid About Learning How To Act Differently After Schitt’s Creek: ‘It’s Physically…
  • Building a Rock Shelter & Overnight Stay in Heavy Snow 🏕️⛰️
  • Les milliardaires Elon Musk et Xavier Niel s’insultent copieusement

Categories

  • Android
  • Linux
  • News
  • Open Source
©2025 Open World News | Powered by Superb Themes
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT