From 03eec7da2b31db19d56bdac2441b9d0ce2e4e427 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Tue, 1 Aug 2023 13:55:53 -0700 Subject: [PATCH] Remove redundant SILType::isMoveOnlyNominalType (NFC) and implement `SILType::isPureMoveOnly` in terms of `Type::isPureMoveOnly`. --- include/swift/SIL/SILType.h | 4 ---- lib/SIL/IR/SILType.cpp | 16 ++++------------ lib/SIL/Verifier/SILVerifier.cpp | 2 +- .../MoveOnlyDeinitDevirtualization.cpp | 16 ++++++++++++---- 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/include/swift/SIL/SILType.h b/include/swift/SIL/SILType.h index 447ee237636..fa408927323 100644 --- a/include/swift/SIL/SILType.h +++ b/include/swift/SIL/SILType.h @@ -756,10 +756,6 @@ public: /// deinitialization beyond destruction of its members. bool isValueTypeWithDeinit() const; - /// Returns true if and only if this type is a first class move only - /// type. NOTE: Returns false if the type is a move only wrapped type. - bool isMoveOnlyNominalType() const; - /// Returns true if this SILType is a move only wrapper type. /// /// Canonical way to check if a SILType is move only. Using is/getAs/castTo diff --git a/lib/SIL/IR/SILType.cpp b/lib/SIL/IR/SILType.cpp index 75a91a8f519..01dfea4d1e2 100644 --- a/lib/SIL/IR/SILType.cpp +++ b/lib/SIL/IR/SILType.cpp @@ -1030,7 +1030,7 @@ SILType::getSingletonAggregateFieldType(SILModule &M, bool SILType::isMoveOnly() const { // Nominal types are move-only if declared as such. - if (isMoveOnlyNominalType()) + if (isPureMoveOnly()) return true; @@ -1048,19 +1048,11 @@ bool SILType::isMoveOnly() const { return isMoveOnlyWrapped(); } -bool SILType::isMoveOnlyNominalType() const { - if (auto *nom = getNominalOrBoundGenericNominal()) - if (nom->isMoveOnly()) - return true; - return false; +bool SILType::isPureMoveOnly() const { + return getASTType()->isPureMoveOnly(); } -bool SILType::isPureMoveOnly() const { - if (auto *nom = getNominalOrBoundGenericNominal()) - if (nom->isMoveOnly()) - return true; - return false; -} + bool SILType::isValueTypeWithDeinit() const { // Do not look inside an aggregate type that has a user-deinit, for which diff --git a/lib/SIL/Verifier/SILVerifier.cpp b/lib/SIL/Verifier/SILVerifier.cpp index 66ee58e9914..0bf3941d6a3 100644 --- a/lib/SIL/Verifier/SILVerifier.cpp +++ b/lib/SIL/Verifier/SILVerifier.cpp @@ -6016,7 +6016,7 @@ public: auto type = ddi->getType(); require(type == ddi->getOperand()->getType(), "Result and operand must have the same type."); - require(type.isMoveOnlyNominalType(), + require(type.isPureMoveOnly(), "drop_deinit only allowed for move-only types"); require(type.getNominalOrBoundGenericNominal() ->getValueTypeDestructor(), "drop_deinit only allowed for " diff --git a/lib/SILOptimizer/Transforms/MoveOnlyDeinitDevirtualization.cpp b/lib/SILOptimizer/Transforms/MoveOnlyDeinitDevirtualization.cpp index f537b6bf56f..ae671e69742 100644 --- a/lib/SILOptimizer/Transforms/MoveOnlyDeinitDevirtualization.cpp +++ b/lib/SILOptimizer/Transforms/MoveOnlyDeinitDevirtualization.cpp @@ -69,11 +69,15 @@ static bool performTransform(SILFunction &fn) { if (auto *dvi = dyn_cast(inst)) { auto destroyType = dvi->getOperand()->getType(); - if (destroyType.isMoveOnlyNominalType() && + if (destroyType.isPureMoveOnly() && !isa(lookThroughOwnershipInsts(dvi->getOperand()))) { LLVM_DEBUG(llvm::dbgs() << "Handling: " << *dvi); auto *nom = destroyType.getNominalOrBoundGenericNominal(); - assert(nom); + if (!nom) { + LLVM_DEBUG(llvm::dbgs() + << "Not a nominal type, so no deinit! Skipping!\n"); + continue; + } auto *deinitFunc = mod.lookUpMoveOnlyDeinitFunction(nom); if (!deinitFunc) { LLVM_DEBUG(llvm::dbgs() @@ -108,11 +112,15 @@ static bool performTransform(SILFunction &fn) { if (auto *dai = dyn_cast(inst)) { auto destroyType = dai->getOperand()->getType(); - if (destroyType.isLoadable(fn) && destroyType.isMoveOnlyNominalType() && + if (destroyType.isLoadable(fn) && destroyType.isPureMoveOnly() && !isa(dai->getOperand())) { LLVM_DEBUG(llvm::dbgs() << "Handling: " << *dai); auto *nom = destroyType.getNominalOrBoundGenericNominal(); - assert(nom); + if (!nom) { + LLVM_DEBUG(llvm::dbgs() + << "Not a nominal type, so no deinit! Skipping!\n"); + continue; + } auto *deinitFunc = mod.lookUpMoveOnlyDeinitFunction(nom); if (!deinitFunc) { LLVM_DEBUG(llvm::dbgs()