Adding #file_name like clang's recent addition of __FILE_NAME__

Clang recently merged a change to have __FILE_NAME__ directive that will be replaced by a C string of the current compiling file's name, without the path leading up to the file name (which would be in __FILE__).

https://reviews.llvm.org/D61756

This addition has a great deal of value. When full path is not necessary, the many places where it is common to use __FILE__ (asserts, logging, etc) can move to using __FILE_NAME__. This would reduce the binary size (paths of build systems often get very long) and avoid leaking the file hierarchy of the system that built the project.

This can also benefit unit tests that would like to use the file's name for testing against conditions but across different machines would have different values for __FILE__ but would be the same for __FILE_NAME__.

For Swift, I would propose we follow the naming convention and add a new directive along side #file called #file_name or #filename

3 Likes

Reference to prior discussion: We need `#fileName`.

3 Likes