Skip to content

Commit 83684eb

Browse files
committed
Sema: Remove LookupResult::Entry in favor of AST's LookupResultEntry
Both types store a base declaration and a result declaration; we can remove one. Soon, it will change to store a base declaration context, instead.
1 parent fb9d410 commit 83684eb

18 files changed

+113
-100
lines changed

lib/Sema/CSApply.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -7813,7 +7813,7 @@ Solution::convertBooleanTypeToBuiltinI1(Expr *expr, ConstraintLocator *locator)
78137813
tc.diagnose(expr->getLoc(), diag::broken_bool);
78147814
return nullptr;
78157815
}
7816-
auto *builtinMethod = dyn_cast<FuncDecl>(members[0].Decl);
7816+
auto *builtinMethod = dyn_cast<FuncDecl>(members[0].getValueDecl());
78177817
if (!builtinMethod) {
78187818
tc.diagnose(expr->getLoc(), diag::broken_bool);
78197819
return nullptr;

lib/Sema/CSDiag.cpp

+21-17
Original file line numberDiff line numberDiff line change
@@ -1561,8 +1561,8 @@ void CalleeCandidateInfo::collectCalleeCandidates(Expr *fn,
15611561
auto ctors = CS.TC.lookupConstructors(
15621562
CS.DC, instanceType, NameLookupFlags::IgnoreAccessibility);
15631563
for (auto ctor : ctors)
1564-
if (ctor->hasInterfaceType())
1565-
candidates.push_back({ ctor, 1 });
1564+
if (ctor.getValueDecl()->hasInterfaceType())
1565+
candidates.push_back({ ctor.getValueDecl(), 1 });
15661566
}
15671567

15681568
declName = instanceType->getString();
@@ -2490,10 +2490,10 @@ findCorrectEnumCaseName(Type Ty, LookupResult &Result,
24902490
return DeclName();
24912491
llvm::SmallVector<DeclName, 4> candidates;
24922492
for (auto &correction : Result) {
2493-
DeclName correctName = correction.Decl->getFullName();
2493+
DeclName correctName = correction.getValueDecl()->getFullName();
24942494
if (!correctName.isSimpleName())
24952495
continue;
2496-
if (!isa<EnumElementDecl>(correction.Decl))
2496+
if (!isa<EnumElementDecl>(correction.getValueDecl()))
24972497
continue;
24982498
if (correctName.getBaseIdentifier().str().equals_lower(
24992499
memberName.getBaseIdentifier().str()))
@@ -2571,7 +2571,8 @@ diagnoseUnviableLookupResults(MemberLookupResult &result, Type baseObjTy,
25712571

25722572
// Note all the correction candidates.
25732573
for (auto &correction : correctionResults) {
2574-
CS.TC.noteTypoCorrection(memberName, nameLoc, correction);
2574+
CS.TC.noteTypoCorrection(memberName, nameLoc,
2575+
correction.getValueDecl());
25752576
}
25762577

25772578
// TODO: recover?
@@ -2967,7 +2968,7 @@ bool FailureDiagnosis::diagnoseGeneralConversionFailure(Constraint *constraint){
29672968
auto LookupResult = CS.TC.lookupMember(
29682969
CS.DC, fromType, DeclName(CS.TC.Context.getIdentifier("boolValue")));
29692970
if (!LookupResult.empty()) {
2970-
if (isa<VarDecl>(LookupResult.begin()->Decl)) {
2971+
if (isa<VarDecl>(LookupResult.begin()->getValueDecl())) {
29712972
if (anchor->canAppendPostfixExpression())
29722973
diagnose(anchor->getLoc(), diag::types_not_convertible_use_bool_value,
29732974
fromType, toType).fixItInsertAfter(anchor->getEndLoc(),
@@ -4776,23 +4777,24 @@ static bool diagnoseImplicitSelfErrors(Expr *fnExpr, Expr *argExpr,
47764777

47774778
CandidateMap candidates;
47784779
for (const auto &candidate : result) {
4779-
auto base = candidate.Base;
4780-
if ((base && base->isInvalid()) || candidate->isInvalid())
4780+
auto base = candidate.getBaseDecl();
4781+
auto decl = candidate.getValueDecl();
4782+
if ((base && base->isInvalid()) || decl->isInvalid())
47814783
continue;
47824784

47834785
// If base is present but it doesn't represent a valid nominal,
47844786
// we can't use current candidate as one of the choices.
47854787
if (base && !base->getInterfaceType()->getNominalOrBoundGenericNominal())
47864788
continue;
47874789

4788-
auto context = candidate->getDeclContext();
4790+
auto context = decl->getDeclContext();
47894791
// We are only interested in static or global functions, because
47904792
// there is no way to call anything else properly.
4791-
if (!candidate->isStatic() && !context->isModuleScopeContext())
4793+
if (!decl->isStatic() && !context->isModuleScopeContext())
47924794
continue;
47934795

47944796
OverloadChoice choice(base ? base->getInterfaceType() : nullptr,
4795-
candidate, UDE->getFunctionRefKind());
4797+
decl, UDE->getFunctionRefKind());
47964798

47974799
if (base) { // Let's group all of the candidates have a common base.
47984800
candidates[base].push_back(choice);
@@ -7637,7 +7639,7 @@ static bool diagnoseKeyPathComponents(ConstraintSystem &CS, KeyPathExpr *KPE,
76377639
// Note all the correction candidates.
76387640
for (auto &result : lookup) {
76397641
TC.noteTypoCorrection(componentName, DeclNameLoc(componentNameLoc),
7640-
result);
7642+
result.getValueDecl());
76417643
}
76427644

76437645
isInvalid = true;
@@ -7651,13 +7653,14 @@ static bool diagnoseKeyPathComponents(ConstraintSystem &CS, KeyPathExpr *KPE,
76517653
// If we have more than one result, filter out unavailable or
76527654
// obviously unusable candidates.
76537655
if (lookup.size() > 1) {
7654-
lookup.filter([&](LookupResult::Result result) -> bool {
7656+
lookup.filter([&](LookupResultEntry result) -> bool {
76557657
// Drop unavailable candidates.
7656-
if (result->getAttrs().isUnavailable(TC.Context))
7658+
if (result.getValueDecl()->getAttrs().isUnavailable(TC.Context))
76577659
return false;
76587660

76597661
// Drop non-property, non-type candidates.
7660-
if (!isa<VarDecl>(result.Decl) && !isa<TypeDecl>(result.Decl))
7662+
if (!isa<VarDecl>(result.getValueDecl()) &&
7663+
!isa<TypeDecl>(result.getValueDecl()))
76617664
return false;
76627665

76637666
return true;
@@ -7677,13 +7680,14 @@ static bool diagnoseKeyPathComponents(ConstraintSystem &CS, KeyPathExpr *KPE,
76777680
TC.diagnose(componentNameLoc, diag::ambiguous_decl_ref, componentName);
76787681

76797682
for (auto result : lookup) {
7680-
TC.diagnose(result, diag::decl_declared_here, result->getFullName());
7683+
TC.diagnose(result.getValueDecl(), diag::decl_declared_here,
7684+
result.getValueDecl()->getFullName());
76817685
}
76827686
isInvalid = true;
76837687
break;
76847688
}
76857689

7686-
auto found = lookup.front().Decl;
7690+
auto found = lookup.front().getValueDecl();
76877691

76887692
// Handle property references.
76897693
if (auto var = dyn_cast<VarDecl>(found)) {

lib/Sema/CSSimplify.cpp

+17-7
Original file line numberDiff line numberDiff line change
@@ -3119,7 +3119,9 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
31193119
// Introduce a new overload set.
31203120
retry_ctors_after_fail:
31213121
bool labelMismatch = false;
3122-
for (auto ctor : ctors) {
3122+
for (auto entry : ctors) {
3123+
auto *ctor = entry.getValueDecl();
3124+
31233125
// If the constructor is invalid, we fail entirely to avoid error cascade.
31243126
TC.validateDecl(ctor);
31253127
if (ctor->isInvalid())
@@ -3162,7 +3164,7 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
31623164
fnTypeWithSelf->getResult()->getAs<FunctionType>()) {
31633165

31643166
auto argType = fnType->getInput()->getWithoutParens();
3165-
argType = ctor.Decl->getInnermostDeclContext()
3167+
argType = ctor->getInnermostDeclContext()
31663168
->mapTypeIntoContext(argType);
31673169
if (argType->isEqual(favoredType))
31683170
if (!ctor->getAttrs().isUnavailable(getASTContext()))
@@ -3339,7 +3341,9 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
33393341
retry_after_fail:
33403342
labelMismatch = false;
33413343
for (auto result : lookup)
3342-
addChoice(result, /*isBridged=*/false, /*isUnwrappedOptional=*/false);
3344+
addChoice(result.getValueDecl(),
3345+
/*isBridged=*/false,
3346+
/*isUnwrappedOptional=*/false);
33433347

33443348
// If the instance type is a bridged to an Objective-C type, perform
33453349
// a lookup into that Objective-C type.
@@ -3350,7 +3354,7 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
33503354
// Ignore results from the Objective-C "Foundation"
33513355
// module. Those core APIs are explicitly provided by the
33523356
// Foundation module overlay.
3353-
auto module = result->getModuleContext();
3357+
auto module = result.getValueDecl()->getModuleContext();
33543358
if (foundationModule) {
33553359
if (module == foundationModule)
33563360
continue;
@@ -3362,7 +3366,9 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
33623366
continue;
33633367
}
33643368

3365-
addChoice(result, /*isBridged=*/true, /*isUnwrappedOptional=*/false);
3369+
addChoice(result.getValueDecl(),
3370+
/*isBridged=*/true,
3371+
/*isUnwrappedOptional=*/false);
33663372
}
33673373
}
33683374

@@ -3376,7 +3382,9 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
33763382
if (objectType->mayHaveMembers()) {
33773383
LookupResult &optionalLookup = lookupMember(objectType, memberName);
33783384
for (auto result : optionalLookup)
3379-
addChoice(result, /*bridged*/false, /*isUnwrappedOptional=*/true);
3385+
addChoice(result.getValueDecl(),
3386+
/*bridged*/false,
3387+
/*isUnwrappedOptional=*/true);
33803388
}
33813389
}
33823390
}
@@ -3404,7 +3412,9 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
34043412

34053413
auto lookup = TC.lookupMember(DC, instanceTy,
34063414
memberName, lookupOptions);
3407-
for (auto cand : lookup) {
3415+
for (auto entry : lookup) {
3416+
auto *cand = entry.getValueDecl();
3417+
34083418
// If the result is invalid, skip it.
34093419
TC.validateDecl(cand);
34103420
if (cand->isInvalid()) {

lib/Sema/CodeSynthesis.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1758,7 +1758,7 @@ void swift::maybeAddAccessorsToVariable(VarDecl *var, TypeChecker &TC) {
17581758
// sure the property type matches later after validation.
17591759
auto lookup = TC.lookupMember(dc, behaviorProtoTy, TC.Context.Id_value);
17601760
for (auto found : lookup) {
1761-
if (auto foundVar = dyn_cast<VarDecl>(found.Decl)) {
1761+
if (auto foundVar = dyn_cast<VarDecl>(found.getValueDecl())) {
17621762
if (valueProp) {
17631763
TC.diagnose(behavior->getLoc(),
17641764
diag::property_behavior_protocol_reqt_ambiguous,

lib/Sema/ConstraintSystem.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,9 @@ LookupResult &ConstraintSystem::lookupMember(Type base, DeclName name) {
249249

250250
// We are performing dynamic lookup. Filter out redundant results early.
251251
llvm::DenseSet<std::tuple<char, ObjCSelector, CanType>> known;
252-
result->filter([&](ValueDecl *decl) -> bool {
252+
result->filter([&](LookupResultEntry entry) -> bool {
253+
auto *decl = entry.getValueDecl();
254+
253255
if (decl->isInvalid())
254256
return false;
255257

lib/Sema/MiscDiagnostics.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -3087,8 +3087,8 @@ class ObjCSelectorWalker : public ASTWalker {
30873087
if (result.size() > 2) return true;
30883088

30893089
// Dig out the methods.
3090-
auto firstMethod = dyn_cast<FuncDecl>(result[0].Decl);
3091-
auto secondMethod = dyn_cast<FuncDecl>(result[1].Decl);
3090+
auto firstMethod = dyn_cast<FuncDecl>(result[0].getValueDecl());
3091+
auto secondMethod = dyn_cast<FuncDecl>(result[1].getValueDecl());
30923092
if (!firstMethod || !secondMethod) return true;
30933093

30943094
// If one is a static/class method and the other is not...

lib/Sema/TypeCheckAttr.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,7 @@ void AttributeChecker::checkApplicationMainAttribute(DeclAttribute *attr,
12321232
SourceLoc(), lookupOptions);
12331233

12341234
for (const auto &result : lookupMain) {
1235-
TC.validateDecl(result.Decl);
1235+
TC.validateDecl(result.getValueDecl());
12361236
}
12371237
auto Foundation = TC.Context.getLoadedModule(C.Id_Foundation);
12381238
if (Foundation) {
@@ -1242,7 +1242,7 @@ void AttributeChecker::checkApplicationMainAttribute(DeclAttribute *attr,
12421242
SourceLoc(),
12431243
lookupOptions);
12441244
for (const auto &result : lookupString) {
1245-
TC.validateDecl(result.Decl);
1245+
TC.validateDecl(result.getValueDecl());
12461246
}
12471247
}
12481248
}

lib/Sema/TypeCheckConstraints.cpp

+16-14
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ static bool matchesDeclRefKind(ValueDecl *value, DeclRefKind refKind) {
253253
static bool containsDeclRefKind(LookupResult &lookupResult,
254254
DeclRefKind refKind) {
255255
for (auto candidate : lookupResult) {
256-
ValueDecl *D = candidate.Decl;
256+
ValueDecl *D = candidate.getValueDecl();
257257
if (!D || !D->hasInterfaceType())
258258
continue;
259259
if (matchesDeclRefKind(D, refKind))
@@ -428,15 +428,15 @@ resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE, DeclContext *DC) {
428428
relookupOptions);
429429
if (inaccessibleResults) {
430430
// FIXME: What if the unviable candidates have different levels of access?
431-
const ValueDecl *first = inaccessibleResults.front().Decl;
431+
const ValueDecl *first = inaccessibleResults.front().getValueDecl();
432432
diagnose(Loc, diag::candidate_inaccessible,
433433
Name, first->getFormalAccess());
434434

435435
// FIXME: If any of the candidates (usually just one) are in the same
436436
// module we could offer a fix-it.
437437
for (auto lookupResult : inaccessibleResults) {
438-
diagnose(lookupResult.Decl, diag::decl_declared_here,
439-
lookupResult.Decl->getFullName());
438+
diagnose(lookupResult.getValueDecl(), diag::decl_declared_here,
439+
lookupResult.getValueDecl()->getFullName());
440440
}
441441

442442
// Don't try to recover here; we'll get more access-related diagnostics
@@ -485,7 +485,7 @@ resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE, DeclContext *DC) {
485485
} else {
486486
// Note all the correction candidates.
487487
for (auto &result : Lookup) {
488-
noteTypoCorrection(Name, nameLoc, result);
488+
noteTypoCorrection(Name, nameLoc, result.getValueDecl());
489489
}
490490
}
491491

@@ -499,8 +499,8 @@ resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE, DeclContext *DC) {
499499

500500
// If we have an unambiguous reference to a type decl, form a TypeExpr.
501501
if (Lookup.size() == 1 && UDRE->getRefKind() == DeclRefKind::Ordinary &&
502-
isa<TypeDecl>(Lookup[0].Decl)) {
503-
auto *D = cast<TypeDecl>(Lookup[0].Decl);
502+
isa<TypeDecl>(Lookup[0].getValueDecl())) {
503+
auto *D = cast<TypeDecl>(Lookup[0].getValueDecl());
504504
// FIXME: This is odd.
505505
if (isa<ModuleDecl>(D)) {
506506
return new (Context) DeclRefExpr(D, UDRE->getNameLoc(),
@@ -517,13 +517,14 @@ resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE, DeclContext *DC) {
517517
SmallVector<ValueDecl*, 4> ResultValues;
518518
for (auto Result : Lookup) {
519519
// If we find a member, then all of the results aren't non-members.
520-
bool IsMember = Result.Base && !isa<ModuleDecl>(Result.Base);
520+
bool IsMember = (Result.getBaseDecl() &&
521+
!isa<ModuleDecl>(Result.getBaseDecl()));
521522
if (IsMember) {
522523
AllDeclRefs = false;
523524
break;
524525
}
525526

526-
ValueDecl *D = Result.Decl;
527+
ValueDecl *D = Result.getValueDecl();
527528
if (!D->hasInterfaceType()) validateDecl(D);
528529

529530
// FIXME: Circularity hack.
@@ -590,14 +591,15 @@ resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE, DeclContext *DC) {
590591
ValueDecl *Base = nullptr;
591592
for (auto Result : Lookup) {
592593
// Track the base for member declarations.
593-
if (Result.Base && !isa<ModuleDecl>(Result.Base)) {
594-
ResultValues.push_back(Result.Decl);
595-
if (Base && Result.Base != Base) {
594+
if (Result.getBaseDecl() &&
595+
!isa<ModuleDecl>(Result.getBaseDecl())) {
596+
ResultValues.push_back(Result.getValueDecl());
597+
if (Base && Result.getBaseDecl() != Base) {
596598
AllMemberRefs = false;
597599
break;
598600
}
599601

600-
Base = Result.Base;
602+
Base = Result.getBaseDecl();
601603
continue;
602604
}
603605

@@ -2609,7 +2611,7 @@ bool TypeChecker::typeCheckExprPattern(ExprPattern *EP, DeclContext *DC,
26092611

26102612
SmallVector<ValueDecl*, 4> choices;
26112613
for (auto &result : matchLookup) {
2612-
choices.push_back(result.Decl);
2614+
choices.push_back(result.getValueDecl());
26132615
}
26142616

26152617
if (choices.empty()) {

lib/Sema/TypeCheckDecl.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -3409,7 +3409,7 @@ static void checkVarBehavior(VarDecl *decl, TypeChecker &TC) {
34093409
FuncDecl *defaultInitStorageDecl = nullptr;
34103410
FuncDecl *parameterizedInitStorageDecl = nullptr;
34113411
for (auto found : lookup) {
3412-
if (auto foundFunc = dyn_cast<FuncDecl>(found.Decl)) {
3412+
if (auto foundFunc = dyn_cast<FuncDecl>(found.getValueDecl())) {
34133413
if (!foundFunc->isStatic())
34143414
continue;
34153415
auto methodTy = foundFunc->getInterfaceType()
@@ -3442,7 +3442,7 @@ static void checkVarBehavior(VarDecl *decl, TypeChecker &TC) {
34423442
expectedDefaultInitStorageTy,
34433443
expectedParameterizedInitStorageTy);
34443444
for (auto found : lookup)
3445-
TC.diagnose(found.Decl->getLoc(),
3445+
TC.diagnose(found.getValueDecl()->getLoc(),
34463446
diag::found_candidate);
34473447
conformance->setInvalid();
34483448
continue;
@@ -5731,7 +5731,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
57315731
}
57325732

57335733
for (auto memberResult : members) {
5734-
auto member = memberResult.Decl;
5734+
auto member = memberResult.getValueDecl();
57355735

57365736
if (member->isInvalid())
57375737
continue;
@@ -8244,7 +8244,7 @@ void TypeChecker::addImplicitConstructors(NominalTypeDecl *decl) {
82448244
NameLookupFlags::IgnoreAccessibility);
82458245

82468246
for (auto memberResult : ctors) {
8247-
auto member = memberResult.Decl;
8247+
auto member = memberResult.getValueDecl();
82488248

82498249
// Skip unavailable superclass initializers.
82508250
if (AvailableAttr::isUnavailable(member))
@@ -8468,7 +8468,7 @@ void TypeChecker::defineDefaultConstructor(NominalTypeDecl *decl) {
84688468
// tuple.
84698469
bool foundDefaultConstructor = false;
84708470
for (auto memberResult : ctors) {
8471-
auto member = memberResult.Decl;
8471+
auto member = memberResult.getValueDecl();
84728472

84738473
// Dig out the parameter tuple for this constructor.
84748474
auto ctor = dyn_cast<ConstructorDecl>(member);

0 commit comments

Comments
 (0)