Hacker News new | ask | show | jobs
by asibahi 4 days ago
The Zig compiler compiles lazily and does not detect dead code. (Read: functions that are not called from any compiled functions)
1 comments

That makes total sense (though it would be nice if it could do that detected, I suppose), but what makes less sense to me is the accumulation of unnecessary code (and presumably unit tests for that code) that isn't removed as soon as it's no longer needed.
hard to detect. what if a whole code branch is used by macos and you're on x86?
I don't understand - wouldn't this be observable by the person making the change? They used to call this function / use this class and now they don't any more? Even if it's inside a conditional compilation block.
The hard to detect is the compilers technical reason for not doing the analysis. Maybe it will one day.

In practice, it's annoying to track if those small util functions become dead code.

i did not say "Impossible to detect"!

in practice the exponential explosion of options may become intractable. lets say you have 10 compilation flags with 10 options each. not syre you want the compiler scanning through all that on each pass

Yes - I was only talking about when a person removes some code from use, removing the code as well as the call to the code. I wasn't meaning the compiler at all (although it would be nice if the compiler could autodetect it, as you say, that could become tricky).
That requires a person to be making that change. If the change is vibe coded and the person is only checking that the tests pass, it's not hard for cruft to accumulate.