Skip to content

Commit c476b54

Browse files
authored
---
yaml --- r: 341713 b: refs/heads/rxwei-patch-1 c: 690409d h: refs/heads/master i: 341711: 5be83fe
1 parent e2348e3 commit c476b54

Some content is hidden

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

56 files changed

+442
-245
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-08-18-a: b10b1fce14385faa6d44f6b933e95
10151015
refs/heads/rdar-43033749-fix-batch-mode-no-diags-swift-5.0-branch: a14e64eaad30de89f0f5f0b2a782eed7ecdcb255
10161016
refs/heads/revert-19006-error-bridging-integer-type: 8a9065a3696535305ea53fe9b71f91cbe6702019
10171017
refs/heads/revert-19050-revert-19006-error-bridging-integer-type: ecf752d54b05dd0a20f510f0bfa54a3fec3bcaca
1018-
refs/heads/rxwei-patch-1: f0513aef003a447fb834aa0677e556a1ac53cac0
1018+
refs/heads/rxwei-patch-1: 690409d04fbd8183bd13088910167d627c293d84
10191019
refs/heads/shahmishal-patch-1: e58ec0f7488258d42bef51bc3e6d7b3dc74d7b2a
10201020
refs/heads/typelist-existential: 4046359efd541fb5c72d69a92eefc0a784df8f5e
10211021
refs/tags/swift-4.2-DEVELOPMENT-SNAPSHOT-2018-08-20-a: 4319ba09e4fb8650ee86061075c74a016b6baab9

branches/rxwei-patch-1/docs/ABI/Mangling.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ conformance within the witness table, identified by the dependent type and
717717
protocol. In all cases, the DEPENDENT-CONFORMANCE-INDEX is an INDEX value
718718
indicating the position of the appropriate value within the generic environment
719719
(for "HD") or witness table (for "HI" and "HA") when it is known to be at a
720-
fixed position. An index of 1 ("0_") is used to indicate "unknown"; all other
720+
fixed position. An index of 1 ("0\_") is used to indicate "unknown"; all other
721721
values are adjusted by 2. That these indexes are not 0-based is a bug that's
722722
now codified into the ABI; the index 0 is therefore reserved.
723723

branches/rxwei-patch-1/docs/SIL.rst

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

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

5115-
cond_fail %0 : $Builtin.Int1
5115+
cond_fail %0 : $Builtin.Int1, "failure reason"
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.
51205122

51215123
Terminators
51225124
~~~~~~~~~~~

branches/rxwei-patch-1/include/swift/AST/Builtins.def

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,6 @@ 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-
321317
/// fixLifetime(T) -> ()
322318
/// Fixes the lifetime of any heap references in a value.
323319
BUILTIN_SIL_OPERATION(FixLifetime, "fixLifetime", Special)
@@ -404,6 +400,10 @@ BUILTIN_RUNTIME_CALL(IsOptionalType, "isOptional", "")
404400
BUILTIN(Id, Name, Attrs)
405401
#endif
406402

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

branches/rxwei-patch-1/include/swift/SIL/SILBuilder.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,15 +1775,15 @@ class SILBuilder {
17751775
//===--------------------------------------------------------------------===//
17761776

17771777
CondFailInst *createCondFail(SILLocation Loc, SILValue Operand,
1778-
bool Inverted = false) {
1778+
StringRef Message, 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(new (getModule())
1786-
CondFailInst(getSILDebugLocation(Loc), Operand));
1785+
return insert(CondFailInst::create(getSILDebugLocation(Loc), Operand,
1786+
Message, getModule()));
17871787
}
17881788

17891789
BuiltinInst *createBuiltinTrap(SILLocation Loc) {

branches/rxwei-patch-1/include/swift/SIL/SILCloner.h

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

24532454
template<typename ImplClass>

branches/rxwei-patch-1/include/swift/SIL/SILInstruction.h

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6715,14 +6715,28 @@ class ProjectExistentialBoxInst
67156715
//===----------------------------------------------------------------------===//
67166716

67176717
/// Trigger a runtime failure if the given Int1 value is true.
6718-
class CondFailInst
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
67196722
: public UnaryInstructionBase<SILInstructionKind::CondFailInst,
6720-
NonValueInstruction>
6723+
NonValueInstruction>,
6724+
private llvm::TrailingObjects<CondFailInst, char>
67216725
{
6726+
friend TrailingObjects;
67226727
friend SILBuilder;
67236728

6724-
CondFailInst(SILDebugLocation DebugLoc, SILValue Operand)
6725-
: UnaryInstructionBase(DebugLoc, Operand) {}
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+
}
67266740
};
67276741

67286742
//===----------------------------------------------------------------------===//

branches/rxwei-patch-1/include/swift/Serialization/ModuleFormat.h

Lines changed: 1 addition & 1 deletion
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 = 500; // dependency types for protocols
55+
const uint16_t SWIFTMODULE_VERSION_MINOR = 501; // cond_fail messages
5656

5757
using DeclIDField = BCFixed<31>;
5858

branches/rxwei-patch-1/lib/AST/ASTVerifier.cpp

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2471,44 +2471,48 @@ class Verifier : public ASTWalker {
24712471
Out << "property getter has parameters\n";
24722472
abort();
24732473
}
2474-
Type getterResultType = getter->getResultInterfaceType();
2475-
getterResultType =
2476-
var->getDeclContext()->mapTypeIntoContext(getterResultType);
2477-
if (!getterResultType->isEqual(typeForAccessors)) {
2478-
Out << "property and getter have mismatched types: '";
2479-
typeForAccessors.print(Out);
2480-
Out << "' vs. '";
2481-
getterResultType.print(Out);
2482-
Out << "'\n";
2483-
abort();
2474+
if (getter->hasInterfaceType()) {
2475+
Type getterResultType = getter->getResultInterfaceType();
2476+
getterResultType =
2477+
var->getDeclContext()->mapTypeIntoContext(getterResultType);
2478+
if (!getterResultType->isEqual(typeForAccessors)) {
2479+
Out << "property and getter have mismatched types: '";
2480+
typeForAccessors.print(Out);
2481+
Out << "' vs. '";
2482+
getterResultType.print(Out);
2483+
Out << "'\n";
2484+
abort();
2485+
}
24842486
}
24852487
}
24862488
}
24872489

