dcbaker / meson-plus-plus

An experimental and incomplete implementation of Meson in C++, for solving Meson's bootstrapping issue.
Apache License 2.0
50 stars 7 forks source link

Handle `subdir(if_found : ...)` #3

Open dcbaker opened 3 years ago

dcbaker commented 3 years ago

I'd like to handle all subdir() invocations in the frontend, and have a complete tree for the MIR level, I think the best thing to do is have a pass that converts

subdir('foo', if_found : foo_dep)

into

if foo_dep.found()
  subdir('foo')
endif

This means we can have the full tree available, and use dead code elimination to get rid of it if we don't need it.

for arrays this is more complicated, as meson doesn't have an all(), I could, however have an all() implementation in my AST level code, and have HIR deal with that, or I could reduce it to something like:

use = true
foreach d : foo_deps
  if not d.found()
    use = false
    break
  endif
endforeach
if use
  subdir('foo')
endif

Which is advantageous because the subdir() can be lowered away in the AST leve, but the if use would be resolved in the MIR level.