Skip to content

Commit d5a2912

Browse files
authored
Revert "Better runtime failure messages (not yet enabled by default)"
1 parent b28b44b commit d5a2912

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+137
-296
lines changed

Diff for: docs/SIL.rst

+2-4
Original file line numberDiff line numberDiff line change
@@ -5110,15 +5110,13 @@ cond_fail
51105110
`````````
51115111
::
51125112

5113-
sil-instruction ::= 'cond_fail' sil-operand, string-literal
5113+
sil-instruction ::= 'cond_fail' sil-operand
51145114

5115-
cond_fail %0 : $Builtin.Int1, "failure reason"
5115+
cond_fail %0 : $Builtin.Int1
51165116
// %0 must be of type $Builtin.Int1
51175117

51185118
This instruction produces a `runtime failure`_ if the operand is one.
51195119
Execution proceeds normally if the operand is zero.
5120-
The second operand is a static failure message, which is displayed by the
5121-
debugger in case the failure is triggered.
51225120

51235121
Terminators
51245122
~~~~~~~~~~~

Diff for: include/swift/AST/Builtins.def

+4-4
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,10 @@ BUILTIN_SIL_OPERATION(BeginUnpairedModifyAccess, "beginUnpairedModifyAccess",
314314
/// be a pointer to an UnsafeValueBuffer that records an in progress access.
315315
BUILTIN_SIL_OPERATION(EndUnpairedAccess, "endUnpairedAccess", Special)
316316

317+
/// condfail(Int1) -> ()
318+
/// Triggers a runtime failure if the condition is true.
319+
BUILTIN_SIL_OPERATION(CondFail, "condfail", Special)
320+
317321
/// fixLifetime(T) -> ()
318322
/// Fixes the lifetime of any heap references in a value.
319323
BUILTIN_SIL_OPERATION(FixLifetime, "fixLifetime", Special)
@@ -400,10 +404,6 @@ BUILTIN_RUNTIME_CALL(IsOptionalType, "isOptional", "")
400404
BUILTIN(Id, Name, Attrs)
401405
#endif
402406

403-
/// condfail(Int1, RawPointer) -> ()
404-
/// Triggers a runtime failure if the condition is true.
405-
BUILTIN_MISC_OPERATION(CondFail, "condfail", "", Special)
406-
407407
/// Sizeof has type T.Type -> Int
408408
BUILTIN_MISC_OPERATION(Sizeof, "sizeof", "n", Special)
409409

Diff for: include/swift/SIL/SILBuilder.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -1775,15 +1775,15 @@ class SILBuilder {
17751775
//===--------------------------------------------------------------------===//
17761776

17771777
CondFailInst *createCondFail(SILLocation Loc, SILValue Operand,
1778-
StringRef Message, bool Inverted = false) {
1778+
bool Inverted = false) {
17791779
if (Inverted) {
17801780
SILType Ty = Operand->getType();
17811781
SILValue True(createIntegerLiteral(Loc, Ty, 1));
17821782
Operand =
17831783
createBuiltinBinaryFunction(Loc, "xor", Ty, Ty, {Operand, True});
17841784
}
1785-
return insert(CondFailInst::create(getSILDebugLocation(Loc), Operand,
1786-
Message, getModule()));
1785+
return insert(new (getModule())
1786+
CondFailInst(getSILDebugLocation(Loc), Operand));
17871787
}
17881788

17891789
BuiltinInst *createBuiltinTrap(SILLocation Loc) {

Diff for: include/swift/SIL/SILCloner.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -2447,8 +2447,7 @@ SILCloner<ImplClass>::visitCondFailInst(CondFailInst *Inst) {
24472447
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
24482448
recordClonedInstruction(
24492449
Inst, getBuilder().createCondFail(getOpLocation(Inst->getLoc()),
2450-
getOpValue(Inst->getOperand()),
2451-
Inst->getMessage()));
2450+
getOpValue(Inst->getOperand())));
24522451
}
24532452

24542453
template<typename ImplClass>

Diff for: include/swift/SIL/SILInstruction.h

+4-18
Original file line numberDiff line numberDiff line change
@@ -6715,28 +6715,14 @@ class ProjectExistentialBoxInst
67156715
//===----------------------------------------------------------------------===//
67166716

67176717
/// Trigger a runtime failure if the given Int1 value is true.
6718-
///
6719-
/// Optionally cond_fail has a static failure message, which is displayed in the debugger in case the failure
6720-
/// is triggered.
6721-
class CondFailInst final
6718+
class CondFailInst
67226719
: public UnaryInstructionBase<SILInstructionKind::CondFailInst,
6723-
NonValueInstruction>,
6724-
private llvm::TrailingObjects<CondFailInst, char>
6720+
NonValueInstruction>
67256721
{
6726-
friend TrailingObjects;
67276722
friend SILBuilder;
67286723

6729-
unsigned MessageSize;
6730-
6731-
CondFailInst(SILDebugLocation DebugLoc, SILValue Operand, StringRef Message);
6732-
6733-
static CondFailInst *create(SILDebugLocation DebugLoc, SILValue Operand,
6734-
StringRef Message, SILModule &M);
6735-
6736-
public:
6737-
StringRef getMessage() const {
6738-
return {getTrailingObjects<char>(), MessageSize};
6739-
}
6724+
CondFailInst(SILDebugLocation DebugLoc, SILValue Operand)
6725+
: UnaryInstructionBase(DebugLoc, Operand) {}
67406726
};
67416727

67426728
//===----------------------------------------------------------------------===//

Diff for: include/swift/Serialization/ModuleFormat.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5252
/// describe what change you made. The content of this comment isn't important;
5353
/// it just ensures a conflict if two people change the module format.
5454
/// Don't worry about adhering to the 80-column limit for this line.
55-
const uint16_t SWIFTMODULE_VERSION_MINOR = 501; // cond_fail messages
55+
const uint16_t SWIFTMODULE_VERSION_MINOR = 500; // dependency types for protocols
5656

5757
using DeclIDField = BCFixed<31>;
5858

Diff for: lib/AST/Builtins.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1037,9 +1037,8 @@ static ValueDecl *getCanBeObjCClassOperation(ASTContext &Context,
10371037
static ValueDecl *getCondFailOperation(ASTContext &C, Identifier Id) {
10381038
// Int1 -> ()
10391039
auto CondTy = BuiltinIntegerType::get(1, C);
1040-
auto MsgTy = C.TheRawPointerType;
10411040
auto VoidTy = TupleType::getEmpty(C);
1042-
return getBuiltinFunction(Id, {CondTy, MsgTy}, VoidTy);
1041+
return getBuiltinFunction(Id, {CondTy}, VoidTy);
10431042
}
10441043

10451044
static ValueDecl *getAssertConfOperation(ASTContext &C, Identifier Id) {

Diff for: lib/IRGen/GenBuiltin.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin,
204204

205205
// Emit non-mergeable traps only.
206206
if (IGF.Builder.isTrapIntrinsic(IID)) {
207-
IGF.Builder.CreateNonMergeableTrap(IGF.IGM, StringRef());
207+
IGF.Builder.CreateNonMergeableTrap(IGF.IGM);
208208
return;
209209
}
210210

@@ -359,8 +359,7 @@ if (Builtin.ID == BuiltinValueKind::id) { \
359359
// string literal. If we ever get to the point of executing this builtin
360360
// at run time, it implies an incorrect use of the builtin and must result
361361
// in a trap.
362-
IGF.emitTrap("invalid use of globalStringTablePointer",
363-
/*Unreachable=*/false);
362+
IGF.emitTrap(/*Unreachable=*/false);
364363
auto returnValue = llvm::UndefValue::get(IGF.IGM.Int8PtrTy);
365364
// Consume the arguments of the builtin.
366365
(void)args.claimAll();

Diff for: lib/IRGen/GenCast.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ emitExistentialScalarCastFn(IRGenModule &IGM,
469469
}
470470

471471
case CheckedCastMode::Unconditional: {
472-
IGF.emitTrap("type cast failed", /*EmitUnreachable=*/true);
472+
IGF.emitTrap(/*EmitUnreachable=*/true);
473473
break;
474474
}
475475
}

Diff for: lib/IRGen/IRBuilder.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ class IRBuilder : public IRBuilderBase {
307307
/// Call the trap intrinsic. If optimizations are enabled, an inline asm
308308
/// gadget is emitted before the trap. The gadget inhibits transforms which
309309
/// merge trap calls together, which makes debugging crashes easier.
310-
llvm::CallInst *CreateNonMergeableTrap(IRGenModule &IGM, StringRef failureMsg);
310+
llvm::CallInst *CreateNonMergeableTrap(IRGenModule &IGM);
311311

312312
/// Split a first-class aggregate value into its component pieces.
313313
template <unsigned N>

Diff for: lib/IRGen/IRGenDebugInfo.cpp

-39
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,6 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
148148

149149
void setCurrentLoc(IRBuilder &Builder, const SILDebugScope *DS,
150150
SILLocation Loc);
151-
152-
void addFailureMessageToCurrentLoc(IRBuilder &Builder, StringRef failureMsg);
153-
154151
void clearLoc(IRBuilder &Builder);
155152
void pushLoc();
156153
void popLoc();
@@ -1831,37 +1828,7 @@ void IRGenDebugInfoImpl::setCurrentLoc(IRBuilder &Builder,
18311828
auto DL = llvm::DebugLoc::get(L.Line, L.Column, Scope, InlinedAt);
18321829
Builder.SetCurrentDebugLocation(DL);
18331830
}
1834-
1835-
void IRGenDebugInfoImpl::addFailureMessageToCurrentLoc(IRBuilder &Builder,
1836-
StringRef failureMsg) {
1837-
auto TrapLoc = Builder.getCurrentDebugLocation();
1838-
1839-
// Create a function in the debug info which has failureMsg as name.
1840-
// TrapSc is the SIL debug scope which corresponds to TrapSP in the LLVM debug
1841-
// info.
1842-
RegularLocation ALoc = RegularLocation::getAutoGeneratedLocation();
1843-
const SILDebugScope *TrapSc = new (IGM.getSILModule()) SILDebugScope(ALoc);
1844-
1845-
llvm::DISubroutineType *DIFnTy = DBuilder.createSubroutineType(nullptr);
1846-
1847-
std::string FuncName = "Swift runtime failure: ";
1848-
FuncName += failureMsg;
1849-
1850-
llvm::DISubprogram *TrapSP = DBuilder.createFunction(
1851-
MainModule, StringRef(), FuncName, TrapLoc->getFile(), 0, DIFnTy, 0,
1852-
llvm::DINode::FlagArtificial, llvm::DISubprogram::SPFlagDefinition,
1853-
nullptr, nullptr, nullptr);
18541831

1855-
ScopeCache[TrapSc] = llvm::TrackingMDNodeRef(TrapSP);
1856-
LastScope = TrapSc;
1857-
1858-
assert(parentScopesAreSane(TrapSc) && "parent scope sanity check failed");
1859-
1860-
// Wrap the existing TrapLoc into the failure function.
1861-
auto DL = llvm::DebugLoc::get(0, 0, TrapSP, TrapLoc);
1862-
Builder.SetCurrentDebugLocation(DL);
1863-
}
1864-
18651832
void IRGenDebugInfoImpl::clearLoc(IRBuilder &Builder) {
18661833
LastDebugLoc = {};
18671834
LastScope = nullptr;
@@ -2353,12 +2320,6 @@ void IRGenDebugInfo::setCurrentLoc(IRBuilder &Builder, const SILDebugScope *DS,
23532320
static_cast<IRGenDebugInfoImpl *>(this)->setCurrentLoc(Builder, DS, Loc);
23542321
}
23552322

2356-
void IRGenDebugInfo::addFailureMessageToCurrentLoc(IRBuilder &Builder,
2357-
StringRef failureMsg) {
2358-
static_cast<IRGenDebugInfoImpl *>(this)->
2359-
addFailureMessageToCurrentLoc(Builder, failureMsg);
2360-
}
2361-
23622323
void IRGenDebugInfo::clearLoc(IRBuilder &Builder) {
23632324
static_cast<IRGenDebugInfoImpl *>(this)->clearLoc(Builder);
23642325
}

Diff for: lib/IRGen/IRGenDebugInfo.h

-6
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,6 @@ class IRGenDebugInfo {
5959
void setCurrentLoc(IRBuilder &Builder, const SILDebugScope *DS,
6060
SILLocation Loc);
6161

62-
/// Replace the current debug location in \p Builder with the same location, but contained in an
63-
/// inlined function which is named like \p failureMsg.
64-
///
65-
/// This lets the debugger display the \p failureMsg as an inlined function frame.
66-
void addFailureMessageToCurrentLoc(IRBuilder &Builder, StringRef failureMsg);
67-
6862
void clearLoc(IRBuilder &Builder);
6963

7064
/// Push the current debug location onto a stack and initialize the

Diff for: lib/IRGen/IRGenFunction.cpp

+3-11
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@
3131
using namespace swift;
3232
using namespace irgen;
3333

34-
static llvm::cl::opt<bool> EnableTrapDebugInfo(
35-
"enable-trap-debug-info", llvm::cl::Hidden,
36-
llvm::cl::desc("Generate failure-message functions in the debug info"));
37-
3834
IRGenFunction::IRGenFunction(IRGenModule &IGM, llvm::Function *Fn,
3935
OptimizationMode OptMode,
4036
const SILDebugScope *DbgScope,
@@ -436,8 +432,7 @@ Address IRGenFunction::emitAddressAtOffset(llvm::Value *base, Offset offset,
436432
return Address(slotPtr, objectAlignment);
437433
}
438434

439-
llvm::CallInst *IRBuilder::CreateNonMergeableTrap(IRGenModule &IGM,
440-
StringRef failureMsg) {
435+
llvm::CallInst *IRBuilder::CreateNonMergeableTrap(IRGenModule &IGM) {
441436
if (IGM.IRGen.Opts.shouldOptimize()) {
442437
// Emit unique side-effecting inline asm calls in order to eliminate
443438
// the possibility that an LLVM optimization or code generation pass
@@ -457,16 +452,13 @@ llvm::CallInst *IRBuilder::CreateNonMergeableTrap(IRGenModule &IGM,
457452
// Emit the trap instruction.
458453
llvm::Function *trapIntrinsic =
459454
llvm::Intrinsic::getDeclaration(&IGM.Module, llvm::Intrinsic::ID::trap);
460-
if (EnableTrapDebugInfo && IGM.DebugInfo && !failureMsg.empty()) {
461-
IGM.DebugInfo->addFailureMessageToCurrentLoc(*this, failureMsg);
462-
}
463455
auto Call = IRBuilderBase::CreateCall(trapIntrinsic, {});
464456
setCallingConvUsingCallee(Call);
465457
return Call;
466458
}
467459

468-
void IRGenFunction::emitTrap(StringRef failureMessage, bool EmitUnreachable) {
469-
Builder.CreateNonMergeableTrap(IGM, failureMessage);
460+
void IRGenFunction::emitTrap(bool EmitUnreachable) {
461+
Builder.CreateNonMergeableTrap(IGM);
470462
if (EmitUnreachable)
471463
Builder.CreateUnreachable();
472464
}

Diff for: lib/IRGen/IRGenFunction.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ class IRGenFunction {
287287
void setDereferenceableLoad(llvm::LoadInst *load, unsigned size);
288288

289289
/// Emit a non-mergeable trap call, optionally followed by a terminator.
290-
void emitTrap(StringRef failureMessage, bool EmitUnreachable);
290+
void emitTrap(bool EmitUnreachable);
291291

292292
private:
293293
llvm::Instruction *AllocaIP;

Diff for: lib/IRGen/IRGenSIL.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -3880,7 +3880,7 @@ static bool hasReferenceSemantics(IRGenSILFunction &IGF,
38803880
static llvm::Value *emitIsUnique(IRGenSILFunction &IGF, SILValue operand,
38813881
SourceLoc loc) {
38823882
if (!hasReferenceSemantics(IGF, operand->getType())) {
3883-
IGF.emitTrap("isUnique called for a non-reference", /*EmitUnreachable=*/false);
3883+
IGF.emitTrap(/*EmitUnreachable=*/false);
38843884
return llvm::UndefValue::get(IGF.IGM.Int1Ty);
38853885
}
38863886

@@ -4540,7 +4540,7 @@ static void emitTrapAndUndefValue(IRGenSILFunction &IGF,
45404540
IGF.FailBBs.push_back(failBB);
45414541

45424542
IGF.Builder.emitBlock(failBB);
4543-
IGF.emitTrap("mismatching type layouts", /*EmitUnreachable=*/true);
4543+
IGF.emitTrap(/*EmitUnreachable=*/true);
45444544

45454545
llvm::BasicBlock *contBB = llvm::BasicBlock::Create(IGF.IGM.getLLVMContext());
45464546
IGF.Builder.emitBlock(contBB);
@@ -5441,7 +5441,7 @@ void IRGenSILFunction::visitCondFailInst(swift::CondFailInst *i) {
54415441
// debug location. This is because zero is not an artificial line location
54425442
// in CodeView.
54435443
IGM.DebugInfo->setInlinedTrapLocation(Builder, i->getDebugScope());
5444-
emitTrap(i->getMessage(), /*EmitUnreachable=*/true);
5444+
emitTrap(/*EmitUnreachable=*/true);
54455445
Builder.emitBlock(contBB);
54465446
FailBBs.push_back(failBB);
54475447
}

Diff for: lib/ParseSIL/ParseSIL.cpp

+1-27
Original file line numberDiff line numberDiff line change
@@ -2635,33 +2635,6 @@ bool SILParser::parseSILInstruction(SILBuilder &B) {
26352635
break;
26362636
}
26372637

2638-
case SILInstructionKind::CondFailInst: {
2639-
2640-
if (parseTypedValueRef(Val, B))
2641-
return true;
2642-
2643-
SmallVector<char, 128> stringBuffer;
2644-
StringRef message;
2645-
if (P.consumeIf(tok::comma)) {
2646-
// Parse the string.
2647-
if (P.Tok.getKind() != tok::string_literal) {
2648-
P.diagnose(P.Tok, diag::expected_tok_in_sil_instr, "string");
2649-
return true;
2650-
}
2651-
SmallVector<Lexer::StringSegment, 1> segments;
2652-
P.L->getStringLiteralSegments(P.Tok, segments);
2653-
assert(segments.size() == 1);
2654-
2655-
P.consumeToken(tok::string_literal);
2656-
message = P.L->getEncodedStringSegment(segments.front(), stringBuffer);
2657-
}
2658-
if (parseSILDebugLocation(InstLoc, B))
2659-
return true;
2660-
2661-
ResultVal = B.createCondFail(InstLoc, Val, message);
2662-
break;
2663-
}
2664-
26652638
case SILInstructionKind::AllocValueBufferInst: {
26662639
SILType Ty;
26672640
if (parseSILType(Ty) ||
@@ -2914,6 +2887,7 @@ bool SILParser::parseSILInstruction(SILBuilder &B) {
29142887
UNARY_INSTRUCTION(DestroyAddr)
29152888
UNARY_INSTRUCTION(CopyValue)
29162889
UNARY_INSTRUCTION(DestroyValue)
2890+
UNARY_INSTRUCTION(CondFail)
29172891
UNARY_INSTRUCTION(EndBorrow)
29182892
UNARY_INSTRUCTION(DestructureStruct)
29192893
UNARY_INSTRUCTION(DestructureTuple)

Diff for: lib/SIL/OperandOwnership.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,6 @@ ANY_OWNERSHIP_BUILTIN(AtomicRMW)
953953
ANY_OWNERSHIP_BUILTIN(AtomicStore)
954954
ANY_OWNERSHIP_BUILTIN(BitCast)
955955
ANY_OWNERSHIP_BUILTIN(CanBeObjCClass)
956-
ANY_OWNERSHIP_BUILTIN(CondFail)
957956
ANY_OWNERSHIP_BUILTIN(CmpXChg)
958957
ANY_OWNERSHIP_BUILTIN(CondUnreachable)
959958
ANY_OWNERSHIP_BUILTIN(CopyArray)

Diff for: lib/SIL/SILInstructions.cpp

-15
Original file line numberDiff line numberDiff line change
@@ -773,21 +773,6 @@ StringLiteralInst *StringLiteralInst::create(SILDebugLocation Loc,
773773
return ::new (buf) StringLiteralInst(Loc, text, encoding, Ty);
774774
}
775775

776-
CondFailInst::CondFailInst(SILDebugLocation DebugLoc, SILValue Operand,
777-
StringRef Message)
778-
: UnaryInstructionBase(DebugLoc, Operand),
779-
MessageSize(Message.size()) {
780-
memcpy(getTrailingObjects<char>(), Message.data(), Message.size());
781-
}
782-
783-
CondFailInst *CondFailInst::create(SILDebugLocation DebugLoc, SILValue Operand,
784-
StringRef Message, SILModule &M) {
785-
786-
auto Size = totalSizeToAlloc<char>(Message.size());
787-
auto Buffer = M.allocateInst(Size, alignof(CondFailInst));
788-
return ::new (Buffer) CondFailInst(DebugLoc, Operand, Message);
789-
}
790-
791776
uint64_t StringLiteralInst::getCodeUnitCount() {
792777
auto E = unsigned(Encoding::UTF16);
793778
if (SILInstruction::Bits.StringLiteralInst.TheEncoding == E)

Diff for: lib/SIL/SILPrinter.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1866,8 +1866,7 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
18661866
}
18671867

18681868
void visitCondFailInst(CondFailInst *FI) {
1869-
*this << getIDAndType(FI->getOperand()) << ", "
1870-
<< QuotedString(FI->getMessage());
1869+
*this << getIDAndType(FI->getOperand());
18711870
}
18721871

18731872
void visitIndexAddrInst(IndexAddrInst *IAI) {

Diff for: lib/SIL/ValueOwnership.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,6 @@ CONSTANT_OWNERSHIP_BUILTIN(Any, And)
378378
CONSTANT_OWNERSHIP_BUILTIN(Any, AssumeNonNegative)
379379
CONSTANT_OWNERSHIP_BUILTIN(Any, AssumeTrue)
380380
CONSTANT_OWNERSHIP_BUILTIN(Any, BitCast)
381-
CONSTANT_OWNERSHIP_BUILTIN(Any, CondFail)
382381
CONSTANT_OWNERSHIP_BUILTIN(Any, ExactSDiv)
383382
CONSTANT_OWNERSHIP_BUILTIN(Any, ExactUDiv)
384383
CONSTANT_OWNERSHIP_BUILTIN(Any, FAdd)

0 commit comments

Comments
 (0)