24882490
if (const FuncDecl *setter = var->getSetter()) {
2489-
if (!setter->getResultInterfaceType()->isVoid()) {
2490-
Out << "property setter has non-Void result type\n";
2491-
abort();
2492-
}
2493-
if (setter->getParameters()->size() == 0) {
2494-
Out << "property setter has no parameters\n";
2495-
abort();
2496-
}
2497-
if (setter->getParameters()->size() != 1) {
2498-
Out << "property setter has 2+ parameters\n";
2499-
abort();
2500-
}
2501-
const ParamDecl *param = setter->getParameters()->get(0);
2502-
Type paramType = param->getInterfaceType();
2503-
if (!var->getDeclContext()->contextHasLazyGenericEnvironment()) {
2504-
paramType = var->getDeclContext()->mapTypeIntoContext(paramType);
2505-
if (!paramType->isEqual(typeForAccessors)) {
2506-
Out << "property and setter param have mismatched types:\n";
2507-
typeForAccessors.dump(Out, 2);
2508-
Out << "vs.\n";
2509-
paramType.dump(Out, 2);
2491+
if (setter->hasInterfaceType()) {
2492+
if (!setter->getResultInterfaceType()->isVoid()) {
2493+
Out << "property setter has non-Void result type\n";
2494+
abort();
2495+
}
2496+
if (setter->getParameters()->size() == 0) {
2497+
Out << "property setter has no parameters\n";
25102498
abort();
25112499
}
2500+
if (setter->getParameters()->size() != 1) {
2501+
Out << "property setter has 2+ parameters\n";
2502+
abort();
2503+
}
2504+
const ParamDecl *param = setter->getParameters()->get(0);
2505+
Type paramType = param->getInterfaceType();
2506+
if (!var->getDeclContext()->contextHasLazyGenericEnvironment()) {
2507+
paramType = var->getDeclContext()->mapTypeIntoContext(paramType);
2508+
if (!paramType->isEqual(typeForAccessors)) {
2509+
Out << "property and setter param have mismatched types:\n";
2510+
typeForAccessors.dump(Out, 2);
2511+
Out << "vs.\n";
2512+
paramType.dump(Out, 2);
2513+
abort();
2514+
}
2515+
}
25122516
}
25132517
}
25142518

@@ -3010,6 +3014,16 @@ class Verifier : public ASTWalker {
30103014
void verifyChecked(AbstractFunctionDecl *AFD) {
30113015
PrettyStackTraceDecl debugStack("verifying AbstractFunctionDecl", AFD);
30123016

3017+
if (!AFD->hasValidSignature()) {
3018+
if (isa<AccessorDecl>(AFD) && AFD->isImplicit())
3019+
return;
3020+
3021+
Out << "All functions except implicit accessors should be "
3022+
"validated by now\n";
3023+
AFD->dump(Out);
3024+
abort();
3025+
}
3026+
30133027
// If this function is generic or is within a generic context, it should
30143028
// have an interface type.
30153029
if (AFD->isGenericContext() !=

branches/rxwei-patch-1/lib/AST/Builtins.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,8 +1037,9 @@ 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;
10401041
auto VoidTy = TupleType::getEmpty(C);
1041-
return getBuiltinFunction(Id, {CondTy}, VoidTy);
1042+
return getBuiltinFunction(Id, {CondTy, MsgTy}, VoidTy);
10421043
}
10431044

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

branches/rxwei-patch-1/lib/AST/Decl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2701,7 +2701,8 @@ bool ValueDecl::canInferObjCFromRequirement(ValueDecl *requirement) {
27012701
// If there is already an @objc attribute with an explicit name, we
27022702
// can't infer a name (it's already there).
27032703
if (auto objcAttr = getAttrs().getAttribute<ObjCAttr>()) {
2704-
if (!objcAttr->isNameImplicit()) return false;
2704+
if (objcAttr->hasName() && !objcAttr->isNameImplicit())
2705+
return false;
27052706
}
27062707

27072708
// If the nominal type doesn't conform to the protocol at all, we

branches/rxwei-patch-1/lib/IRGen/GenBuiltin.cpp

Lines changed: 3 additions & 2 deletions
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);
207+
IGF.Builder.CreateNonMergeableTrap(IGF.IGM, StringRef());
208208
return;
209209
}
210210

@@ -359,7 +359,8 @@ 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(/*Unreachable=*/false);
362+
IGF.emitTrap("invalid use of globalStringTablePointer",
363+
/*Unreachable=*/false);
363364
auto returnValue = llvm::UndefValue::get(IGF.IGM.Int8PtrTy);
364365
// Consume the arguments of the builtin.
365366
(void)args.claimAll();

branches/rxwei-patch-1/lib/IRGen/GenCast.cpp

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

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

branches/rxwei-patch-1/lib/IRGen/IRBuilder.h

Lines changed: 1 addition & 1 deletion
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);
310+
llvm::CallInst *CreateNonMergeableTrap(IRGenModule &IGM, StringRef failureMsg);
311311

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

branches/rxwei-patch-1/lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ 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+
151154
void clearLoc(IRBuilder &Builder);
152155
void pushLoc();
153156
void popLoc();
@@ -1828,7 +1831,37 @@ void IRGenDebugInfoImpl::setCurrentLoc(IRBuilder &Builder,
18281831
auto DL = llvm::DebugLoc::get(L.Line, L.Column, Scope, InlinedAt);
18291832
Builder.SetCurrentDebugLocation(DL);
18301833
}
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);
18311854

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+
18321865
void IRGenDebugInfoImpl::clearLoc(IRBuilder &Builder) {
18331866
LastDebugLoc = {};
18341867
LastScope = nullptr;
@@ -2320,6 +2353,12 @@ void IRGenDebugInfo::setCurrentLoc(IRBuilder &Builder, const SILDebugScope *DS,
23202353
static_cast<IRGenDebugInfoImpl *>(this)->setCurrentLoc(Builder, DS, Loc);
23212354
}
23222355

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

branches/rxwei-patch-1/lib/IRGen/IRGenDebugInfo.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ 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+
6268
void clearLoc(IRBuilder &Builder);
6369

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

branches/rxwei-patch-1/lib/IRGen/IRGenFunction.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
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+
3438
IRGenFunction::IRGenFunction(IRGenModule &IGM, llvm::Function *Fn,
3539
OptimizationMode OptMode,
3640
const SILDebugScope *DbgScope,
@@ -432,7 +436,8 @@ Address IRGenFunction::emitAddressAtOffset(llvm::Value *base, Offset offset,
432436
return Address(slotPtr, objectAlignment);
433437
}
434438

435-
llvm::CallInst *IRBuilder::CreateNonMergeableTrap(IRGenModule &IGM) {
439+
llvm::CallInst *IRBuilder::CreateNonMergeableTrap(IRGenModule &IGM,
440+
StringRef failureMsg) {
436441
if (IGM.IRGen.Opts.shouldOptimize()) {
437442
// Emit unique side-effecting inline asm calls in order to eliminate
438443
// the possibility that an LLVM optimization or code generation pass
@@ -452,13 +457,16 @@ llvm::CallInst *IRBuilder::CreateNonMergeableTrap(IRGenModule &IGM) {
452457
// Emit the trap instruction.
453458
llvm::Function *trapIntrinsic =
454459
llvm::Intrinsic::getDeclaration(&IGM.Module, llvm::Intrinsic::ID::trap);
460+
if (EnableTrapDebugInfo && IGM.DebugInfo && !failureMsg.empty()) {
461+
IGM.DebugInfo->addFailureMessageToCurrentLoc(*this, failureMsg);
462+
}
455463
auto Call = IRBuilderBase::CreateCall(trapIntrinsic, {});
456464
setCallingConvUsingCallee(Call);
457465
return Call;
458466
}
459467

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

0 commit comments

Comments
 (0)