Mirah Office Hours: After the hiatus

August 16th, 2011

Lower Falls of the Yellowstone
I took last week off, I was a little busy vacationing and all. I had a very nice time and enjoyed not having internet or cell service. But this last Sunday I was back at it, hacking away on Mirah.

Getting Started

I started by pulling latest, because there had been some changes since the last time I checked out Mirah. Immediately I went from having 2 test failures to having 200 some errors with the message NativeException: java.lang.ClassNotFoundException: mirah.impl.Map$Extension4.

This had something to do with the bootstrap jar being upgraded, but I wasn’t sure what.
I tried updating my local Java from 1.6.0_22 to 1.6.0_24, that didn’t work–but it changed the error to RuntimeError: Compilation error.

I also ran rake clean and rake clobber and poked around for other stale files. It was weird because if I checked out the jar from before the change everything worked again.

Finally, I tried making a fresh clone of the repo and that worked–which I found a little strange. My suspicion is that somewhere I missed some build files that were screwing things up on the path, but I’m really not sure.

Somewhere in there I also blew away my rvm JRuby install and reinstalled it. When I did that, I also chmoded .rvm/hooks/after_use_jruby so nailgun wouldn’t cause issues like it did before.

Actually doing stuff

I looked at pull request #95, and couldn’t reproduce the issue it solved, so I left a comment to that effect.

On StackOverflow, I answered a question about Mirah’s metaprogramming support. I think I should work up a page like that to put in the wiki, so there is a canonical place to look for macro and metaprogramming information.

test reorg continues
I finished teasing apart the bytecode and javac jvm tests. Now, they run the same suite but use different helpers instead of sharing through subclassing. This means we can start to break apart the big test_jvm_compiler.rb file(2876 lines!) into more focused test files, which I think will be a big win for helping new people find a place to put new tests.

The only problem with the current implementation is that the rake test task is dependent on the sub tasks instead of calling them inside itself. This is a problem because the task stops at the last suite to fail, instead of doing like Rails does and running them all and telling you error in test:units or whatever.

I continued poking at the main method thing I’ve been working on, and managed to completely hose the test suite–clearly I’m doing something wrong somewhere. So I think I’ll take another crack at it next weekend. I think I was trying too hard to decompose the compile helper methods, rather than getting it working and then decomposing it.

Scoping Thoughts

I read the scoping discussion about macro scoping and formed an opinion about it.

The discussion boils down to how to handle scoping within macros. For macros to be useful, you need to be able to refer to variables from the outer scope. The problem is that just dropping the code the macro generates into the outer scope can be problematic when the code the macro generates has its own variables. Hmm, that explanation wasn’t great–how ’bout an example:

Here, if we use the outer scope without making temporary variables for the variables in the macro, we’ll get as output 4, which is probably not what we expected.

My Scoped Opinion

My thought is that anything assigned/declared to in the quote block in a macro should be turned into a variable local to the macro–eg foo’s bar becomes bar_1, or something. But, unquoted elements within the quote should use the outer scoping and not create temporary variables, so that when the macro is put in place, the function baz looks like:

That gets you the ability to reference things outside the macro, letting you manipulate them within it, but does not bleed temporary variables from the macro into the outer scope. Now, how to implement that, I don’t really have a good idea. An exercise for the reader.

I think it was a pretty productive four hours. See you next week!

Mirah Office Hours

August 2nd, 2011


This time I tried to tackle the improperly generated main bug that’s been a problem with java source generation for a while. It took me a couple of hours to figure out where the relevant code was because I’m not as familiar with that part of the compiler.

The problem was that when the main method was generated for a file with the same name as a class in it, the source for the class’s source code would be generated before the main method’s body.

huh? Lets see some examples

Say we have a file test.mirah that looks like this:

When we run mirahc -j test.mirah, we get this Test.java out:

Notice anything funny? The main method isn’t finished. This is because when we generate the main method, we compile the whole script–which includes the class. The problem is that we finish generating the class’s source code before we get to Test.new.a, leaving the main we added to the class unfinished.

My hackish solution to this was to check if we were generating a main or not in the class source builder, and not finish the class until the main method was finished. I did this by checking to see if we were in a main method generation in the class generator and not finishing the class source generation until after the main method was generated if that’s true. But of course, that by itself added new problems because you can have multiple classes in a .mirah file. So I added a klass method on the Mirah::JavaSource::MethodBuilder so I could check both whether we are in a main method and whether it is the main method of the current class.

After doing that, the generated code looks like this:

Much better

Since I haven’t written tests specifically for this yet, I put it on a branch on my fork of Mirah so I can get some other eyeballs on it. I’m also sure there’s a better approach than the one I took.

