Skip to content

Commit 78e07c1

Browse files
authored
Merge pull request #31159 from CodaFi/track-star
Remove Fallback Infrastructure For Evaluator-Based Dependencies
2 parents f1ab4f8 + 5b22910 commit 78e07c1

23 files changed

+47
-335
lines changed

include/swift/AST/SourceFile.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ class SourceFile final : public FileUnit {
138138
TypeRefinementContext *TRC = nullptr;
139139

140140
/// If non-null, used to track name lookups that happen within this file.
141-
Optional<ReferencedNameTracker> ReferencedNames;
142141
Optional<ReferencedNameTracker> RequestReferencedNames;
143142

144143
/// The class in this file marked \@NS/UIApplicationMain.
@@ -452,13 +451,6 @@ class SourceFile final : public FileUnit {
452451

453452
virtual bool walk(ASTWalker &walker) override;
454453

455-
ReferencedNameTracker *getLegacyReferencedNameTracker() {
456-
return ReferencedNames ? ReferencedNames.getPointer() : nullptr;
457-
}
458-
const ReferencedNameTracker *getLegacyReferencedNameTracker() const {
459-
return ReferencedNames ? ReferencedNames.getPointer() : nullptr;
460-
}
461-
462454
ReferencedNameTracker *getRequestBasedReferencedNameTracker() {
463455
return RequestReferencedNames ? RequestReferencedNames.getPointer() : nullptr;
464456
}
@@ -472,8 +464,7 @@ class SourceFile final : public FileUnit {
472464
/// else reference dependencies will not be registered.
473465
void createReferencedNameTracker();
474466

475-
/// Retrieves the name tracker instance corresponding to
476-
/// \c EnableRequestBasedIncrementalDependencies
467+
/// Retrieves the appropriate referenced name tracker instance.
477468
///
478469
/// If incremental dependencies tracking is not enabled or \c createReferencedNameTracker()
479470
/// has not been invoked on this source file, the result is \c nullptr.

include/swift/Basic/LangOptions.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,6 @@ namespace swift {
347347
/// Enable verification when every SubstitutionMap is constructed.
348348
bool VerifyAllSubstitutionMaps = false;
349349

350-
/// If set to \c false, fall back to the legacy manual reference name tracking code.
351-
bool EnableRequestBasedIncrementalDependencies = true;
352-
353350
/// Sets the target we are building for and updates platform conditions
354351
/// to match.
355352
///

lib/AST/Module.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,10 +1279,6 @@ OperatorType *LookupOperatorRequest<OperatorType>::evaluate(
12791279
if (!result.hasValue())
12801280
return nullptr;
12811281

1282-
if (!result.getValue() ||
1283-
result.getValue()->getDeclContext()->getModuleScopeContext() != file) {
1284-
namelookup::recordLookupOfTopLevelName(file, desc.name, desc.isCascading);
1285-
}
12861282
if (!result.getValue()) {
12871283
result = lookupOperatorDeclForName<OperatorType>(file->getParentModule(),
12881284
desc.diagLoc, desc.name,
@@ -2605,19 +2601,13 @@ void SourceFile::setTypeRefinementContext(TypeRefinementContext *Root) {
26052601
}
26062602

26072603
void SourceFile::createReferencedNameTracker() {
2608-
assert(!ReferencedNames && "This file already has a name tracker.");
26092604
assert(!RequestReferencedNames && "This file already has a name tracker.");
2610-
ReferencedNames.emplace(ReferencedNameTracker());
26112605
RequestReferencedNames.emplace(ReferencedNameTracker());
26122606
}
26132607

26142608
const ReferencedNameTracker *
26152609
SourceFile::getConfiguredReferencedNameTracker() const {
2616-
if (getASTContext().LangOpts.EnableRequestBasedIncrementalDependencies) {
2617-
return getRequestBasedReferencedNameTracker();
2618-
} else {
2619-
return getLegacyReferencedNameTracker();
2620-
}
2610+
return getRequestBasedReferencedNameTracker();
26212611
}
26222612

26232613
ArrayRef<OpaqueTypeDecl *> SourceFile::getOpaqueReturnTypeDecls() {

lib/AST/NameLookup.cpp

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -707,20 +707,6 @@ void namelookup::filterForDiscriminator(SmallVectorImpl<Result> &results,
707707
template void namelookup::filterForDiscriminator<LookupResultEntry>(
708708
SmallVectorImpl<LookupResultEntry> &results, DebuggerClient *debugClient);
709709

710-
// FIXME(Evaluator Incremental Dependencies): Remove this function. It is
711-
// obviated by ModuleQualifiedLookupRequest and LookupInModuleRequest, which
712-
// both automatically register edges into the request-based name tracker.
713-
void namelookup::recordLookupOfTopLevelName(DeclContext *topLevelContext,
714-
DeclName name, bool isCascading) {
715-
auto SF = dyn_cast<SourceFile>(topLevelContext);
716-
if (!SF)
717-
return;
718-
auto *nameTracker = SF->getLegacyReferencedNameTracker();
719-
if (!nameTracker)
720-
return;
721-
nameTracker->addTopLevelName(name.getBaseName(), isCascading);
722-
}
723-
724710
namespace {
725711
/// Whether we're looking up outer results or not.
726712
enum class LookupOuterResults {
@@ -1370,51 +1356,6 @@ void ClassDecl::recordObjCMethod(AbstractFunctionDecl *method,
13701356
vec.push_back(method);
13711357
}
13721358

1373-
/// Configure name lookup for the given declaration context and options.
1374-
///
1375-
/// This utility is used by qualified name lookup.
1376-
static void configureLookup(const DeclContext *dc,
1377-
NLOptions options,
1378-
ReferencedNameTracker *&tracker,
1379-
bool &isLookupCascading) {
1380-
// Find the dependency tracker we'll need for this lookup.
1381-
tracker = nullptr;
1382-
if (auto containingSourceFile =
1383-
dyn_cast<SourceFile>(dc->getModuleScopeContext())) {
1384-
tracker = containingSourceFile->getLegacyReferencedNameTracker();
1385-
}
1386-
1387-
auto checkLookupCascading = [dc, options]() -> Optional<bool> {
1388-
switch (static_cast<unsigned>(options & NL_KnownDependencyMask)) {
1389-
case 0:
1390-
return dc->isCascadingContextForLookup(
1391-
/*functionsAreNonCascading=*/false);
1392-
case NL_KnownNonCascadingDependency:
1393-
return false;
1394-
case NL_KnownCascadingDependency:
1395-
return true;
1396-
case NL_KnownNoDependency:
1397-
return None;
1398-
default:
1399-
// FIXME: Use llvm::CountPopulation_64 when that's declared constexpr.
1400-
#if defined(__clang__) || defined(__GNUC__)
1401-
static_assert(__builtin_popcountll(NL_KnownDependencyMask) == 2,
1402-
"mask should only include four values");
1403-
#endif
1404-
llvm_unreachable("mask only includes four values");
1405-
}
1406-
};
1407-
1408-
// Determine whether a lookup here will cascade.
1409-
isLookupCascading = false;
1410-
if (tracker) {
1411-
if (auto maybeLookupCascade = checkLookupCascading())
1412-
isLookupCascading = maybeLookupCascade.getValue();
1413-
else
1414-
tracker = nullptr;
1415-
}
1416-
}
1417-
14181359
/// Determine whether the given declaration is an acceptable lookup
14191360
/// result when searching from the given DeclContext.
14201361
static bool isAcceptableLookupResult(const DeclContext *dc,
@@ -1580,11 +1521,6 @@ QualifiedLookupRequest::evaluate(Evaluator &eval, const DeclContext *DC,
15801521
using namespace namelookup;
15811522
QualifiedLookupResult decls;
15821523

1583-
// Configure lookup and dig out the tracker.
1584-
ReferencedNameTracker *tracker = nullptr;
1585-
bool isLookupCascading;
1586-
configureLookup(DC, options, tracker, isLookupCascading);
1587-
15881524
// Tracking for the nominal types we'll visit.
15891525
SmallVector<NominalTypeDecl *, 4> stack;
15901526
llvm::SmallPtrSet<NominalTypeDecl *, 4> visited;
@@ -1617,11 +1553,6 @@ QualifiedLookupRequest::evaluate(Evaluator &eval, const DeclContext *DC,
16171553
auto current = stack.back();
16181554
stack.pop_back();
16191555

1620-
// FIXME(Evaluator Incremental Dependencies): Remove this. Each direct
1621-
// lookup in the stack registers this edge automatically.
1622-
if (tracker)
1623-
tracker->addUsedMember({current, member.getBaseName()},isLookupCascading);
1624-
16251556
// Make sure we've resolved property wrappers, if we need them.
16261557
installPropertyWrapperMembersIfNeeded(current, member);
16271558

@@ -1721,20 +1652,11 @@ ModuleQualifiedLookupRequest::evaluate(Evaluator &eval, const DeclContext *DC,
17211652
using namespace namelookup;
17221653
QualifiedLookupResult decls;
17231654

1724-
// Configure lookup and dig out the tracker.
1725-
ReferencedNameTracker *tracker = nullptr;
1726-
bool isLookupCascading;
1727-
configureLookup(DC, options, tracker, isLookupCascading);
1728-
17291655
auto kind = (options & NL_OnlyTypes
17301656
? ResolutionKind::TypesOnly
17311657
: ResolutionKind::Overloadable);
17321658
auto topLevelScope = DC->getModuleScopeContext();
17331659
if (module == topLevelScope->getParentModule()) {
1734-
if (tracker) {
1735-
recordLookupOfTopLevelName(topLevelScope, member.getFullName(),
1736-
isLookupCascading);
1737-
}
17381660
lookupInModule(module, member.getFullName(), decls,
17391661
NLKind::QualifiedLookup, kind, topLevelScope);
17401662
} else {
@@ -1773,15 +1695,6 @@ AnyObjectLookupRequest::evaluate(Evaluator &evaluator, const DeclContext *dc,
17731695
using namespace namelookup;
17741696
QualifiedLookupResult decls;
17751697

1776-
// Configure lookup and dig out the tracker.
1777-
ReferencedNameTracker *tracker = nullptr;
1778-
bool isLookupCascading;
1779-
configureLookup(dc, options, tracker, isLookupCascading);
1780-
1781-
// Record this lookup.
1782-
if (tracker)
1783-
tracker->addDynamicLookupName(member.getBaseName(), isLookupCascading);
1784-
17851698
// Type-only lookup won't find anything on AnyObject.
17861699
if (options & NL_OnlyTypes)
17871700
return decls;

lib/AST/UnqualifiedLookup.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,6 @@ void UnqualifiedLookupFactory::setAsideUnavailableResults(
10481048

10491049
void UnqualifiedLookupFactory::recordDependencyOnTopLevelName(
10501050
DeclContext *topLevelContext, DeclNameRef name, bool isCascadingUse) {
1051-
recordLookupOfTopLevelName(topLevelContext, Name.getFullName(), isCascadingUse);
10521051
recordedSF = dyn_cast<SourceFile>(topLevelContext);
10531052
recordedIsCascadingUse = isCascadingUse;
10541053
}

lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
402402
}
403403

404404
Opts.DisableParserLookup |= Args.hasArg(OPT_disable_parser_lookup);
405-
Opts.EnableRequestBasedIncrementalDependencies =
406-
Args.hasFlag(OPT_enable_request_based_incremental_dependencies,
407-
OPT_disable_request_based_incremental_dependencies,
408-
Opts.EnableRequestBasedIncrementalDependencies);
409405
Opts.EnableASTScopeLookup =
410406
Args.hasFlag(options::OPT_enable_astscope_lookup,
411407
options::OPT_disable_astscope_lookup, Opts.EnableASTScopeLookup) ||

lib/Sema/CSApply.cpp

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Solution::computeSubstitutions(GenericSignature sig,
9191
// FIXME: Retrieve the conformance from the solution itself.
9292
return TypeChecker::conformsToProtocol(replacement, protoType,
9393
getConstraintSystem().DC,
94-
ConformanceCheckFlags::InExpression);
94+
None);
9595
};
9696

9797
return SubstitutionMap::get(sig,
@@ -499,9 +499,7 @@ namespace {
499499
// the protocol requirement with Self == the concrete type, and SILGen
500500
// (or later) can devirtualize as appropriate.
501501
auto conformance =
502-
TypeChecker::conformsToProtocol(
503-
baseTy, proto, cs.DC,
504-
ConformanceCheckFlags::InExpression);
502+
TypeChecker::conformsToProtocol(baseTy, proto, cs.DC, None);
505503
if (conformance.isConcrete()) {
506504
if (auto witness = conformance.getConcrete()->getWitnessDecl(decl)) {
507505
bool isMemberOperator = witness->getDeclContext()->isTypeContext();
@@ -2137,7 +2135,7 @@ namespace {
21372135
= TypeChecker::conformsToProtocol(valueType,
21382136
bridgedProto,
21392137
cs.DC,
2140-
ConformanceCheckFlags::InExpression);
2138+
None);
21412139

21422140
FuncDecl *fn = nullptr;
21432141

@@ -2397,8 +2395,7 @@ namespace {
23972395
ProtocolDecl *protocol = TypeChecker::getProtocol(
23982396
ctx, expr->getLoc(), KnownProtocolKind::ExpressibleByStringLiteral);
23992397

2400-
if (!TypeChecker::conformsToProtocol(
2401-
type, protocol, cs.DC, ConformanceCheckFlags::InExpression)) {
2398+
if (!TypeChecker::conformsToProtocol(type, protocol, cs.DC, None)) {
24022399
// If the type does not conform to ExpressibleByStringLiteral, it should
24032400
// be ExpressibleByExtendedGraphemeClusterLiteral.
24042401
protocol = TypeChecker::getProtocol(
@@ -2407,8 +2404,7 @@ namespace {
24072404
isStringLiteral = false;
24082405
isGraphemeClusterLiteral = true;
24092406
}
2410-
if (!TypeChecker::conformsToProtocol(
2411-
type, protocol, cs.DC, ConformanceCheckFlags::InExpression)) {
2407+
if (!TypeChecker::conformsToProtocol(type, protocol, cs.DC, None)) {
24122408
// ... or it should be ExpressibleByUnicodeScalarLiteral.
24132409
protocol = TypeChecker::getProtocol(
24142410
cs.getASTContext(), expr->getLoc(),
@@ -2523,8 +2519,7 @@ namespace {
25232519
assert(proto && "Missing string interpolation protocol?");
25242520

25252521
auto conformance =
2526-
TypeChecker::conformsToProtocol(type, proto, cs.DC,
2527-
ConformanceCheckFlags::InExpression);
2522+
TypeChecker::conformsToProtocol(type, proto, cs.DC, None);
25282523
assert(conformance && "string interpolation type conforms to protocol");
25292524

25302525
DeclName constrName(ctx, DeclBaseName::createConstructor(), argLabels);
@@ -2630,8 +2625,7 @@ namespace {
26302625
auto proto = TypeChecker::getLiteralProtocol(cs.getASTContext(), expr);
26312626
assert(proto && "Missing object literal protocol?");
26322627
auto conformance =
2633-
TypeChecker::conformsToProtocol(conformingType, proto, cs.DC,
2634-
ConformanceCheckFlags::InExpression);
2628+
TypeChecker::conformsToProtocol(conformingType, proto, cs.DC, None);
26352629
assert(conformance && "object literal type conforms to protocol");
26362630

26372631
auto constrName = TypeChecker::getObjectLiteralConstructorName(ctx, expr);
@@ -3336,8 +3330,7 @@ namespace {
33363330
assert(arrayProto && "type-checked array literal w/o protocol?!");
33373331

33383332
auto conformance =
3339-
TypeChecker::conformsToProtocol(arrayTy, arrayProto, cs.DC,
3340-
ConformanceCheckFlags::InExpression);
3333+
TypeChecker::conformsToProtocol(arrayTy, arrayProto, cs.DC, None);
33413334
assert(conformance && "Type does not conform to protocol?");
33423335

33433336
DeclName name(ctx, DeclBaseName::createConstructor(),
@@ -3382,7 +3375,7 @@ namespace {
33823375

33833376
auto conformance =
33843377
TypeChecker::conformsToProtocol(dictionaryTy, dictionaryProto, cs.DC,
3385-
ConformanceCheckFlags::InExpression);
3378+
None);
33863379
if (conformance.isInvalid())
33873380
return nullptr;
33883381

@@ -4121,8 +4114,7 @@ namespace {
41214114
// Special handle for literals conditional checked cast when they can
41224115
// be statically coerced to the cast type.
41234116
if (protocol && TypeChecker::conformsToProtocol(
4124-
toType, protocol, cs.DC,
4125-
ConformanceCheckFlags::InExpression)) {
4117+
toType, protocol, cs.DC, None)) {
41264118
ctx.Diags
41274119
.diagnose(expr->getLoc(),
41284120
diag::literal_conditional_downcast_to_coercion,
@@ -4999,8 +4991,7 @@ namespace {
49994991
// verified by the solver, we just need to get it again
50004992
// with all of the generic parameters resolved.
50014993
auto hashableConformance =
5002-
TypeChecker::conformsToProtocol(indexType, hashable, cs.DC,
5003-
ConformanceCheckFlags::InExpression);
4994+
TypeChecker::conformsToProtocol(indexType, hashable, cs.DC, None);
50044995
assert(hashableConformance);
50054996

50064997
conformances.push_back(hashableConformance);
@@ -5324,7 +5315,7 @@ collectExistentialConformances(Type fromType, Type toType,
53245315
SmallVector<ProtocolConformanceRef, 4> conformances;
53255316
for (auto proto : layout.getProtocols()) {
53265317
conformances.push_back(TypeChecker::containsProtocol(
5327-
fromType, proto->getDecl(), DC, ConformanceCheckFlags::InExpression));
5318+
fromType, proto->getDecl(), DC, None));
53285319
}
53295320

53305321
return toType->getASTContext().AllocateCopy(conformances);
@@ -6490,8 +6481,7 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
64906481
auto hashable = ctx.getProtocol(KnownProtocolKind::Hashable);
64916482
auto conformance =
64926483
TypeChecker::conformsToProtocol(
6493-
cs.getType(expr), hashable, cs.DC,
6494-
ConformanceCheckFlags::InExpression);
6484+
cs.getType(expr), hashable, cs.DC, None);
64956485
assert(conformance && "must conform to Hashable");
64966486

64976487
return cs.cacheType(
@@ -7026,7 +7016,7 @@ Expr *ExprRewriter::convertLiteralInPlace(Expr *literal,
70267016
// initialize via the builtin protocol.
70277017
if (builtinProtocol) {
70287018
auto builtinConformance = TypeChecker::conformsToProtocol(
7029-
type, builtinProtocol, cs.DC, ConformanceCheckFlags::InExpression);
7019+
type, builtinProtocol, cs.DC, None);
70307020
if (builtinConformance) {
70317021
// Find the witness that we'll use to initialize the type via a builtin
70327022
// literal.
@@ -7058,8 +7048,7 @@ Expr *ExprRewriter::convertLiteralInPlace(Expr *literal,
70587048

70597049
// This literal type must conform to the (non-builtin) protocol.
70607050
assert(protocol && "requirements should have stopped recursion");
7061-
auto conformance = TypeChecker::conformsToProtocol(type, protocol, cs.DC,
7062-
ConformanceCheckFlags::InExpression);
7051+
auto conformance = TypeChecker::conformsToProtocol(type, protocol, cs.DC, None);
70637052
assert(conformance && "must conform to literal protocol");
70647053

70657054
// Dig out the literal type and perform a builtin literal conversion to it.
@@ -7196,8 +7185,7 @@ ExprRewriter::buildDynamicCallable(ApplyExpr *apply, SelectedOverload selected,
71967185
auto dictLitProto =
71977186
ctx.getProtocol(KnownProtocolKind::ExpressibleByDictionaryLiteral);
71987187
auto conformance =
7199-
TypeChecker::conformsToProtocol(argumentType, dictLitProto, cs.DC,
7200-
ConformanceCheckFlags::InExpression);
7188+
TypeChecker::conformsToProtocol(argumentType, dictLitProto, cs.DC, None);
72017189
auto keyType = conformance.getTypeWitnessByName(argumentType, ctx.Id_Key);
72027190
auto valueType =
72037191
conformance.getTypeWitnessByName(argumentType, ctx.Id_Value);
@@ -8468,8 +8456,7 @@ ProtocolConformanceRef Solution::resolveConformance(
84688456
// itself rather than another conforms-to-protocol check.
84698457
Type substConformingType = simplifyType(conformingType);
84708458
return TypeChecker::conformsToProtocol(
8471-
substConformingType, proto, constraintSystem->DC,
8472-
ConformanceCheckFlags::InExpression);
8459+
substConformingType, proto, constraintSystem->DC, None);
84738460
}
84748461

84758462
return ProtocolConformanceRef::forInvalid();

0 commit comments

Comments
 (0)