This Weekend in Meson++ (January 23rd)

 Assert() and unary operations

We have assertions, which are super useful for unit tests. There's still a bit of work as we don't print location data (like messages), but it's enough to be useful for testing, which is frankly what assert() is for.

Interestingly, with assert() we really need at least the `not` keyword. This wasn't too hard to implement, but turned up some bugs. Basically at the MIR level, we treat everything as control flow or an object. Function calls are objects too. In this case the not keyword is lowered to a not() function, which takes a boolean and returns a boolean. I did uncover a parser bug in the process, which was thankfully easy to fix.

I wrote the following code:
assert(not x.found(), 'message')
The way this is supposed to be parsed is as
assert(not(x.found()), 'message')
but it was getting parsed as:
assert(not(x).found(), 'message')
Which is obviously wrong, and not what we want (thankfully booleans don't have a found method). Thankfully changing operator precedent in Bison/Yacc is super easy, move the lower precedent up in the file.

find_program()

Finding programs is pretty important for nontrivial builds, meson++ uses this to find flex and bison, for example. One of my goals in using an optimizing/lowering compiler model instead of a just-in-time interpreter, is that it should make doing work in parallel very simple. For example, finding programs. In meson (and muon) programs are found as they are encountered in the AST, and they hold up further parsing until they are available. Meson++ does not have this restriction, and instead we do the following
  1. Lower/optimize as much as possible
  2. using threads, search for all programs
  3. replace any calls to `find_program()` with the Program objects
  4. lower again (hopefully completely)
This means that we not only get the faster performance of C++ vs Python, but we can also find multiple programs at once. For a truly large build like mesa, this can speed things up significantly. Eventually I'd like to also do dependency() and compiler methods in the same threaded loop. This could result in some wasted effort (such as looking up a find_library() after a dependency check()), but I think the parallelism will be worth it.

Having find_program also means we're on our way to being ready to implement custom_target, which is a big blocker for getting toward self hosting, but not as big as something like test() which will be a massive undertaking to implement. 

Comments

Popular posts from this blog

This Weekend in Meson++ (February 6th)

Introducing Meson++

Rust in Meson — 0.57 Edition