Day 6 — Raku beyond Roast: what is enough?

There are two main sources from which you can learn the rules of the Raku programming language. The first is the official documentation. The second is the test suite called Roast.

An interesting thing about Roast is that if a Raku engine (an interpreter or a compiler) passes all the tests in Roast, it can be called a Raku implementation.

Any compiler that passes the tests is deemed to implement that version of the Raku specification.

Until recently, we had only one Raku engine, Rakudo. This year added two more implementations: Raku++ and mutsu. All three pass 100% of Roast.

In Roast, more than 220,000 individual tests are hosted in about 1500 files. There is also a spectest list, which includes 1425 file names that are the absolute minimum (in fact, the list excludes just a few files with not-yet-implemented syntax). Roast isn’t carved in stone and gets updates quite often, so make sure you git pull it from time to time.

Now that it’s already December, let’s look at what it costs a compiler developer to prepare a Raku engine and make sure it is released before Christmas. Let me share my experience here.

The first steps to pass Roast

Moving towards the 100% mark was one of the main initial tasks for the Raku++ compiler. The first implementation easily reached about 50-60%. Then another jump happened after implementing Unicode support, which made about 90k tests pass at once.

Getting from 90-95% to 100% took more time, but now the engine passes 100.00%. I intentionally write two zeros after the decimal point to indicate that the coverage is complete. With fewer digits, you could technically still have a gap of a few tests but fairly claim 100%.

A full Roast run (at the time of writing) includes 219,394 tests, and Raku++ fully passes it in about 30-40 seconds on a MacBook.

$ raku++ tools/run-roast.raku

The interesting part comes after you’ve reached the 100% bar. It turns out that many existing Raku programs still fail, and many modules from the ecosystem do not compile.

Are 220k tests really not enough?

Roast isn’t enough to ensure the compiler understands the whole language. To complement it, you need a deeper understanding of the rules. One such source is the official Raku documentation, from which you can extract code snippets and learn how language constructs must work.

So, on top of Roast comes the documentation. But that’s not enough either. I gathered all the programs and snippets I had written earlier for blog posts and books. That’s my Raku corpus. Another source of test programs is the vast archive of solutions to the Weekly Challenge, which has already been running for about than 8 years. Next, there are about 2500 Raku modules in the ecosystem.

Each source adds new use cases not covered by Roast or the documentation. The compiler must understand all of that.

A few more ideas came along. They are not yet fully implemented, but they have already helped to find and close more gaps. Below is an overview, maybe even a bit outdated 🙂

This is a simplified diagram of the Raku++ compiler ecosystem, with the compiler parts themselves and the various testing sub-projects around it. I won’t dig into it in this post, but you are welcome to explore the details.

Each section below describes a single initiative that I started to make the compiler better and to allow it to run more real-life Raku.

The Raku Corpus, a collection of real programs

The Raku Corpus is a collection of my own small programs that I wrote while working on different Raku projects, from books and the Raku Course to contributions to The Weekly Challenge. It contains about 1900 programs, and it helped to discover quite a few compiler gaps: grammar and Match (the biggest cluster), parse gaps (around 20 cases), glued -ne'…' flags (14), exceptions and exit codes (12), module-qualified calls, dates, slurpy hash issues, first(:k), and gists.

Later it became a check run against every larger change, and every week by Raku Eye (see below). Whatever it catches is cut down to a t/regression case, and that case goes into the gate.

Raku module battery with the ecosystem’s own tests

Being able to use modules submitted by Raku enthusiasts to the Raku ecosystem is one of the compiler’s main goals (which is obvious). The non-obvious part comes when you have reached full Roast coverage and some modules still cannot be compiled or run.

On the other hand, downloading modules from the Internet and running their code on your computer is risky. So I started with a battery of about 50 top modules. Surprisingly, a new factor popped up: the most popular modules use Rakudo internals. For example, to install a JSON-parsing module, you already need to be able to parse JSON, as the ecosystem index is a JSON file. Such chicken-and-egg problems are solved by embedding the required parts directly into the engine, which, in turn, makes a number of the most popular modules implementation-dependent.

No Roast test could predict that a new Raku engine must understand how to handle this name: Rakudo::Internals::JSON. Working with the top ecosystem modules is a good reality check. Nine of the top 200 modules call Rakudo::Internals. One module reads MoarVM’s object layout. JSON::Class refuses a compiler older than v2023.12, so Raku++ had to report Rakudo’s version. In total, about 500 of the first 4000 commits to Raku++ were about aligning these things.

Rakuglaze — module battery, but in seconds

Running the whole sweep over more than 2500 ecosystem modules takes a long time, and it’s mostly unnecessary for every release, as it does not catch new bugs. I had an idea to extract the most syntactically interesting parts from the modules’ sources and keep them both as a bug-finding test and as a set of regression tests.

This is what Rakuglaze (as in a shell over the modules) is. It is a collection that covers most of the ecosystem but can be run in seconds (and is most likely quite safe).

Each snippet contains a compilable piece of code and the expected result. For example:

