Skip to content

Commit b81c0d6

Browse files
committed
AST: Remove SourceFileKind::REPL
1 parent 2813f68 commit b81c0d6

15 files changed

+16
-48
lines changed

include/swift/AST/Module.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ enum class FileUnitKind {
107107
enum class SourceFileKind {
108108
Library, ///< A normal .swift file.
109109
Main, ///< A .swift file that can have top-level code.
110-
REPL, ///< A virtual file that holds the user's input in the REPL.
111110
SIL, ///< Came from a .sil file.
112111
Interface ///< Came from a .swiftinterface file, representing another module.
113112
};

include/swift/AST/SourceFile.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,6 @@ class SourceFile final : public FileUnit {
524524
bool isScriptMode() const {
525525
switch (Kind) {
526526
case SourceFileKind::Main:
527-
case SourceFileKind::REPL:
528527
return true;
529528

530529
case SourceFileKind::Library:

lib/AST/ASTVerifier.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,9 +1196,7 @@ class Verifier : public ASTWalker {
11961196
// it should be parented by the innermost function.
11971197
auto enclosingScope = Scopes[Scopes.size() - 2];
11981198
auto enclosingDC = enclosingScope.dyn_cast<DeclContext*>();
1199-
if (enclosingDC && !isa<AbstractClosureExpr>(enclosingDC)
1200-
&& !(isa<SourceFile>(enclosingDC)
1201-
&& cast<SourceFile>(enclosingDC)->Kind == SourceFileKind::REPL)){
1199+
if (enclosingDC && !isa<AbstractClosureExpr>(enclosingDC)){
12021200
auto parentDC = E->getParent();
12031201
if (!isa<Initializer>(parentDC)) {
12041202
Out << "a closure in non-local context should be parented "

lib/AST/Module.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,12 +1686,6 @@ SourceFile::collectLinkLibraries(ModuleDecl::LinkLibraryCallback callback) const
16861686
continue;
16871687

16881688
if (next->getName() != getParentModule()->getName()) {
1689-
// Hack: Assume other REPL files already have their libraries linked.
1690-
if (!next->getFiles().empty())
1691-
if (auto *nextSource = dyn_cast<SourceFile>(next->getFiles().front()))
1692-
if (nextSource->Kind == SourceFileKind::REPL)
1693-
continue;
1694-
16951689
next->collectLinkLibraries(callback);
16961690
}
16971691

@@ -2461,7 +2455,6 @@ bool SourceFile::shouldCollectToken() const {
24612455
case SourceFileKind::Main:
24622456
case SourceFileKind::Interface:
24632457
return (bool)AllCorrectedTokens;
2464-
case SourceFileKind::REPL:
24652458
case SourceFileKind::SIL:
24662459
return false;
24672460
}
@@ -2478,7 +2471,6 @@ bool SourceFile::canBeParsedInFull() const {
24782471
case SourceFileKind::Main:
24792472
case SourceFileKind::Interface:
24802473
return true;
2481-
case SourceFileKind::REPL:
24822474
case SourceFileKind::SIL:
24832475
return false;
24842476
}
@@ -2490,7 +2482,7 @@ bool SourceFile::hasDelayedBodyParsing() const {
24902482
return false;
24912483

24922484
// Not supported right now.
2493-
if (Kind == SourceFileKind::REPL || Kind == SourceFileKind::SIL)
2485+
if (Kind == SourceFileKind::SIL)
24942486
return false;
24952487
if (hasInterfaceHash())
24962488
return false;

lib/AST/TypeCheckRequests.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,6 @@ void TypeCheckSourceFileRequest::cacheResult(evaluator::SideEffect) const {
14681468
// skip verification and avoid caching it.
14691469
#ifndef NDEBUG
14701470
if (!Ctx.TypeCheckerOpts.DelayWholeModuleChecking &&
1471-
SF->Kind != SourceFileKind::REPL &&
14721471
SF->Kind != SourceFileKind::SIL &&
14731472
!Ctx.LangOpts.DebuggerSupport) {
14741473
Ctx.verifyAllLoadedModules();

lib/Frontend/CompilerInvocation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ SourceFileKind CompilerInvocation::getSourceFileKind() const {
197197
case InputFileKind::SwiftLibrary:
198198
return SourceFileKind::Library;
199199
case InputFileKind::SwiftREPL:
200-
return SourceFileKind::REPL;
200+
return SourceFileKind::Main;
201201
case InputFileKind::SwiftModuleInterface:
202202
return SourceFileKind::Interface;
203203
case InputFileKind::SIL:

lib/Frontend/Frontend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ void CompilerInstance::performSemaUpTo(SourceFile::ASTStage_t LimitStage) {
783783
// Create the initial empty REPL file. This only exists to feed in the
784784
// implicit imports such as the standard library.
785785
auto *replFile =
786-
createSourceFileForMainModule(SourceFileKind::REPL, /*BufferID*/ None);
786+
createSourceFileForMainModule(SourceFileKind::Main, /*BufferID*/ None);
787787
performImportResolution(*replFile);
788788
return;
789789
}

lib/IDE/REPLCodeCompletion.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ doCodeCompletion(SourceFile &SF, StringRef EnteredCode, unsigned *BufferID,
235235
auto *newModule = ModuleDecl::create(
236236
Ctx.getIdentifier("REPL_Code_Completion"), Ctx, implicitImports);
237237
auto &newSF =
238-
*new (Ctx) SourceFile(*newModule, SourceFileKind::REPL, *BufferID);
238+
*new (Ctx) SourceFile(*newModule, SourceFileKind::Main, *BufferID);
239239
newModule->addFile(newSF);
240240

241241
performImportResolution(newSF);
@@ -256,8 +256,6 @@ void REPLCompletions::populate(SourceFile &SF, StringRef EnteredCode) {
256256
CompletionStrings.clear();
257257
CookedResults.clear();
258258

259-
assert(SF.Kind == SourceFileKind::REPL && "Can't append to a non-REPL file");
260-
261259
unsigned BufferID;
262260
doCodeCompletion(SF, EnteredCode, &BufferID,
263261
CompletionCallbacksFactory.get());

lib/Parse/ParseDecl.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7414,7 +7414,6 @@ parseDeclDeinit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
74147414
break;
74157415
case SourceFileKind::Library:
74167416
case SourceFileKind::Main:
7417-
case SourceFileKind::REPL:
74187417
if (Tok.is(tok::identifier)) {
74197418
diagnose(Tok, diag::destructor_has_name).fixItRemove(Tok.getLoc());
74207419
consumeToken();

lib/Parse/Parser.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,6 @@ static LexerMode sourceFileKindToLexerMode(SourceFileKind kind) {
361361
return LexerMode::SIL;
362362
case swift::SourceFileKind::Library:
363363
case swift::SourceFileKind::Main:
364-
case swift::SourceFileKind::REPL:
365364
return LexerMode::Swift;
366365
}
367366
llvm_unreachable("covered switch");

lib/Sema/ImportResolution.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,8 @@ ImportResolver::getModule(ArrayRef<Located<Identifier>> modulePath) {
370370
assert(!modulePath.empty());
371371
auto moduleID = modulePath[0];
372372

373-
// The Builtin module cannot be explicitly imported unless we're a .sil file
374-
// or in the REPL.
375-
if ((SF.Kind == SourceFileKind::SIL || SF.Kind == SourceFileKind::REPL) &&
373+
// The Builtin module cannot be explicitly imported unless we're a .sil file.
374+
if (SF.Kind == SourceFileKind::SIL &&
376375
moduleID.Item == ctx.TheBuiltinModule->getName())
377376
return ctx.TheBuiltinModule;
378377

@@ -563,7 +562,7 @@ bool UnboundImport::checkModuleLoaded(ModuleDecl *M, SourceFile &SF) {
563562
[&] { modulePathStr += "."; });
564563

565564
auto diagKind = diag::sema_no_import;
566-
if (SF.Kind == SourceFileKind::REPL || ctx.LangOpts.DebuggerSupport)
565+
if (ctx.LangOpts.DebuggerSupport)
567566
diagKind = diag::sema_no_import_repl;
568567
ctx.Diags.diagnose(importLoc, diagKind, modulePathStr);
569568

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,6 @@ static void maybeDiagnoseClassWithoutInitializers(ClassDecl *classDecl) {
11791179
return;
11801180
case SourceFileKind::Library:
11811181
case SourceFileKind::Main:
1182-
case SourceFileKind::REPL:
11831182
break;
11841183
}
11851184
}
@@ -1499,7 +1498,6 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
14991498
case SourceFileKind::SIL:
15001499
return;
15011500
case SourceFileKind::Main:
1502-
case SourceFileKind::REPL:
15031501
case SourceFileKind::Library:
15041502
break;
15051503
}
@@ -1514,7 +1512,6 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
15141512
if (DC->isModuleScopeContext()) {
15151513
switch (SF->Kind) {
15161514
case SourceFileKind::Main:
1517-
case SourceFileKind::REPL:
15181515
case SourceFileKind::Interface:
15191516
case SourceFileKind::SIL:
15201517
return;
@@ -2121,7 +2118,6 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
21212118
return false;
21222119
case SourceFileKind::Library:
21232120
case SourceFileKind::Main:
2124-
case SourceFileKind::REPL:
21252121
break;
21262122
}
21272123
}

lib/Sema/TypeCheckStmt.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,6 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
320320

321321
SourceLoc EndTypeCheckLoc;
322322

323-
/// Used to check for discarded expression values: in the REPL top-level
324-
/// expressions are not discarded.
325-
bool IsREPL;
326-
327323
/// Used to distinguish the first BraceStmt that starts a TopLevelCodeDecl.
328324
bool IsBraceStmtFromTopLevelDecl;
329325

@@ -369,20 +365,16 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
369365
};
370366

371367
StmtChecker(AbstractFunctionDecl *AFD)
372-
: Ctx(AFD->getASTContext()), TheFunc(AFD), DC(AFD), IsREPL(false),
368+
: Ctx(AFD->getASTContext()), TheFunc(AFD), DC(AFD),
373369
IsBraceStmtFromTopLevelDecl(false) {}
374370

375371
StmtChecker(ClosureExpr *TheClosure)
376372
: Ctx(TheClosure->getASTContext()), TheFunc(TheClosure),
377-
DC(TheClosure), IsREPL(false), IsBraceStmtFromTopLevelDecl(false) {}
373+
DC(TheClosure), IsBraceStmtFromTopLevelDecl(false) {}
378374

379375
StmtChecker(DeclContext *DC)
380-
: Ctx(DC->getASTContext()), TheFunc(), DC(DC), IsREPL(false),
376+
: Ctx(DC->getASTContext()), TheFunc(), DC(DC),
381377
IsBraceStmtFromTopLevelDecl(false) {
382-
if (const SourceFile *SF = DC->getParentSourceFile())
383-
if (SF->Kind == SourceFileKind::REPL)
384-
IsREPL = true;
385-
386378
IsBraceStmtFromTopLevelDecl = isa<TopLevelCodeDecl>(DC);
387379
}
388380

@@ -1579,9 +1571,8 @@ Stmt *StmtChecker::visitBraceStmt(BraceStmt *BS) {
15791571

15801572
// Type check the expression.
15811573
TypeCheckExprOptions options = TypeCheckExprFlags::IsExprStmt;
1582-
bool isDiscarded = !(IsREPL && isa<TopLevelCodeDecl>(DC))
1583-
&& !getASTContext().LangOpts.Playground
1584-
&& !getASTContext().LangOpts.DebuggerSupport;
1574+
bool isDiscarded = (!getASTContext().LangOpts.Playground &&
1575+
!getASTContext().LangOpts.DebuggerSupport);
15851576
if (isDiscarded)
15861577
options |= TypeCheckExprFlags::IsDiscarded;
15871578

lib/Sema/TypeChecker.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,7 @@ void swift::performWholeModuleTypeChecking(SourceFile &SF) {
394394
// FIXME: some playgrounds tests (playground_lvalues.swift) fail with
395395
// verification enabled.
396396
#if 0
397-
if (SF.Kind != SourceFileKind::REPL &&
398-
SF.Kind != SourceFileKind::SIL &&
397+
if (SF.Kind != SourceFileKind::SIL &&
399398
!Ctx.LangOpts.DebuggerSupport) {
400399
Ctx.verifyAllLoadedModules();
401400
}

tools/swift-ide-test/swift-ide-test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ static int doREPLCodeCompletion(const CompilerInvocation &InitInvok,
900900
registerIDERequestFunctions(CI.getASTContext().evaluator);
901901
CI.performSema();
902902

903-
SourceFile &SF = CI.getMainModule()->getMainSourceFile(SourceFileKind::REPL);
903+
SourceFile &SF = CI.getMainModule()->getMainSourceFile(SourceFileKind::Main);
904904

905905
REPLCompletions REPLCompl;
906906
REPLCompl.populate(SF, BufferText);
@@ -1656,7 +1656,7 @@ static int doInputCompletenessTest(StringRef SourceFilename) {
16561656
llvm::raw_ostream &OS = llvm::outs();
16571657
OS << SourceFilename << ": ";
16581658
if (isSourceInputComplete(std::move(FileBuf),
1659-
SourceFileKind::REPL).IsComplete) {
1659+
SourceFileKind::Main).IsComplete) {
16601660
OS << "IS_COMPLETE\n";
16611661
} else {
16621662
OS << "IS_INCOMPLETE\n";

0 commit comments

Comments
 (0)