Skip to content

Commit e312f8e

Browse files
committed
Add an option to get the native abstraction pattern of a storage decl.
For the most part, code should be working with the as-declared abstraction pattern of the storage, because that's the pattern produced by its accessors. However, in the special case of an accessor synthesized on demand to satisfy a protocol conformance, that accessor will use the native abstraction pattern of the declaration, and so the witness thunk that uses that accessor must use that pattern when generating its access. This doesn't matter today because the only on-demand synthesized accessor is materializeForSet, and witnesses for materializeForSet don't actually call the synthetic materializeForSet --- in fact, nothing does. But the modify accessor uses the otherwise-standard pattern where the witness modify calls the concrete modify, and that modify currently uses the native abstraction pattern.
1 parent 2fe4235 commit e312f8e

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

include/swift/SIL/TypeLowering.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -796,9 +796,12 @@ class TypeConverter {
796796
return ti.getLoweredType();
797797
}
798798

799-
AbstractionPattern getAbstractionPattern(AbstractStorageDecl *storage);
800-
AbstractionPattern getAbstractionPattern(VarDecl *var);
801-
AbstractionPattern getAbstractionPattern(SubscriptDecl *subscript);
799+
AbstractionPattern getAbstractionPattern(AbstractStorageDecl *storage,
800+
bool isNonObjC = false);
801+
AbstractionPattern getAbstractionPattern(VarDecl *var,
802+
bool isNonObjC = false);
803+
AbstractionPattern getAbstractionPattern(SubscriptDecl *subscript,
804+
bool isNonObjC = false);
802805
AbstractionPattern getIndicesAbstractionPattern(SubscriptDecl *subscript);
803806
AbstractionPattern getAbstractionPattern(EnumElementDecl *element);
804807

lib/SIL/AbstractionPattern.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,18 @@
3131
using namespace swift;
3232
using namespace swift::Lowering;
3333

34-
AbstractionPattern TypeConverter::getAbstractionPattern(AbstractStorageDecl *decl) {
34+
AbstractionPattern
35+
TypeConverter::getAbstractionPattern(AbstractStorageDecl *decl,
36+
bool isNonObjC) {
3537
if (auto var = dyn_cast<VarDecl>(decl)) {
36-
return getAbstractionPattern(var);
38+
return getAbstractionPattern(var, isNonObjC);
3739
} else {
38-
return getAbstractionPattern(cast<SubscriptDecl>(decl));
40+
return getAbstractionPattern(cast<SubscriptDecl>(decl), isNonObjC);
3941
}
4042
}
4143

42-
AbstractionPattern TypeConverter::getAbstractionPattern(SubscriptDecl *decl) {
44+
AbstractionPattern
45+
TypeConverter::getAbstractionPattern(SubscriptDecl *decl, bool isNonObjC) {
4346
CanGenericSignature genericSig;
4447
if (auto sig = decl->getGenericSignatureOfContext())
4548
genericSig = sig->getCanonicalSignature();
@@ -67,14 +70,18 @@ static const clang::Type *getClangType(const clang::Decl *decl) {
6770
return cast<clang::ObjCPropertyDecl>(decl)->getType().getTypePtr();
6871
}
6972

70-
AbstractionPattern TypeConverter::getAbstractionPattern(VarDecl *var) {
73+
AbstractionPattern
74+
TypeConverter::getAbstractionPattern(VarDecl *var, bool isNonObjC) {
7175
CanGenericSignature genericSig;
7276
if (auto sig = var->getDeclContext()->getGenericSignatureOfContext())
7377
genericSig = sig->getCanonicalSignature();
7478

7579
CanType swiftType = var->getInterfaceType()
7680
->getCanonicalType();
7781

82+
if (isNonObjC)
83+
return AbstractionPattern(genericSig, swiftType);
84+
7885
if (auto clangDecl = var->getClangDecl()) {
7986
auto clangType = getClangType(clangDecl);
8087
auto contextType = var->getDeclContext()->mapTypeIntoContext(swiftType);

0 commit comments

Comments
 (0)