From fd03de4cd6d9c7b009e499d49c2b331ba74e75a8 Mon Sep 17 00:00:00 2001 From: Andrew Trick Date: Thu, 23 Mar 2023 11:34:51 -0700 Subject: [PATCH 1/2] PrunedLiveness; remove SWIFT_ASSERT_ONLY_DECL There's no value in hiding this flag in release builds. I meant to remove SWIFT_ASSERT_ONLY_DECL in the previous commit. --- include/swift/SIL/PrunedLiveness.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/swift/SIL/PrunedLiveness.h b/include/swift/SIL/PrunedLiveness.h index 7c8eececbe784..9172d4c1fd230 100644 --- a/include/swift/SIL/PrunedLiveness.h +++ b/include/swift/SIL/PrunedLiveness.h @@ -191,10 +191,10 @@ class PrunedLiveBlocks { SmallVectorImpl *discoveredBlocks = nullptr; /// Only a clean bitfield can be initialized. - SWIFT_ASSERT_ONLY_DECL(bool cleanFlag = true); + bool cleanFlag = true; /// Once the first def has been initialized, uses can be added. - SWIFT_ASSERT_ONLY_DECL(bool initializedFlag = false); + bool initializedFlag = false; public: PrunedLiveBlocks(SILFunction *function, From 4ea51cfe33f50d83741e3c8a08dcedfc455be2a2 Mon Sep 17 00:00:00 2001 From: nate-chandler <46721658+nate-chandler@users.noreply.github.com> Date: Thu, 23 Mar 2023 13:22:25 -0700 Subject: [PATCH 2/2] Revert "Add a verify-di-hole assertion to SILBuilder." --- include/swift/SIL/SILBuilder.h | 25 +++---------------------- include/swift/SIL/SILDebugScope.h | 3 --- lib/SIL/IR/SILBuilder.cpp | 19 ------------------- lib/SIL/IR/SILDebugScope.cpp | 11 ----------- lib/SIL/Verifier/SILVerifier.cpp | 17 ++++++++++++++++- lib/SILGen/SILGenBuilder.cpp | 20 +++----------------- lib/SILGen/SILGenBuilder.h | 6 +----- 7 files changed, 23 insertions(+), 78 deletions(-) diff --git a/include/swift/SIL/SILBuilder.h b/include/swift/SIL/SILBuilder.h index 4490a72140b61..66838593aab48 100644 --- a/include/swift/SIL/SILBuilder.h +++ b/include/swift/SIL/SILBuilder.h @@ -106,16 +106,6 @@ class SILBuilder { /// are not auto-inserted. SILBasicBlock *BB; SILBasicBlock::iterator InsertPt; -#ifndef NDEBUG - /// Used in the di-hole verifier assertion. - /// \{ -protected: - bool EnableDIHoleVerification = false; - -private: - const SILDebugScope *PrevDebugScope = nullptr; - /// \} -#endif const SILDebugScope *CurDebugScope = nullptr; Optional CurDebugLocOverride = None; @@ -125,8 +115,7 @@ class SILBuilder { SILBuilder(SILFunction &F, SmallVectorImpl *InsertedInstrs) : TempContext(F.getModule(), InsertedInstrs), C(TempContext), F(&F), - BB(nullptr) { - } + BB(nullptr) {} explicit SILBuilder(SILInstruction *I, SmallVectorImpl *InsertedInstrs = 0) @@ -233,7 +222,7 @@ class SILBuilder { return getModule().Types.getTypeLowering(T, expansion); } - void setCurrentDebugScope(const SILDebugScope *DS); + void setCurrentDebugScope(const SILDebugScope *DS) { CurDebugScope = DS; } const SILDebugScope *getCurrentDebugScope() const { return CurDebugScope; } /// Apply a debug location override. If loc is None, the current override is @@ -290,18 +279,10 @@ class SILBuilder { /// clearInsertionPoint - Clear the insertion point: created instructions will /// not be inserted into a block. - void clearInsertionPoint() { -#ifndef NDEBUG - PrevDebugScope = nullptr; -#endif - BB = nullptr; - } + void clearInsertionPoint() { BB = nullptr; } /// setInsertionPoint - Set the insertion point. void setInsertionPoint(SILBasicBlock *BB, SILBasicBlock::iterator insertPt) { -#ifndef NDEBUG - PrevDebugScope = nullptr; -#endif this->BB = BB; this->InsertPt = insertPt; assert(insertPt == BB->end() || insertPt->getParent() == BB); diff --git a/include/swift/SIL/SILDebugScope.h b/include/swift/SIL/SILDebugScope.h index 9fb1efdd12201..789ef02c61586 100644 --- a/include/swift/SIL/SILDebugScope.h +++ b/include/swift/SIL/SILDebugScope.h @@ -66,9 +66,6 @@ class SILDebugScope : public SILAllocated { /// into. SILFunction *getParentFunction() const; - /// Determine whether other is an (indirect) parent of this scope. - bool isAncestor(const SILDebugScope *other) const; - /// If this is a debug scope associated with an inlined call site, return the /// SILLocation associated with the call site resulting from the final /// inlining. diff --git a/lib/SIL/IR/SILBuilder.cpp b/lib/SIL/IR/SILBuilder.cpp index 3b11c9bbb0439..43495b7ad7d4c 100644 --- a/lib/SIL/IR/SILBuilder.cpp +++ b/lib/SIL/IR/SILBuilder.cpp @@ -28,22 +28,6 @@ SILBuilder::SILBuilder(SILGlobalVariable *GlobVar, setInsertionPoint(&GlobVar->StaticInitializerBlock); } -void SILBuilder::setCurrentDebugScope(const SILDebugScope *DS) { -#ifndef NDEBUG - if (EnableDIHoleVerification && DS != CurDebugScope) { - // Detect a situation where: - // PrevDebugScope = sil_scope(parent: CurDebugScope) - // CurDebugScope = sil_scope(parent:) - // DS = PrevDebugScope - if (DS && DS == PrevDebugScope) - assert(!CurDebugScope->isAncestor(PrevDebugScope) && - "attempting to re-enter scope within same basic block"); - PrevDebugScope = CurDebugScope; - } -#endif - CurDebugScope = DS; -} - IntegerLiteralInst *SILBuilder::createIntegerLiteral(IntegerLiteralExpr *E) { return insert(IntegerLiteralInst::create(E, getSILDebugLocation(E), getModule())); @@ -257,9 +241,6 @@ void SILBuilder::emitBlock(SILBasicBlock *BB, SILLocation BranchLoc) { /// instruction) then split the block at that instruction and return the /// continuation block. SILBasicBlock *SILBuilder::splitBlockForFallthrough() { -#ifndef NDEBUG - PrevDebugScope = nullptr; -#endif // If we are concatenating, just create and return a new block. if (insertingAtEndOfBlock()) { return getFunction().createBasicBlockAfter(BB); diff --git a/lib/SIL/IR/SILDebugScope.cpp b/lib/SIL/IR/SILDebugScope.cpp index d059f2cec5250..9212d4991ccd2 100644 --- a/lib/SIL/IR/SILDebugScope.cpp +++ b/lib/SIL/IR/SILDebugScope.cpp @@ -37,17 +37,6 @@ SILDebugScope::SILDebugScope(SILLocation Loc, SILFunction *SILFn, SILDebugScope::SILDebugScope(SILLocation Loc) : Loc(Loc), InlinedCallSite(nullptr) {} -bool SILDebugScope::isAncestor(const SILDebugScope *other) const { - while (other) { - auto Parent = other->Parent; - auto *ParentScope = Parent.dyn_cast(); - if (ParentScope == this) - return true; - other = ParentScope; - } - return false; -} - SILFunction *SILDebugScope::getInlinedFunction() const { if (Parent.isNull()) return nullptr; diff --git a/lib/SIL/Verifier/SILVerifier.cpp b/lib/SIL/Verifier/SILVerifier.cpp index 0fb5afdb63c31..920133d0b2590 100644 --- a/lib/SIL/Verifier/SILVerifier.cpp +++ b/lib/SIL/Verifier/SILVerifier.cpp @@ -6272,7 +6272,22 @@ class SILVerifier : public SILVerifierBase { // Otherwise, we're allowed to re-enter a scope only if // the scope is an ancestor of the scope we're currently leaving. - if (DS->isAncestor(LastSeenScope)) { + auto isAncestorScope = [](const SILDebugScope *Cur, + const SILDebugScope *Previous) { + assert(Cur && "null current scope queried"); + assert(Previous && "null previous scope queried"); + const SILDebugScope *Tmp = Previous; + while (Tmp) { + auto Parent = Tmp->Parent; + auto *ParentScope = Parent.dyn_cast(); + if (ParentScope == Cur) + return true; + Tmp = ParentScope; + } + return false; + }; + + if (isAncestorScope(DS, LastSeenScope)) { LastSeenScope = DS; LastSeenScopeInst = &SI; continue; diff --git a/lib/SILGen/SILGenBuilder.cpp b/lib/SILGen/SILGenBuilder.cpp index a55c5fcc0e8bf..d679592ef5b5e 100644 --- a/lib/SILGen/SILGenBuilder.cpp +++ b/lib/SILGen/SILGenBuilder.cpp @@ -1,5 +1,3 @@ - - //===--- SILGenBuilder.cpp ------------------------------------------------===// // // This source file is part of the Swift.org open source project @@ -38,27 +36,15 @@ SILGenModule &SILGenBuilder::getSILGenModule() const { return SGF.SGM; } //===----------------------------------------------------------------------===// SILGenBuilder::SILGenBuilder(SILGenFunction &SGF) - : SILBuilder(SGF.F), SGF(SGF) { -#ifndef NDEBUG - EnableDIHoleVerification = true; -#endif -} + : SILBuilder(SGF.F), SGF(SGF) {} SILGenBuilder::SILGenBuilder(SILGenFunction &SGF, SILBasicBlock *insertBB, SmallVectorImpl *insertedInsts) - : SILBuilder(insertBB, insertedInsts), SGF(SGF) { -#ifndef NDEBUG - EnableDIHoleVerification = true; -#endif -} + : SILBuilder(insertBB, insertedInsts), SGF(SGF) {} SILGenBuilder::SILGenBuilder(SILGenFunction &SGF, SILBasicBlock *insertBB, SILBasicBlock::iterator insertInst) - : SILBuilder(insertBB, insertInst), SGF(SGF) { -#ifndef NDEBUG - EnableDIHoleVerification = true; -#endif -} + : SILBuilder(insertBB, insertInst), SGF(SGF) {} //===----------------------------------------------------------------------===// // Managed Value APIs diff --git a/lib/SILGen/SILGenBuilder.h b/lib/SILGen/SILGenBuilder.h index 79854ed7da1b8..2161735ce0369 100644 --- a/lib/SILGen/SILGenBuilder.h +++ b/lib/SILGen/SILGenBuilder.h @@ -55,11 +55,7 @@ class SILGenBuilder : public SILBuilder { SILGenBuilder(SILGenBuilder &builder, SILBasicBlock *insertBB) : SILBuilder(insertBB, builder.getCurrentDebugScope(), builder.getBuilderContext()), - SGF(builder.SGF) { -#ifndef NDEBUG - EnableDIHoleVerification = true; -#endif - } + SGF(builder.SGF) {} SILGenModule &getSILGenModule() const; SILGenFunction &getSILGenFunction() const { return SGF; }