Skip to content

Commit 89ad597

Browse files
committed
Sema: Use getAllMembers() from collectVisibleMemberDecls()
I had to disable typo correction in one test case to get it to pass without diagnosing a cycle as a result of Sendable checking. But that's OK, because: - Sendable checking is prone to request cycles and needs to be redesigned - Typo correction is turned off in production
1 parent fdb42fe commit 89ad597

File tree

4 files changed

+9
-82
lines changed

4 files changed

+9
-82
lines changed

lib/Sema/LookupVisibleDecls.cpp

Lines changed: 4 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ static void collectVisibleMemberDecls(const DeclContext *CurrDC, LookupState LS,
230230
FoundDecls.push_back(VD);
231231
};
232232

233-
for (auto Member : Parent->getMembers()) {
233+
for (auto Member : Parent->getAllMembers()) {
234234
check(Member);
235235
Member->visitAuxiliaryDecls([&](Decl *d) {
236236
check(d);
@@ -258,28 +258,6 @@ static void doGlobalExtensionLookup(Type BaseType,
258258
extension)), false))
259259
continue;
260260

261-
synthesizePropertyWrapperVariables(extension);
262-
263-
// Expand member macros.
264-
ASTContext &ctx = nominal->getASTContext();
265-
if (!ctx.evaluator.hasActiveRequest(
266-
ExpandSynthesizedMemberMacroRequest{extension})) {
267-
(void)evaluateOrDefault(
268-
ctx.evaluator,
269-
ExpandSynthesizedMemberMacroRequest{extension},
270-
false);
271-
}
272-
273-
// Expand peer macros.
274-
for (auto *member : extension->getMembers()) {
275-
if (!ctx.evaluator.hasActiveRequest(ExpandPeerMacroRequest{member})) {
276-
(void)evaluateOrDefault(
277-
ctx.evaluator,
278-
ExpandPeerMacroRequest{member},
279-
{});
280-
}
281-
}
282-
283261
collectVisibleMemberDecls(CurrDC, LS, BaseType, extension, FoundDecls);
284262
}
285263

@@ -606,52 +584,6 @@ synthesizePropertyWrapperVariables(IterableDeclContext *IDC) {
606584
}
607585
}
608586