=== list-kv-map-two-params
from: Getopt::Long 0.4.2 lib/Getopt/Long.rakumod:646
license: Artistic-2.0
feature: method kv
--- code
my @list = <file.txt out.txt>;
my @positionals = @list.kv.map: -> $index, $value {
"\$$index=$value"
};
say @positionals;
--- expect
[$0=file.txt $1=out.txt]

What it has caught so far: a try block is use fatal; $n max= *.elems curried the whole assignment; KEEP after a method’s Nil; Hash.push with a Slip; a list of an Array’s elements must write through to the array; say + (…) and f - 5 with f a declared sub; $*name interpolated in a regex; a type named Req read as reversed eq.

As you may notice from this dense description, the problems come when you combine the individual syntax elements. Each one may work well in Roast but break when it meets another part that works just as well on its own.

RakuGrid — element combinations as a matrix

And so we seamlessly come to the RakuGrid project, which aims to put isolated elements of syntax together in different possible combinations. The original idea was to make a matrix where the Raku ‘atoms’ sit along the axes, and the cells are thus combinations of two of them. Such two-item ‘molecules’ do actually find bugs. Additionally, corner cases such as -Inf, Inf, NaN, and -0e0 are added to the suite.

For example, one of the tests looks like this. Its combinational code is (2**64) - (1/3):

- id 0038
from ladder:numeric×numeric
cell 2**64 | 1/3
code (2**64) - (1/3)
is <55340232221128654847/3>
type Rat
oracle rakudo-2026.07 → <55340232221128654847/3>
oracle rakupp-v3.14.0-77-gf431f48-dirty → <55340232221128654847/3>

It may look trivial, but in reality it helps a lot. 2**64 is an Int, and 1/3 is a Rat, so here we test how these two combine and how the infix - handles them. The expected result is also a number of the Rat type. The exact digits in the stringified result must also agree.

Currently, RakuGrid contains about 170k tests with about 800 individual atoms. Testing with this suite allowed me to halve the number of failing grid cells in just a single day (from 9518 to 4930 on 16 August 2026).

RakuMap — generated programs shrunk to evidence

RakuMap, although its name may be confused with RakuGrid, is a different initiative. The core of the project is a code generator that creates small programs in 16 different domains: numeric calculations, containers, signatures, Unicode, regexes, phasers, concurrency, deliberately invalid code, etc.

Currently, there are about 200 programs, but that number should definitely grow. Let us look at one of the examples:

my @events;
{ LEAVE @events.push("leave"); @events.push("body") }
my $value = @events.Array;

This is a minimal program that, when run, must put the strings into the @events array in reverse order: $["body", "leave"]. All the programs print the main characteristics of the output using this similar boilerplate code:

sub safe-str($v) { my $s = try $v.Str; $s.defined ?? $s !! '<undefined>' }
say "TYPE\t" ~ $value.^name;
say "RAKU\t" ~ $value.raku;
say "STR\t" ~ safe-str($value);
say "BOOL\t" ~ $value.Bool;

In most cases, incorrect behaviour in a particular engine is discovered when its output differs from another engine’s output. And that brings us to the next problem.

Raku Behind the Docs and the need for a human in the loop

Rakudo can be considered a reference compiler, so when the documentation doesn’t answer a question and Roast doesn’t test it, Rakudo’s behaviour can usually be taken as the correct one. Usually, but not always.

Raku Behind the Docs was created as an educational project for readers who already know the Raku documentation and want to go further. But it also helped to find more bugs in the engine(s). It explains the things that the documentation doesn’t cover for one reason or another.

Every code example was run on both Rakudo and Raku++, and each difference was first treated as a potential Raku++ bug. But about 70 cases point the other way. These are the places where Rakudo’s behaviour may be worth a second look. Most of those cases can’t be settled mechanically, by AI or otherwise. Each one needs a human to decide what the right answer is.

Let’s examine a real case where this test suite helped to fix a tricky bug in Rakudo.

Can you tell what this one-liner should print?

say "abc".rindex(<a b>, 1);

The documentation describes rindex as taking two arguments. The first is the pattern, which may also be a List, but there is no example where both a list and a starting position (1 in the snippet above) are passed. Roast doesn’t test this combination either.

Let’s dig a bit into compiler internals. To see how Raku++ parses this code, use the --ast command-line option:

$ raku++ --ast -e"'abc'.rindex(<a b>, 1)"
Program
MethodCall │ .rindex
invocant:
StrLit │ "abc"
ArrayLit
StrLit │ "a"
StrLit │ "b"
IntLit │ 1

So, rindex gets a List as its first argument.

In Rakudo, you can use --target=ast to see the tree, or, better, ask for the RakuAST equivalent:

