Skip to content

Commit 08fcf7d

Browse files
committed
[NFC] Internalize the REPL's LLVMContext
There's no reason the REPL needs to generate its starting module in the global LLVMContext. Give it a local context.
1 parent ec9afec commit 08fcf7d

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

lib/Immediate/REPL.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -765,13 +765,13 @@ static void printOrDumpDecl(Decl *d, PrintOrDump which) {
765765

766766
/// The compiler and execution environment for the REPL.
767767
class REPLEnvironment {
768+
std::unique_ptr<llvm::LLVMContext> LLVMContext;
768769
CompilerInstance &CI;
769770
ModuleDecl *MostRecentModule;
770771
ProcessCmdLine CmdLine;
771772
llvm::SmallPtrSet<swift::ModuleDecl *, 8> ImportedModules;
772773
SmallVector<llvm::Function*, 8> InitFns;
773774
bool RanGlobalInitializers;
774-
llvm::LLVMContext &LLVMContext;
775775
llvm::Module *Module;
776776
llvm::StringSet<> FuncsAlreadyGenerated;
777777
llvm::StringSet<> GlobalsAlreadyEmitted;
@@ -1028,15 +1028,14 @@ class REPLEnvironment {
10281028
public:
10291029
REPLEnvironment(CompilerInstance &CI,
10301030
const ProcessCmdLine &CmdLine,
1031-
llvm::LLVMContext &LLVMCtx,
10321031
bool ParseStdlib)
1033-
: CI(CI),
1032+
: LLVMContext(std::make_unique<llvm::LLVMContext>()),
1033+
CI(CI),
10341034
MostRecentModule(CI.getMainModule()),
10351035
CmdLine(CmdLine),
10361036
RanGlobalInitializers(false),
1037-
LLVMContext(LLVMCtx),
1038-
Module(new llvm::Module("REPL", LLVMContext)),
1039-
DumpModule("REPL", LLVMContext),
1037+
Module(new llvm::Module("REPL", *LLVMContext.get())),
1038+
DumpModule("REPL", *LLVMContext.get()),
10401039
IRGenOpts(),
10411040
SILOpts(),
10421041
Input(*this)
@@ -1281,7 +1280,7 @@ void PrettyStackTraceREPL::print(llvm::raw_ostream &out) const {
12811280

12821281
void swift::runREPL(CompilerInstance &CI, const ProcessCmdLine &CmdLine,
12831282
bool ParseStdlib) {
1284-
REPLEnvironment env(CI, CmdLine, getGlobalLLVMContext(), ParseStdlib);
1283+
REPLEnvironment env(CI, CmdLine, ParseStdlib);
12851284
if (CI.getASTContext().hadError())
12861285
return;
12871286

0 commit comments

Comments
 (0)