?

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: tim.dreamwidth.org
2011-04-15 03:30 am (UTC)
I have serious concerns about the use of "as" to denote type coercions, Lindsey. And those curly brackets! So sharp and pointy!
(Reply) (Thread)
[User Picture]From: lindseykuper
2011-04-15 03:37 am (UTC)
Hey, I think you're in the wrong place. You want es-discuss.
(Reply) (Parent) (Thread)
[User Picture]From: tim.dreamwidth.org
2011-04-15 03:38 am (UTC)
I got told.
(Reply) (Parent) (Thread)
[User Picture]From: nibot
2011-04-15 04:49 am (UTC)
I had no idea that Mozilla had so many employees, and, you know, buildings and stuff(??).

This sounds like a great, exciting project!
(Reply) (Thread)
[User Picture]From: simrob
2011-04-15 05:02 am (UTC)
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

In case it hasn't been pointed out, you are awesome.
(Reply) (Thread)
[User Picture]From: lindseykuper
2011-04-15 05:48 am (UTC)
Thank you! I write this stuff for all of you, you know.
(Reply) (Parent) (Thread)
(Deleted comment)
[User Picture]From: sstrickl
2011-04-15 06:22 am (UTC)
Redex! I can't wait to see the final model, not only because it's always interesting to see how different people write different things in Redex, but also because I'm sure you'll have lots of feedback for it once you're wrestling in the muck with it.
(Reply) (Thread)
[User Picture]From: lindseykuper
2011-04-15 07:20 pm (UTC)
It's a super-cool tool. I wish I'd tried it out a long time ago.
(Reply) (Parent) (Thread)
[User Picture]From: nibot
2011-04-15 05:51 pm (UTC)
What does Mozilla want to do with rust?
(Reply) (Thread)
[User Picture]From: lindseykuper
2011-04-15 07:14 pm (UTC)
The project FAQ explains it best. In a word, though: "Experiment."
(Reply) (Parent) (Thread)
(Deleted comment)
[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)
(Deleted comment)
(Deleted comment)
[User Picture]From: lindseykuper
2011-04-16 02:17 am (UTC)
If I understand you correctly, it's possible to fake the behavior you want using generics. It ain't pretty, though.

If Rust has subclassing (which I assume it does)

Actually, no, right now it doesn't have subclassing (it doesn't have classes at all) or subtyping.
(Reply) (Parent) (Thread)
(Deleted comment)
[User Picture]From: lindseykuper
2011-04-17 12:14 am (UTC)

Well, we don't have subclassing, we don't have inheritance, and as our most recent doc snapshot points out, "Method overriding and object restriction are performed explicitly on object values." That sounds kind of prototype-y to me, but we're getting into territory that I don't know a lot about, so I could be wrong about that.

In any case, this is not the kind of language where you ever have to use the object system, and I suspect that Rust's modules will take the place of a bunch of the stuff that people resort to using objects for when they're programming in a language without modules. Also, by saying "right now it doesn't have subclassing" I certainly didn't mean to imply that it ever would. I just meant that the language is still under development and subject to change. If any of this sounds interesting to you, I'd encourage you to read the docs and play around with it yourself, with the caveat that things might break at any moment!

(Reply) (Parent) (Thread)
[User Picture]From: pmb
2011-04-16 03:53 am (UTC)
I so agree about being annoyed that one cannot refine return types in subclasses.
(Reply) (Parent) (Thread)
[User Picture]From: lindseykuper
2011-04-23 08:00 am (UTC)
Yes. This is actually one of the big arguments for self-types. In a system with self-types, if an inherited method returns self, its return type will automatically be the type of the child rather than the more general type of the parent. (It's a moot point for Rust right now, since we don't have inheritance, but we might one day!)
(Reply) (Parent) (Thread)