Tuesday, February 17, 2009
Parrot 0.9.1 "Final Countdown" released!
Friday, October 3, 2008
Tracking down an IMCC bug
The problem is approximately this:
$I0 = defined, stuff_to_loop_over
unless $I0, for_loop_end
push_eh for_loop_next
...
for_loop_end:
pop_eh
I'm adding the error handler there after a conditional jump, but popping the error handler off after the target of that jump, but I didn't notice this at the time. That's going to at least cause bugs at runtime, but this also caused the PIR compiler to hang. I beat my head against it for a while, posted a bug about it, and went to sleep.
The next day, I used valgrind's callgrind tool to find where it was spending it's time. The output is:
--------------------------------------------------------------------------------
Ir file:function
--------------------------------------------------------------------------------
13,455,028,108 /home/sweeks/src/parrot/compilers/imcc/sets.c:set_add [/home/sweeks/src/parrot/blib/lib/libparrot.so.0.7.1]
11,209,537,812 /home/sweeks/src/parrot/compilers/imcc/cfg.c:compute_dominance_frontiers [/home/sweeks/src/parrot/blib/lib/libparrot.so.0.7.1]
135,234,114 /home/sweeks/src/parrot/compilers/imcc/imclexer.c:yylex [/home/sweeks/src/parrot/blib/lib/libparrot.so.0.7.1]
128,962,606 /home/sweeks/src/parrot/compilers/imcc/sets.c:set_contains [/home/sweeks/src/parrot/blib/lib/libparrot.so.0.7.1]
88,825,729 /home/sweeks/src/parrot/compilers/imcc/imcparser.c:yyparse [/home/sweeks/src/parrot/blib/lib/libparrot.so.0.7.1]
70,349,560 /home/sweeks/src/parrot/compilers/imcc/instructions.c:instruction_reads [/home/sweeks/src/parrot/blib/lib/libparrot.so.0.7.1]
65,814,257 /home/sweeks/src/parrot/compilers/imcc/cfg.c:compute_dominators [/home/sweeks/src/parrot/blib/lib/libparrot.so.0.7.1]
56,483,518 /home/sweeks/src/parrot/compilers/imcc/instructions.c:instruction_writes [/home/sweeks/src/parrot/blib/lib/libparrot.so.0.7.1]
48,013,979 ???:_int_malloc [/lib64/libc-2.8.so]
46,419,350 /home/sweeks/src/parrot/compilers/imcc/pbc.c:constant_folding [/home/sweeks/src/parrot/blib/lib/libparrot.so.0.7.1]
33,201,086 /home/sweeks/src/parrot/compilers/imcc/sets.c:set_intersec_inplace [/home/sweeks/src/parrot/blib/lib/libparrot.so.0.7.1]
29,624,696 /home/sweeks/src/parrot/compilers/imcc/symreg.c:hash_str [/home/sweeks/src/parrot/blib/lib/libparrot.so.0.7.1]
20,719,320 ???:calloc [/lib64/ld-2.8.so]
18,291,953 /home/sweeks/src/parrot/compilers/imcc/cfg.c:bb_check_set_addr [/home/sweeks/src/parrot/blib/lib/libparrot.so.0.7.1]
17,404,418 /home/sweeks/src/parrot/compilers/imcc/reg_alloc.c:compute_one_du_chain [/home/sweeks/src/parrot/blib/lib/libparrot.so.0.7.1]
13,809,278 /home/sweeks/src/parrot/compilers/imcc/imcc.l:yylex
12,337,246 /home/sweeks/src/parrot/src/ops/core_ops.c:hash_str [/home/sweeks/src/parrot/blib/lib/libparrot.so.0.7.1]
12,162,840 ???:memcpy [/lib64/ld-2.8.so]
11,450,969 ???:strcmp'2 [/lib64/ld-2.8.so]
So it's in IMCC, the PIR compiler, specifically in compute_dominance_frontiers... which is what? So let's find out.
The POD for that function says:
=item C<void compute_dominance_frontiers>
Algorithm to find dominance frontiers described in paper "A Simple, Fast
Dominance Algorithm", Cooper et al. (2001)
A quick check with google turns up the PDF I linked.
Skimming over that and the surrounding code that calls compute_dominance_frontier reveals that it's related to register allocation. I read it another couple of times, think I understand the general ideas, and go to sleep.
The next day, I chat with pmichaud about it, and he manages to trim down a simplifed test case, and also notices the actual bug in my patch, which allows me to commit that and pass a half-dozen more tests. He passes the minimal test off to chromatic, who debugs it for a bit and finds that an inner loop in compute_dominance_frontiers is alternating between 8 and 9.
chromatic suggests that I find a way to dump out the register and basic blocks information, and look for the edge identification between blocks. I only have a vague idea of what this means then, so I ask for more information. Here's chromatic's explanation:
<@chromatic> I can give you a quick overview.
<@chromatic> The alligator divides every compilation unit into basic blocks.
<@chromatic> A block is a single block of code between branch points.
<@chromatic> Every entrance and exit point demarcates a block.
<@chromatic> If you arrange the blocks in terms of a control flow graph, you can evaluate all of the possible ways you can reach a point within the block.
<@chromatic> You also keep track of which registers you use within a block.
<@chromatic> If all of the paths to a block go through another block, the latter dominates the former.
<@chromatic> All of this is to say, if you have a named register used in the first block of a unit and the final block of the unit can branch back to the first unit, you have to keep the physical register untouched.
<@chromatic> If there's a block beyond which you can never branch back, you can reuse physical registers unique to that branch and never used later.
<@chromatic> I've been unclear about name/physical register mapping, but I think you get the picture.
<@chromatic> It's the mapping of name to register that really matters.
So I start browsing that code again, but fall asleep before doing anything. Do you see the pattern here yet? ;)
The next day, I go look around in there and I find a couple of debug functions I can use to dump relevant information. Here's what I find:
Dumping the CFG:
-------------------------------
0 (3) -> 8 1 2 <-
1 (3) -> 2 <- 0
2 (3) -> 3 9 <- 1 0
3 (2) -> 4 <- 2
4 (2) -> 5 <- 3
5 (3) -> 6 9 <- 8 7 4
6 (3) -> 7 <- 5
7 (3) -> 5 <- 6
8 (2) -> 5 <- 9 0
9 (3) -> 8 <- 5 2
This is:
block number (loop depth) -> blocks that this block can branch to <- blocks that can branch to this block
We also have:
Dumping the Dominators Tree:
-------------------------------
0 <- ( 0) 0
1 <- ( 0) 0 1 8 9
2 <- ( 0) 0 2 8 9
3 <- ( 2) 0 2 3 8 9
4 <- ( 3) 0 2 3 4 8 9
5 <- ( 0) 0 5 8 9
6 <- ( 5) 0 5 6 8 9
7 <- ( 6) 0 5 6 7 8 9
8 <- ( 9) 0 8 9
9 <- ( 8) 0 8 9
This is:
block number <- (immediate dominator) full list of dominators
The loop that was spinning was:
while (runner >= 0 && runner != unit->idoms[b]) {
/* add b to runner's dominance frontier set */
set_add(unit->dominance_frontiers[runner], b);
/* runner = idoms[runner] */
if (runner == 0)
runner = -1;
else
runner = unit->idoms[runner];
}
Where 'runner' is the node we're currently evaluating, unit is the overall compilation unit, and idoms[] is the list of immediate dominators.
Adding some debugging printfs, I discover that the problem is when the algorithm follows block five, it spins with the runner alternating between 8 and 9. If you look back up at the dominators tree, you'll see that the immediate dominator of block 8 is block 9, and the idom of block 9 is block 8. Infinite loop.
After re-reading the algorithm and paper a few times to verify that I undersand what's going on, I add a conditional to break out of the statement if we're trying to add a block to the dominance frontiers list of a block that we've already added the current block to.
while (runner >= 0 && runner != unit->idoms[b]) {
if (set_contains(unit->dominance_frontiers[runner], b))
/* we've already gone down this path once before */
runner = 0;
else
/* add b to runner's dominance frontier set */
set_add(unit->dominance_frontiers[runner], b);
/* runner = idoms[runner] */
if (runner == 0)
runner = -1;
else
runner = unit->idoms[runner];
}
Everything seemed to work fine, so after getting a review from particle, I committed.
Wednesday, September 10, 2008
"Final report" for Mozilla Foundation and TPF grant
Last year I received a Perl 6 development grant from the Mozilla Foundation and The Perl Foundation. Below is a copy of the final report I've submitted to close out the grant. It's also available in PDF if anyone wants a more printable version.
My thanks to everyone who helped me with this grant, and I'm looking forward to the next one.
[2008-09-11 update: the original version of this report mis-attributed the Squaak tutorial to Kevin Tew; the corrected author is Klaas-Jan Stol (kjs). My sincere apologies for the mistake, it is now corrected below.]
Perl 6 Development Grant
Final Report
Patrick R. MichaudSeptember 10, 2008
INTRODUCTION
This is the final report for the Perl 6 and Parrot development grant provided by the Mozilla Foundation and The Perl Foundation. This report summarizes the work performed under the grant, what has been accomplished, and where things are headed from here. As this report illustrates, we have achieved all of the goals and outcomes intended for this grant.REPORT
The primary focus of the project was to get Perl 6 on Parrot development "over the hump" and acquire a critical mass of infrastructure, developers, and tools from which sustained further development of Perl 6 can take place. The project proposal identified five specific expected outcomes:- A working Perl 6 on Parrot implementation that supports commonly used Perl constructs and operators
- Review and improvements to the Perl 6 language test suite
- A substantially complete Parrot Compiler Toolkit, with documentation
- Ongoing, active development efforts for other languages based on the Parrot Compiler Toolkit
- An increased number of participants in Perl 6 and Parrot design, implementation, and testing
We now have a substantial Perl 6 implementation on Parrot. At the beginning of this project, we had a rudimentary Perl 6 compiler that could handle some of the basic features and syntax of Perl. However, some key features such as arrays and hashes were only marginally implemented, and most of the translation components of the compiler were written in Parrot's intermediate assembly language (PIR).
Today the Perl 6 on Parrot compiler has been substantially rewritten using the Parrot Compiler Toolkit (described below), and is now known as "Rakudo Perl" or "Rakudo" [1]. Rakudo currently supports arrays, hashes, classes, objects, inheritance, roles, enumeration types, subset types, role composition, multimethod dispatch, type checking, basic I/O, named regular expressions, grammars, optional parameters, named parameters, slurpy parameters, closures, smart match, junctions, and many other features expected from Perl 6. Rakudo has progressed to the point that others are now using Rakudo as an Apache handler ("mod_perl6") [2], a wiki engine ("November") [3], and recently to build applications on Xlib [4]. The Perl Foundation also recently awarded a grant to Vadim Konovalov to implement a Tk GUI interface for Rakudo [5].
During the project there have been many contributors to the development of Rakudo Perl; some of the major contributors include chromatic, Vasily Chekalkin (bacek), Jerry Gay, Jeff Horwitz, Moritz Lenz, Carl Mäsak, Cory Spencer, Stephen Weeks (Tene), and Jonathan Worthington. Jonathan Worthington's efforts deserve special mention: he is primarily responsible for the bulk of the work on classes and types in Rakudo Perl, and much of his work was supported by a grant from Vienna.pm [6].
2. Review and improvements to the Perl 6 test suite
At the beginning of this project, the test suite that existed for Perl 6 had been implemented as part of the Pugs effort and contained approximately 16,000 tests. However, in many cases the tests were out of date with respect to the current Perl 6 language specification, and we needed a way for multiple independent Perl 6 implementations to be able to easily make use of the test suite.
In December 2007 I proposed a structure for reorganizing the test suite [7]; Jerry Gay and Larry Wall then extended this proposal and developed tools to make it easier to share the tests among multiple implementations. In May 2008 Moritz Lenz refactored Rakudo's test harness to provide a "make spectest_regression" target -- since then this has become our primary measure of Rakudo progress [8]. Moritz Lenz also developed a tool to display the progress in graphical form:
Adrian Kreher received a Google Summer of Code grant (with Moritz Lenz and Jerry Gay as mentors) to continue the test suite refactoring [9]. As of early September 2008, the official, refactored test suite contains a little over 8,000 tests, or approximately half the size of the original Pugs test suite. Furthermore, the official suite includes many new tests for object-oriented and typing features of Perl 6 that weren't present in the original test suite. As the graph above indicates, Rakudo is currently passing over 3,200 of the tests in the official suite, and work is continuing on refactoring the suite and increasing Rakudo's pass rate.
3. A substantially complete Parrot Compiler Toolkit, with documentation
As mentioned previously, the compilers that existed for Parrot at the beginning of the project (such as Perl 6) were primarily written in Parrot's intermediate assembly language. This made working on the compilers less accessible to new developers, as well as increasing the time needed to build a compiler. Therefore, the first couple of months of this project were spent on developing the Parrot Compiler Toolkit (PCT) and a simple Parrot language called Not Quite Perl (NQP). PCT provides an abstract syntax tree representation and code generator for Parrot languages; NQP enables compiler writers to easily create compilers and builtin functions for Parrot using a simplified Perl 6 syntax.
Once PCT and NQP were substantially complete, we were then able to convert Perl 6 (now "Rakudo Perl") and many other Parrot compilers to use the new toolkit. This went surprisingly quickly -- most of the existing compilers were converted within just a couple of weeks. In addition, a few new compilers and languages arrived on the scene: Will Coleda and Simon Cozens quickly created an implementation of LOLCODE [10], and Klaas-Jan Stol created a language called "Squaak" as a demonstration and tutorial for the toolkit [11]. A couple of quotes from the period give a sense of how these tools opened up Parrot development to others:
"The real fun, though, has been digging into perl6, the Parrot Perl 6 implementation. Recently, Patrick Michaud has been doing some incredible work building NQP (Not Quite Perl 6), a bootstrapping language for implementing Perl 6, and extensively refactoring the existing Perl 6 on Parrot compiler to fit with it. I'm still very much getting my head wrapped around the whole thing, but it's been easy enough to start digging into and implementing and fixing a few things."Both PCT and NQP stabilized early in the project; recent changes have been primarily to optimize existing features or make other minor improvements. We expect these tools to continue to evolve as needed to support compiler development; however, given the wide variety of languages being implemented using the toolkit surprisingly few changes have been needed. Primary documentation for the toolkit consists of a Parrot Design Document (PDD26) for the abstract syntax tree representation [14], the Squaak tutorial [11], and numerous example languages in the Parrot repository. More detailed documentation and examples for the toolkit are expected to be developed over the coming months.- Jonathan Worthington, December 2007 [12]"It's really, really true. Parrot lets you implement your own languages using Perl 6 rules for the grammar and Perl 6 for the compiler."- Simon Cozens, January 2008 [13]
4. Ongoing, active development efforts for other languages based on the Parrot Compiler Toolkit
Currently there is active development on at least three languages for Parrot; these include Perl 6 (Rakudo Perl), PHP (Pipp), and Ruby (Cardinal). In addition, there is ongoing but less active
development on implementations of Python (Pynie) and Smalltalk (ChitChat). All of these are based on the tools from the Parrot Compiler Toolkit. The Perl 6 and PHP implementations are usable from mod_parrot [2], and our next steps are to improve the toolkit and library conventions to support loading multiple languages simultaneously in Parrot.
5. An increased number of participants in Perl 6 and Parrot design, implementation, and testing
There can be little question that momentum for Perl 6 and Parrot development continues to grow, and the work supported by this grant has been a major catalyst for that growth. For the twelve months prior to September 2007 the Parrot subversion repository had a total of 6,634 commits; in the subsequent twelve months Parrot had 9,686 commits -- a year-over-year increase of 46% in the commit rate.
At the beginning of this project there were perhaps three or four active contributors to the Perl 6 on Parrot compiler (i.e., Rakudo Perl); over the course of the past year that number has increased to at least ten active contributors and at least as many more occasional contributors to Rakudo Perl. Parrot and the Parrot Compiler Toolkit have also garnered new contributors, including several new committers. There are also new teams of developers working on applications based on Rakudo Perl and Parrot, such as the November wiki engine and the Rakudo/Tk GUI interface.
Lastly, recent improvements in the Rakudo compiler architecture will allow much of the Perl 6 runtime library currently written in PIR to be rewritten substantially in Perl 6. This will enable even more new contributors to participate in Perl 6 development.
PROJECT EVALUATION
The project proposal identified five criteria by which the success of this project could be measured:- Ability to write and test Perl 6 programs and language features
- Passing rate for Perl 6 language test suite
- Improved coverage and accuracy of the Perl 6 language test suite
- Increased number of participants in Perl 6 and Parrot development
- Active development of at least two other languages using Parrot compiler tools
Moreover, this project helped jump-start even larger fund-raising efforts. In May 2008 the Perl Foundation received a $200,000 philanthropic donation from Ian Hague; roughly half of this donation is intended to continue the Perl 6 development efforts that have been part of this project [15]. And, as mentioned earlier, Jonathan Worthington and others are receiving grants for continued work on Rakudo Perl and Parrot [6,8,16].
CONCLUSION AND FUTURE WORK
The funding provided by the Mozilla Foundation and The Perl Foundation has indeed enabled us to get Perl 6 on Parrot development "over the hump" in development. We now have a robust platform for higher-level language development on Parrot, along with an active and growing development and support community (which is the hallmark of any successful open source project). All of the desired outcomes of this project have been realized.Our next steps will be to continue to extend and build upon the work of this project -- increasing Rakudo's coverage of the Perl 6 language and bringing all of our efforts much closer to production releases. In fact, we recently developed a "road map" for Rakudo Perl that identifies the major steps to be taken in the upcoming months and assists in coordinating the remaining development activities [17].
Lastly, I want to express my sincere appreciation to the many people who contribute time and energy to Perl 6 and Parrot, and to give special thanks to the people of the Mozilla Foundation and The Perl Foundation for their ongoing support and enthusiasm for this project. It is a great honor to work and correspond with such a terrific and professional group of individuals.
REFERENCES
- P. Michaud (January 16, 2008), "The compiler formerly known as 'perl6'", http://use.perl.org/~pmichaud/journal/35400
- J. Horwitz, "Mod_parrot website", http://www.smashing.org/mod_parrot/
- C. Mäsak, "Announcing November, a wiki in Perl 6", http://use.perl.org/~masak/journal/37212
- http://svn.perl.org/parrot/trunk/examples/nci/xlibtest.p6
- Alberto Sim&otild;es (August 30, 2008), "2008Q3 Grants Results", http://news.perlfoundation.org/2008/08/2008q3_grants_results.html
- "Vienna.pm funds Jonathan Worthington to work on Ra[kudo]" (April 23, 2008), http://use.perl.org/article.pl?sid=08/04/23/2314234
- P. Michaud (December 20, 2007), "Proposal: refactor the test suite according to synopsis, http://groups.google.com/group/perl.perl6.compiler/msg/ed748490f030da2f
- P. Michaud (June 16, 2008), "Rakudo test suite progress", http://use.perl.org/~pmichaud/journal/36695
- A. Kreher, "Auzon's Blog: gsoc2008", http://auzon.blogspot.com/search/label/gsoc2008
- "I HAZ A PARROT" (January 3, 2008), http://lolcode.com/news/i-haz-a-parrot
- K. Stol (March 9, 2008), "PCT Tutorial Episode 1: Introduction", http://www.parrotblog.org/2008/03/targeting-parrot-vm.html
- J. Worthington, "Chipping away at perl6", http://www.jnthn.net/cgi-bin/blog_read.pl?id=589
- S. Cozens (January 3, 2008), "Parrot is really quite wonderful", http://blog.simon-cozens.org/post/view/132
- "Parrot Abstract Syntax Tree (PDD 26)", http://www.parrotcode.org/docs/pdd/pdd26_ast.html
- R. Dice (May 16, 2008), "TPF receives large donation in support of Perl 6 development", http://news.perlfoundation.org/2008/05/tpf_receives_large_donation_in.html
- J. Worthington (August 5, 2008), "Multiple Dispatch Design Work", http://use.perl.org/~JonathanWorthington/journal/37101
- "Perl 6 Development Roadmap", http://svn.perl.org/parrot/trunk/languages/perl6/ROADMAP
Tuesday, May 20, 2008
Parrot 0.6.2 "Reverse Sublimation" Released!
— The Book of Sorrows, by Walter Wangerin Jr.They were walking to the Hemlock, the Rooster and the Mice, and
the Mice kept looking at one another, questioning."We don't know what the future holds, do we?" said Chauntecleer. The Mice all shook their heads. They knew very little of anything. "If," said Chauntecleer, "I say, if I don't come back again, then you must make this food to last a long, long time. I trust your prudence, don't I?" he asked, and they nodded automatically, but their eyes were very big. "And I trust your integrity, right?" They nodded. "And you are mature, now, and I respect your maturity, isn't that so?" Poor Mice, they nodded and nodded, and they blinked, and they nodded. They looked afraid. "Good," said Chauntecleer. "I know I won't be disappointed."
In this way he gave each Mouse a manhood. They couldn't talk to him just now, having so much to turn over in their minds. But neither did they cry.
On behalf of the Parrot team, I'm proud to announce Parrot 0.6.2
"Reverse Sublimation." Parrot is a virtual machine aimed at running all dynamic languages.
Parrot 0.6.2 News:
- Specification
- updated and launched pdd28_strings.pod
- updated pdd19_pir.pod
- updated and launched pdd28_strings.pod
- Implementation
- added implementation of Rational PMC
- simplified ops control flow syntax
- enabled backtrace on non-glibc platforms too
- improved some PIR error reporting
- removed user stack opcodes (save, restore, lookback, entrytype, depth, rotate_up)
(NOTE: This was scheduled to occur after 0.7.0, moved up to this release) - removed register stack, saveall, and restoreall opcodes
- removed various deprecated features and unused code
- added implementation of Rational PMC
- Languages
- Amber: retired
- C99: grammar updated
- Cardinal: resurrected, method calls and do blocks work now
- Eclectus: use NQP as PAST generating code
- Lua:
- added big number library
- updated to match PGE changes
- added a bytecode disassembler & a Lua 5.1 VM bytecode translator
- added big number library
- Pheme: updated to match PGE/PCT changes
- Plumhead:
- use NQP as PAST generating code
- use riaxpander for macro expansion
- use NQP as PAST generating code
- Rakudo:
- updated ROADMAP
- conditional and loop statement modifiers
- lots of class, object, role, and method improvements
- Str increment and decrement
- improved spectest reporting
- type checking on assignment
- regexes and grammars
- undef and self
- placeholder vars
- updated ROADMAP
- Squaak: added to repository
- TAP: retired
- Amber: retired
- Compilers
- PGE: updated to match Synopsis 5, deprecated features removed
- PCT:
- improve handling of register types, conversion between registers
- improved error diagnostics
- add 'arity' to for loops
- improve handling of register types, conversion between registers
- PGE: updated to match Synopsis 5, deprecated features removed
- Configuration
- added step auto::opengl
- added step gen::opengl
- added step gen::call_list
- added step auto::opengl
- Miscellaneous
- still more optimizations and performance improvements, especially in GC
- new libraries: OpenGL/GLU/GLUT bindings (small subset working)
- new dump_pbc.pl utility: PBC disassembly/source code weaver
- improved C++ compiler support
- optimized builds work again
- still more optimizations and performance improvements, especially in GC
Gracias to all our contributors for making this possible, and our sponsors for supporting this project. The next scheduled release will occur on 17 June 2008.
Enjoy!