Skip to content

More generics gardening #6063

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -4580,10 +4580,6 @@ class AbstractFunctionDecl : public ValueDecl, public DeclContext {
// FIXME: Hack that provides names with keyword arguments for accessors.
DeclName getEffectiveFullName() const;

/// \brief If this is a method in a type extension for some type,
/// return that type, otherwise return Type().
Type getExtensionType() const;

/// Returns true if the function has a body written in the source file.
///
/// Note that a true return value does not imply that the body was actually
Expand Down
3 changes: 2 additions & 1 deletion include/swift/AST/DiagnosticsParse.def
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,8 @@ ERROR(sil_member_lookup_bad_type,none,
ERROR(sil_member_decl_type_mismatch,none,
"member defined with mismatching type %0 (expected %1)", (Type, Type))
ERROR(sil_substitution_mismatch,none,
"substitution conformances don't match archetype", ())
"substitution replacement type %0 does not conform to protocol %1",
(Type, DeclName))
ERROR(sil_missing_substitutions,none,
"missing substitutions", ())
ERROR(sil_too_many_substitutions,none,
Expand Down
18 changes: 0 additions & 18 deletions include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -916,9 +916,6 @@ class alignas(1 << TypeAlignInBits) TypeBase {

/// Whether this is the AnyObject type.
bool isAnyObject();

/// Whether this is an empty existential composition ("{}").
bool isEmptyExistentialComposition();

/// Whether this is an existential composition containing
/// Error.
Expand All @@ -938,16 +935,6 @@ class alignas(1 << TypeAlignInBits) TypeBase {
/// Return whether this type is or can be substituted for a bridgeable
/// object type.
TypeTraitResult canBeClass();

/// Returns true if the type conforms to protocols using witnesses from the
/// environment or from within the value. Generic parameters and existentials
/// meet this criteria. In these cases we represent the
/// conformance as a null ProtocolConformance* pointer, because there is no
/// static conformance associated with the conforming type.
bool hasDependentProtocolConformances();

/// Retrieve the type declaration directly referenced by this type, if any.
TypeDecl *getDirectlyReferencedTypeDecl() const;

private:
// Make vanilla new/delete illegal for Types.
Expand Down Expand Up @@ -4618,11 +4605,6 @@ inline CanType Type::getCanonicalTypeOrNull() const {
return isNull() ? CanType() : getPointer()->getCanonicalType();
}

inline bool TypeBase::hasDependentProtocolConformances() {
return is<SubstitutableType>() || is<GenericTypeParamType>()
|| isAnyExistentialType();
}

#define TYPE(id, parent)
#define SUGARED_TYPE(id, parent) \
template <> \
Expand Down
4 changes: 2 additions & 2 deletions lib/AST/ASTVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2005,7 +2005,7 @@ struct ASTNodeBase {};
void verifyChecked(ConstructorDecl *CD) {
PrettyStackTraceDecl debugStack("verifying ConstructorDecl", CD);

auto *ND = CD->getExtensionType()->getNominalOrBoundGenericNominal();
auto *ND = CD->getDeclContext()->getAsNominalTypeOrNominalTypeExtensionContext();
if (!isa<ClassDecl>(ND) && !isa<StructDecl>(ND) && !isa<EnumDecl>(ND) &&
!isa<ProtocolDecl>(ND) && !CD->isInvalid()) {
Out << "ConstructorDecls outside structs, classes or enums "
Expand Down Expand Up @@ -2188,7 +2188,7 @@ struct ASTNodeBase {};
void verifyChecked(DestructorDecl *DD) {
PrettyStackTraceDecl debugStack("verifying DestructorDecl", DD);

auto *ND = DD->getExtensionType()->getNominalOrBoundGenericNominal();
auto *ND = DD->getDeclContext()->getAsNominalTypeOrNominalTypeExtensionContext();
if (!isa<ClassDecl>(ND) && !DD->isInvalid()) {
Out << "DestructorDecls outside classes should be marked invalid";
abort();
Expand Down
10 changes: 3 additions & 7 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2935,7 +2935,7 @@ bool AbstractStorageDecl::isGetterMutating() const {
/// called even on an immutable base value.
bool AbstractStorageDecl::isSetterNonMutating() const {
// Setters declared in reference type contexts are never mutating.
if (auto contextType = getDeclContext()->getDeclaredTypeInContext()) {
if (auto contextType = getDeclContext()->getDeclaredInterfaceType()) {
if (contextType->hasReferenceSemantics())
return true;
}
Expand Down Expand Up @@ -3608,7 +3608,7 @@ void VarDecl::emitLetToVarNoteIfSimple(DeclContext *UseDC) const {
// a property in a non-mutating method.
auto FD = dyn_cast_or_null<FuncDecl>(UseDC->getInnermostMethodContext());
if (FD && !FD->isMutating() && !FD->isImplicit() && FD->isInstanceMember()&&
!FD->getDeclContext()->getDeclaredTypeInContext()
!FD->getDeclContext()->getDeclaredInterfaceType()
->hasReferenceSemantics()) {
auto &d = getASTContext().Diags;
d.diagnose(FD->getFuncLoc(), diag::change_to_mutating, FD->isAccessor())
Expand Down Expand Up @@ -4030,10 +4030,6 @@ ParamDecl *AbstractFunctionDecl::getImplicitSelfDecl() {
return nullptr;
}

Type AbstractFunctionDecl::getExtensionType() const {
return getDeclContext()->getDeclaredTypeInContext();
}

std::pair<DefaultArgumentKind, Type>
AbstractFunctionDecl::getDefaultArg(unsigned Index) const {
auto paramLists = getParameterLists();
Expand Down Expand Up @@ -4323,7 +4319,7 @@ bool FuncDecl::isExplicitNonMutating() const {
return !isMutating() &&
isAccessor() && !isGetter() &&
isInstanceMember() &&
!getDeclContext()->getDeclaredTypeInContext()->hasReferenceSemantics();
!getDeclContext()->getDeclaredInterfaceType()->hasReferenceSemantics();
}

void FuncDecl::setDeserializedSignature(ArrayRef<ParameterList *> BodyParams,
Expand Down
7 changes: 2 additions & 5 deletions lib/AST/LookupVisibleDecls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -827,14 +827,11 @@ void swift::lookupVisibleDecls(VisibleDeclConsumer &Consumer,
Consumer.foundDecl(const_cast<ParamDecl*>(AFD->getImplicitSelfDecl()),
DeclVisibilityKind::FunctionParameter);

if (AFD->getExtensionType()) {
ExtendedType = AFD->getExtensionType();
if (AFD->getDeclContext()->isTypeContext()) {
ExtendedType = AFD->getDeclContext()->getSelfTypeInContext();
BaseDecl = AFD->getImplicitSelfDecl();
DC = DC->getParent();

if (DC->getAsProtocolExtensionContext())
ExtendedType = DC->getSelfTypeInContext();

if (auto *FD = dyn_cast<FuncDecl>(AFD))
if (FD->isStatic())
ExtendedType = MetatypeType::get(ExtendedType);
Expand Down
22 changes: 11 additions & 11 deletions lib/AST/NameLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ bool swift::removeShadowedDecls(SmallVectorImpl<ValueDecl*> &decls,
if (decl->hasClangNode()) {
if (auto ctor = dyn_cast<ConstructorDecl>(decl)) {
auto ctorSignature
= std::make_pair(ctor->getExtensionType()->getCanonicalType(),
= std::make_pair(ctor->getDeclContext()->getDeclaredInterfaceType()
->getCanonicalType(),
decl->getFullName());
auto &knownCtors = ObjCCollidingConstructors[ctorSignature];
if (!knownCtors.empty())
Expand Down Expand Up @@ -722,18 +723,17 @@ UnqualifiedLookup::UnqualifiedLookup(DeclName Name, DeclContext *DC,
if (!isCascadingUse.hasValue() || isCascadingUse.getValue())
isCascadingUse = AFD->isCascadingContextForLookup(false);

if (AFD->getExtensionType()) {
if (AFD->getDeclContext()->getAsProtocolOrProtocolExtensionContext()) {
ExtendedType = AFD->getDeclContext()->getSelfTypeInContext();
if (AFD->getDeclContext()->isTypeContext()) {
ExtendedType = AFD->getDeclContext()->getSelfTypeInContext();
// FIXME: Hack to deal with missing 'Self' archetypes.
if (!ExtendedType)
if (auto *PD = AFD->getDeclContext()
->getAsProtocolOrProtocolExtensionContext())
ExtendedType = PD->getDeclaredType();

// Fallback path.
if (!ExtendedType)
ExtendedType = AFD->getExtensionType();
} else {
ExtendedType = AFD->getExtensionType();
}
BaseDecl = AFD->getImplicitSelfDecl();
MetaBaseDecl = AFD->getExtensionType()->getAnyNominal();
MetaBaseDecl = AFD->getDeclContext()
->getAsNominalTypeOrNominalTypeExtensionContext();
DC = DC->getParent();

if (auto *FD = dyn_cast<FuncDecl>(AFD))
Expand Down
13 changes: 4 additions & 9 deletions lib/AST/Substitution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,10 @@ Substitution Substitution::subst(Module *module,
conformance = ProtocolConformanceRef(lookupResults.front());
}

if (conformance) {
if (conformance->isConcrete())
conformancesChanged = true;
substConformances.push_back(*conformance);
} else {
assert(substReplacement->hasDependentProtocolConformances() &&
"couldn't find concrete conformance for concrete type?");
substConformances.push_back(ProtocolConformanceRef(proto));
}
assert(conformance);
if (conformance->isConcrete())
conformancesChanged = true;
substConformances.push_back(*conformance);
}
assert(substConformances.size() == Conformance.size());

Expand Down
43 changes: 0 additions & 43 deletions lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,17 +659,6 @@ bool TypeBase::isAnyObject() {
return false;
}

bool TypeBase::isEmptyExistentialComposition() {
if (auto emtType = ExistentialMetatypeType::get(this)) {
if (auto pcType = emtType->getInstanceType()->
getAs<ProtocolCompositionType>()) {
return pcType->getProtocols().empty();
}
}

return false;
}

bool TypeBase::isExistentialWithError() {
// FIXME: Compute this as a bit in TypeBase so this operation isn't
// overly expensive.
Expand Down Expand Up @@ -955,38 +944,6 @@ Type TypeBase::getRValueInstanceType() {
return type->getInOutObjectType();
}

TypeDecl *TypeBase::getDirectlyReferencedTypeDecl() const {
if (auto module = dyn_cast<ModuleType>(this))
return module->getModule();

if (auto nominal = dyn_cast<NominalType>(this))
return nominal->getDecl();

if (auto bound = dyn_cast<BoundGenericType>(this))
return bound->getDecl();

if (auto unbound = dyn_cast<UnboundGenericType>(this))
return unbound->getDecl();

if (auto alias = dyn_cast<NameAliasType>(this))
return alias->getDecl();

if (auto gp = dyn_cast<GenericTypeParamType>(this))
return gp->getDecl();

if (auto depMem = dyn_cast<DependentMemberType>(this))
return depMem->getAssocType();

if (auto archetype = dyn_cast<ArchetypeType>(this)) {
if (auto assoc = archetype->getAssocType())
return assoc;

return nullptr;
}

return nullptr;
}

/// \brief Collect the protocols in the existential type T into the given
/// vector.
static void addProtocols(Type T, SmallVectorImpl<ProtocolDecl *> &Protocols) {
Expand Down
3 changes: 2 additions & 1 deletion lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5414,7 +5414,8 @@ ConstructorDecl *SwiftDeclConverter::importConstructor(

void SwiftDeclConverter::recordObjCOverride(AbstractFunctionDecl *decl) {
// Figure out the class in which this method occurs.
auto classTy = decl->getExtensionType()->getAs<ClassType>();
auto classTy = decl->getDeclContext()->getDeclaredInterfaceType()
->getAs<ClassType>();
if (!classTy)
return;
auto superTy = classTy->getSuperclass(nullptr);
Expand Down
6 changes: 2 additions & 4 deletions lib/Index/Index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,7 @@ bool IndexSwiftASTWalker::passRelatedType(const TypeLoc &Ty) {
}

if (Ty.getType()) {
if (auto nominal = dyn_cast_or_null<NominalTypeDecl>(
Ty.getType()->getDirectlyReferencedTypeDecl()))
if (auto nominal = Ty.getType()->getAnyNominal())
if (!passRelated(nominal, Ty.getLoc()))
return false;
}
Expand Down Expand Up @@ -644,8 +643,7 @@ bool IndexSwiftASTWalker::reportPseudoAccessor(AbstractStorageDecl *D,
NominalTypeDecl *
IndexSwiftASTWalker::getTypeLocAsNominalTypeDecl(const TypeLoc &Ty) {
if (Type T = Ty.getType())
return dyn_cast_or_null<NominalTypeDecl>(
T->getDirectlyReferencedTypeDecl());
return T->getAnyNominal();
if (IdentTypeRepr *T = dyn_cast_or_null<IdentTypeRepr>(Ty.getTypeRepr())) {
auto Comp = T->getComponentRange().back();
if (auto NTD = dyn_cast_or_null<NominalTypeDecl>(Comp->getBoundDecl()))
Expand Down
Loading