Skip to content

Commit 56f6d9e

Browse files
authored
Merge pull request swiftlang#33805 from slavapestov/remove-enable-astscope-lookup-flag
Remove -enable-astscope-lookup flag
2 parents a7e8dbf + 193cf0d commit 56f6d9e

19 files changed

+56
-378
lines changed

include/swift/AST/ASTScope.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,10 @@
4444
/// try disabling it.
4545
/// \p message must be a string literal
4646
#define ASTScopeAssert(predicate, message) \
47-
assert((predicate) && message \
48-
" Try compiling with '-disable-astscope-lookup'.")
47+
assert((predicate) && message)
4948

5049
#define ASTScope_unreachable(message) \
51-
llvm_unreachable(message " Try compiling with '-disable-astscope-lookup'.")
50+
llvm_unreachable(message)
5251

5352
namespace swift {
5453

include/swift/AST/SourceFile.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,7 @@ class SourceFile final : public FileUnit {
236236
}
237237

238238
/// Add a hoisted declaration. See Decl::isHoisted().
239-
void addHoistedDecl(Decl *d) {
240-
Hoisted.push_back(d);
241-
}
239+
void addHoistedDecl(Decl *d);
242240

243241
/// Retrieves an immutable view of the list of top-level decls in this file.
244242
ArrayRef<Decl *> getTopLevelDecls() const;

include/swift/Basic/LangOptions.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -248,25 +248,12 @@ namespace swift {
248248
/// This is a staging flag; eventually it will be removed.
249249
bool EnableDeserializationRecovery = true;
250250

251-
/// Should we use \c ASTScope-based resolution for unqualified name lookup?
252-
/// Default is in \c ParseLangArgs
253-
///
254-
/// This is a staging flag; eventually it will be removed.
255-
bool EnableASTScopeLookup = true;
256-
257251
/// Someday, ASTScopeLookup will supplant lookup in the parser
258252
bool DisableParserLookup = false;
259253

260-
/// Should we compare to ASTScope-based resolution for debugging?
261-
bool CrosscheckUnqualifiedLookup = false;
262-
263254
/// Should we stress ASTScope-based resolution for debugging?
264255
bool StressASTScopeLookup = false;
265256

266-
/// Since some tests fail if the warning is output, use a flag to decide
267-
/// whether it is. The warning is useful for testing.
268-
bool WarnIfASTScopeLookup = false;
269-
270257
/// Build the ASTScope tree lazily
271258
bool LazyASTScopes = true;
272259

include/swift/Frontend/Frontend.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,6 @@ class CompilerInvocation {
328328
return CodeCompletionOffset != ~0U;
329329
}
330330

331-
/// Called from lldb, see rdar://53971116
332-
void disableASTScopeLookup() {
333-
LangOpts.EnableASTScopeLookup = false;
334-
}
335-
336331
/// Retrieve a module hash string that is suitable for uniquely
337332
/// identifying the conditions under which the module was built, for use
338333
/// in generating a cached PCH file for the bridging header.

include/swift/Option/FrontendOptions.td

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,6 @@ def crosscheck_unqualified_lookup : Flag<["-"], "crosscheck-unqualified-lookup">
160160
def stress_astscope_lookup : Flag<["-"], "stress-astscope-lookup">,
161161
HelpText<"Stress ASTScope-based unqualified name lookup (for testing)">;
162162

163-
def warn_if_astscope_lookup : Flag<["-"], "warn-if-astscope-lookup">,
164-
HelpText<"Print a warning if ASTScope lookup is used">;
165-
166163
def lazy_astscopes : Flag<["-"], "lazy-astscopes">,
167164
HelpText<"Build ASTScopes lazily">;
168165

include/swift/Option/Options.td

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,14 +1107,6 @@ def scan_clang_dependencies : Flag<["-"], "scan-clang-dependencies">,
11071107
HelpText<"Scan dependencies of the given Clang module">, ModeOpt,
11081108
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild]>;
11091109

1110-
def enable_astscope_lookup : Flag<["-"], "enable-astscope-lookup">,
1111-
Flags<[FrontendOption]>,
1112-
HelpText<"Enable ASTScope-based unqualified name lookup">;
1113-
1114-
def disable_astscope_lookup : Flag<["-"], "disable-astscope-lookup">,
1115-
Flags<[FrontendOption]>,
1116-
HelpText<"Disable ASTScope-based unqualified name lookup">;
1117-
11181110
def disable_parser_lookup : Flag<["-"], "disable-parser-lookup">,
11191111
Flags<[FrontendOption]>,
11201112
HelpText<"Disable parser lookup & use ast scope lookup only (experimental)">;

lib/AST/ASTScopeCreation.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,8 +1086,6 @@ void ASTScopeImpl::disownDescendants(ScopeCreator &scopeCreator) {
10861086

10871087
ASTScopeImpl *
10881088
ASTScopeImpl::expandAndBeCurrentDetectingRecursion(ScopeCreator &scopeCreator) {
1089-
assert(scopeCreator.getASTContext().LangOpts.EnableASTScopeLookup &&
1090-
"Should not be getting here if ASTScopes are disabled");
10911089
return evaluateOrDefault(scopeCreator.getASTContext().evaluator,
10921090
ExpandASTScopeRequest{this, &scopeCreator}, nullptr);
10931091
}

lib/AST/Module.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,6 +2337,12 @@ bool SourceFile::hasDelayedBodyParsing() const {
23372337
return true;
23382338
}
23392339

2340+
/// Add a hoisted declaration. See Decl::isHoisted().
2341+
void SourceFile::addHoistedDecl(Decl *d) {
2342+
assert(d->isHoisted());
2343+
Hoisted.push_back(d);
2344+
}
2345+
23402346
ArrayRef<Decl *> SourceFile::getTopLevelDecls() const {
23412347
auto &ctx = getASTContext();
23422348
auto *mutableThis = const_cast<SourceFile *>(this);

lib/AST/UnqualifiedLookup.cpp

Lines changed: 0 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,6 @@ namespace {
235235

236236
bool useASTScopesForLookup() const;
237237

238-
/// For testing, assume this lookup is enabled:
239-
bool wouldUseASTScopesForLookupIfItWereEnabled() const;
240-
241238
void lookUpTopLevelNamesInModuleScopeContext(DeclContext *);
242239

243240
void lookInASTScopes();
@@ -399,13 +396,6 @@ namespace {
399396
void print(raw_ostream &OS) const;
400397
void printResults(raw_ostream &OS) const;
401398

402-
bool verifyEqualTo(const UnqualifiedLookupFactory &&, StringRef thisLabel,
403-
StringRef otherLabel) const;
404-
405-
/// Legacy lookup is wrong here; we should NOT find this symbol.
406-
bool shouldDiffer() const;
407-
StringRef getSourceFileName() const;
408-
409399
#ifndef NDEBUG
410400
bool isTargetLookup() const;
411401
void stopForDebuggingIfStartingTargetLookup(bool isASTScopeLookup) const;
@@ -497,14 +487,7 @@ void UnqualifiedLookupFactory::performUnqualifiedLookup() {
497487

498488
ContextAndUnresolvedIsCascadingUse contextAndIsCascadingUse{
499489
DC, initialIsCascadingUse};
500-
const bool crosscheckUnqualifiedLookup =
501-
Ctx.LangOpts.CrosscheckUnqualifiedLookup;
502490
if (useASTScopesForLookup()) {
503-
static bool haveWarned = false;
504-
if (!haveWarned && Ctx.LangOpts.WarnIfASTScopeLookup) {
505-
haveWarned = true;
506-
llvm::errs() << "WARNING: TRYING Scope exclusively\n";
507-
}
508491
lookInASTScopes();
509492
} else {
510493
#ifndef NDEBUG
@@ -516,28 +499,6 @@ void UnqualifiedLookupFactory::performUnqualifiedLookup() {
516499
else
517500
lookupNamesIntroducedBy(contextAndIsCascadingUse, NULL);
518501
}
519-
520-
if (crosscheckUnqualifiedLookup &&
521-
wouldUseASTScopesForLookupIfItWereEnabled()) {
522-
ResultsVector results;
523-
size_t indexOfFirstOuterResult = 0;
524-
UnqualifiedLookupFactory altLookup(Name, DC, Loc, options, results,
525-
indexOfFirstOuterResult);
526-
if (!useASTScopesForLookup())
527-
altLookup.lookInASTScopes();
528-
else if (Name.isOperator())
529-
altLookup.lookupOperatorInDeclContexts(contextAndIsCascadingUse);
530-
else
531-
altLookup.lookupNamesIntroducedBy(contextAndIsCascadingUse, NULL);
532-
533-
const auto *ASTScopeLabel = "ASTScope lookup";
534-
const auto *contextLabel = "context-bsed lookup";
535-
const auto *mainLabel =
536-
useASTScopesForLookup() ? ASTScopeLabel : contextLabel;
537-
const auto *alternateLabel =
538-
useASTScopesForLookup() ? contextLabel : ASTScopeLabel;
539-
assert(verifyEqualTo(std::move(altLookup), mainLabel, alternateLabel));
540-
}
541502
}
542503

543504
void UnqualifiedLookupFactory::lookUpTopLevelNamesInModuleScopeContext(
@@ -562,12 +523,6 @@ void UnqualifiedLookupFactory::lookUpTopLevelNamesInModuleScopeContext(
562523
}
563524

564525
bool UnqualifiedLookupFactory::useASTScopesForLookup() const {
565-
return Ctx.LangOpts.EnableASTScopeLookup &&
566-
wouldUseASTScopesForLookupIfItWereEnabled();
567-
}
568-
569-
bool UnqualifiedLookupFactory::wouldUseASTScopesForLookupIfItWereEnabled()
570-
const {
571526
if (!Loc.isValid())
572527
return false;
573528
return (bool) DC->getParentSourceFile();
@@ -1335,124 +1290,6 @@ void UnqualifiedLookupFactory::print(raw_ostream &OS) const {
13351290
OS << "\n";
13361291
}
13371292

1338-
#pragma mark debugging: output utilities for grepping
1339-
1340-
static void writeLine(std::string s) {
1341-
llvm::errs() << "\n+-+-+-+- " << s << "\n";
1342-
}
1343-
1344-
StringRef UnqualifiedLookupFactory::getSourceFileName() const {
1345-
return DC->getParentSourceFile()->getFilename();
1346-
}
1347-
1348-
static void writeFirstLine(const UnqualifiedLookupFactory &ul, llvm::Twine s) {
1349-
std::string line =
1350-
std::string("In file: ") + ul.getSourceFileName().str() + ", " + s.str();
1351-
writeLine(line);
1352-
}
1353-
1354-
static void writeInconsistent(const UnqualifiedLookupFactory &me,
1355-
StringRef thisLabel,
1356-
const UnqualifiedLookupFactory &other,
1357-
StringRef otherLabel, llvm::Twine s) {
1358-
writeFirstLine(me, s);
1359-
other.print(llvm::errs());
1360-
llvm::errs() << "\n" << thisLabel << " Results:\n";
1361-
me.printResults(llvm::errs());
1362-
llvm::errs() << "\n" << otherLabel << " Results:\n";
1363-
other.printResults(llvm::errs());
1364-
me.printScopes(llvm::errs());
1365-
}
1366-
1367-
#pragma mark comparing results
1368-
1369-
bool UnqualifiedLookupFactory::verifyEqualTo(
1370-
const UnqualifiedLookupFactory &&other, const StringRef thisLabel,
1371-
StringRef otherLabel) const {
1372-
if (shouldDiffer()) {
1373-
return true;
1374-
}
1375-
auto writeErr = [&](llvm::Twine s) {
1376-
writeInconsistent(*this, thisLabel, other, otherLabel, s);
1377-
};
1378-
if (Results.size() != other.Results.size()) {
1379-
writeErr(thisLabel + " found " + std::to_string(Results.size()) + " but " +
1380-
otherLabel + " found " + std::to_string(other.Results.size()));
1381-
assert(false && "mismatch in number of results");
1382-
}
1383-
for (size_t i : indices(Results)) {
1384-
const auto &e = Results[i];
1385-
const auto &oe = other.Results[i];
1386-
if (e.getValueDecl() != oe.getValueDecl()) {
1387-
// print_ast_tc_function_bodies.swift generic from subscript vs get fn
1388-
std::string a; llvm::raw_string_ostream as(a);
1389-
std::string b; llvm::raw_string_ostream bs(b);
1390-
e.getValueDecl()->print(as);
1391-
oe.getValueDecl()->print(bs);
1392-
if (a == b)
1393-
llvm::errs() << "ValueDecls differ but print same\n";
1394-
else {
1395-
writeErr(std::string( "ValueDecls differ at ") + std::to_string(i));
1396-
assert(false && "other lookup found different Decl");
1397-
}
1398-
}
1399-
if (e.getDeclContext() != oe.getDeclContext()) {
1400-
writeErr((std::string("Contexts differ at ")) + std::to_string(i));
1401-
assert(false && "ASTScopeImpl found different context");
1402-
}
1403-
// unsigned printContext(llvm::raw_ostream &OS, unsigned indent = 0,
1404-
// bool onlyAPartialLine = false) const;
1405-
}
1406-
if (IndexOfFirstOuterResult != other.IndexOfFirstOuterResult) {
1407-
writeErr( std::string("IndexOfFirstOuterResult differs, should be: ")
1408-
+ std::to_string(IndexOfFirstOuterResult)
1409-
+ std::string( ", is: ")
1410-
+ std::to_string(other.IndexOfFirstOuterResult));
1411-
assert(false && "other lookup IndexOfFirstOuterResult differs");
1412-
}
1413-
if (recordedSF != other.recordedSF) {
1414-
writeErr(std::string("recordedSF differs: shouldBe: ") +
1415-
(recordedSF ? recordedSF->getFilename().str()
1416-
: std::string("<no name>")) +
1417-
std::string(" is: ") +
1418-
(other.recordedSF ? other.recordedSF->getFilename().str()
1419-
: std::string("<no name>")));
1420-
assert(false && "other lookup recordedSF differs");
1421-
}
1422-
if (recordedSF && recordedIsCascadingUse != other.recordedIsCascadingUse) {
1423-
writeErr(std::string("recordedIsCascadingUse differs: shouldBe: ") +
1424-
std::to_string(recordedIsCascadingUse) + std::string(" is: ") +
1425-
std::to_string(other.recordedIsCascadingUse));
1426-
assert(false && "other lookup recordedIsCascadingUse differs");
1427-
}
1428-
return true;
1429-
}
1430-
1431-
bool UnqualifiedLookupFactory::shouldDiffer() const {
1432-
auto *SF = dyn_cast<SourceFile>(DC->getModuleScopeContext());
1433-
if (!SF)
1434-
return false;
1435-
1436-
static std::vector<const char*> testsThatShouldDiffer {
1437-
"swift/test/Constraints/diagnostics.swift",
1438-
"swift/test/Constraints/enum_cases.swift",
1439-
"swift/test/Constraints/rdar39401774.swift",
1440-
"swift/test/Constraints/rdar39401774-astscope.swift",
1441-
"swift/test/Interpreter/repl.swift",
1442-
"swift/test/Sema/diag_defer_captures.swift",
1443-
"swift/test/Sema/diag_use_before_declaration.swift",
1444-
"swift/test/SourceKit/CodeFormat/indent-closure.swift",
1445-
"swift/test/TypeCoercion/overload_noncall.swift",
1446-
"swift/test/expr/capture/nested_class.swift",
1447-
"swift/test/expr/capture/order.swift",
1448-
"swift/test/NameLookup/name_lookup2.swift"
1449-
};
1450-
StringRef fileName = SF->getFilename();
1451-
return llvm::any_of(testsThatShouldDiffer, [&](const char *testFile) {
1452-
return fileName.endswith(testFile);
1453-
});
1454-
}
1455-
14561293
#pragma mark breakpointing
14571294
#ifndef NDEBUG
14581295

lib/Driver/ToolChains.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,6 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
259259
inputArgs.AddLastArg(arguments, options::OPT_debug_diagnostic_names);
260260
inputArgs.AddLastArg(arguments, options::OPT_print_educational_notes);
261261
inputArgs.AddLastArg(arguments, options::OPT_diagnostic_style);
262-
inputArgs.AddLastArg(arguments, options::OPT_enable_astscope_lookup);
263-
inputArgs.AddLastArg(arguments, options::OPT_disable_astscope_lookup);
264262
inputArgs.AddLastArg(arguments, options::OPT_disable_parser_lookup);
265263
inputArgs.AddLastArg(arguments,
266264
options::OPT_enable_experimental_concise_pound_file);

lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -443,14 +443,7 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
443443
}
444444

445445
Opts.DisableParserLookup |= Args.hasArg(OPT_disable_parser_lookup);
446-
Opts.EnableASTScopeLookup =
447-
Args.hasFlag(options::OPT_enable_astscope_lookup,
448-
options::OPT_disable_astscope_lookup, Opts.EnableASTScopeLookup) ||
449-
Opts.DisableParserLookup;
450-
Opts.CrosscheckUnqualifiedLookup |=
451-
Args.hasArg(OPT_crosscheck_unqualified_lookup);
452446
Opts.StressASTScopeLookup |= Args.hasArg(OPT_stress_astscope_lookup);
453-
Opts.WarnIfASTScopeLookup |= Args.hasArg(OPT_warn_if_astscope_lookup);
454447
Opts.LazyASTScopes |= Args.hasArg(OPT_lazy_astscopes);
455448
Opts.EnableNewOperatorLookup = Args.hasFlag(OPT_enable_new_operator_lookup,
456449
OPT_disable_new_operator_lookup,

lib/Parse/ParseDecl.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,30 +104,24 @@ namespace {
104104
template <typename T>
105105
ParserResult<T>
106106
fixupParserResult(T *D) {
107-
if (movedToTopLevel()) {
108-
D->setHoisted();
109-
SF->addHoistedDecl(D);
110-
getDebuggerClient()->didGlobalize(D);
111-
}
107+
if (movedToTopLevel())
108+
hoistDecl(D);
112109
return ParserResult<T>(D);
113110
}
114111

115112
template <typename T>
116113
ParserResult<T>
117114
fixupParserResult(ParserStatus Status, T *D) {
118-
if (movedToTopLevel()) {
119-
D->setHoisted();
120-
SF->addHoistedDecl(D);
121-
getDebuggerClient()->didGlobalize(D);
122-
}
115+
if (movedToTopLevel())
116+
hoistDecl(D);
123117
return makeParserResult(Status, D);
124118
}
125119

126120
// The destructor doesn't need to do anything, the CC's destructor will
127121
// pop the context if we set it.
128122
~DebuggerContextChange () {}
129-
protected:
130-
123+
124+
private:
131125
DebuggerClient *getDebuggerClient() {
132126
ModuleDecl *M = P.CurDeclContext->getParentModule();
133127
return M->getDebugClient();
@@ -152,6 +146,13 @@ namespace {
152146
SF = P.CurDeclContext->getParentSourceFile();
153147
CC.emplace(P, SF);
154148
}
149+
150+
template<typename T>
151+
void hoistDecl(T *D) {
152+
D->setHoisted();
153+
SF->addHoistedDecl(D);
154+
getDebuggerClient()->didGlobalize(D);
155+
}
155156
};
156157
} // end anonymous namespace
157158

0 commit comments

Comments
 (0)