miking-lang / miking

Miking - the meta viking: a meta-language system for creating embedded languages
Other
51 stars 31 forks source link

Deadcode elimination in `boot` is not conservative #875

Open elegios opened 2 weeks ago

elegios commented 2 weeks ago

This is an issue I ran into working on #738 where calls to a (side-effecting) function for marking files to run or not were being removed. I think this is a minimal case that shows the issue:

let testMain = lam f. f dprint in
testMain (lam call. call 1; ())

which when running boot --debug-dead-code-elim pprints as (modulo whitespace)

let testMain = lam f. f dprint in
testMain (lam call. ())

Note that call 1; is removed. The important factor seems to be that we have a function bound via lambda parameter or pattern match, that we then call it, and that we're not in the right-hand side of a let or recursive let.

I'm not entirely sure what an appropriate fix would be. Two options/possible causes:


Addendum: I found a smaller case, but I'm not sure it's truly illustrative. The program lam f. f 1; () is deadcode eliminated to lam f. (), but of course the two are not observably different since they're never called.