One other thing I found is that if the name of the .mirah file is different than any of the classes in it, it compiles correctly even w/o the patch. Which makes sense because in that case there is no class body for the class with the same name as the file.

Mirah Office Hours

July 25th, 2011

Mirah Office Hours Prep Jul 24th 2011 I had my regular Mirah office hours on Sunday.

This week I focused on getting all the tests passing for the patches that were merged earlier in the week, which were among the things that fell out of this big thread on the mailing list. One of the other things was that a number of people became collaborators on the repository (like me :D ).

When trying to get tests working, I ran into some issues with JRuby and NailGun. RVM latest starts up a nailgun server by default when using JRuby, which is cool because it’s faster, but I had some problems. Essentially, Mirah’s compile scripts were attempting to run in NailGun’s home directory, which didn’t work very well…

I fixed it by setting JRUBY_OPT=”", which told JRuby not to send requests to NailGun. Better would be to chmod -x .rvm/hooks/after_use_jruby, which would additionally avoid starting a NailGun server. The best thing would be to figure out what happened and fix it in JRuby’s NailGun integration. Unfortunately, after I got Mirah’s test suite working, I couldn’t reproduce the issue with NailGun reenabled.

In the end, I got all the tests passing except the one for the new loop macro, which still has an inference error.

The new addition of a top_level? method on AST nodes cleaned things up pretty nicely by not requiring a script class unless there are things defined in the top level scope. Most of my changes dealt with that–fewer classes were generated out of the compiled code (commit).

I had fun fixing things, even though it was frustrating that I couldn’t get to the more interesting things I wanted to work on (closures, Dubious, Shatner). Maybe I’ll get to them on my next set of office hours.

Brewed Some Beer On Saturday

May 19th, 2011

Brewed my second batch of homebrew ever. It was the same bbq wit as before, with fresher spices. I’m hoping it turns out as awesomely as the first batch. The second batch is harder though because sanitizing becomes that much more important. I’ll know in a week and a half.

I followed the basic outline for brewing an extract beer from beerdude, which worked really well last time.

Here’s it steeping some grain.

Summer BBQ Wit II: A New Beginning

Mirah Talk at Boulder Ruby Group

May 18th, 2011

Tonight I spoke about Mirah at Boulder Ruby Group. It went well and people had a lot of good questions for me. I found answering questions about Mirah to be really fun, especially now that I’m starting to get a better handle on the language and tool chain.

Here’s my slides.

Links

Rails BugMash This Saturday

May 6th, 2011

@_prakash and I are hosting a Rails BugMash at Gnip’s offices from 11-5. Hopefully it will be a lot of fun and we’ll mash some bugs. Squash them even. More seriously, it’s a good way to get involved with open source by getting together with a group of friendly people who know something about contributing or are interesting learning about it.

It’s registered on plancast at http://plancast.com/p/4yvw

You can read more about how bug mashes have been done in the past at RailsBridge’s Wiki page on them. Rails’ own contrib guide is also a fairly good resource for getting started.

Zounds!

See everybody tomorrow.

Mountain West Ruby Conf

March 22nd, 2011

Badge & Breakfast

Mountain West Ruby Conf last week rocked. It was well organized as always–props to Mike Moore(@blowmage) for putting it together and Confreaks for recording it and all the other people who made it the awesome conf that I like coming to every year(e.g. Jeremy Nicoll-Smashing Photographer).

CHE-UP my friends.

More seriously, Zed’s talk made me think more carefully about my open source contributions in terms of who benefits from my work. Am I just a sucker for working on stuff like Dubious or am I just doing it because I find it interesting and engaging. I think he crafted a really good talk and a good meme(CHE-UP) and made a good point about being aware of the motivations behind projects you contribute to. Now I just need to find some suckers/contributors to help me with my plans for world domination ;) .

Mind Monkey Patching

David Brady’s talk about head hacking reminded me that I need to finish Pragmatic Thinking & Learning, a good book I’ve been reading off and on for more than 6 months now. I need to try using that crazy cat picture (the one with too many eyes) to trigger hardware interrupts at interesting times. Might be fun.

“Web” Development

Wayne Seguin’s talk was very topical as MWRC is my favorite conference to meet new and interesting Rubyists. I feel like I did some definite “web” development while I was there. I met new people and spent more time getting to know better some of the people in the community I’d met at other conferences.

I came away from the talk feeling inspired to do more looking at teaching and mentoring, something I looked at a little at RubyConf.

Concurrency

Concurrency was a big theme at the conference with Ilya Grigorick talking about more advanced concurrency models, and Preston Lee presenting about using the GPU and CUDA to solve embarrassingly parallel problems.

