Skip to content

Commit 397e36a

Browse files
committed
Sema: Remove TypeChecker::lookupConstructor()
1 parent 1dc4797 commit 397e36a

File tree

5 files changed

+30
-43
lines changed

5 files changed

+30
-43
lines changed

lib/Sema/CodeSynthesis.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -911,8 +911,8 @@ static bool canInheritDesignatedInits(Evaluator &eval, ClassDecl *decl) {
911911

912912
static void collectNonOveriddenSuperclassInits(
913913
ClassDecl *subclass, SmallVectorImpl<ConstructorDecl *> &results) {
914-
auto superclassTy = subclass->getSuperclass();
915-
assert(superclassTy);
914+
auto *superclassDecl = subclass->getSuperclassDecl();
915+
assert(superclassDecl);
916916

917917
// Record all of the initializers the subclass has overriden, excluding stub
918918
// overrides, which we don't want to consider as viable delegates for
@@ -924,11 +924,17 @@ static void collectNonOveriddenSuperclassInits(
924924
if (auto overridden = ctor->getOverriddenDecl())
925925
overriddenInits.insert(overridden);
926926

927-
auto superclassCtors = TypeChecker::lookupConstructors(
928-
subclass, superclassTy, NameLookupFlags::IgnoreAccessControl);
927+
superclassDecl->synthesizeSemanticMembersIfNeeded(
928+
DeclBaseName::createConstructor());
929929

930-
for (auto memberResult : superclassCtors) {
931-
auto superclassCtor = cast<ConstructorDecl>(memberResult.getValueDecl());
930+
NLOptions subOptions = (NL_QualifiedDefault | NL_IgnoreAccessControl);
931+
SmallVector<ValueDecl *, 4> lookupResults;
932+
subclass->lookupQualified(
933+
superclassDecl, DeclNameRef::createConstructor(),
934+
subOptions, lookupResults);
935+
936+
for (auto decl : lookupResults) {
937+
auto superclassCtor = cast<ConstructorDecl>(decl);
932938

933939
// Skip invalid superclass initializers.
934940
if (superclassCtor->isInvalid())
@@ -958,12 +964,7 @@ static void addImplicitInheritedConstructorsToClass(ClassDecl *decl) {
958964
decl->setAddedImplicitInitializers();
959965

960966
// We can only inherit initializers if we have a superclass.
961-
// FIXME: We should be bailing out earlier in the function, but unfortunately
962-
// that currently regresses associated type inference for cases like
963-
// compiler_crashers_2_fixed/0124-sr5825.swift due to the fact that we no
964-
// longer eagerly compute the interface types of the other constructors.
965-
auto superclassTy = decl->getSuperclass();
966-
if (!superclassTy)
967+
if (!decl->getSuperclassDecl() || !decl->getSuperclass())
967968
return;
968969

969970
// Check whether the user has defined a designated initializer for this class,

lib/Sema/MiscDiagnostics.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,8 +594,8 @@ static void diagSyntacticUseRestrictions(const Expr *E, const DeclContext *DC,
594594
isExistential = instanceTy->isExistentialType();
595595
if (!isExistential &&
596596
instanceTy->mayHaveMembers() &&
597-
!TypeChecker::lookupConstructors(const_cast<DeclContext *>(DC),
598-
instanceTy).empty()) {
597+
!TypeChecker::lookupMember(const_cast<DeclContext *>(DC), instanceTy,
598+
DeclNameRef::createConstructor()).empty()) {
599599
Ctx.Diags.diagnose(E->getEndLoc(), diag::add_parens_to_type)
600600
.fixItInsertAfter(E->getEndLoc(), "()");
601601
}

lib/Sema/TypeCheckNameLookup.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -511,11 +511,6 @@ LookupTypeResult TypeChecker::lookupMemberType(DeclContext *dc,
511511
return result;
512512
}
513513

514-
LookupResult TypeChecker::lookupConstructors(DeclContext *dc, Type type,
515-
NameLookupOptions options) {
516-
return lookupMember(dc, type, DeclNameRef::createConstructor(), options);
517-
}
518-
519514
unsigned TypeChecker::getCallEditDistance(DeclNameRef writtenName,
520515
DeclName correctedName,
521516
unsigned maxEditDistance) {

lib/Sema/TypeCheckStmt.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,19 +1754,21 @@ static bool checkSuperInit(ConstructorDecl *fromCtor,
17541754
// For an implicitly generated super.init() call, make sure there's
17551755
// only one designated initializer.
17561756
if (implicitlyGenerated) {
1757-
auto superclassTy = ctor->getDeclContext()->getDeclaredInterfaceType();
1758-
auto lookupOptions = defaultConstructorLookupOptions;
1759-
lookupOptions |= NameLookupFlags::KnownPrivate;
1760-
1761-
// If a constructor is only visible as a witness for a protocol
1762-
// requirement, it must be an invalid override. Also, protocol
1763-
// extensions cannot yet define designated initializers.
1764-
lookupOptions -= NameLookupFlags::ProtocolMembers;
1765-
lookupOptions -= NameLookupFlags::PerformConformanceCheck;
1766-
1767-
for (auto member : TypeChecker::lookupConstructors(fromCtor, superclassTy,
1768-
lookupOptions)) {
1769-
auto superclassCtor = dyn_cast<ConstructorDecl>(member.getValueDecl());
1757+
auto *dc = ctor->getDeclContext();
1758+
auto *superclassDecl = dc->getSelfClassDecl();
1759+
1760+
superclassDecl->synthesizeSemanticMembersIfNeeded(
1761+
DeclBaseName::createConstructor());
1762+
1763+
NLOptions subOptions = NL_QualifiedDefault | NL_KnownNonCascadingDependency;
1764+
1765+
SmallVector<ValueDecl *, 4> lookupResults;
1766+
dc->lookupQualified(superclassDecl,
1767+
DeclNameRef::createConstructor(),
1768+
subOptions, lookupResults);
1769+
1770+
for (auto decl : lookupResults) {
1771+
auto superclassCtor = dyn_cast<ConstructorDecl>(decl);
17701772
if (!superclassCtor || !superclassCtor->isDesignatedInit() ||
17711773
superclassCtor == ctor)
17721774
continue;

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -941,17 +941,6 @@ LookupTypeResult
941941
lookupMemberType(DeclContext *dc, Type type, DeclNameRef name,
942942
NameLookupOptions options = defaultMemberTypeLookupOptions);
943943

944-
/// Look up the constructors of the given type.
945-
///
946-
/// \param dc The context that needs the constructor.
947-
/// \param type The type for which we will look for constructors.
948-
/// \param options Options that control name lookup.
949-
///
950-
/// \returns the constructors found for this type.
951-
LookupResult lookupConstructors(
952-
DeclContext *dc, Type type,
953-
NameLookupOptions options = defaultConstructorLookupOptions);
954-
955944
/// Given an expression that's known to be an infix operator,
956945
/// look up its precedence group.
957946
PrecedenceGroupDecl *lookupPrecedenceGroupForInfixOperator(DeclContext *dc,

0 commit comments

Comments
 (0)