Skip to content

Commit b6af269

Browse files
committed
[AST] Remove TypeDecl::hasInverse and move canBe{Copyable, Escapable} to NominalTypeDecl`
1 parent b09aad8 commit b6af269

File tree

3 files changed

+25
-38
lines changed

3 files changed

+25
-38
lines changed

include/swift/AST/Decl.h

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3215,32 +3215,6 @@ class TypeDecl : public ValueDecl {
32153215
};
32163216
};
32173217

3218-
/// "Does a conformance for Copyable exist for this type declaration?"
3219-
///
3220-
/// This doesn't mean that all instance of this type are Copyable, because
3221-
/// if a conditional conformance to Copyable exists, this method will return
3222-
/// true.
3223-
///
3224-
/// If you need a more precise answer, ask this Decl's corresponding
3225-
/// Type if it `isCopyable` instead of using this.
3226-
CanBeInvertible::Result canBeCopyable() const;
3227-
3228-
/// "Does a conformance for Escapable exist for this type declaration?"
3229-
///
3230-
/// This doesn't mean that all instance of this type are Escapable, because
3231-
/// if a conditional conformance to Escapable exists, this method will return
3232-
/// true.
3233-
///
3234-
/// If you need a more precise answer, ask this Decl's corresponding
3235-
/// Type if it `isEscapable` instead of using this.
3236-
CanBeInvertible::Result canBeEscapable() const;
3237-
3238-
InverseMarking::Mark hasInverseMarking(InvertibleProtocolKind target) const;
3239-
3240-
/// Determine how the given invertible protocol was written on this TypeDecl,
3241-
/// if at all.
3242-
InverseMarking getMarking(InvertibleProtocolKind ip) const;
3243-
32443218
static bool classof(const Decl *D) {
32453219
return D->getKind() >= DeclKind::First_TypeDecl &&
32463220
D->getKind() <= DeclKind::Last_TypeDecl;
@@ -3258,7 +3232,7 @@ class TypeDecl : public ValueDecl {
32583232
}
32593233
};
32603234

3261-
/// A type declaration that can have generic parameters attached to it. Because
3235+
/// A type declaration that have generic parameters attached to it. Because
32623236
/// it has these generic parameters, it is always a DeclContext.
32633237
class GenericTypeDecl : public GenericContext, public TypeDecl {
32643238
public:
@@ -4374,6 +4348,26 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
43744348
/// Returns null if the type is a class, or does not have a declared `deinit`.
43754349
DestructorDecl *getValueTypeDestructor();
43764350

4351+
/// "Does a conformance for Copyable exist for this type declaration?"
4352+
///
4353+
/// This doesn't mean that all instance of this type are Copyable, because
4354+
/// if a conditional conformance to Copyable exists, this method will return
4355+
/// true.
4356+
///
4357+
/// If you need a more precise answer, ask this Decl's corresponding
4358+
/// Type if it `isCopyable` instead of using this.
4359+
CanBeInvertible::Result canBeCopyable() const;
4360+
4361+
/// "Does a conformance for Escapable exist for this type declaration?"
4362+
///
4363+
/// This doesn't mean that all instance of this type are Escapable, because
4364+
/// if a conditional conformance to Escapable exists, this method will return
4365+
/// true.
4366+
///
4367+
/// If you need a more precise answer, ask this Decl's corresponding
4368+
/// Type if it `isEscapable` instead of using this.
4369+
CanBeInvertible::Result canBeEscapable() const;
4370+
43774371
/// Determine whether this type has `: <target>` stated explicitly in
43784372
/// its inheritance clause.
43794373
bool hasMarking(InvertibleProtocolKind target) const;

lib/AST/Decl.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4901,14 +4901,6 @@ GenericParameterReferenceInfo ValueDecl::findExistentialSelfReferences(
49014901
llvm::None);
49024902
}
49034903

4904-
InverseMarking::Mark
4905-
TypeDecl::hasInverseMarking(InvertibleProtocolKind target) const {
4906-
if (auto NTD = dyn_cast<NominalTypeDecl>(this))
4907-
return NTD->hasInverseMarking(target);
4908-
4909-
return InverseMarking::Mark(InverseMarking::Kind::None);
4910-
}
4911-
49124904
static TypeDecl::CanBeInvertible::Result
49134905
conformanceExists(TypeDecl const *decl, InvertibleProtocolKind ip) {
49144906
auto *proto = decl->getASTContext().getProtocol(getKnownProtocolKind(ip));
@@ -4935,7 +4927,7 @@ conformanceExists(TypeDecl const *decl, InvertibleProtocolKind ip) {
49354927
return TypeDecl::CanBeInvertible::Always;
49364928
}
49374929

4938-
TypeDecl::CanBeInvertible::Result TypeDecl::canBeCopyable() const {
4930+
TypeDecl::CanBeInvertible::Result NominalTypeDecl::canBeCopyable() const {
49394931
if (!getASTContext().LangOpts.hasFeature(Feature::NoncopyableGenerics)) {
49404932
return !hasInverseMarking(InvertibleProtocolKind::Copyable)
49414933
? CanBeInvertible::Always
@@ -4945,7 +4937,7 @@ TypeDecl::CanBeInvertible::Result TypeDecl::canBeCopyable() const {
49454937
return conformanceExists(this, InvertibleProtocolKind::Copyable);
49464938
}
49474939

4948-
TypeDecl::CanBeInvertible::Result TypeDecl::canBeEscapable() const {
4940+
TypeDecl::CanBeInvertible::Result NominalTypeDecl::canBeEscapable() const {
49494941
if (!getASTContext().LangOpts.hasFeature(Feature::NoncopyableGenerics)) {
49504942
return !hasInverseMarking(InvertibleProtocolKind::Escapable)
49514943
? CanBeInvertible::Always

lib/IRGen/GenDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,8 @@ void IRGenModule::addObjCClassStub(llvm::Constant *classPtr) {
10671067

10681068
void IRGenModule::addRuntimeResolvableType(GenericTypeDecl *type) {
10691069
// Collect the nominal type records we emit into a special section.
1070-
if (!type->canBeCopyable()) {
1070+
if (isa<NominalTypeDecl>(type) &&
1071+
!cast<NominalTypeDecl>(type)->canBeCopyable()) {
10711072
// Older runtimes should not be allowed to discover noncopyable types, since
10721073
// they will try to expose them dynamically as copyable types. Record
10731074
// noncopyable type descriptors in a separate vector so that future

0 commit comments

Comments
 (0)