Skip to content

Commit 69e991f

Browse files
committed
---
yaml --- r: 349348 b: refs/heads/master-next c: 380670f h: refs/heads/master
1 parent f14efce commit 69e991f

35 files changed

+189
-231
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 3574c513bbc5578dd9346b4ea9ab5995c5927bb5
3-
refs/heads/master-next: 6bca134a930a7dd2e77da52aa8264b0b49a7ec81
3+
refs/heads/master-next: 380670fd01d8d02279cd14aab4d8cfd5127b56db
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea
66
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-b: 66d897bfcf64a82cb9a87f5e663d889189d06d07

branches/master-next/include/swift/AST/Decl.h

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -556,13 +556,9 @@ class alignas(1 << DeclAlignInBits) Decl {
556556

557557
/// \see ClassDecl::ForeignKind
558558
RawForeignKind : 2,
559-
560-
/// Whether this class contains a destructor decl.
561-
///
562-
/// A fully type-checked class always contains a destructor member, even if
563-
/// it is implicit. This bit is used during parsing and type-checking to
564-
/// control inserting the implicit destructor.
565-
HasDestructorDecl : 1,
559+
560+
/// \see ClassDecl::getEmittedMembers()
561+
HasForcedEmittedMembers : 1,
566562

567563
/// Information about the class's ancestry.
568564
Ancestry : 7,
@@ -3765,8 +3761,17 @@ class ClassDecl final : public NominalTypeDecl {
37653761
llvm::PointerIntPair<Type, 1, bool> SuperclassType;
37663762
} LazySemanticInfo;
37673763

3764+
bool hasForcedEmittedMembers() const {
3765+
return Bits.ClassDecl.HasForcedEmittedMembers;
3766+
}
3767+
3768+
void setHasForcedEmittedMembers() {
3769+
Bits.ClassDecl.HasForcedEmittedMembers = true;
3770+
}
3771+
37683772
friend class SuperclassDeclRequest;
37693773
friend class SuperclassTypeRequest;
3774+
friend class EmittedMembersRequest;
37703775
friend class TypeChecker;
37713776

37723777
public:
@@ -3914,23 +3919,9 @@ class ClassDecl final : public NominalTypeDecl {
39143919
/// either from a class itself or its direct or indirect superclasses.
39153920
AbstractFunctionDecl *findImplementingMethod(
39163921
const AbstractFunctionDecl *method) const;
3917-
3918-
/// True if the class has a destructor.
3919-
///
3920-
/// Fully type-checked classes always contain destructors, but during parsing
3921-
/// or type-checking, the implicit destructor may not have been synthesized
3922-
/// yet if one was not explicitly declared.
3923-
bool hasDestructor() const { return Bits.ClassDecl.HasDestructorDecl; }
3924-
3925-
/// Set the 'has destructor' flag.
3926-
void setHasDestructor() { Bits.ClassDecl.HasDestructorDecl = 1; }
39273922

39283923
/// Retrieve the destructor for this class.
3929-
DestructorDecl *getDestructor();
3930-
3931-
/// Synthesize implicit, trivial destructor, add it to this ClassDecl
3932-
/// and return it.
3933-
void addImplicitDestructor();
3924+
DestructorDecl *getDestructor() const;
39343925

39353926
/// Determine whether this class inherits the convenience initializers
39363927
/// from its superclass.
@@ -3993,6 +3984,10 @@ class ClassDecl final : public NominalTypeDecl {
39933984
/// Record the presence of an @objc method with the given selector.
39943985
void recordObjCMethod(AbstractFunctionDecl *method, ObjCSelector selector);
39953986

3987+
/// Get all the members of this class, synthesizing any implicit members
3988+
/// that appear in the vtable if needed.
3989+
DeclRange getEmittedMembers() const;
3990+
39963991
// Implement isa/cast/dyncast/etc.
39973992
static bool classof(const Decl *D) {
39983993
return D->getKind() == DeclKind::Class;

branches/master-next/include/swift/AST/NameLookupRequests.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
namespace swift {
2525

2626
class ClassDecl;
27+
class DestructorDecl;
2728
class TypeAliasDecl;
2829
class TypeDecl;
2930

@@ -231,6 +232,28 @@ class CustomAttrNominalRequest :
231232
bool isCached() const { return true; }
232233
};
233234

235+
/// Finds or synthesizes a destructor for the given class.
236+
class GetDestructorRequest :
237+
public SimpleRequest<GetDestructorRequest,
238+
DestructorDecl *(ClassDecl *),
239+
CacheKind::SeparatelyCached> {
240+
public:
241+
using SimpleRequest::SimpleRequest;
242+
243+
private:
244+
friend SimpleRequest;
245+
246+
// Evaluation.
247+
llvm::Expected<DestructorDecl *>
248+
evaluate(Evaluator &evaluator, ClassDecl *classDecl) const;
249+
250+
public:
251+
// Caching
252+
bool isCached() const { return true; }
253+
Optional<DestructorDecl *> getCachedResult() const;
254+
void cacheResult(DestructorDecl *value) const;
255+
};
256+
234257
/// The zone number for name-lookup requests.
235258
#define SWIFT_NAME_LOOKUP_REQUESTS_TYPEID_ZONE 9
236259

branches/master-next/include/swift/AST/NameLookupTypeIDZone.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ SWIFT_TYPEID(ExtendedNominalRequest)
2121
SWIFT_TYPEID(SelfBoundsFromWhereClauseRequest)
2222
SWIFT_TYPEID(TypeDeclsFromWhereClauseRequest)
2323
SWIFT_TYPEID(CustomAttrNominalRequest)
24+
SWIFT_TYPEID(GetDestructorRequest)

branches/master-next/include/swift/AST/TypeCheckRequests.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,27 @@ class SynthesizeAccessorRequest :
10101010
void cacheResult(AccessorDecl *value) const;
10111011
};
10121012

1013+
class EmittedMembersRequest :
1014+
public SimpleRequest<EmittedMembersRequest,
1015+
DeclRange(ClassDecl *),
1016+
CacheKind::SeparatelyCached> {
1017+
public:
1018+
using SimpleRequest::SimpleRequest;
1019+
1020+
private:
1021+
friend SimpleRequest;
1022+
1023+
// Evaluation.
1024+
llvm::Expected<DeclRange>
1025+
evaluate(Evaluator &evaluator, ClassDecl *classDecl) const;
1026+
1027+
public:
1028+
// Separate caching.
1029+
bool isCached() const { return true; }
1030+
Optional<DeclRange> getCachedResult() const;
1031+
void cacheResult(DeclRange value) const;
1032+
};
1033+
10131034
// Allow AnyValue to compare two Type values, even though Type doesn't
10141035
// support ==.
10151036
template<>

branches/master-next/include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,4 @@ SWIFT_TYPEID(RequiresOpaqueAccessorsRequest)
5454
SWIFT_TYPEID(RequiresOpaqueModifyCoroutineRequest)
5555
SWIFT_TYPEID(IsAccessorTransparentRequest)
5656
SWIFT_TYPEID(SynthesizeAccessorRequest)
57+
SWIFT_TYPEID(EmittedMembersRequest)

branches/master-next/include/swift/Basic/Statistics.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,6 @@ FRONTEND_STATISTIC(Sema, NumDeclsValidated)
176176
/// Number of declarations type checked.
177177
FRONTEND_STATISTIC(Sema, NumDeclsTypechecked)
178178

179-
/// Number of declarations finalized.
180-
FRONTEND_STATISTIC(Sema, NumDeclsFinalized)
181-
182179
/// Number of synthesized accessors.
183180
FRONTEND_STATISTIC(Sema, NumAccessorsSynthesized)
184181

branches/master-next/include/swift/SIL/SILVTableVisitor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ template <class T> class SILVTableVisitor {
166166
// forced at the end.
167167
SortedFuncList synthesizedMembers;
168168

169-
for (auto member : theClass->getMembers()) {
169+
for (auto member : theClass->getEmittedMembers()) {
170170
if (auto *afd = dyn_cast<AbstractFunctionDecl>(member)) {
171171
if (afd->isSynthesized()) {
172172
synthesizedMembers.add(afd);

branches/master-next/lib/AST/ASTVerifier.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3289,17 +3289,12 @@ class Verifier : public ASTWalker {
32893289
NumDestructors++;
32903290
}
32913291
}
3292-
if (NumDestructors != 1) {
3293-
Out << "every class should have exactly one destructor, "
3292+
if (NumDestructors > 1) {
3293+
Out << "every class should have at most one destructor, "
32943294
"explicitly provided or created by the type checker\n";
32953295
abort();
32963296
}
32973297
}
3298-
3299-
if (!CD->hasDestructor()) {
3300-
Out << "every class's 'has destructor' bit must be set\n";
3301-
abort();
3302-
}
33033298

33043299
verifyCheckedBase(CD);
33053300
}

branches/master-next/lib/AST/Decl.cpp

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3823,7 +3823,6 @@ ClassDecl::ClassDecl(SourceLoc ClassLoc, Identifier Name, SourceLoc NameLoc,
38233823
= static_cast<unsigned>(CircularityCheck::Unchecked);
38243824
Bits.ClassDecl.InheritsSuperclassInits = 0;
38253825
Bits.ClassDecl.RawForeignKind = 0;
3826-
Bits.ClassDecl.HasDestructorDecl = 0;
38273826
Bits.ClassDecl.Ancestry = 0;
38283827
Bits.ClassDecl.AncestryComputed = 0;
38293828
Bits.ClassDecl.HasMissingDesignatedInitializers = 0;
@@ -3860,11 +3859,18 @@ bool ClassDecl::hasResilientMetadata(ModuleDecl *M,
38603859
llvm_unreachable("bad resilience expansion");
38613860
}
38623861

3863-
DestructorDecl *ClassDecl::getDestructor() {
3864-
auto results = lookupDirect(DeclBaseName::createDestructor());
3865-
assert(!results.empty() && "Class without destructor?");
3866-
assert(results.size() == 1 && "More than one destructor?");
3867-
return cast<DestructorDecl>(results.front());
3862+
DestructorDecl *ClassDecl::getDestructor() const {
3863+
ASTContext &ctx = getASTContext();
3864+
return evaluateOrDefault(ctx.evaluator,
3865+
GetDestructorRequest{const_cast<ClassDecl *>(this)},
3866+
nullptr);
3867+
}
3868+
3869+
DeclRange ClassDecl::getEmittedMembers() const {
3870+
ASTContext &ctx = getASTContext();
3871+
return evaluateOrDefault(ctx.evaluator,
3872+
EmittedMembersRequest{const_cast<ClassDecl *>(this)},
3873+
getMembers());
38683874
}
38693875

38703876
/// Synthesizer callback for an empty implicit function body.
@@ -3875,34 +3881,32 @@ synthesizeEmptyFunctionBody(AbstractFunctionDecl *afd, void *context) {
38753881
/*isTypeChecked=*/true };
38763882
}
38773883

3878-
void ClassDecl::addImplicitDestructor() {
3879-
if (hasDestructor() || isInvalid())
3880-
return;
3881-
3882-
auto &ctx = getASTContext();
3883-
auto *DD = new (ctx) DestructorDecl(getLoc(), this);
3884+
llvm::Expected<DestructorDecl *>
3885+
GetDestructorRequest::evaluate(Evaluator &evaluator, ClassDecl *CD) const {
3886+
auto &ctx = CD->getASTContext();
3887+
auto *DD = new (ctx) DestructorDecl(CD->getLoc(), CD);
38843888

38853889
DD->setImplicit();
38863890
DD->setValidationToChecked();
38873891

38883892
// Synthesize an empty body for the destructor as needed.
38893893
DD->setBodySynthesizer(synthesizeEmptyFunctionBody);
3890-
addMember(DD);
38913894

38923895
// Propagate access control and versioned-ness.
3893-
DD->copyFormalAccessFrom(this, /*sourceIsParentContext*/true);
3896+
DD->copyFormalAccessFrom(CD, /*sourceIsParentContext*/true);
38943897

38953898
// Wire up generic environment of DD.
3896-
DD->setGenericEnvironment(getGenericEnvironmentOfContext());
3899+
DD->setGenericEnvironment(CD->getGenericEnvironmentOfContext());
38973900

38983901
// Mark DD as ObjC, as all dtors are.
3899-
DD->setIsObjC(getASTContext().LangOpts.EnableObjCInterop);
3900-
if (getASTContext().LangOpts.EnableObjCInterop) {
3901-
recordObjCMethod(DD, DD->getObjCSelector());
3902-
}
3902+
DD->setIsObjC(ctx.LangOpts.EnableObjCInterop);
3903+
if (ctx.LangOpts.EnableObjCInterop)
3904+
CD->recordObjCMethod(DD, DD->getObjCSelector());
39033905

39043906
// Assign DD the interface type (Self) -> () -> ()
39053907
DD->computeType();
3908+
3909+
return DD;
39063910
}
39073911

39083912

branches/master-next/lib/AST/DeclContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,8 @@ ResilienceExpansion DeclContext::getResilienceExpansion() const {
318318
}
319319

320320
llvm::Expected<ResilienceExpansion>
321-
swift::ResilienceExpansionRequest::evaluate(Evaluator &eval,
322-
DeclContext *context) const {
321+
swift::ResilienceExpansionRequest::evaluate(Evaluator &evaluator,
322+
DeclContext *context) const {
323323
for (const auto *dc = context->getLocalContext(); dc && dc->isLocalContext();
324324
dc = dc->getParent()) {
325325
// Default argument initializer contexts have their resilience expansion

branches/master-next/lib/AST/NameLookup.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -886,11 +886,6 @@ void MemberLookupTable::updateLookupTable(NominalTypeDecl *nominal) {
886886
}
887887

888888
void NominalTypeDecl::addedMember(Decl *member) {
889-
// Remember if we added a destructor.
890-
if (auto *CD = dyn_cast<ClassDecl>(this))
891-
if (isa<DestructorDecl>(member))
892-
CD->setHasDestructor();
893-
894889
// If we have a lookup table, add the new member to it.
895890
if (LookupTable.getPointer()) {
896891
LookupTable.getPointer()->addMember(member);

branches/master-next/lib/AST/NameLookupRequests.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,23 @@ void ExtendedNominalRequest::cacheResult(NominalTypeDecl *value) const {
9494
ext->ExtendedNominal = value;
9595
}
9696

97+
//----------------------------------------------------------------------------//
98+
// Destructor computation.
99+
//----------------------------------------------------------------------------//
100+
Optional<DestructorDecl *> GetDestructorRequest::getCachedResult() const {
101+
auto *classDecl = std::get<0>(getStorage());
102+
auto results = classDecl->lookupDirect(DeclBaseName::createDestructor());
103+
if (results.empty())
104+
return None;
105+
106+
return cast<DestructorDecl>(results.front());
107+
}
108+
109+
void GetDestructorRequest::cacheResult(DestructorDecl *value) const {
110+
auto *classDecl = std::get<0>(getStorage());
111+
classDecl->addMember(value);
112+
}
113+
97114
// Define request evaluation functions for each of the name lookup requests.
98115
static AbstractRequestFunction *nameLookupRequestFunctions[] = {
99116
#define SWIFT_TYPEID(Name) \

branches/master-next/lib/AST/TypeCheckRequests.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,3 +790,20 @@ void SynthesizeAccessorRequest::cacheResult(AccessorDecl *accessor) const {
790790

791791
storage->setSynthesizedAccessor(kind, accessor);
792792
}
793+
794+
//----------------------------------------------------------------------------//
795+
// EmittedMembersRequest computation.
796+
//----------------------------------------------------------------------------//
797+
798+
Optional<DeclRange>
799+
EmittedMembersRequest::getCachedResult() const {
800+
auto *classDecl = std::get<0>(getStorage());
801+
if (classDecl->hasForcedEmittedMembers())
802+
return classDecl->getMembers();
803+
return None;
804+
}
805+
806+
void EmittedMembersRequest::cacheResult(DeclRange result) const {
807+
auto *classDecl = std::get<0>(getStorage());
808+
classDecl->setHasForcedEmittedMembers();
809+
}

branches/master-next/lib/ClangImporter/ImportDecl.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4634,7 +4634,6 @@ namespace {
46344634
result->setSuperclass(Type());
46354635
result->setAddedImplicitInitializers(); // suppress all initializers
46364636
addObjCAttribute(result, Impl.importIdentifier(decl->getIdentifier()));
4637-
result->addImplicitDestructor();
46384637
return result;
46394638
};
46404639

@@ -4802,7 +4801,6 @@ namespace {
48024801
result->setIsIncompatibleWithWeakReferences();
48034802

48044803
result->setMemberLoader(&Impl, 0);
4805-
result->addImplicitDestructor();
48064804

48074805
return result;
48084806
}
@@ -5250,7 +5248,6 @@ SwiftDeclConverter::importCFClassType(const clang::TypedefNameDecl *decl,
52505248
}
52515249
}
52525250

5253-
theClass->addImplicitDestructor();
52545251
return theClass;
52555252
}
52565253

branches/master-next/lib/IRGen/GenProto.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "swift/AST/Types.h"
3333
#include "swift/AST/Decl.h"
3434
#include "swift/AST/GenericEnvironment.h"
35+
#include "swift/AST/LazyResolver.h"
3536
#include "swift/AST/IRGenOptions.h"
3637
#include "swift/AST/PrettyStackTrace.h"
3738
#include "swift/AST/SubstitutionMap.h"
@@ -2959,6 +2960,10 @@ GenericTypeRequirements::GenericTypeRequirements(IRGenModule &IGM,
29592960
NominalTypeDecl *typeDecl)
29602961
: TheDecl(typeDecl) {
29612962

2963+
// FIXME: Remove this once getGenericSignature() is a request.
2964+
if (!typeDecl->hasInterfaceType())
2965+
IGM.Context.getLazyResolver()->resolveDeclSignature(typeDecl);
2966+
29622967
// We only need to do something here if the declaration context is
29632968
// somehow generic.
29642969
auto ncGenerics = typeDecl->getGenericSignatureOfContext();

branches/master-next/lib/ParseSIL/ParseSIL.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,8 +1193,14 @@ static ValueDecl *lookupMember(Parser &P, Type Ty, DeclBaseName Name,
11931193
CheckTy = MetaTy->getInstanceType();
11941194

11951195
if (auto nominal = CheckTy->getAnyNominal()) {
1196-
auto found = nominal->lookupDirect(Name);
1197-
Lookup.append(found.begin(), found.end());
1196+
if (Name == DeclBaseName::createDestructor() &&
1197+
isa<ClassDecl>(nominal)) {
1198+
auto *classDecl = cast<ClassDecl>(nominal);
1199+
Lookup.push_back(classDecl->getDestructor());
1200+
} else {
1201+
auto found = nominal->lookupDirect(Name);
1202+
Lookup.append(found.begin(), found.end());
1203+
}
11981204
} else if (auto moduleTy = CheckTy->getAs<ModuleType>()) {
11991205
moduleTy->getModule()->lookupValue({ }, Name, NLKind::QualifiedLookup,
12001206
Lookup);

0 commit comments

Comments
 (0)