mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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:
@@ -179,7 +179,7 @@ public:
|
||||
StandardLibrary,
|
||||
Library,
|
||||
Main,
|
||||
Repl,
|
||||
REPL,
|
||||
SIL // Came from a .sil file.
|
||||
} Kind;
|
||||
|
||||
|
||||
@@ -243,7 +243,7 @@ void IRGenModule::emitTranslationUnit(TranslationUnit *tunit,
|
||||
attrs);
|
||||
llvm::Function *initFn = nullptr;
|
||||
if (tunit->Kind != TranslationUnit::Main &&
|
||||
tunit->Kind != TranslationUnit::Repl) {
|
||||
tunit->Kind != TranslationUnit::REPL) {
|
||||
// Create a global initializer for library modules.
|
||||
// FIXME: This is completely, utterly, wrong.
|
||||
initFn = llvm::Function::Create(fnType, llvm::GlobalValue::ExternalLinkage,
|
||||
@@ -258,7 +258,7 @@ void IRGenModule::emitTranslationUnit(TranslationUnit *tunit,
|
||||
|
||||
SmallVector<llvm::Constant *, 2> allInits;
|
||||
if (tunit->Kind == TranslationUnit::Main ||
|
||||
tunit->Kind == TranslationUnit::Repl) {
|
||||
tunit->Kind == TranslationUnit::REPL) {
|
||||
// We don't need global init to call main().
|
||||
} else if (isTrivialGlobalInit(topLevelCodeFn)) {
|
||||
// Not all translation units need a global initialization function.
|
||||
@@ -292,7 +292,7 @@ void IRGenModule::emitTranslationUnit(TranslationUnit *tunit,
|
||||
emitGlobalLists();
|
||||
|
||||
if (tunit->Kind == TranslationUnit::Main ||
|
||||
tunit->Kind == TranslationUnit::Repl) {
|
||||
tunit->Kind == TranslationUnit::REPL) {
|
||||
// Emit main().
|
||||
// FIXME: We should only emit this in non-JIT modes.
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ bool swift::parseIntoTranslationUnit(TranslationUnit *TU,
|
||||
SILModule *SIL) {
|
||||
Parser P(BufferID, TU, BufferOffset ? *BufferOffset : 0, BufferEndOffset,
|
||||
TU->Kind == TranslationUnit::Main ||
|
||||
TU->Kind == TranslationUnit::Repl, SIL);
|
||||
TU->Kind == TranslationUnit::REPL, SIL);
|
||||
PrettyStackTraceParser stackTrace(P);
|
||||
bool FoundSideEffects = P.parseTranslationUnit(TU);
|
||||
if (BufferOffset)
|
||||
|
||||
@@ -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
|
||||
// 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.
|
||||
if (TU->Kind == TranslationUnit::SIL && moduleID.first.str() == "Builtin")
|
||||
// The Builtin module cannot be explicitly imported unless we're a .sil file
|
||||
// or in the REPL.
|
||||
if ((TU->Kind == TranslationUnit::SIL || TU->Kind == TranslationUnit::REPL) &&
|
||||
moduleID.first.str() == "Builtin")
|
||||
return TU->Ctx.TheBuiltinModule;
|
||||
|
||||
// If the imported module name is the same as the current translation unit,
|
||||
|
||||
@@ -533,7 +533,7 @@ Stmt *StmtChecker::visitBraceStmt(BraceStmt *BS) {
|
||||
// Type check the expression.
|
||||
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);
|
||||
elem = SubExpr;
|
||||
continue;
|
||||
|
||||
@@ -934,7 +934,7 @@ void swift::performTypeChecking(TranslationUnit *TU, unsigned StartElem) {
|
||||
|
||||
// If we're in REPL mode, inject temporary result variables and other stuff
|
||||
// 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);
|
||||
|
||||
// Check overloaded vars/funcs.
|
||||
|
||||
@@ -107,7 +107,7 @@ bool swift::appendToREPLTranslationUnit(TranslationUnit *TU,
|
||||
llvm::MemoryBuffer *Buffer,
|
||||
unsigned &BufferOffset,
|
||||
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
|
||||
= TU->getASTContext().SourceMgr.AddNewSourceBuffer(Buffer, llvm::SMLoc());
|
||||
|
||||
@@ -980,7 +980,7 @@ public:
|
||||
CmdLine(CmdLine),
|
||||
Comp(new (Context.Allocate<Component>(1)) Component()),
|
||||
TU(new (Context) TranslationUnit(Context.getIdentifier("REPL"),
|
||||
Comp, Context, TranslationUnit::Repl)),
|
||||
Comp, Context, TranslationUnit::REPL)),
|
||||
RanGlobalInitializers(false),
|
||||
Module("REPL", LLVMContext),
|
||||
DumpModule("REPL", LLVMContext),
|
||||
|
||||
Reference in New Issue
Block a user