Skip to content

Commit 4dc4879

Browse files
authored
Merge pull request #23003 from davezarzycki/fix_always_loadable_ref_stor_types
[AST] Reference ownership macro fixes and cleanup
2 parents 9e5d8ee + b6b5ea5 commit 4dc4879

File tree

7 files changed

+36
-64
lines changed

7 files changed

+36
-64
lines changed

include/swift/SIL/SILInstruction.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3929,30 +3929,26 @@ class StoreReferenceInstBase : public InstructionBase<K, NonValueInstruction> {
39293929
/// \param loc The location of the expression that caused the load.
39303930
/// \param lvalue The SILValue representing the address to
39313931
/// use for the load.
3932-
#define NEVER_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
3932+
#define NEVER_OR_SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
39333933
class Load##Name##Inst \
39343934
: public LoadReferenceInstBase<SILInstructionKind::Load##Name##Inst> { \
39353935
friend SILBuilder; \
39363936
Load##Name##Inst(SILDebugLocation loc, SILValue lvalue, IsTake_t isTake) \
39373937
: LoadReferenceInstBase(loc, lvalue, isTake) {} \
39383938
};
3939-
#define SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
3940-
NEVER_LOADABLE_CHECKED_REF_STORAGE(Name, "...")
39413939
#include "swift/AST/ReferenceStorage.def"
39423940

39433941
/// Represents a store to a dynamic reference storage memory location.
39443942
/// This is only required for address-only scenarios; for loadable
39453943
/// references, it's better to use a ref_to_##name and a store.
3946-
#define NEVER_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
3944+
#define NEVER_OR_SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
39473945
class Store##Name##Inst \
39483946
: public StoreReferenceInstBase<SILInstructionKind::Store##Name##Inst> { \
39493947
friend SILBuilder; \
39503948
Store##Name##Inst(SILDebugLocation loc, SILValue src, SILValue dest, \
39513949
IsInitialization_t isInit) \
39523950
: StoreReferenceInstBase(loc, src, dest, isInit) {} \
39533951
};
3954-
#define SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
3955-
NEVER_LOADABLE_CHECKED_REF_STORAGE(Name, "...")
39563952
#include "swift/AST/ReferenceStorage.def"
39573953

39583954
/// CopyAddrInst - Represents a copy from one memory location to another. This

lib/IRGen/GenHeap.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ RESULT IRGenFunction::emit##KIND(TYPE1 val1, ReferenceCounting style) { \
10771077
llvm_unreachable("bad refcounting style"); \
10781078
}
10791079

