Skip to content

Commit aa397c7

Browse files
authored
Merge pull request #67657 from jckarter/sil-type-consolidate-move-only-predicate
Remove redundant SILType::isMoveOnlyNominalType (NFC)
2 parents 7c0a9cc + 03eec7d commit aa397c7

File tree

4 files changed

+17
-21
lines changed

4 files changed

+17
-21
lines changed

include/swift/SIL/SILType.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -756,10 +756,6 @@ class SILType {
756756
/// deinitialization beyond destruction of its members.
757757
bool isValueTypeWithDeinit() const;
758758

759-
/// Returns true if and only if this type is a first class move only
760-
/// type. NOTE: Returns false if the type is a move only wrapped type.
761-
bool isMoveOnlyNominalType() const;
762-
763759
/// Returns true if this SILType is a move only wrapper type.
764760
///
765761
/// Canonical way to check if a SILType is move only. Using is/getAs/castTo

lib/SIL/IR/SILType.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ SILType::getSingletonAggregateFieldType(SILModule &M,
10301030

10311031
bool SILType::isMoveOnly() const {
10321032
// Nominal types are move-only if declared as such.
1033-
if (isMoveOnlyNominalType())
1033+
if (isPureMoveOnly())
10341034
return true;
10351035

10361036

@@ -1048,20 +1048,12 @@ bool SILType::isMoveOnly() const {
10481048
return isMoveOnlyWrapped();
10491049
}
10501050

1051-
bool SILType::isMoveOnlyNominalType() const {
1052-
if (auto *nom = getNominalOrBoundGenericNominal())
1053-
if (nom->isMoveOnly())
1054-
return true;
1055-
return false;
1056-
}
1057-
10581051
bool SILType::isPureMoveOnly() const {
1059-
if (auto *nom = getNominalOrBoundGenericNominal())
1060-
if (nom->isMoveOnly())
1061-
return true;
1062-
return false;
1052+
return getASTType()->isPureMoveOnly();
10631053
}
10641054

1055+
1056+
10651057
bool SILType::isValueTypeWithDeinit() const {
10661058
// Do not look inside an aggregate type that has a user-deinit, for which
10671059
// memberwise-destruction is not equivalent to aggregate destruction.

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6016,7 +6016,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
60166016
auto type = ddi->getType();
60176017
require(type == ddi->getOperand()->getType(),
60186018
"Result and operand must have the same type.");
6019-
require(type.isMoveOnlyNominalType(),
6019+
require(type.isPureMoveOnly(),
60206020
"drop_deinit only allowed for move-only types");
60216021
require(type.getNominalOrBoundGenericNominal()
60226022
->getValueTypeDestructor(), "drop_deinit only allowed for "

lib/SILOptimizer/Transforms/MoveOnlyDeinitDevirtualization.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,15 @@ static bool performTransform(SILFunction &fn) {
6969

7070
if (auto *dvi = dyn_cast<DestroyValueInst>(inst)) {
7171
auto destroyType = dvi->getOperand()->getType();
72-
if (destroyType.isMoveOnlyNominalType() &&
72+
if (destroyType.isPureMoveOnly() &&
7373
!isa<DropDeinitInst>(lookThroughOwnershipInsts(dvi->getOperand()))) {
7474
LLVM_DEBUG(llvm::dbgs() << "Handling: " << *dvi);
7575
auto *nom = destroyType.getNominalOrBoundGenericNominal();
76-
assert(nom);
76+
if (!nom) {
77+
LLVM_DEBUG(llvm::dbgs()
78+
<< "Not a nominal type, so no deinit! Skipping!\n");
79+
continue;
80+
}
7781
auto *deinitFunc = mod.lookUpMoveOnlyDeinitFunction(nom);
7882
if (!deinitFunc) {
7983
LLVM_DEBUG(llvm::dbgs()
@@ -108,11 +112,15 @@ static bool performTransform(SILFunction &fn) {
108112

109113
if (auto *dai = dyn_cast<DestroyAddrInst>(inst)) {
110114
auto destroyType = dai->getOperand()->getType();
111-
if (destroyType.isLoadable(fn) && destroyType.isMoveOnlyNominalType() &&
115+
if (destroyType.isLoadable(fn) && destroyType.isPureMoveOnly() &&
112116
!isa<DropDeinitInst>(dai->getOperand())) {
113117
LLVM_DEBUG(llvm::dbgs() << "Handling: " << *dai);
114118
auto *nom = destroyType.getNominalOrBoundGenericNominal();
115-
assert(nom);
119+
if (!nom) {
120+
LLVM_DEBUG(llvm::dbgs()
121+
<< "Not a nominal type, so no deinit! Skipping!\n");
122+
continue;
123+
}
116124
auto *deinitFunc = mod.lookUpMoveOnlyDeinitFunction(nom);
117125
if (!deinitFunc) {
118126
LLVM_DEBUG(llvm::dbgs()

0 commit comments

Comments
 (0)