@@ -633,9 +633,9 @@ bool CompilerInstance::setUpInputs() {
633633
634634Optional<unsigned > CompilerInstance::getRecordedBufferID (const InputFile &input,
635635 bool &failed) {
636- if (!input.buffer ()) {
636+ if (!input.getBuffer ()) {
637637 if (Optional<unsigned > existingBufferID =
638- SourceMgr.getIDForBufferIdentifier (input.file ())) {
638+ SourceMgr.getIDForBufferIdentifier (input.getFileName ())) {
639639 return existingBufferID;
640640 }
641641 }
@@ -663,17 +663,18 @@ Optional<unsigned> CompilerInstance::getRecordedBufferID(const InputFile &input,
663663
664664Optional<ModuleBuffers> CompilerInstance::getInputBuffersIfPresent (
665665 const InputFile &input) {
666- if (auto b = input.buffer ()) {
666+ if (auto b = input.getBuffer ()) {
667667 return ModuleBuffers (llvm::MemoryBuffer::getMemBufferCopy (b->getBuffer (),
668668 b->getBufferIdentifier ()));
669669 }
670670 // FIXME: Working with filenames is fragile, maybe use the real path
671671 // or have some kind of FileManager.
672672 using FileOrError = llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>;
673673 FileOrError inputFileOrErr = swift::vfs::getFileOrSTDIN (getFileSystem (),
674- input.file ());
674+ input.getFileName ());
675675 if (!inputFileOrErr) {
676- Diagnostics.diagnose (SourceLoc (), diag::error_open_input_file, input.file (),
676+ Diagnostics.diagnose (SourceLoc (), diag::error_open_input_file,
677+ input.getFileName (),
677678 inputFileOrErr.getError ().message ());
678679 return None;
679680 }
@@ -689,7 +690,7 @@ Optional<ModuleBuffers> CompilerInstance::getInputBuffersIfPresent(
689690
690691Optional<std::unique_ptr<llvm::MemoryBuffer>>
691692CompilerInstance::openModuleSourceInfo (const InputFile &input) {
692- llvm::SmallString<128 > pathWithoutProjectDir (input.file ());
693+ llvm::SmallString<128 > pathWithoutProjectDir (input.getFileName ());
693694 llvm::sys::path::replace_extension (pathWithoutProjectDir,
694695 file_types::getExtension (file_types::TY_SwiftSourceInfoFile));
695696 llvm::SmallString<128 > pathWithProjectDir = pathWithoutProjectDir.str ();
@@ -708,7 +709,7 @@ CompilerInstance::openModuleSourceInfo(const InputFile &input) {
708709
709710Optional<std::unique_ptr<llvm::MemoryBuffer>>
710711CompilerInstance::openModuleDoc (const InputFile &input) {
711- llvm::SmallString<128 > moduleDocFilePath (input.file ());
712+ llvm::SmallString<128 > moduleDocFilePath (input.getFileName ());
712713 llvm::sys::path::replace_extension (
713714 moduleDocFilePath,
714715 file_types::getExtension (file_types::TY_SwiftModuleDocFile));
@@ -773,9 +774,12 @@ ImplicitImportInfo CompilerInstance::getImplicitImportInfo() const {
773774
774775bool CompilerInstance::createFilesForMainModule (
775776 ModuleDecl *mod, SmallVectorImpl<FileUnit *> &files) const {
776- // Make sure the main file is the first file in the module.
777- if (MainBufferID != NO_SUCH_BUFFER) {
778- files.push_back (mainFile);
777+ // Try to pull out the main source file, if any. This ensures that it
778+ // is at the start of the list of files.
779+ Optional<unsigned > MainBufferID = None;
780+ if (SourceFile *mainSourceFile = computeMainSourceFileForModule (mod)) {
781+ MainBufferID = mainSourceFile->getBufferID ();
782+ files.push_back (mainSourceFile);
779783 }
780784
781785 // If we have partial modules to load, do so now, bailing if any failed to
0 commit comments