Ilya talked about the Actor model, which Erlang uses as well as Pi-Calculus/CSP which is what Go uses. Both deal with concurrency by providing constraints on what you can do within them. Interestingly, their constraints are very similar, but have different abstractions with regard to what is named.

In the Actor model,

  1. Name every process
  2. Every process has a mailbox
  3. Communicate via messages

In the CSP,

  1. Processes are anonymous
  2. Every channel has a name
  3. Processes communicate over channels

He wrote a gem that acts like CSP called agent

 

5K

I ran in the 5k. I slept through it last year and decided that I had to do it this year. There were 13 of us. It was very dramatic.

Rounding the last corner

Rounding the last corner (pic by smashingshots.com)

I think I was last.

Mirah & Dubious

Mirah and Dubious were represented. I did a lightning talk on Dubious Thursday and Joe O’Brien showed off what is going on with Pindah as part of his Ruby on Android talk. I got to introduce a few people to Mirah and Dubious which was pretty cool. It seems like people are getting more interested in Mirah and projects written in it, which I think is pretty awesome.

Some other thoughts

Redis is a pretty cool project that I’d like to look at more than I have.

Wood cuts make for nifty slides.

Figs are killer.

 

Thanks again everybody for a great conference.

 

 

 

It’s That Time of Year Again: Mountain West Ruby Conf Time.

March 15th, 2011

I’m going to Mountain West Ruby Conf again this year. The talks look great, the venue, as always is awesome and this year I might even run the 5k(in my VFFs of course).

I’m hoping to get some hacking done on Dubious and introduce some more people to it. You can do some really cool things with it, even in its current, limited state, and I’d like to see it played with and used more.

If you see me there, I’ll probably be wearing my black fedora and sporting a nice beard. Not as big as last year’s though(exhibit A).

Matz & me at last year's MWRC
Matz & me at last year’s MWRC

Snowshoeing With Dog near Brainard Lake

March 2nd, 2011

The Dog and I in Our Snow Shoes
Sara and the dog and I went snowshoeing last Sunday near Brainard Lake. The day started out really windy and I was worried it would be even worse on the trail. Getting to the trailhead confirmed my worries. The wind blew hard and the snow around the parking lot was contoured into low drifts.

It was windy and cold and we were worried that once we got our ‘shoes on and started up the trail that it was going to royally suck. I’d read that the way to the lake went along the road in my trail book and I figured that we’d be exposed to the wind the whole time.

But after we got out of the parking lot, we found the start of the snowshoeing trail somewhat hidden behind the the big map of the area, going up into the trees. Once we got into the trees we were protected from the wind. The trail itself wasn’t too bad, though it did get steep in a few places.

There were a fair number of cars parked at the trail head and we were worried that we’d run into a lot of people. Once we were on the trail though, we didn’t see many at all. I guess because there were enough different trails to take people just spread out.

In the end we didn’t make it to the lake, only about half way. We did however, successfully test our new snowshoes and Ada’s new boots. I’m not sure she liked them, but they did stay on pretty well as far as that goes.

If you’re going to go, you might want to check out the nearby  Snow levels.


Map

View Larger Map

JRuby, Can’t Find File in Classpath (You Needed a Slash, in <= 1.5.6)

January 10th, 2011

Update: this is no longer valid as of the release of 1.6.0.

I was debugging this Dubious problem where a class I was sure was on the class path couldn’t be found(link). First, I tried compiling on my local checkout, and it worked oddly. Then I realized I was dumb, because the class was being picked up from the finished jar. So, I clobbered my build artifacts and then my local copy didn’t compile either.

I did some digging and found out why.

In the end it was because of how JRuby implements $CLASSPATH–the way you can modify the classpath from within JRuby. JRuby uses a subclass of URLClassLoader to implement it which gives it some possibly unexpected behavior. In particular, URLClassLoader treats anything that does not end in a slash as a jar. That’s why the class files in my build directory were not being picked up properly.

Lessons Learned:

Combat “It Works on My Machine™”. Clobber local generated files every now and again, and checkout a fresh tree from time to time to reduce the chance something local is weird.

Look for and ask for help when you don’t know something. First time I tried to figure out the problem, I just tinkered and compiled and tinkered and compiled. A little research would have saved some time.

TL;DR

If JRuby can’t find your classes and you think they should have been added to $CLASSPATH, make sure you have trailing slashes on your directory names.

Update:

This has actually been fixed, but not released yet: https://github.com/jruby/jruby/commit/8740a6b3ea946a1442dd7fa833aed3c30d82e23f