$ rakudo -e"say q{'abc'.rindex(<a b>, 1)}.AST"
RakuAST::StatementList.new(
RakuAST::Statement::Expression.new(
expression => RakuAST::ApplyPostfix.new(
operand => RakuAST::QuotedString.new(
segments => (
RakuAST::StrLiteral.new("abc"),
)
),
postfix => RakuAST::Call::Method.new(
name => RakuAST::Name.from-identifier("rindex"),
args => RakuAST::ArgList.new(
RakuAST::QuotedString.new(
processors => <words val>,
segments => (
RakuAST::StrLiteral.new("a b"),
)
),
RakuAST::IntLiteral.new(1)
)
)
)
)
)

Both compilers read the code the same way, so parsing isn’t the issue. The difference was at run time: in Rakudo, the call never returned because of an infinite loop in which the same multi-method was called again and again. That’s an easy corner to miss, as each half is tested separately and works on its own. Once discovered, the bug was fixed within a few hours, even faster than an AI would pick it up 🙂

This is exactly the kind of case a second implementation is good at finding. Two engines that disagree make you ask which one is right, and sometimes the answer helps both. The whole Raku galaxy wins.

FatRoast, the same Roast with fat added

This collection repeats the same Roast tests but with altered characters. Literally: wherever Latin letters stand, they are replaced with Cyrillic or CJK ones. In place of ASCII operators come their Unicode equivalents: ≤ ≠ × ÷ − ∈. The third branch changes the names: every declared variable, sub, class, role, and grammar is renamed.

Here’s one of the modified tests:

{
my $中 = '';
$中 ~= "|$_" for (<a b c> Z <X Y Z>).tree[];
is $中, "|a X|b Y|c Z", '(list of lists).tree';
}

Rakudo’s issue tracker as a test suite

Probably the most unexpected idea was to collect the code snippets from the issues that users have submitted to Rakudo’s GitHub repository.

More than 3000 issues have been submitted so far, and most of them are closed and resolved, so we know not only what was wrong, but also that it is now correct and how it behaves in the end. The snippets that are runnable (that is, not isolated fragments that you cannot compile without context) are first fed to Rakudo to get the expected result. The second phase is to run everything with your own engine.

If you agree that Rakudo is the de facto reference compiler, you get a great source of truth for your implementation. In the Raku++ repo, there are now about 100 commits prompted by this research.

In some cases, it was not only about correctness but also about performance. With Raku, one of the most difficult parts is lazy infinite lists and sequences like 1, 1, * + * ... *. For example, a series of 40k terms took 0.92 s before and 0.03 s after the fix (compared to Rakudo’s 0.07 s).

For the record, when you develop software with AI and fix very well-defined bugs, it is important to stop from time to time and do a round of generalisation. It helps to extend a fix that focused only on one narrow behaviour to a wide class of similar cases that nobody has reported yet: other spellings of the same operation, other methods of the same family, other types and other argument shapes. A precise bug report gets a precise fix, and the more exact the report, the narrower the fix tends to be.

The weekly Raku Eye

The weekly Raku Eye is a GitHub pipeline that runs every Monday, after the next batch of Weekly Challenge solutions has most likely landed in the repo. This tool runs them, as well as the new modules submitted to the ecosystem, with Raku++. It logs regressions and fixes, and it also runs the performance benchmarks, so it’s easy to track changes over time (although you have to be careful, as CI pipelines on GitHub do not always run under the same CPU conditions).

Performance tests

Before we wrap up for today, let’s continue with performance graphs. The tests in Roast only check whether the code runs correctly, but they don’t take into account how fast it compiles or how fast it runs. These parameters, though, may be crucial for real-life applications.

The most obvious parameter is execution time. It is less obvious how to measure it for isolated test cases. One possible solution is to create a collection of programs that are specially constructed to perform heavy computations.

Raku++ has such a collection in tools/bench. Each file is a short program that does one thing many times, so whatever an engine does slowly shows up in the total time. A few examples:

  • fib.raku: naive recursive Fibonacci fib(29)
  • objects.raku: creates 100,000 objects and uses their methods and attributes
  • multiwhere.raku: a multi-method with a where constraint, called 400,000 times
  • intcat.raku: a string built by appending a million integers to it: $s ~= $_ for ^1_000_000

The results are published in BENCHMARKS.md.

Mutsu has its own set of benchmark programs: grammars, JSON and YAML parsing, regexes, threads, Mandelbrot and more. Its CI runs them after changes, and draws the history as a trend chart.

Since 30 September, mutsu’s CI also runs Raku++ as a second reference implementation next to Rakudo. Every benchmark is timed on the same machine, and the chart can show mutsu’s speed relative to Raku++.

So two independent implementations now use each other as a measure of speed. Roast does not offer this, because it only checks that the answer is right.

It is worth mentioning that if an engine offers a profiler or stage statistics, those can also be used to draw some conclusions about performance. All three engines accept the --profile CLI option, whose results can be used in performance tests too. Rakudo and Raku++ additionally offer --stagestats.

Epilogue

What is described in today’s Advent post is not the final state of the global Raku test suite that I’d like to have by some Christmas yet to come. As you can see, I tried many directions. Some of them went further, and some are still at the proof-of-concept stage.

Altogether, it helped to make this year’s Christmas merrier.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.