?

Log in

No account? Create an account
My first month at Mozilla - Lindsey Kuper [entries|archive|friends|userinfo]
Lindsey Kuper

[ website | composition.al ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

My first month at Mozilla [Apr. 14th, 2011|08:03 pm]
Lindsey Kuper
[Tags|, ]

As it turns out, I picked an interesting month to start working at Mozilla. On Tuesday of my second week, Firefox 4 launched, followed by the launch of Firefox Mobile during my third week, then the launch of a big advertising campaign. And last week, which was my fourth, was "all hands" week, during which Mozilla employees from around the world descended on the main office here in Mountain View so that they could work in person with folks that they usually mostly interact with over IRC. Mozilla is widely distributed geographically; there are 400 employees, but only 150 or so are in Mountain View. The rest either work from home or from the six other, much smaller Mozilla offices in Auckland, Beijing, Paris, Tokyo, Toronto, and Vancouver. A lot of those 400 are, like me, new employees -- 50 new hires in 2011 so far, or so I hear. With all these events and product launches and new people and visitors to entertain, it's been something of a non-stop party at work. As I told Jesse jes5199 when he was here to visit this weekend, "They just keep on feeding us and feeding us and giving us t-shirts and feeding us."

In spite of all the partying, we're managing to get quite a lot of work done on Rust. The first Rust compiler, which we call the bootstrap compiler, is written in OCaml and is being used to develop a second compiler, which is self-hosted, that is, written in Rust. Very soon, we'll be at the point where the self-hosted compiler can compile itself. When that happens, which should be within weeks, maybe even days, the bootstrap compiler can go onto the scrap heap.

I've been working on the self-hosted compiler. As a starter project, I made an improvement to the typechecker's error messages: if you try to do something like, say, add 5 to an instance of an object, your code now fails to compile with a nice, short error message like "expected int but found thingie", instead of "expected int but found [hundred-line pretty-print dump of thingie's internal structure]" as was happening before. Most of the infrastructure for doing this existed in the compiler already, so all I had to do was take advantage of it. I'm pleased, though, that I managed to land this first patch on March 22nd, which happened to be the day of the Firefox 4 launch. Actually, I'm impressed that I was lucid enough to write code that day at all, after having gotten up at five in the morning for the Firefox launch party!

Next, Patrick asked me to implement the n-body benchmark from the Computer Language Benchmarks Game in Rust. Here's how new of a language Rust is: I needed to read a string from the command line and parse it into an integer (which ends up being the number of time steps that a toy physics simulation runs for) . The Java version, for instance, uses Integer.parseInt() for this. I poked around in the Rust standard library for a while, looking for the analogous thing in Rust and not finding it anywhere. Finally, I asked on IRC, "How do I turn a string into an int?" People said, "Oh, I don't think that's implemented yet. Go for it!" And that's how I found myself writing a piece of code that sort of looks like atoi went to grad school and started dating ML.1

// eventually this'll live in a library, hopefully with some error
// checking or something.  only works up to 2^^31 - 1.  quality first!
fn str_to_int(str s) -> int {
    let int res = 0;

    for (u8 a in s) {
        // 48 = ascii for '0'
        res = (res * 10) + (a as int - 48);
    }

    ret res;
}

This ended up not making it into our final version of the program, because we decided to just hard-code the number of steps that the simulation would run. It's just as well, because, you know, when code that I helped write is being demoed by Brendan Eich in front of 400 Mozilla employees on the first morning of all-hands week, I'd really prefer my contribution to not be the kind of code about which "quality first!" can only be said sarcastically.

I've now started working on my longer-term goal for the summer, which is to design and implement self-types (that is, "the type of the current object", as found in, for example, Scala) for the Rust type system. Rust has the beginnings of an object system, but until a couple weeks ago, there wasn't even such a thing as a self keyword yet, so the first thing I did was implement that, along with support for self-calls like self.foo(). This took about a week and a half and necessitated touching pretty much every part of the compiler. I learned a lot from doing it, and now you can compile programs you couldn't before. (And they even work!) But self still doesn't exist as a standalone, first-class entity; right now, it's really nothing more than a magic prefix to method calls, and you can't do things like return self, nor can you write functions that take arguments of type self. For that, we need self-types. I know very little about object systems, but I find it reassuring that, deep down in their heart of hearts, self-types are just a special case of recursive types. That shouldn't make me less scared, but somehow it does.

So, that's what's been going on! Finally, this week I've also been spending some time learning my way around PLT Redex so that we can use it to develop an operational semantics for (a very small subset of) Rust. We really need a semantics, and I've been wanting to try out Redex for a while, so now seems like a good opportunity. I just started learning Redex, and I don't have a lot of experience doing this kind of thing, so chances are I'm not doinitrite. But I'm doin' it out in the open, 'cause that's how we do.


  1. My jokey commentary notwithstanding, you shouldn't read too much into the way Rust code looks right now. The syntax is subject to change, and it'll probably change significantly once we're self-hosting.
LinkReply

Comments:
[User Picture]From: lindseykuper
2011-04-16 02:03 am (UTC)
Do you mean portability in the sense that you need a working binary to start with for each platform you might want to build on? We've done a lot of thinking about how to handle bootstrapping, and we think we have a good plan, but I'd be curious to know your thoughts. (Accidentally? How'd they manage that?)
(Reply) (Parent) (Thread)