LangProc / langproc-2017-lab

4 stars 8 forks source link

dead_branch_removal: Do we eliminate 'Seq' and 'While' nodes? #51

Closed M1LL3RB0Y closed 7 years ago

M1LL3RB0Y commented 7 years ago

Are we supposed to eliminate 'Seq' and/or 'While' nodes?

For example, in the case where you somehow have a constant condition for 'While' (through error of the programmer perhaps), would the following:

Seq [
  While [ 0
    Seq [
      Assign : i [ Input ]
      Assign : a [ i ]
    ]
  ]
]

Be simplified to something like:

Seq [
]

Or because 'Seq' is then empty, simplified to nothing:

Or do we not even try to eliminate these, and just concern ourselves with 'If' nodes?

-Cheers

m8pple commented 7 years ago

You aren't required to simplify them for the pass, as I don't see them as "branches" in the normal sense. My test-cases should (hopefully) be setup so that the only optimisations possible are exactly the ones I'm expecting, which only relate to If nodes in order to keep things simple.

However, you are correct that the optimisations you suggest are another form of dead branch elimination, and in principle there is no problem implementing them.