Skip to content

Commit cb57bdf

Browse files
committed
---
yaml --- r: 341755 b: refs/heads/rxwei-patch-1 c: c138722 h: refs/heads/master i: 341753: 61daad1 341751: 8c7b393
1 parent 863cf8b commit cb57bdf

File tree

116 files changed

+746
-565
lines changed

Some content is hidden

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

116 files changed

+746
-565
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: 3601cc05fbd67212b3dc28d2e03d10ffd1aafedc
1018+
refs/heads/rxwei-patch-1: c13872248da2ae995f9e868cb18273f7dd05040f
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/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/AST/Expr.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,12 @@ class CodeCompletionExpr : public Expr {
599599
class LiteralExpr : public Expr {
600600
public:
601601
LiteralExpr(ExprKind Kind, bool Implicit) : Expr(Kind, Implicit) {}
602+
603+
// Make an exact copy of this one AST node.
604+
LiteralExpr *
605+
shallowClone(ASTContext &Ctx,
606+
llvm::function_ref<void(Expr *, Type)> setType,
607+
llvm::function_ref<Type(const Expr *)> getType) const;
602608

603609
static bool classof(const Expr *E) {
604610
return E->getKind() >= ExprKind::First_LiteralExpr &&
@@ -1125,6 +1131,7 @@ class ObjectLiteralExpr final
11251131

11261132
private:
11271133
Expr *Arg;
1134+
Expr *SemanticExpr;
11281135
SourceLoc PoundLoc;
11291136
ConcreteDeclRef Initializer;
11301137

@@ -1174,6 +1181,9 @@ class ObjectLiteralExpr final
11741181
return Bits.ObjectLiteralExpr.HasTrailingClosure;
11751182
}
11761183

1184+
Expr *getSemanticExpr() const { return SemanticExpr; }
1185+
void setSemanticExpr(Expr *expr) { SemanticExpr = expr; }
1186+
11771187
SourceLoc getSourceLoc() const { return PoundLoc; }
11781188
SourceRange getSourceRange() const {
11791189
return SourceRange(PoundLoc, Arg->getEndLoc());

branches/rxwei-patch-1/include/swift/AST/SimpleRequest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ namespace detail {
113113

114114
/// Extract the first, nearest source location from a tuple.
115115
template<unsigned Index, typename ...Types,
116-
typename = typename std::enable_if<(Index < sizeof...(Types))>::type>
116+
typename = typename std::enable_if<Index < sizeof...(Types)>::type>
117117
SourceLoc extractNearestSourceLocTuple(const std::tuple<Types...> &value) {
118118
SourceLoc loc = maybeExtractNearestSourceLoc(std::get<Index>(value));
119119
if (loc.isValid())

branches/rxwei-patch-1/include/swift/Basic/SourceManager.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,9 @@ class SourceManager {
231231
void verifyAllBuffers() const;
232232

233233
/// Translate line and column pair to the offset.
234-
/// If the column number is the maximum unsinged int, return the offset of the end of the line.
235234
llvm::Optional<unsigned> resolveFromLineCol(unsigned BufferId, unsigned Line,
236235
unsigned Col) const;
237236

238-
/// Translate the end position of the given line to the offset.
239-
llvm::Optional<unsigned> resolveOffsetForEndOfLine(unsigned BufferId,
240-
unsigned Line) const;
241-
242237
SourceLoc getLocForLineCol(unsigned BufferId, unsigned Line, unsigned Col) const {
243238
auto Offset = resolveFromLineCol(BufferId, Line, Col);
244239
return Offset.hasValue() ? getLocForOffset(BufferId, Offset.getValue()) :

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/ASTDumper.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,6 +1977,7 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
19771977
printArgumentLabels(E->getArgumentLabels());
19781978
OS << "\n";
19791979
printRec(E->getArg());
1980+
printSemanticExpr(E->getSemanticExpr());
19801981
PrintWithColorRAII(OS, ParenthesisColor) << ')';
19811982
}
19821983

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,8 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
484484
}
485485

486486
Expr *visitObjectLiteralExpr(ObjectLiteralExpr *E) {
487+
HANDLE_SEMANTIC_EXPR(E);
488+
487489
if (Expr *arg = E->getArg()) {
488490
if (Expr *arg2 = doIt(arg)) {
489491
E->setArg(arg2);

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: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3775,6 +3775,14 @@ DestructorDecl *ClassDecl::getDestructor() {
37753775
return cast<DestructorDecl>(results.front());
37763776
}
37773777

3778+
/// Synthesizer callback for an empty implicit function body.
3779+
static std::pair<BraceStmt *, bool>
3780+
synthesizeEmplyFunctionBody(AbstractFunctionDecl *afd, void *context) {
3781+
ASTContext &ctx = afd->getASTContext();
3782+
return { BraceStmt::create(ctx, afd->getLoc(), { }, afd->getLoc(), true),
3783+
/*isTypeChecked=*/true };
3784+
}
3785+
37783786
void ClassDecl::addImplicitDestructor() {
37793787
if (hasDestructor() || isInvalid())
37803788
return;
@@ -3785,8 +3793,8 @@ void ClassDecl::addImplicitDestructor() {
37853793
DD->setImplicit();
37863794
DD->setValidationToChecked();
37873795

3788-
// Create an empty body for the destructor.
3789-
DD->setBody(BraceStmt::create(ctx, getLoc(), { }, getLoc(), true));
3796+
// Synthesize an empty body for the destructor as needed.
3797+
DD->setBodySynthesizer(synthesizeEmplyFunctionBody);
37903798
addMember(DD);
37913799

37923800
// Propagate access control and versioned-ness.

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

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,104 @@ llvm::DenseMap<Expr *, unsigned> Expr::getPreorderIndexMap() {
773773
// Support methods for Exprs.
774774
//===----------------------------------------------------------------------===//
775775

776+
static LiteralExpr *
777+
shallowCloneImpl(const NilLiteralExpr *E, ASTContext &Ctx,
778+
llvm::function_ref<Type(const Expr *)> getType) {
779+
return new (Ctx) NilLiteralExpr(E->getLoc());
780+
}
781+
782+
static LiteralExpr *
783+
shallowCloneImpl(const IntegerLiteralExpr *E, ASTContext &Ctx,
784+
llvm::function_ref<Type(const Expr *)> getType) {
785+
auto res = new (Ctx) IntegerLiteralExpr(E->getDigitsText(),
786+
E->getSourceRange().End);
787+
if (E->isNegative())
788+
res->setNegative(E->getSourceRange().Start);
789+
return res;
790+
}
791+
792+
static LiteralExpr *
793+
shallowCloneImpl(const FloatLiteralExpr *E, ASTContext &Ctx,
794+
llvm::function_ref<Type(const Expr *)> getType) {
795+
auto res = new (Ctx) FloatLiteralExpr(E->getDigitsText(),
796+
E->getSourceRange().End);
797+
if (E->isNegative())
798+
res->setNegative(E->getSourceRange().Start);
799+
return res;
800+
}
801+
static LiteralExpr *
802+
shallowCloneImpl(const BooleanLiteralExpr *E, ASTContext &Ctx,
803+
llvm::function_ref<Type(const Expr *)> getType) {
804+
return new (Ctx) BooleanLiteralExpr(E->getValue(), E->getLoc());
805+
}
806+
static LiteralExpr *
807+
shallowCloneImpl(const StringLiteralExpr *E, ASTContext &Ctx,
808+
llvm::function_ref<Type(const Expr *)> getType) {
809+
auto res = new (Ctx) StringLiteralExpr(E->getValue(), E->getSourceRange());
810+
res->setEncoding(E->getEncoding());
811+
return res;
812+
}
813+
814+
static LiteralExpr *
815+
shallowCloneImpl(const InterpolatedStringLiteralExpr *E, ASTContext &Ctx,
816+
llvm::function_ref<Type(const Expr *)> getType) {
817+
auto res = new (Ctx) InterpolatedStringLiteralExpr(E->getLoc(),
818+
E->getTrailingQuoteLoc(),
819+
E->getLiteralCapacity(),
820+
E->getInterpolationCount(),
821+
E->getAppendingExpr());
822+
res->setSemanticExpr(E->getSemanticExpr());
823+
return res;
824+
}
825+
826+
static LiteralExpr *
827+
shallowCloneImpl(const MagicIdentifierLiteralExpr *E, ASTContext &Ctx,
828+
llvm::function_ref<Type(const Expr *)> getType) {
829+
auto res = new (Ctx) MagicIdentifierLiteralExpr(E->getKind(),
830+
E->getSourceRange().End);
831+
if (res->isString())
832+
res->setStringEncoding(E->getStringEncoding());
833+
return res;
834+
}
835+
836+
static LiteralExpr *
837+
shallowCloneImpl(const ObjectLiteralExpr *E, ASTContext &Ctx,
838+
llvm::function_ref<Type(const Expr *)> getType) {
839+
auto res =
840+
ObjectLiteralExpr::create(Ctx, E->getStartLoc(), E->getLiteralKind(),
841+
E->getArg(), E->isImplicit(), getType);
842+
res->setSemanticExpr(E->getSemanticExpr());
843+
return res;
844+
}
845+
846+
// Make an exact copy of this AST node.
847+
LiteralExpr *LiteralExpr::shallowClone(
848+
ASTContext &Ctx, llvm::function_ref<void(Expr *, Type)> setType,
849+
llvm::function_ref<Type(const Expr *)> getType) const {
850+
LiteralExpr *Result = nullptr;
851+
switch (getKind()) {
852+
default: llvm_unreachable("Unknown literal type!");
853+
#define DISPATCH_CLONE(KIND) \
854+
case ExprKind::KIND: \
855+
Result = shallowCloneImpl(cast<KIND##Expr>(this), Ctx, getType); \
856+
break;
857+
858+
DISPATCH_CLONE(NilLiteral)
859+
DISPATCH_CLONE(IntegerLiteral)
860+
DISPATCH_CLONE(FloatLiteral)
861+
DISPATCH_CLONE(BooleanLiteral)
862+
DISPATCH_CLONE(StringLiteral)
863+
DISPATCH_CLONE(InterpolatedStringLiteral)
864+
DISPATCH_CLONE(ObjectLiteral)
865+
DISPATCH_CLONE(MagicIdentifierLiteral)
866+
#undef DISPATCH_CLONE
867+
}
868+
869+
setType(Result, getType(this));
870+
Result->setImplicit(isImplicit());
871+
return Result;
872+
}
873+
776874
IntegerLiteralExpr * IntegerLiteralExpr::createFromUnsigned(ASTContext &C, unsigned value) {
777875
llvm::SmallString<8> Scratch;
778876
llvm::APInt(sizeof(unsigned)*8, value).toString(Scratch, 10, /*signed*/ false);
@@ -1098,7 +1196,7 @@ ObjectLiteralExpr::ObjectLiteralExpr(SourceLoc PoundLoc, LiteralKind LitKind,
10981196
bool hasTrailingClosure,
10991197
bool implicit)
11001198
: LiteralExpr(ExprKind::ObjectLiteral, implicit),
1101-
Arg(Arg), PoundLoc(PoundLoc) {
1199+
Arg(Arg), SemanticExpr(nullptr), PoundLoc(PoundLoc) {
11021200
Bits.ObjectLiteralExpr.LitKind = static_cast<unsigned>(LitKind);
11031201
assert(getLiteralKind() == LitKind);
11041202
Bits.ObjectLiteralExpr.NumArgLabels = argLabels.size();

branches/rxwei-patch-1/lib/Basic/SourceLoc.cpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -310,19 +310,12 @@ void CharSourceRange::dump(const SourceManager &SM) const {
310310
print(llvm::errs(), SM);
311311
}
312312

313-
llvm::Optional<unsigned>
314-
SourceManager::resolveOffsetForEndOfLine(unsigned BufferId,
315-
unsigned Line) const {
316-
return resolveFromLineCol(BufferId, Line, ~0u);
317-
}
318-
319313
llvm::Optional<unsigned> SourceManager::resolveFromLineCol(unsigned BufferId,
320314
unsigned Line,
321315
unsigned Col) const {
322316
if (Line == 0 || Col == 0) {
323317
return None;
324318
}
325-
const bool LineEnd = Col == ~0u;
326319
auto InputBuf = getLLVMSourceMgr().getMemoryBuffer(BufferId);
327320
const char *Ptr = InputBuf->getBufferStart();
328321
const char *End = InputBuf->getBufferEnd();
@@ -338,18 +331,14 @@ llvm::Optional<unsigned> SourceManager::resolveFromLineCol(unsigned BufferId,
338331
return None;
339332
}
340333
Ptr = LineStart;
334+
341335
// The <= here is to allow for non-inclusive range end positions at EOF
342-
for (; ; ++Ptr) {
336+
for (; Ptr <= End; ++Ptr) {
343337
--Col;
344338
if (Col == 0)
345339
return Ptr - InputBuf->getBufferStart();
346-
if (*Ptr == '\n' || Ptr == End) {
347-
if (LineEnd) {
348-
return Ptr - InputBuf->getBufferStart();
349-
} else {
350-
break;
351-
}
352-
}
340+
if (*Ptr == '\n')
341+
break;
353342
}
354343
return None;
355344
}

0 commit comments

Comments
 (0)