Skip to content

Commit 499fe6d

Browse files
authored
Merge pull request swiftlang#77072 from hamishknight/complete-options
[IDE] Pass LangOptions to `ide::isSourceInputComplete`
2 parents e3d53dc + b840730 commit 499fe6d

File tree

11 files changed

+52
-117
lines changed

11 files changed

+52
-117
lines changed

include/swift/IDE/Utils.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,11 @@ struct SourceCompleteResult {
8080
};
8181

8282
SourceCompleteResult
83-
isSourceInputComplete(std::unique_ptr<llvm::MemoryBuffer> MemBuf, SourceFileKind SFKind);
84-
SourceCompleteResult isSourceInputComplete(StringRef Text, SourceFileKind SFKind);
83+
isSourceInputComplete(std::unique_ptr<llvm::MemoryBuffer> MemBuf,
84+
SourceFileKind SFKind, const LangOptions &LangOpts);
85+
SourceCompleteResult isSourceInputComplete(StringRef Text,
86+
SourceFileKind SFKind,
87+
const LangOptions &LangOpts);
8588

8689
/// Visits all overridden declarations exhaustively from VD, including protocol
8790
/// conformances and clang declarations.

include/swift/Subsystems.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,7 @@ namespace swift {
321321
class ParserUnit {
322322
public:
323323
ParserUnit(SourceManager &SM, SourceFileKind SFKind, unsigned BufferID,
324-
const LangOptions &LangOpts, const TypeCheckerOptions &TyOpts,
325-
const SILOptions &SILOpts, StringRef ModuleName);
324+
const LangOptions &LangOpts, StringRef ModuleName);
326325
ParserUnit(SourceManager &SM, SourceFileKind SFKind, unsigned BufferID);
327326
ParserUnit(SourceManager &SM, SourceFileKind SFKind, unsigned BufferID,
328327
unsigned Offset, unsigned EndOffset);

lib/DriverTool/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ set(driver_sources_and_options
1111
modulewrap_main.cpp
1212
swift_api_digester_main.cpp
1313
swift_cache_tool_main.cpp
14-
swift_indent_main.cpp
1514
swift_symbolgraph_extract_main.cpp
1615
swift_synthesize_interface_main.cpp
1716
swift_parse_test_main.cpp)

lib/DriverTool/swift_indent_main.cpp

-78
This file was deleted.

lib/IDE/Utils.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ static const char *skipStringInCode(const char *p, const char *End) {
9696

9797
SourceCompleteResult
9898
ide::isSourceInputComplete(std::unique_ptr<llvm::MemoryBuffer> MemBuf,
99-
SourceFileKind SFKind) {
99+
SourceFileKind SFKind, const LangOptions &LangOpts) {
100100
SourceManager SM;
101101
auto BufferID = SM.addNewSourceBuffer(std::move(MemBuf));
102-
ParserUnit Parse(SM, SFKind, BufferID);
102+
ParserUnit Parse(SM, SFKind, BufferID, LangOpts, "input");
103103
Parse.parse();
104104
SourceCompleteResult SCR;
105105
SCR.IsComplete = !Parse.getParser().isInputIncomplete();
@@ -177,10 +177,11 @@ ide::isSourceInputComplete(std::unique_ptr<llvm::MemoryBuffer> MemBuf,
177177
return SCR;
178178
}
179179

180-
SourceCompleteResult
181-
ide::isSourceInputComplete(StringRef Text,SourceFileKind SFKind) {
180+
SourceCompleteResult ide::isSourceInputComplete(StringRef Text,
181+
SourceFileKind SFKind,
182+
const LangOptions &LangOpts) {
182183
return ide::isSourceInputComplete(llvm::MemoryBuffer::getMemBufferCopy(Text),
183-
SFKind);
184+
SFKind, LangOpts);
184185
}
185186

186187
template <typename FnTy>

lib/Parse/ParseDecl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2135,7 +2135,7 @@ AvailabilityMacroMap &Parser::parseAllAvailabilityMacroArguments() {
21352135
for (unsigned bufferID: bufferIDs) {
21362136
// Create temporary parser.
21372137
swift::ParserUnit PU(SM, SourceFileKind::Main, bufferID, LangOpts,
2138-
TypeCheckerOptions(), SILOptions(), "unknown");
2138+
"unknown");
21392139

21402140
ForwardingDiagnosticConsumer PDC(Context.Diags);
21412141
PU.getDiagnosticEngine().addConsumer(PDC);

lib/Parse/Parser.cpp

+7-11
Original file line numberDiff line numberDiff line change
@@ -1132,9 +1132,9 @@ struct ParserUnit::Implementation {
11321132
std::unique_ptr<Parser> TheParser;
11331133

11341134
Implementation(SourceManager &SM, SourceFileKind SFKind, unsigned BufferID,
1135-
const LangOptions &Opts, const TypeCheckerOptions &TyOpts,
1136-
const SILOptions &silOpts, StringRef ModuleName)
1137-
: LangOpts(Opts), TypeCheckerOpts(TyOpts), SILOpts(silOpts), Diags(SM),
1135+
const LangOptions &Opts, StringRef ModuleName)
1136+
: LangOpts(Opts), TypeCheckerOpts(TypeCheckerOptions()),
1137+
SILOpts(SILOptions()), Diags(SM),
11381138
Ctx(*ASTContext::get(LangOpts, TypeCheckerOpts, SILOpts, SearchPathOpts,
11391139
clangImporterOpts, symbolGraphOpts, CASOpts, SM,
11401140
Diags)) {
@@ -1156,23 +1156,19 @@ struct ParserUnit::Implementation {
11561156

11571157
ParserUnit::ParserUnit(SourceManager &SM, SourceFileKind SFKind,
11581158
unsigned BufferID)
1159-
: ParserUnit(SM, SFKind, BufferID, LangOptions(), TypeCheckerOptions(),
1160-
SILOptions(), "input") {}
1159+
: ParserUnit(SM, SFKind, BufferID, LangOptions(), "input") {}
11611160

11621161
ParserUnit::ParserUnit(SourceManager &SM, SourceFileKind SFKind,
11631162
unsigned BufferID, const LangOptions &LangOpts,
1164-
const TypeCheckerOptions &TypeCheckOpts,
1165-
const SILOptions &SILOpts, StringRef ModuleName)
1166-
: Impl(*new Implementation(SM, SFKind, BufferID, LangOpts, TypeCheckOpts,
1167-
SILOpts, ModuleName)) {
1163+
StringRef ModuleName)
1164+
: Impl(*new Implementation(SM, SFKind, BufferID, LangOpts, ModuleName)) {
11681165
Impl.TheParser.reset(new Parser(BufferID, *Impl.SF, /*SIL=*/nullptr,
11691166
/*PersistentState=*/nullptr));
11701167
}
11711168

11721169
ParserUnit::ParserUnit(SourceManager &SM, SourceFileKind SFKind,
11731170
unsigned BufferID, unsigned Offset, unsigned EndOffset)
1174-
: Impl(*new Implementation(SM, SFKind, BufferID, LangOptions(),
1175-
TypeCheckerOptions(), SILOptions(), "input")) {
1171+
: Impl(*new Implementation(SM, SFKind, BufferID, LangOptions(), "input")) {
11761172

11771173
std::unique_ptr<Lexer> Lex;
11781174
Lex.reset(new Lexer(Impl.LangOpts, SM,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
4+
// Make sure we consider the below source complete.
5+
// RUN: %swift-ide-test -test-input-complete -enable-bare-slash-regex -source-filename %t/bare-slash.swift | %FileCheck %s -check-prefix=COMPLETE
6+
7+
// Bare slash is currently disabled by default.
8+
// RUN: %swift-ide-test -test-input-complete -source-filename %t/bare-slash.swift | %FileCheck %s -check-prefix=INCOMPLETE
9+
10+
// RUN: %swift-ide-test -test-input-complete -source-filename %t/extended.swift | %FileCheck %s -check-prefix=COMPLETE
11+
12+
// INCOMPLETE: IS_INCOMPLETE
13+
// COMPLETE: IS_COMPLETE
14+
15+
//--- bare-slash.swift
16+
/\(/
17+
18+
//--- extended.swift
19+
#/\(/#

tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -745,10 +745,9 @@ class SwiftDocumentSyntaxInfo {
745745

746746
BufferID = SM.addNewSourceBuffer(std::move(BufCopy));
747747

748-
Parser.reset(new ParserUnit(
749-
SM, SourceFileKind::Main, BufferID, CompInv.getLangOptions(),
750-
CompInv.getTypeCheckerOptions(), CompInv.getSILOptions(),
751-
CompInv.getModuleName()));
748+
Parser.reset(new ParserUnit(SM, SourceFileKind::Main, BufferID,
749+
CompInv.getLangOptions(),
750+
CompInv.getModuleName()));
752751

753752
registerTypeCheckerRequestFunctions(
754753
Parser->getParser().Context.evaluator);

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

+9-11
Original file line numberDiff line numberDiff line change
@@ -2000,10 +2000,8 @@ static int doSyntaxColoring(const CompilerInvocation &InitInvok,
20002000
SourceManager SM;
20012001
unsigned BufferID = SM.addNewSourceBuffer(std::move(FileBuf));
20022002

2003-
ParserUnit Parser(
2004-
SM, SourceFileKind::Main, BufferID, Invocation.getLangOptions(),
2005-
Invocation.getTypeCheckerOptions(), Invocation.getSILOptions(),
2006-
Invocation.getModuleName());
2003+
ParserUnit Parser(SM, SourceFileKind::Main, BufferID,
2004+
Invocation.getLangOptions(), Invocation.getModuleName());
20072005

20082006
registerTypeCheckerRequestFunctions(Parser.getParser().Context.evaluator);
20092007
registerClangImporterRequestFunctions(Parser.getParser().Context.evaluator);
@@ -2229,9 +2227,7 @@ static int doStructureAnnotation(const CompilerInvocation &InitInvok,
22292227
unsigned BufferID = SM.addNewSourceBuffer(std::move(FileBuf));
22302228

22312229
ParserUnit Parser(SM, SourceFileKind::Main, BufferID,
2232-
Invocation.getLangOptions(),
2233-
Invocation.getTypeCheckerOptions(),
2234-
Invocation.getSILOptions(), Invocation.getModuleName());
2230+
Invocation.getLangOptions(), Invocation.getModuleName());
22352231

22362232
registerTypeCheckerRequestFunctions(
22372233
Parser.getParser().Context.evaluator);
@@ -2512,15 +2508,17 @@ static int doSemanticAnnotation(const CompilerInvocation &InitInvok,
25122508
return 0;
25132509
}
25142510

2515-
static int doInputCompletenessTest(StringRef SourceFilename) {
2511+
static int doInputCompletenessTest(const CompilerInvocation &InitInvok,
2512+
StringRef SourceFilename) {
25162513
std::unique_ptr<llvm::MemoryBuffer> FileBuf;
25172514
if (setBufferForFile(SourceFilename, FileBuf))
25182515
return 1;
25192516

25202517
llvm::raw_ostream &OS = llvm::outs();
25212518
OS << SourceFilename << ": ";
2522-
if (isSourceInputComplete(std::move(FileBuf),
2523-
SourceFileKind::Main).IsComplete) {
2519+
if (isSourceInputComplete(std::move(FileBuf), SourceFileKind::Main,
2520+
InitInvok.getLangOptions())
2521+
.IsComplete) {
25242522
OS << "IS_COMPLETE\n";
25252523
} else {
25262524
OS << "IS_INCOMPLETE\n";
@@ -4748,7 +4746,7 @@ int main(int argc, char *argv[]) {
47484746
break;
47494747

47504748
case ActionType::TestInputCompleteness:
4751-
ExitCode = doInputCompletenessTest(options::SourceFilename);
4749+
ExitCode = doInputCompletenessTest(InitInvok, options::SourceFilename);
47524750
break;
47534751

47544752
case ActionType::PrintASTNotTypeChecked:

unittests/Parse/TokenizerTests.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ class TokenizerTest : public ::testing::Test {
8282
}
8383

8484
std::vector<Token> parseAndGetSplitTokens(unsigned BufID) {
85-
swift::ParserUnit PU(SM, SourceFileKind::Main, BufID, LangOpts,
86-
TypeCheckerOptions(), SILOptions(), "unknown");
85+
swift::ParserUnit PU(SM, SourceFileKind::Main, BufID, LangOpts, "unknown");
8786
SmallVector<ASTNode, 8> items;
8887
PU.getParser().parseTopLevelItems(items);
8988
return PU.getParser().getSplitTokens();

0 commit comments

Comments
 (0)