Skip to content

Commit 56f7164

Browse files
committed
Remove support for -enable-source-import in JIT or REPL modes
This was full of cruft to begin with, and -enable-source-import has plenty of other problems. Remove support for IRGen-ing those other modules.
1 parent a25a0da commit 56f7164

File tree

4 files changed

+8
-89
lines changed

4 files changed

+8
-89
lines changed

lib/Immediate/Immediate.cpp

Lines changed: 6 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,8 @@ bool swift::immediate::linkLLVMModules(llvm::Module *Module,
204204
return !Failed;
205205
}
206206

207-
bool swift::immediate::IRGenImportedModules(
208-
CompilerInstance &CI, llvm::Module &Module,
209-
llvm::SmallPtrSetImpl<swift::ModuleDecl *> &ImportedModules,
210-
SmallVectorImpl<llvm::Function *> &InitFns, IRGenOptions &IRGenOpts,
211-
const SILOptions &SILOpts) {
212-
swift::ModuleDecl *M = CI.getMainModule();
213-
207+
bool swift::immediate::autolinkImportedModules(ModuleDecl *M,
208+
IRGenOptions &IRGenOpts) {
214209
// Perform autolinking.
215210
SmallVector<LinkLibrary, 4> AllLinkLibraries(IRGenOpts.LinkLibraries);
216211
auto addLinkLibrary = [&](LinkLibrary linkLib) {
@@ -219,63 +214,9 @@ bool swift::immediate::IRGenImportedModules(
219214

220215
M->collectLinkLibraries(addLinkLibrary);
221216

222-
tryLoadLibraries(AllLinkLibraries, CI.getASTContext().SearchPathOpts,
223-
CI.getDiags());
224-
225-
ImportedModules.insert(M);
226-
if (!CI.hasSourceImport())
227-
return false;
228-
229-
// IRGen the modules this module depends on. This is only really necessary
230-
// for imported source, but that's a very convenient thing to do in -i mode.
231-
// FIXME: Crawling all loaded modules is a hack.
232-
// FIXME: And re-doing SILGen, SIL-linking, SIL diagnostics, and IRGen is
233-
// expensive, because it's not properly being limited to new things right now.
234-
bool hadError = false;
235-
for (auto &entry : CI.getASTContext().LoadedModules) {
236-
swift::ModuleDecl *import = entry.second;
237-
if (!ImportedModules.insert(import).second)
238-
continue;
239-
240-
std::unique_ptr<SILModule> SILMod = performSILGeneration(import,
241-
CI.getSILOptions());
242-
if (runSILDiagnosticPasses(*SILMod)) {
243-
hadError = true;
244-
break;
245-
}
246-
runSILLoweringPasses(*SILMod);
247-
248-
const auto PSPs = CI.getPrimarySpecificPathsForAtMostOnePrimary();
249-
// FIXME: We shouldn't need to use the global context here, but
250-
// something is persisting across calls to performIRGeneration.
251-
auto SubModule = performIRGeneration(
252-
IRGenOpts, import, std::move(SILMod), import->getName().str(), PSPs,
253-
getGlobalLLVMContext(), ArrayRef<std::string>());
254-
255-
if (CI.getASTContext().hadError()) {
256-
hadError = true;
257-
break;
258-
}
259-
260-
if (!linkLLVMModules(&Module, std::move(SubModule)
261-
// TODO: reactivate the linker mode if it is
262-
// supported in llvm again. Otherwise remove the
263-
// commented code completely.
264-
/*, llvm::Linker::DestroySource */)) {
265-
hadError = true;
266-
break;
267-
}
268-
269-
// FIXME: This is an ugly hack; need to figure out how this should
270-
// actually work.
271-
SmallVector<char, 20> NameBuf;
272-
StringRef InitFnName = (import->getName().str() + ".init").toStringRef(NameBuf);
273-
llvm::Function *InitFn = Module.getFunction(InitFnName);
274-
if (InitFn)
275-
InitFns.push_back(InitFn);
276-
}
277-
278-
return hadError;
217+
tryLoadLibraries(AllLinkLibraries, M->getASTContext().SearchPathOpts,
218+
M->getASTContext().Diags);
219+
return false;
279220
}
280221

281222
int swift::RunImmediately(CompilerInstance &CI, const ProcessCmdLine &CmdLine,
@@ -330,9 +271,7 @@ int swift::RunImmediately(CompilerInstance &CI, const ProcessCmdLine &CmdLine,
330271
(*emplaceProcessArgs)(argBuf.data(), CmdLine.size());
331272

332273
SmallVector<llvm::Function*, 8> InitFns;
333-
llvm::SmallPtrSet<swift::ModuleDecl *, 8> ImportedModules;
334-
if (IRGenImportedModules(CI, *Module, ImportedModules, InitFns,
335-
IRGenOpts, SILOpts))
274+
if (autolinkImportedModules(swiftModule, IRGenOpts))
336275
return -1;
337276

338277
llvm::PassManagerBuilder PMBuilder;

lib/Immediate/ImmediateImpl.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,7 @@ bool tryLoadLibraries(ArrayRef<LinkLibrary> LinkLibraries,
4444
DiagnosticEngine &Diags);
4545
bool linkLLVMModules(llvm::Module *Module,
4646
std::unique_ptr<llvm::Module> SubModule);
47-
bool IRGenImportedModules(
48-
CompilerInstance &CI, llvm::Module &Module,
49-
llvm::SmallPtrSetImpl<swift::ModuleDecl *> &ImportedModules,
50-
SmallVectorImpl<llvm::Function *> &InitFns, IRGenOptions &IRGenOpts,
51-
const SILOptions &SILOpts);
47+
bool autolinkImportedModules(ModuleDecl *M, IRGenOptions &IRGenOpts);
5248

5349
} // end namespace immediate
5450
} // end namespace swift

lib/Immediate/REPL.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -929,8 +929,7 @@ class REPLEnvironment {
929929
llvm::Function *DumpModuleMain = DumpModule.getFunction("main");
930930
DumpModuleMain->setName("repl.line");
931931

932-
if (IRGenImportedModules(CI, *NewModule, ImportedModules, InitFns,
933-
IRGenOpts, SILOpts))
932+
if (autolinkImportedModules(getMainModule(), IRGenOpts))
934933
return false;
935934

936935
llvm::Module *TempModule = NewModule.get();

test/Interpreter/import.swift

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)