Jonathan Worthington writes:
If it weren't for the fact that you said you were going to do it,
I would've doubted it could be done at all in current Parrot.
In many senses, this Hague Grant was rather more challenging than my last one. In the course of it, I've been dealing with major changes to some of the things most fundamental to any Perl 6 implementation, including method dispatch, trait application and metaclasses. Happily, I have been able to meet the challenges and complete all of the deliverables laid out in the grant application, and had no shortage of fun in doing so.
I proposed six deliverables. Here I will detail what was achieved in each of them.
D1. This deliverable was by far the most challenging of the grant. At the heart of it was completely replacing the existing method dispatcher, which allowed us to implement many features but was never going to be sufficiently performant, mapped onto Parrot's primitives poorly and did not provide a good way to support deferral.
The new dispatcher gave support for deferral from the start. Furthermore, it computes the list of candidates we could defer to lazily, so as to limit the cost to those methods that choose to defer. Since we had never supported the $foo.@candidates syntax, I was able to partly introduce it there, but there was no getting away from eventually needing a large patch that updated all other method calls forms to work with the new dispatcher. I was happy that the landing of this patch caused very little disruption to Rakudo users, despite it marking a very large change to the way something very fundamental to the language worked. As an additional bonus, replacing the dispatcher forced various corner cases to be explored, and shook out a lot of places where we had been cheating.
All of the promised trimmings on the side of the dispatcher replacement were also completed: .WALK, .can, lastcall, the hides trait modifier and the hidden trait. Additionally, dispatches for the form .+, .? and .* that take an indirect method or a list of methods are also now supported. All of these, and deferral, have had their test coverage reviewed and improved.
D2. I refactored .wrap and .unwrap to work in terms of candidate lists. This also fixed some tests that the previous implementation had been failing.
D3. I implemented parallel dispatch and reviewed and extended testing for this feature.
D4. I started off my work on improving Rakudo's introspection capabilities by reviewing, getting input on and then improving the specification itself to be more clear. I then worked on implementing these parts of the specification. Along the way I did a refactor to give Rakudo it's own metaclasses for roles and classes, which means we don't poke so much stuff into P6object in the Parrot namespace. The spectest suite was extremely lacking in test coverage for this area; I wrote over 150 new tests.
D5. I implemented support for defining methods on the metaclass, as specified in S12, and reviewed and enabled the tests for this.
D6. The traits part of the grant was something of an adventure. When I started asking for clarifications on various aspects of it during planning the implementation, it soon became clear that the design team wanted to re-visit some aspects of it. Shortly afterwards, some fairly sizable changes were made. Thus what I have implemented in Rakudo is a greatly updated specification. That needed a little extra refactoring, and some improvements to multiple dispatch along the way.
In implementing traits, I refactored nearly all of the custom trait-application logic out of Rakudo's compiler and into multiple dispatch, as per the specification. In fact, Rakudo uses the very same mechanism that Perl 6 programmers will use to introduce custom traits. (By design, a few traits are still handled directly by the compiler, these now have an improved architecture.) I added some new and passing tests for custom user-defined traits on classes, roles, routines, variable declarations and attribute declarations.
I have attended YAPC::Europe where I gave a talk [pdf] that covered much of my work under this grant. I expect some of it will feature in my forthcoming talks at YAPC::Asia and the Italian Perl Workshop.
I have maintained an active presence on #perl6, and worked to keep everyone aware of what changes were coming. Thanks to the p6eval bot on the channel, people have been able to explore the new features almost as soon as they were committed.
Also, as promised, I have written blog posts (1), (2), (3), (4), about the features implemented in this grant. These have appeared both on the Rakudo homepage and in my use.perl.org journal.
As a result of completing this grant, Rakudo now has some coverage - and in a lot of cases extensive coverage - of every non-conjectural headed section of S12 and S14 applicable to Perl 6.0.0. (In S12, one section is marked not applicable to Perl 6.0.0, and another is marked as conjectural). Of course, there are parts within sections of these
synopses that are yet to be completed, and there will be ongoing work on stability, better handling of edge cases and performance. However, I think the current state is a significant achievement by the Rakudo project, and it's without doubt that this Hague grant and the last one I completed have made a large contribution to that.
Overall, this grant has implemented more of the specification, aided evolution of the specification in some places, and brought areas where Rakudo cheated a bit more in line with the way they are specified. It has provided an implementation of method dispatch that not only implements deferral, but also improves performance in general,
eliminates the huge overhead of multi-method dispatch over only-method dispatch and aids interoperability with other languages on the Parrot platform.