609-
/// Trigger synthesizing implicit member declarations to make them "visible".
610-
static void synthesizeMemberDeclsForLookup(NominalTypeDecl *NTD,
611-
const DeclContext *DC) {
612-
// Synthesize the memberwise initializer for structs or default initializer
613-
// for classes.
614-
if (!NTD->getASTContext().evaluator.hasActiveRequest(
615-
SynthesizeMemberwiseInitRequest{NTD}))
616-
TypeChecker::addImplicitConstructors(NTD);
617-
618-
// Check all conformances to trigger the synthesized decl generation.
619-
// e.g. init(rawValue:) for RawRepresentable.
620-
for (auto Conformance : NTD->getAllConformances()) {
621-
auto Proto = Conformance->getProtocol();
622-
if (!Proto->isAccessibleFrom(DC))
623-
continue;
624-
auto NormalConformance = dyn_cast<NormalProtocolConformance>(
625-
Conformance->getRootConformance());
626-
if (!NormalConformance)
627-
continue;
628-
NormalConformance->forEachTypeWitness(
629-
[](AssociatedTypeDecl *, Type, TypeDecl *) { return false; },
630-
/*useResolver=*/true);
631-
NormalConformance->forEachValueWitness([](ValueDecl *, Witness) {},
632-
/*useResolver=*/true);
633-
}
634-
635-
// Expand synthesized member macros.
636-
auto &ctx = NTD->getASTContext();
637-
if (!ctx.evaluator.hasActiveRequest(
638-
ExpandSynthesizedMemberMacroRequest{NTD})) {
639-
(void)evaluateOrDefault(ctx.evaluator,
640-
ExpandSynthesizedMemberMacroRequest{NTD},
641-
false);
642-
}
643-
644-
// Expand extension macros.
645-
if (!ctx.evaluator.hasActiveRequest(
646-
ExpandExtensionMacros{NTD})) {
647-
(void)evaluateOrDefault(ctx.evaluator,
648-
ExpandExtensionMacros{NTD},
649-
false);
650-
}
651-
652-
synthesizePropertyWrapperVariables(NTD);
653-
}
654-
655587
static void lookupVisibleMemberDeclsImpl(
656588
Type BaseTy, VisibleDeclConsumer &Consumer, const DeclContext *CurrDC,
657589
LookupState LS, DeclVisibilityKind Reason, GenericSignature Sig,
@@ -774,20 +706,14 @@ static void lookupVisibleMemberDeclsImpl(
774706

775707
auto lookupTy = BaseTy;
776708

777-
const auto synthesizeAndLookupTypeMembers = [&](NominalTypeDecl *NTD) {
778-
synthesizeMemberDeclsForLookup(NTD, CurrDC);
779-
780-
// Look in for members of a nominal type.
781-
lookupTypeMembers(BaseTy, lookupTy, Consumer, CurrDC, LS, Reason);
782-
};
783-
784709
llvm::SmallPtrSet<ClassDecl *, 8> Ancestors;
785710
{
786711
const auto NTD = BaseTy->getAnyNominal();
787712
if (NTD == nullptr)
788713
return;
789714

790-
synthesizeAndLookupTypeMembers(NTD);
715+
lookupTypeMembers(BaseTy, lookupTy, Consumer, CurrDC, LS, Reason);
716+
791717
// Look into protocols only on the current nominal to avoid repeatedly
792718
// visiting inherited conformances.
793719
lookupDeclsFromProtocolsBeingConformedTo(BaseTy, Consumer, LS, CurrDC,
@@ -823,7 +749,7 @@ static void lookupVisibleMemberDeclsImpl(
823749
if (!Ancestors.insert(CurClass).second)
824750
break;
825751

826-
synthesizeAndLookupTypeMembers(CurClass);
752+
lookupTypeMembers(BaseTy, lookupTy, Consumer, CurrDC, LS, Reason);
827753

828754
lookupTy = CurClass->getSuperclass();
829755
if (!CurClass->inheritsSuperclassInitializers())

test/IDE/complete_member_basetypes.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,11 @@ extension GenericS: BaseP1 where T == Int {}
8787

8888
func testConditionalConformanceNo(arg: GenericS<String>) {
8989
arg.#^TestConditionalConformanceNo^#
90-
// TestConditionalConformanceNo: LookedupTypeNames: ['Mod.GenericS']
90+
// TestConditionalConformanceNo: LookedupTypeNames: ['Mod.GenericS', 'Swift.Sendable']
9191
}
9292

9393
func testConditionalConformanceYes(arg: GenericS<Int>) {
9494
arg.#^TestConditionalConformanceYes^#
95-
// TestConditionalConformanceYes: LookedupTypeNames: ['Mod.GenericS', 'Mod.BaseP1']
95+
// TestConditionalConformanceYes: LookedupTypeNames: ['Mod.GenericS', 'Mod.BaseP1', 'Swift.Sendable']
96+
9697
}

test/IDE/complete_optionset.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public macro OptionSet<RawType>() =
2828
// MEMBER_STATIC: Decl[StaticVar]/CurrNominal: secondDay[#ShippingOptions#]; name=secondDay
2929
// MEMBER_STATIC: Decl[StaticVar]/CurrNominal: priority[#ShippingOptions#]; name=priority
3030
// MEMBER_STATIC: Decl[StaticVar]/CurrNominal: standard[#ShippingOptions#]; name=standard
31-
// MEMBER_STATIC: Decl[TypeAlias]/CurrNominal: Element[#ShippingOptions#]; name=Element
3231
// MEMBER_STATIC: Decl[TypeAlias]/CurrNominal: ArrayLiteralElement[#ShippingOptions#]; name=ArrayLiteralElement
32+
// MEMBER_STATIC: Decl[TypeAlias]/CurrNominal: Element[#ShippingOptions#]; name=Element
3333
// MEMBER_STATIC: Decl[Constructor]/Super/IsSystem: init()[#ShippingOptions#]; name=init()
3434
// MEMBER_STATIC: Decl[Constructor]/Super/IsSystem: init({#(sequence): Sequence#})[#ShippingOptions#]; name=init(:)

test/type/infer/instance_variables.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift
1+
// RUN: %target-typecheck-verify-swift -disable-typo-correction
22

33
struct X {
44
var b = true, i = 17

0 commit comments

Comments
 (0)