Skip to content

Commit 3ddfcae

Browse files
authored
Merge pull request #27003 from slavapestov/remove-ignore-new-extensions
Remove IgnoreNewExtensions and related cleanups
2 parents 52782cf + a09382c commit 3ddfcae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+474
-590
lines changed

include/swift/AST/ASTContext.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#ifndef SWIFT_AST_ASTCONTEXT_H
1818
#define SWIFT_AST_ASTCONTEXT_H
1919

20-
#include "swift/AST/ClangModuleLoader.h"
2120
#include "swift/AST/Evaluator.h"
2221
#include "swift/AST/GenericSignature.h"
2322
#include "swift/AST/Identifier.h"
@@ -32,6 +31,7 @@
3231
#include "llvm/ADT/MapVector.h"
3332
#include "llvm/ADT/PointerIntPair.h"
3433
#include "llvm/ADT/SetVector.h"
34+
#include "llvm/ADT/SmallPtrSet.h"
3535
#include "llvm/ADT/StringMap.h"
3636
#include "llvm/ADT/TinyPtrVector.h"
3737
#include "llvm/Support/Allocator.h"
@@ -49,10 +49,12 @@ namespace clang {
4949
}
5050

5151
namespace swift {
52+
class AbstractFunctionDecl;
5253
class ASTContext;
5354
enum class Associativity : unsigned char;
5455
class AvailabilityContext;
5556
class BoundGenericType;
57+
class ClangModuleLoader;
5658
class ClangNode;
5759
class ConcreteDeclRef;
5860
class ConstructorDecl;

include/swift/AST/Decl.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ class alignas(1 << DeclAlignInBits) Decl {
543543
NumRequirementsInSignature : 16
544544
);
545545

546-
SWIFT_INLINE_BITFIELD(ClassDecl, NominalTypeDecl, 2+1+2+1+7+1+1+1+1,
546+
SWIFT_INLINE_BITFIELD(ClassDecl, NominalTypeDecl, 2+1+2+1+7+1+1+1+1+1+1,
547547
/// The stage of the inheritance circularity check for this class.
548548
Circularity : 2,
549549

@@ -557,7 +557,10 @@ class alignas(1 << DeclAlignInBits) Decl {
557557
HasForcedEmittedMembers : 1,
558558

559559
HasMissingDesignatedInitializers : 1,
560+
ComputedHasMissingDesignatedInitializers : 1,
561+
560562
HasMissingVTableEntries : 1,
563+
ComputedHasMissingVTableEntries : 1,
561564

562565
/// Whether instances of this class are incompatible
563566
/// with weak and unowned references.
@@ -3272,7 +3275,7 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
32723275
llvm::PointerIntPair<MemberLookupTable *, 1, bool> LookupTable;
32733276

32743277
/// Prepare the lookup table to make it ready for lookups.
3275-
void prepareLookupTable(bool ignoreNewExtensions);
3278+
void prepareLookupTable();
32763279

32773280
/// True if the entries in \c LookupTable are complete--that is, if a
32783281
/// name is present, it contains all members with that name.
@@ -3378,24 +3381,11 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
33783381
/// Retrieve the set of extensions of this type.
33793382
ExtensionRange getExtensions();
33803383

3381-
/// Make a member of this nominal type, or one of its extensions,
3382-
/// immediately visible in the lookup table.
3383-
///
3384-
/// A member of a nominal type or extension thereof will become
3385-
/// visible to name lookup as soon as it is added. However, if the
3386-
/// addition of a member is delayed---for example, because it's
3387-
/// being introduced in response to name lookup---this method can be
3388-
/// called to make it immediately visible.
3389-
void makeMemberVisible(ValueDecl *member);
3390-
33913384
/// Special-behaviour flags passed to lookupDirect()
33923385
enum class LookupDirectFlags {
3393-
/// Whether to avoid loading any new extension.
3394-
/// Used by the module loader to break recursion.
3395-
IgnoreNewExtensions = 1 << 0,
33963386
/// Whether to include @_implements members.
33973387
/// Used by conformance-checking to find special @_implements members.
3398-
IncludeAttrImplements = 1 << 1,
3388+
IncludeAttrImplements = 1 << 0,
33993389
};
34003390

34013391
/// Find all of the declarations with the given name within this nominal type
@@ -3879,6 +3869,7 @@ class ClassDecl final : public NominalTypeDecl {
38793869
bool hasMissingDesignatedInitializers() const;
38803870

38813871
void setHasMissingDesignatedInitializers(bool newValue = true) {
3872+
Bits.ClassDecl.ComputedHasMissingDesignatedInitializers = 1;
38823873
Bits.ClassDecl.HasMissingDesignatedInitializers = newValue;
38833874
}
38843875

@@ -3889,6 +3880,7 @@ class ClassDecl final : public NominalTypeDecl {
38893880
bool hasMissingVTableEntries() const;
38903881

38913882
void setHasMissingVTableEntries(bool newValue = true) {
3883+
Bits.ClassDecl.ComputedHasMissingVTableEntries = 1;
38923884
Bits.ClassDecl.HasMissingVTableEntries = newValue;
38933885
}
38943886

@@ -4195,6 +4187,14 @@ class ProtocolDecl final : public NominalTypeDecl {
41954187
/// a protocol having nested types (ObjC protocols).
41964188
llvm::TinyPtrVector<AssociatedTypeDecl *> getAssociatedTypeMembers() const;
41974189

4190+
/// Returns a protocol requirement with the given name, or nullptr if the
4191+
/// name has multiple overloads, or no overloads at all.
4192+
ValueDecl *getSingleRequirement(DeclName name) const;
4193+
4194+
/// Returns an associated type with the given name, or nullptr if one does
4195+
/// not exist.
4196+
AssociatedTypeDecl *getAssociatedType(Identifier name) const;
4197+
41984198
/// Walk this protocol and all of the protocols inherited by this protocol,
41994199
/// transitively, invoking the callback function for each protocol.
42004200
///

include/swift/ClangImporter/ClangImporter.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ class ClangModuleUnit;
5151
class ClangNode;
5252
class Decl;
5353
class DeclContext;
54+
class EnumDecl;
5455
class ImportDecl;
5556
class IRGenOptions;
5657
class LazyResolver;
5758
class ModuleDecl;
5859
class NominalTypeDecl;
60+
class StructDecl;
5961
class TypeDecl;
6062
class VisibleDeclConsumer;
6163
enum class SelectorSplitKind;
@@ -213,6 +215,9 @@ class ClangImporter final : public ClangModuleLoader {
213215
StringRef relatedEntityKind,
214216
llvm::function_ref<void(TypeDecl *)> receiver) override;
215217

218+
/// Look up the nested 'Code' enum for an error wrapper struct.
219+
EnumDecl *lookupErrorCodeEnum(const StructDecl *errorWrapper) const;
220+
216221
/// Look for textually included declarations from the bridging header.
217222
///
218223
/// \param filter returns true if the given clang decl/macro should be

lib/AST/ASTContext.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "swift/AST/ASTContext.h"
1818
#include "ForeignRepresentationInfo.h"
1919
#include "SubstitutionMapStorage.h"
20+
#include "swift/AST/ClangModuleLoader.h"
2021
#include "swift/AST/ConcreteDeclRef.h"
2122
#include "swift/AST/DiagnosticEngine.h"
2223
#include "swift/AST/DiagnosticsSema.h"

lib/AST/ASTDemangler.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,7 @@ TypeDecl *ASTBuilder::createTypeDecl(NodePointer node) {
8484
return nullptr;
8585

8686
auto name = Ctx.getIdentifier(node->getChild(1)->getText());
87-
auto results = proto->lookupDirect(name);
88-
if (results.size() != 1)
89-
return nullptr;
90-
91-
return dyn_cast<AssociatedTypeDecl>(results[0]);
87+
return proto->getAssociatedType(name);
9288
}
9389

9490
auto *DC = findDeclContext(node);
@@ -585,13 +581,8 @@ Type ASTBuilder::createDependentMemberType(StringRef member,
585581
if (!base->isTypeParameter())
586582
return Type();
587583

588-
auto flags = OptionSet<NominalTypeDecl::LookupDirectFlags>();
589-
flags |= NominalTypeDecl::LookupDirectFlags::IgnoreNewExtensions;
590-
for (auto member : protocol->lookupDirect(Ctx.getIdentifier(member),
591-
flags)) {
592-
if (auto assocType = dyn_cast<AssociatedTypeDecl>(member))
593-
return DependentMemberType::get(base, assocType);
594-
}
584+
if (auto assocType = protocol->getAssociatedType(Ctx.getIdentifier(member)))
585+
return DependentMemberType::get(base, assocType);
595586

596587
return Type();
597588
}

lib/AST/Decl.cpp

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3816,7 +3816,9 @@ ClassDecl::ClassDecl(SourceLoc ClassLoc, Identifier Name, SourceLoc NameLoc,
38163816
Bits.ClassDecl.InheritsSuperclassInits = 0;
38173817
Bits.ClassDecl.RawForeignKind = 0;
38183818
Bits.ClassDecl.HasMissingDesignatedInitializers = 0;
3819+
Bits.ClassDecl.ComputedHasMissingDesignatedInitializers = 0;
38193820
Bits.ClassDecl.HasMissingVTableEntries = 0;
3821+
Bits.ClassDecl.ComputedHasMissingVTableEntries = 0;
38203822
Bits.ClassDecl.IsIncompatibleWithWeakReferences = 0;
38213823
}
38223824

@@ -3901,16 +3903,22 @@ GetDestructorRequest::evaluate(Evaluator &evaluator, ClassDecl *CD) const {
39013903

39023904

39033905
bool ClassDecl::hasMissingDesignatedInitializers() const {
3904-
auto *mutableThis = const_cast<ClassDecl *>(this);
3905-
auto flags = OptionSet<LookupDirectFlags>();
3906-
flags |= LookupDirectFlags::IgnoreNewExtensions;
3907-
(void)mutableThis->lookupDirect(DeclBaseName::createConstructor(),
3908-
flags);
3906+
if (!Bits.ClassDecl.ComputedHasMissingDesignatedInitializers) {
3907+
auto *mutableThis = const_cast<ClassDecl *>(this);
3908+
mutableThis->Bits.ClassDecl.ComputedHasMissingDesignatedInitializers = 1;
3909+
(void)mutableThis->lookupDirect(DeclBaseName::createConstructor());
3910+
}
3911+
39093912
return Bits.ClassDecl.HasMissingDesignatedInitializers;
39103913
}
39113914

39123915
bool ClassDecl::hasMissingVTableEntries() const {
3913-
(void)getMembers();
3916+
if (!Bits.ClassDecl.ComputedHasMissingVTableEntries) {
3917+
auto *mutableThis = const_cast<ClassDecl *>(this);
3918+
mutableThis->Bits.ClassDecl.ComputedHasMissingVTableEntries = 1;
3919+
mutableThis->loadAllMembers();
3920+
}
3921+
39143922
return Bits.ClassDecl.HasMissingVTableEntries;
39153923
}
39163924

@@ -4364,6 +4372,34 @@ ProtocolDecl::getAssociatedTypeMembers() const {
43644372
return result;
43654373
}
43664374

4375+
ValueDecl *ProtocolDecl::getSingleRequirement(DeclName name) const {
4376+
auto results = const_cast<ProtocolDecl *>(this)->lookupDirect(name);
4377+
ValueDecl *result = nullptr;
4378+
for (auto candidate : results) {
4379+
if (candidate->getDeclContext() != this ||
4380+
!candidate->isProtocolRequirement())
4381+
continue;
4382+
if (result) {
4383+
// Multiple results.
4384+
return nullptr;
4385+
}
4386+
result = candidate;
4387+
}
4388+
4389+
return result;
4390+
}
4391+
4392+
AssociatedTypeDecl *ProtocolDecl::getAssociatedType(Identifier name) const {
4393+
auto results = const_cast<ProtocolDecl *>(this)->lookupDirect(name);
4394+
for (auto candidate : results) {
4395+
if (candidate->getDeclContext() == this &&
4396+
isa<AssociatedTypeDecl>(candidate)) {
4397+
return cast<AssociatedTypeDecl>(candidate);
4398+
}
4399+
}
4400+
return nullptr;
4401+
}
4402+
43674403
Type ProtocolDecl::getSuperclass() const {
43684404
ASTContext &ctx = getASTContext();
43694405
return evaluateOrDefault(ctx.evaluator,

lib/AST/ImportCache.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "llvm/ADT/DenseSet.h"
1919
#include "swift/AST/ASTContext.h"
20+
#include "swift/AST/ClangModuleLoader.h"
2021
#include "swift/AST/ImportCache.h"
2122
#include "swift/AST/Module.h"
2223

lib/AST/ModuleNameLookup.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "swift/AST/ModuleNameLookup.h"
1414
#include "swift/AST/ASTContext.h"
15+
#include "swift/AST/ClangModuleLoader.h"
1516
#include "swift/AST/ImportCache.h"
1617
#include "swift/AST/NameLookup.h"
1718
#include "llvm/Support/raw_ostream.h"

0 commit comments

Comments
 (0)