|
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> |
@@ -3900,7 +3901,8 @@ class ClassDecl final : public NominalTypeDecl { |
3900 | 3901 | /// |
3901 | 3902 | /// \see getForeignClassKind |
3902 | 3903 | bool isForeign() const { |
3903 | | - return getForeignClassKind() != ForeignKind::Normal; |
| 3904 | + return getForeignClassKind() != ForeignKind::Normal || |
| 3905 | + const_cast<ClassDecl *>(this)->isForeignReferenceType(); |
3904 | 3906 | } |
3905 | 3907 |
|
3906 | 3908 | /// Whether the class is (known to be) a default actor. |
@@ -3935,9 +3937,22 @@ class ClassDecl final : public NominalTypeDecl { |
3935 | 3937 | bool isNativeNSObjectSubclass() const; |
3936 | 3938 |
|
3937 | 3939 | /// Whether the class uses the ObjC object model (reference counting, |
3938 | | - /// allocation, etc.) instead of the Swift model. |
3939 | | - bool usesObjCObjectModel() const { |
3940 | | - return checkAncestry(AncestryFlags::ObjCObjectModel); |
| 3940 | + /// allocation, etc.), the Swift model, or has no reference counting at all. |
| 3941 | + ReferenceCounting getObjectModel() { |
| 3942 | + if (isForeignReferenceType()) |
| 3943 | + return ReferenceCounting::None; |
| 3944 | + |
| 3945 | + if (checkAncestry(AncestryFlags::ObjCObjectModel)) |
| 3946 | + return ReferenceCounting::ObjC; |
| 3947 | + |
| 3948 | + return ReferenceCounting::Native; |
| 3949 | + } |
| 3950 | + |
| 3951 | + LayoutConstraintKind getLayoutConstraintKind() { |
| 3952 | + if (getObjectModel() == ReferenceCounting::ObjC) |
| 3953 | + return LayoutConstraintKind::Class; |
| 3954 | + |
| 3955 | + return LayoutConstraintKind::NativeClass; |
3941 | 3956 | } |
3942 | 3957 |
|
3943 | 3958 | /// Returns true if the class has designated initializers that are not listed |
@@ -4059,6 +4074,11 @@ class ClassDecl final : public NominalTypeDecl { |
4059 | 4074 | bool hasKnownSwiftImplementation() const { |
4060 | 4075 | return !hasClangNode(); |
4061 | 4076 | } |
| 4077 | + |
| 4078 | + /// Used to determine if this class decl is a foriegn reference type. I.e., a |
| 4079 | + /// non-reference-counted swift reference type that was imported from a C++ |
| 4080 | + /// record. |
| 4081 | + bool isForeignReferenceType(); |
4062 | 4082 | }; |
4063 | 4083 |
|
4064 | 4084 | /// A convenience wrapper around the \c SelfReferencePosition::Kind enum. |
|
0 commit comments