In the REPL, allow access to the Builtin module if explicitly imported,

there is no reason to deny it and it could be theoretically useful.


Swift SVN r5779
This commit is contained in:
Chris Lattner
2013-06-24 16:07:56 +00:00
parent f4a4fad228
commit 1040bfec6a
8 changed files with 13 additions and 11 deletions

View File

@@ -179,7 +179,7 @@ public:
StandardLibrary, StandardLibrary,
Library, Library,
Main, Main,
Repl, REPL,
SIL // Came from a .sil file. SIL // Came from a .sil file.
} Kind; } Kind;

View File

@@ -243,7 +243,7 @@ void IRGenModule::emitTranslationUnit(TranslationUnit *tunit,
attrs); attrs);
llvm::Function *initFn = nullptr; llvm::Function *initFn = nullptr;
if (tunit->Kind != TranslationUnit::Main && if (tunit->Kind != TranslationUnit::Main &&
tunit->Kind != TranslationUnit::Repl) { tunit->Kind != TranslationUnit::REPL) {
// Create a global initializer for library modules. // Create a global initializer for library modules.
// FIXME: This is completely, utterly, wrong. // FIXME: This is completely, utterly, wrong.
initFn = llvm::Function::Create(fnType, llvm::GlobalValue::ExternalLinkage, initFn = llvm::Function::Create(fnType, llvm::GlobalValue::ExternalLinkage,
@@ -258,7 +258,7 @@ void IRGenModule::emitTranslationUnit(TranslationUnit *tunit,
SmallVector<llvm::Constant *, 2> allInits; SmallVector<llvm::Constant *, 2> allInits;
if (tunit->Kind == TranslationUnit::Main || if (tunit->Kind == TranslationUnit::Main ||
tunit->Kind == TranslationUnit::Repl) { tunit->Kind == TranslationUnit::REPL) {
// We don't need global init to call main(). // We don't need global init to call main().
} else if (isTrivialGlobalInit(topLevelCodeFn)) { } else if (isTrivialGlobalInit(topLevelCodeFn)) {
// Not all translation units need a global initialization function. // Not all translation units need a global initialization function.
@@ -292,7 +292,7 @@ void IRGenModule::emitTranslationUnit(TranslationUnit *tunit,
emitGlobalLists(); emitGlobalLists();
if (tunit->Kind == TranslationUnit::Main || if (tunit->Kind == TranslationUnit::Main ||
tunit->Kind == TranslationUnit::Repl) { tunit->Kind == TranslationUnit::REPL) {
// Emit main(). // Emit main().
// FIXME: We should only emit this in non-JIT modes. // FIXME: We should only emit this in non-JIT modes.

View File

@@ -50,7 +50,7 @@ bool swift::parseIntoTranslationUnit(TranslationUnit *TU,
SILModule *SIL) { SILModule *SIL) {
Parser P(BufferID, TU, BufferOffset ? *BufferOffset : 0, BufferEndOffset, Parser P(BufferID, TU, BufferOffset ? *BufferOffset : 0, BufferEndOffset,
TU->Kind == TranslationUnit::Main || TU->Kind == TranslationUnit::Main ||
TU->Kind == TranslationUnit::Repl, SIL); TU->Kind == TranslationUnit::REPL, SIL);
PrettyStackTraceParser stackTrace(P); PrettyStackTraceParser stackTrace(P);
bool FoundSideEffects = P.parseTranslationUnit(TU); bool FoundSideEffects = P.parseTranslationUnit(TU);
if (BufferOffset) if (BufferOffset)

View File

@@ -105,8 +105,10 @@ NameBinder::getModule(ArrayRef<std::pair<Identifier, SourceLoc>> modulePath) {
// fine for now since they are each a single file. Ultimately we'll want a // fine for now since they are each a single file. Ultimately we'll want a
// compiled form of AST's like clang's that support lazy deserialization. // compiled form of AST's like clang's that support lazy deserialization.
// The Builtin module cannot be explicitly imported unless we're a .sil file. // The Builtin module cannot be explicitly imported unless we're a .sil file
if (TU->Kind == TranslationUnit::SIL && moduleID.first.str() == "Builtin") // or in the REPL.
if ((TU->Kind == TranslationUnit::SIL || TU->Kind == TranslationUnit::REPL) &&
moduleID.first.str() == "Builtin")
return TU->Ctx.TheBuiltinModule; return TU->Ctx.TheBuiltinModule;
// If the imported module name is the same as the current translation unit, // If the imported module name is the same as the current translation unit,

View File

@@ -533,7 +533,7 @@ Stmt *StmtChecker::visitBraceStmt(BraceStmt *BS) {
// Type check the expression. // Type check the expression.
if (typeCheckExpr(SubExpr)) continue; if (typeCheckExpr(SubExpr)) continue;
if (TC.TU.Kind != TranslationUnit::Repl || !isa<TopLevelCodeDecl>(DC)) if (TC.TU.Kind != TranslationUnit::REPL || !isa<TopLevelCodeDecl>(DC))
TC.typeCheckIgnoredExpr(SubExpr); TC.typeCheckIgnoredExpr(SubExpr);
elem = SubExpr; elem = SubExpr;
continue; continue;

View File

@@ -934,7 +934,7 @@ void swift::performTypeChecking(TranslationUnit *TU, unsigned StartElem) {
// If we're in REPL mode, inject temporary result variables and other stuff // If we're in REPL mode, inject temporary result variables and other stuff
// that the REPL needs to synthesize. // that the REPL needs to synthesize.
if (TU->Kind == TranslationUnit::Repl && !TC.Context.hadError()) if (TU->Kind == TranslationUnit::REPL && !TC.Context.hadError())
TC.processREPLTopLevel(StartElem); TC.processREPLTopLevel(StartElem);
// Check overloaded vars/funcs. // Check overloaded vars/funcs.

View File

@@ -107,7 +107,7 @@ bool swift::appendToREPLTranslationUnit(TranslationUnit *TU,
llvm::MemoryBuffer *Buffer, llvm::MemoryBuffer *Buffer,
unsigned &BufferOffset, unsigned &BufferOffset,
unsigned BufferEndOffset) { unsigned BufferEndOffset) {
assert(TU->Kind == TranslationUnit::Repl && "Can't append to a non-REPL TU"); assert(TU->Kind == TranslationUnit::REPL && "Can't append to a non-REPL TU");
RC.CurBufferID RC.CurBufferID
= TU->getASTContext().SourceMgr.AddNewSourceBuffer(Buffer, llvm::SMLoc()); = TU->getASTContext().SourceMgr.AddNewSourceBuffer(Buffer, llvm::SMLoc());

View File

@@ -980,7 +980,7 @@ public:
CmdLine(CmdLine), CmdLine(CmdLine),
Comp(new (Context.Allocate<Component>(1)) Component()), Comp(new (Context.Allocate<Component>(1)) Component()),
TU(new (Context) TranslationUnit(Context.getIdentifier("REPL"), TU(new (Context) TranslationUnit(Context.getIdentifier("REPL"),
Comp, Context, TranslationUnit::Repl)), Comp, Context, TranslationUnit::REPL)),
RanGlobalInitializers(false), RanGlobalInitializers(false),
Module("REPL", LLVMContext), Module("REPL", LLVMContext),
DumpModule("REPL", LLVMContext), DumpModule("REPL", LLVMContext),