3 ms·
Why should the compiler compile code that is not called/exported? that's a waste of processing power and therefore a waste of time At best it should give you a
by Kukumber 4y ago
Why should the compiler compile code that is not called/exported? that's a waste of processing power and therefore a waste of time
At best it should give you a warning that the function is not used, that's it
- gavinhoward 4y agoBecause the parser still has to skip it, especially if it's in a file with code that is used. The parser needs to know the beginning and the end to do so. This takes at least rudimentary parsing. Oh, and the compiler may not know it's unused until it processes all files if it's a public function.
- nickcw 4y agoI found it a surprise. However it is really useful when using comptime and doing those really awkward cross platform things (like delving into the innards of a stat_t) - your FreeBSD stuff with its different member names will be completely ignored on Linux.
- titzer 4y agoThe Virgil compiler will typecheck all code given to it on the command-line and then only compile what is reachable from main() after running initialization in the internal interpreter, both code and data. Unused functions and fields and classes will simply never be visited for codegen.