1080-
#define NEVER_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
1080+
#define NEVER_OR_SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
10811081
DEFINE_BINARY_OPERATION(Name##CopyInit, void, Address, Address) \
10821082
DEFINE_BINARY_OPERATION(Name##TakeInit, void, Address, Address) \
10831083
DEFINE_BINARY_OPERATION(Name##CopyAssign, void, Address, Address) \
@@ -1087,8 +1087,6 @@ RESULT IRGenFunction::emit##KIND(TYPE1 val1, ReferenceCounting style) { \
10871087
DEFINE_BINARY_OPERATION(Name##LoadStrong, llvm::Value *, Address,llvm::Type*)\
10881088
DEFINE_BINARY_OPERATION(Name##TakeStrong, llvm::Value *, Address,llvm::Type*)\
10891089
DEFINE_UNARY_OPERATION(Name##Destroy, void, Address)
1090-
#define SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
1091-
NEVER_LOADABLE_CHECKED_REF_STORAGE(Name, "...")
10921090
#include "swift/AST/ReferenceStorage.def"
10931091

10941092

lib/SIL/InstructionUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ struct OwnershipQualifiedKindVisitor : SILInstructionVisitor<OwnershipQualifiedK
532532
QUALIFIED_INST(LoadBorrowInst)
533533
QUALIFIED_INST(CopyValueInst)
534534
QUALIFIED_INST(DestroyValueInst)
535-
#define SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
535+
#define ALWAYS_OR_SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
536536
QUALIFIED_INST(Copy##Name##ValueInst)
537537
#include "swift/AST/ReferenceStorage.def"
538538
#undef QUALIFIED_INST

lib/SIL/MemAccessUtils.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -481,10 +481,7 @@ bool swift::memInstMustInitialize(Operand *memOper) {
481481
return cast<StoreInst>(memInst)->getOwnershipQualifier()
482482
== StoreOwnershipQualifier::Init;
483483

484-
#define NEVER_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
485-
case SILInstructionKind::Store##Name##Inst: \
486-
return cast<Store##Name##Inst>(memInst)->isInitializationOfDest();
487-
#define SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
484+
#define NEVER_OR_SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
488485
case SILInstructionKind::Store##Name##Inst: \
489486
return cast<Store##Name##Inst>(memInst)->isInitializationOfDest();
490487
#include "swift/AST/ReferenceStorage.def"
@@ -694,9 +691,7 @@ void swift::visitAccessedAddress(SILInstruction *I,
694691
visitor(&I->getAllOperands()[CopyAddrInst::Dest]);
695692
return;
696693

697-
#define NEVER_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
698-
case SILInstructionKind::Store##Name##Inst:
699-
#define SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
694+
#define NEVER_OR_SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
700695
case SILInstructionKind::Store##Name##Inst:
701696
#include "swift/AST/ReferenceStorage.def"
702697
case SILInstructionKind::StoreInst:
@@ -708,9 +703,7 @@ void swift::visitAccessedAddress(SILInstruction *I,
708703
visitor(&I->getAllOperands()[0]);
709704
return;
710705

711-
#define NEVER_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
712-
case SILInstructionKind::Load##Name##Inst:
713-
#define SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
706+
#define NEVER_OR_SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
714707
case SILInstructionKind::Load##Name##Inst:
715708
#include "swift/AST/ReferenceStorage.def"
716709
case SILInstructionKind::InitExistentialAddrInst:
@@ -732,7 +725,7 @@ void swift::visitAccessedAddress(SILInstruction *I,
732725
}
733726
// Non-access cases: these are marked with memory side effects, but, by
734727
// themselves, do not access formal memory.
735-
#define SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
728+
#define ALWAYS_OR_SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
736729
case SILInstructionKind::Copy##Name##ValueInst:
737730
#include "swift/AST/ReferenceStorage.def"
738731
case SILInstructionKind::AbortApplyInst:

lib/SIL/SILPrinter.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,7 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
13451345
printDebugVar(DVAI->getVarInfo());
13461346
}
13471347

1348-
#define NEVER_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
1348+
#define NEVER_OR_SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
13491349
void visitLoad##Name##Inst(Load##Name##Inst *LI) { \
13501350
if (LI->isTake()) \
13511351
*this << "[take] "; \
@@ -1357,8 +1357,6 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
13571357
*this << "[initialization] "; \
13581358
*this << getIDAndType(SI->getDest()); \
13591359
}
1360-
#define SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
1361-
NEVER_LOADABLE_CHECKED_REF_STORAGE(Name, "...")
13621360
#include "swift/AST/ReferenceStorage.def"
13631361

13641362
void visitCopyAddrInst(CopyAddrInst *CI) {

lib/SIL/SILVerifier.cpp

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,74 +1814,55 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
18141814
"Operand of " #name "_to_ref does not have the " \
18151815
"operand's type as its referent type"); \
18161816
}
1817-
#define ALWAYS_LOADABLE_CHECKED_REF_STORAGE(Name, name, ...) \
1818-
LOADABLE_REF_STORAGE_HELPER(Name, name) \
1819-
void checkStrongRetain##Name##Inst(StrongRetain##Name##Inst *RI) { \
1820-
requireObjectType(Name##StorageType, RI->getOperand(), \
1821-
"Operand of strong_retain_" #name); \
1822-
require(!F.hasOwnership(), "strong_retain_" #name " is only in " \
1823-
"functions with unqualified " \
1824-
"ownership"); \
1825-
} \
1826-
void check##Name##RetainInst(Name##RetainInst *RI) { \
1827-
requireObjectType(Name##StorageType, RI->getOperand(), \
1828-
"Operand of " #name "_retain"); \
1829-
require(!F.hasOwnership(), \
1830-
#name "_retain is only in functions with unqualified ownership"); \
1831-
} \
1832-
void check##Name##ReleaseInst(Name##ReleaseInst *RI) { \
1833-
requireObjectType(Name##StorageType, RI->getOperand(), \
1834-
"Operand of " #name "_release"); \
1835-
require(!F.hasOwnership(), \
1836-
#name "_release is only in functions with unqualified ownership"); \
1837-
} \
1838-
void checkCopy##Name##ValueInst(Copy##Name##ValueInst *I) { \
1839-
requireObjectType(Name##StorageType, I->getOperand(), \
1840-
"Operand of " #name "_retain"); \
1841-
require(F.hasOwnership(), \
1842-
"copy_" #name "_value is only valid in functions with qualified " \
1843-
"ownership"); \
1844-
}
1845-
#define SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, name, ...) \
1846-
NEVER_LOADABLE_CHECKED_REF_STORAGE(Name, name, "...") \
1847-
LOADABLE_REF_STORAGE_HELPER(Name, name) \
1817+
#define ALWAYS_LOADABLE_CHECKED_REF_STORAGE_HELPER(Name, name, closure) \
18481818
void checkStrongRetain##Name##Inst(StrongRetain##Name##Inst *RI) { \
18491819
auto ty = requireObjectType(Name##StorageType, RI->getOperand(), \
18501820
"Operand of strong_retain_" #name); \
1851-
require(ty->isLoadable(ResilienceExpansion::Maximal), \
1852-
"strong_retain_" #name " requires '" #name "' type to be loadable"); \
1821+
closure(); \
1822+
(void)ty; \
18531823
require(!F.hasOwnership(), "strong_retain_" #name " is only in " \
18541824
"functions with unqualified " \
18551825
"ownership"); \
18561826
} \
18571827
void check##Name##RetainInst(Name##RetainInst *RI) { \
18581828
auto ty = requireObjectType(Name##StorageType, RI->getOperand(), \
18591829
"Operand of " #name "_retain"); \
1860-
require(ty->isLoadable(ResilienceExpansion::Maximal), \
1861-
#name "_retain requires '" #name "' type to be loadable"); \
1830+
closure(); \
1831+
(void)ty; \
18621832
require(!F.hasOwnership(), \
18631833
#name "_retain is only in functions with unqualified ownership"); \
18641834
} \
18651835
void check##Name##ReleaseInst(Name##ReleaseInst *RI) { \
18661836
auto ty = requireObjectType(Name##StorageType, RI->getOperand(), \
18671837
"Operand of " #name "_release"); \
1868-
require(ty->isLoadable(ResilienceExpansion::Maximal), \
1869-
#name "_release requires '" #name "' type to be loadable"); \
1838+
closure(); \
1839+
(void)ty; \
18701840
require(!F.hasOwnership(), \
18711841
#name "_release is only in functions with unqualified ownership"); \
18721842
} \
18731843
void checkCopy##Name##ValueInst(Copy##Name##ValueInst *I) { \
18741844
auto ty = requireObjectType(Name##StorageType, I->getOperand(), \
18751845
"Operand of " #name "_retain"); \
1876-
require(ty->isLoadable(ResilienceExpansion::Maximal), \
1877-
#name "_retain requires '" #name "' type to be loadable"); \
1846+
closure(); \
1847+
(void)ty; \
18781848
/* *NOTE* We allow copy_##name##_value to be used throughout the entire */ \
18791849
/* pipeline even though it is a higher level instruction. */ \
18801850
}
1851+
#define ALWAYS_LOADABLE_CHECKED_REF_STORAGE(Name, name, ...) \
1852+
LOADABLE_REF_STORAGE_HELPER(Name, name) \
1853+
ALWAYS_LOADABLE_CHECKED_REF_STORAGE_HELPER(Name, name, []{})
1854+
#define SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, name, ...) \
1855+
LOADABLE_REF_STORAGE_HELPER(Name, name) \
1856+
NEVER_LOADABLE_CHECKED_REF_STORAGE(Name, name, "...") \
1857+
ALWAYS_LOADABLE_CHECKED_REF_STORAGE_HELPER(Name, name, [&]{ \
1858+
require(ty->isLoadable(ResilienceExpansion::Maximal), \
1859+
"'" #name "' type must be loadable"); \
1860+
})
18811861
#define UNCHECKED_REF_STORAGE(Name, name, ...) \
18821862
LOADABLE_REF_STORAGE_HELPER(Name, name)
18831863
#include "swift/AST/ReferenceStorage.def"
18841864
#undef LOADABLE_REF_STORAGE_HELPER
1865+
#undef ALWAYS_LOADABLE_CHECKED_REF_STORAGE_HELPER
18851866

18861867
void checkMarkUninitializedInst(MarkUninitializedInst *MU) {
18871868
SILValue Src = MU->getOperand();

lib/SIL/TypeLowering.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ namespace {
982982
};
983983

984984
/// A type lowering for loadable @unowned types.
985-
#define SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
985+
#define ALWAYS_OR_SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
986986
class Loadable##Name##TypeLowering final : public LeafLoadableTypeLowering { \
987987
public: \
988988
Loadable##Name##TypeLowering(SILType type) \
@@ -1173,6 +1173,12 @@ namespace {
11731173
return new (TC, Dependent) OpaqueValueTypeLowering(silType, properties);
11741174
}
11751175

1176+
#define ALWAYS_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
1177+
TypeLowering * \
1178+
visit##Name##StorageType(Can##Name##StorageType type) { \
1179+
return new (TC, Dependent) Loadable##Name##TypeLowering( \
1180+
SILType::getPrimitiveObjectType(type)); \
1181+
}
11761182
#define SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
11771183
TypeLowering * \
11781184
visitLoadable##Name##StorageType(Can##Name##StorageType type) { \

0 commit comments

Comments
 (0)