mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Ensure that SourceFiles always have a backing buffer in the SourceManager
The "buffer ID" in a SourceFile, which is used to find the source file's contents in the SourceManager, has always been optional. However, the effectively every SourceFile actually does have a buffer ID, and the vast majority of accesses to this information dereference the optional without checking. Update the handful of call sites that provided `nullopt` as the buffer ID to provide a proper buffer instead. These were mostly unit tests and testing programs, with a few places that passed a never-empty optional through to the SourceFile constructor. Then, remove optionality from the representation and accessors. It is now the case that every SourceFile has a buffer ID, simplying a bunch of code.
This commit is contained in:
@@ -751,9 +751,7 @@ static SourceLoc getDeclStartPosition(SourceFile &File) {
|
||||
}
|
||||
|
||||
static void printUntilFirstDeclStarts(SourceFile &File, ASTPrinter &Printer) {
|
||||
if (!File.getBufferID().has_value())
|
||||
return;
|
||||
auto BufferID = *File.getBufferID();
|
||||
auto BufferID = File.getBufferID();
|
||||
|
||||
auto &SM = File.getASTContext().SourceMgr;
|
||||
CharSourceRange TextRange = SM.getRangeForBuffer(BufferID);
|
||||
|
||||
Reference in New Issue
Block a user