In Swift 6 mode, #file now has the behavior of #fileID. In Swift 5 mode, #file had the behavior of #filePath
SE-0285, which introduced #fileID, said this about the plan for Swift 6 mode:
#file will continue to produce the same string as #filePath in the Swift 5 and earlier language modes. When code is compiled using [Swift 6 mode], #file will generate the same string as #fileID, and #fileID will be deprecated.
#fileID is intended to allow Swift 5.3 code to adopt the new, more compact literals before the behavior of #file changes. In language version modes where #file produces the same string as #fileID, #fileID will be deprecated.
As far as I can tell, #fileID is not currently deprecated in Swift 6 mode. Do we still think it makes sense to deprecate #fileID in favor of preferring #file? If so, when should we do this? Should we make this change now?
I think the API design guidelines are also in a weird spot right now. Since SE-0285, the API design guidelines have said:
If your API will run in production, prefer #fileID over alternatives. #fileID saves space and protects developers’ privacy. Use #filePath in
APIs that are never run by end users (such as test helpers and scripts) if
the full path will simplify development workflows or be used for file I/O.
Use #file to preserve source compatibility with Swift 5.2 or earlier.
If we do indeed prefer #file over #fileID in Swift 6 mode, we should at least mention that. I posted a PR to address this here.
That documentation was written quite a while ago. I think we may want to instead revise the plan to deprecate #file as being ambiguous, and ask developers to explicitly specify #filePath or #fileID depending on which they need.
It's unfortunate to deprecate #file as it's the more concise option. If the goal is to only have one of #file or #fileID in future code, we should strive for the former.
The Language Steering Group discussed today what should be done here. At the time this proposal was accepted and implemented the deprecation part of the implementation was postponed, but then never revisited once Swift 6 drew near.
In discussing the behavior previously accepted (that #fileID be deprecated in Swift 6), the LSG determined that there was no longer consensus that this remains the correct path forward. As such, the LSG has decided that the proposal text should be updated to match the current reality (or at least edited to note that the deprecation portion of the proposal was never realized). The status quo will be that #fileID remains supported.
There was some interest in the direction mentioned by @grynspan above (eventually deprecate #file and require users to choose explicitly between #fileID and #filePath), and the LSG invites further discussion about whether such a change would be worthwhile.