Skip to content

Commit

Permalink
AST: Move DerivedGlobalDecls from NominalTypeDecl to InterableDeclCon…
Browse files Browse the repository at this point in the history
…text, NFC

Progress on <rdar://problem/20981254>.

Swift SVN r28931
  • Loading branch information
slavapestov committed May 22, 2015
1 parent 0affd67 commit 1e31d0c
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 26 deletions.
14 changes: 1 addition & 13 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2837,11 +2837,7 @@ class NominalTypeDecl : public TypeDecl, public DeclContext,
ArrayRef<DelayedDecl> DelayedMembers;

GenericParamList *GenericParams;

/// Global declarations that were synthesized on this type's behalf, such as
/// default operator definitions derived for protocol conformances.
ArrayRef<Decl*> DerivedGlobalDecls;


/// \brief The generic signature of this type.
///
/// This is the semantic representation of a generic parameters and the
Expand Down Expand Up @@ -3155,14 +3151,6 @@ class NominalTypeDecl : public TypeDecl, public DeclContext,
return StoredPropertyRange(getMembers(), ToStoredProperty());
}

ArrayRef<Decl *> getDerivedGlobalDecls() const {
return DerivedGlobalDecls;
}

void setDerivedGlobalDecls(MutableArrayRef<Decl*> decls) {
DerivedGlobalDecls = decls;
}

bool hasDelayedMemberDecls() {
return DelayedMembers.size() != 0;
}
Expand Down
16 changes: 16 additions & 0 deletions include/swift/AST/DeclContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,10 @@ class IterableDeclContext {
/// Lazy member loader context data.
uint64_t LazyLoaderContextData = 0;

/// Global declarations that were synthesized on this declaration's behalf,
/// such as default operator definitions derived for protocol conformances.
ArrayRef<Decl*> DerivedGlobalDecls;

template<class A, class B, class C>
friend struct ::llvm::cast_convert_val;

Expand Down Expand Up @@ -577,6 +581,18 @@ class IterableDeclContext {
/// Load all of the members of this context.
void loadAllMembers() const;

/// Retrieve global declarations that were synthesized on this
/// declaration's behalf.
ArrayRef<Decl *> getDerivedGlobalDecls() const {
return DerivedGlobalDecls;
}

/// Set global declarations that were synthesized on this
/// declaration's behalf.
void setDerivedGlobalDecls(MutableArrayRef<Decl*> decls) {
DerivedGlobalDecls = decls;
}

// Some Decls are IterableDeclContexts, but not all.
static bool classof(const Decl *D);

Expand Down
2 changes: 2 additions & 0 deletions lib/SILGen/SILGenType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,8 @@ class SILGenExtension : public TypeMemberVisitor<SILGenExtension> {
void emitExtension(ExtensionDecl *e) {
for (Decl *member : e->getMembers())
visit(member);
for (Decl *member : e->getDerivedGlobalDecls())
SGM.visit(member);

if (!e->getExtendedType()->isExistentialType()) {
// Emit witness tables for protocol conformances introduced by the
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/DerivedConformanceEquatableHashable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ deriveEquatable_enum_eq(TypeChecker &tc, EnumDecl *enumDecl) {
tc.implicitlyDefinedFunctions.push_back(eqDecl);

// Since it's an operator we insert the decl after the type at global scope.
return insertOperatorDecl(enumDecl, eqDecl);
return insertOperatorDecl(C, enumDecl, eqDecl);
}

ValueDecl *DerivedConformance::deriveEquatable(TypeChecker &tc,
Expand Down
6 changes: 3 additions & 3 deletions lib/Sema/DerivedConformances.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
using namespace swift;
using namespace DerivedConformance;

void DerivedConformance::_insertOperatorDecl(NominalTypeDecl *scope,
void DerivedConformance::_insertOperatorDecl(ASTContext &C,
IterableDeclContext *scope,
Decl *member) {
// Find the module.
auto &C = scope->getASTContext();
auto mod = scope->getModuleContext();
auto mod = member->getModuleContext();

// Add it to the module in a DerivedFileUnit.
mod->getDerivedFileUnit().addDerivedDecl(cast<FuncDecl>(member));
Expand Down
18 changes: 11 additions & 7 deletions lib/Sema/DerivedConformances.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,19 @@ ValueDecl *deriveBridgedNSError(TypeChecker &tc,
NominalTypeDecl *type,
ValueDecl *requirement);

/// Insert an operator declaration associated with a nominal type. The
/// declaration is added at global scope.
void _insertOperatorDecl(NominalTypeDecl *scope, Decl *member);
/// Insert an operator declaration associated with a declaration
/// context. The operator declaration is added at global scope.
void _insertOperatorDecl(ASTContext &C,
IterableDeclContext *scope,
Decl *member);

/// Insert a declaration as a member of a nominal type. The declaration is
/// added at file scope as close as possible to the
/// Insert an operator declaration associated with a declaration
/// context. The operator declaration is added at global scope.
template<typename SomeDecl>
inline SomeDecl *insertOperatorDecl(NominalTypeDecl *scope, SomeDecl *member) {
::swift::DerivedConformance::_insertOperatorDecl(scope, member);
inline SomeDecl *insertOperatorDecl(ASTContext &C,
IterableDeclContext *scope,
SomeDecl *member) {
::swift::DerivedConformance::_insertOperatorDecl(C, scope, member);
return member;
}

Expand Down
6 changes: 4 additions & 2 deletions lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3379,8 +3379,8 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
// Visit each of the members.
for (Decl *Member : SD->getMembers())
visit(Member);
for (Decl *global : SD->getDerivedGlobalDecls())
visit(global);
for (Decl *Global : SD->getDerivedGlobalDecls())
visit(Global);

if (!(IsFirstPass || SD->isInvalid())) {
checkExplicitConformance(SD, SD->getDeclaredTypeInContext());
Expand Down Expand Up @@ -5341,6 +5341,8 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
if (!ED->isInvalid()) {
for (Decl *Member : ED->getMembers())
visit(Member);
for (Decl *Global : ED->getDerivedGlobalDecls())
visit(Global);
}

if (!IsFirstPass) {
Expand Down

0 comments on commit 1e31d0c

Please sign in to comment.