|
28 | 28 | #include "swift/AST/GenericParamKey.h" |
29 | 29 | #include "swift/AST/IfConfigClause.h" |
30 | 30 | #include "swift/AST/LayoutConstraint.h" |
| 31 | +#include "swift/AST/ReferenceCounting.h" |
31 | 32 | #include "swift/AST/StorageImpl.h" |
32 | 33 | #include "swift/AST/TypeAlignments.h" |
33 | 34 | #include "swift/AST/TypeWalker.h" |
|
37 | 38 | #include "swift/Basic/Compiler.h" |
38 | 39 | #include "swift/Basic/Debug.h" |
39 | 40 | #include "swift/Basic/InlineBitfield.h" |
| 41 | +#include "swift/Basic/Located.h" |
40 | 42 | #include "swift/Basic/NullablePtr.h" |
41 | 43 | #include "swift/Basic/OptionalEnum.h" |
42 | 44 | #include "swift/Basic/Range.h" |
43 | | -#include "swift/Basic/Located.h" |
44 | 45 | #include "llvm/ADT/DenseSet.h" |
45 | 46 | #include "llvm/Support/TrailingObjects.h" |
46 | 47 | #include <type_traits> |
@@ -3906,7 +3907,8 @@ class ClassDecl final : public NominalTypeDecl { |
3906 | 3907 | /// |
3907 | 3908 | /// \see getForeignClassKind |
3908 | 3909 | bool isForeign() const { |
3909 | | - return getForeignClassKind() != ForeignKind::Normal; |
| 3910 | + return getForeignClassKind() != ForeignKind::Normal || |
| 3911 | + const_cast<ClassDecl *>(this)->isForeignReferenceType(); |
3910 | 3912 | } |
3911 | 3913 |
|
3912 | 3914 | /// Whether the class is (known to be) a default actor. |
@@ -3941,9 +3943,22 @@ class ClassDecl final : public NominalTypeDecl { |
3941 | 3943 | bool isNativeNSObjectSubclass() const; |
3942 | 3944 |
|
3943 | 3945 | /// Whether the class uses the ObjC object model (reference counting, |
3944 | | - /// allocation, etc.) instead of the Swift model. |
3945 | | - bool usesObjCObjectModel() const { |
3946 | | - return checkAncestry(AncestryFlags::ObjCObjectModel); |
| 3946 | + /// allocation, etc.), the Swift model, or has no reference counting at all. |
| 3947 | + ReferenceCounting getObjectModel() { |
| 3948 | + if (isForeignReferenceType()) |
| 3949 | + return ReferenceCounting::None; |
| 3950 | + |
| 3951 | + if (checkAncestry(AncestryFlags::ObjCObjectModel)) |
| 3952 | + return ReferenceCounting::ObjC; |
| 3953 | + |
| 3954 | + return ReferenceCounting::Native; |
| 3955 | + } |
| 3956 | + |
| 3957 | + LayoutConstraintKind getLayoutConstraintKind() { |
| 3958 | + if (getObjectModel() == ReferenceCounting::ObjC) |
| 3959 | + return LayoutConstraintKind::Class; |
| 3960 | + |
| 3961 | + return LayoutConstraintKind::NativeClass; |
3947 | 3962 | } |
3948 | 3963 |
|
3949 | 3964 | /// Returns true if the class has designated initializers that are not listed |
@@ -4065,6 +4080,11 @@ class ClassDecl final : public NominalTypeDecl { |
4065 | 4080 | bool hasKnownSwiftImplementation() const { |
4066 | 4081 | return !hasClangNode(); |
4067 | 4082 | } |
| 4083 | + |
| 4084 | + /// Used to determine if this class decl is a foriegn reference type. I.e., a |
| 4085 | + /// non-reference-counted swift reference type that was imported from a C++ |
| 4086 | + /// record. |
| 4087 | + bool isForeignReferenceType(); |
4068 | 4088 | }; |
4069 | 4089 |
|
4070 | 4090 | /// A convenience wrapper around the \c SelfReferencePosition::Kind enum. |
|
0 commit comments