Skip to content

Commit 25e5ad8

Browse files
author
Harlan Haskins
authored
---
yaml --- r: 341725 b: refs/heads/rxwei-patch-1 c: 277a4dc h: refs/heads/master i: 341723: c61910d
1 parent 34a8c19 commit 25e5ad8

31 files changed

+170
-93
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: 7022110a05217118cbae2112aa65b8b6b8a20f0a
1018+
refs/heads/rxwei-patch-1: 277a4dc0366f39514434b8916d306e33416e89cc
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/include/swift/AST/Expr.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,6 @@ class ObjectLiteralExpr final
11311131

11321132
private:
11331133
Expr *Arg;
1134-
Expr *SemanticExpr;
11351134
SourceLoc PoundLoc;
11361135
ConcreteDeclRef Initializer;
11371136

@@ -1181,9 +1180,6 @@ class ObjectLiteralExpr final
11811180
return Bits.ObjectLiteralExpr.HasTrailingClosure;
11821181
}
11831182

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

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ 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<sizeof...(Types) - Index
117+
? true
118+
: false>::type>
117119
SourceLoc extractNearestSourceLocTuple(const std::tuple<Types...> &value) {
118120
SourceLoc loc = maybeExtractNearestSourceLoc(std::get<Index>(value));
119121
if (loc.isValid())

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,14 @@ 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.
234235
llvm::Optional<unsigned> resolveFromLineCol(unsigned BufferId, unsigned Line,
235236
unsigned Col) const;
236237

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

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

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

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

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

486486
Expr *visitObjectLiteralExpr(ObjectLiteralExpr *E) {
487-
HANDLE_SEMANTIC_EXPR(E);
488-
489487
if (Expr *arg = E->getArg()) {
490488
if (Expr *arg2 = doIt(arg)) {
491489
E->setArg(arg2);

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,6 @@ shallowCloneImpl(const ObjectLiteralExpr *E, ASTContext &Ctx,
839839
auto res =
840840
ObjectLiteralExpr::create(Ctx, E->getStartLoc(), E->getLiteralKind(),
841841
E->getArg(), E->isImplicit(), getType);
842-
res->setSemanticExpr(E->getSemanticExpr());
843842
return res;
844843
}
845844

@@ -1196,7 +1195,7 @@ ObjectLiteralExpr::ObjectLiteralExpr(SourceLoc PoundLoc, LiteralKind LitKind,
11961195
bool hasTrailingClosure,
11971196
bool implicit)
11981197
: LiteralExpr(ExprKind::ObjectLiteral, implicit),
1199-
Arg(Arg), SemanticExpr(nullptr), PoundLoc(PoundLoc) {
1198+
Arg(Arg), PoundLoc(PoundLoc) {
12001199
Bits.ObjectLiteralExpr.LitKind = static_cast<unsigned>(LitKind);
12011200
assert(getLiteralKind() == LitKind);
12021201
Bits.ObjectLiteralExpr.NumArgLabels = argLabels.size();

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,19 @@ 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+
313319
llvm::Optional<unsigned> SourceManager::resolveFromLineCol(unsigned BufferId,
314320
unsigned Line,
315321
unsigned Col) const {
316322
if (Line == 0 || Col == 0) {
317323
return None;
318324
}
325+
const bool LineEnd = Col == ~0u;
319326
auto InputBuf = getLLVMSourceMgr().getMemoryBuffer(BufferId);
320327
const char *Ptr = InputBuf->getBufferStart();
321328
const char *End = InputBuf->getBufferEnd();
@@ -331,14 +338,18 @@ llvm::Optional<unsigned> SourceManager::resolveFromLineCol(unsigned BufferId,
331338
return None;
332339
}
333340
Ptr = LineStart;
334-
335341
// The <= here is to allow for non-inclusive range end positions at EOF
336-
for (; Ptr <= End; ++Ptr) {
342+
for (; ; ++Ptr) {
337343
--Col;
338344
if (Col == 0)
339345
return Ptr - InputBuf->getBufferStart();
340-
if (*Ptr == '\n')
341-
break;
346+
if (*Ptr == '\n' || Ptr == End) {
347+
if (LineEnd) {
348+
return Ptr - InputBuf->getBufferStart();
349+
} else {
350+
break;
351+
}
352+
}
342353
}
343354
return None;
344355
}

branches/rxwei-patch-1/lib/IDE/Formatting.cpp

Lines changed: 65 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,35 @@ struct SiblingAlignInfo {
2929
};
3030

3131
struct TokenInfo {
32-
const Token *StartOfLineTarget;
33-
const Token *StartOfLineBeforeTarget;
34-
TokenInfo(const Token *StartOfLineTarget,
35-
const Token *StartOfLineBeforeTarget) :
36-
StartOfLineTarget(StartOfLineTarget),
37-
StartOfLineBeforeTarget(StartOfLineBeforeTarget) {}
38-
TokenInfo() : TokenInfo(nullptr, nullptr) {}
39-
operator bool() { return StartOfLineTarget && StartOfLineBeforeTarget; }
32+
// The tokens appearing at the start of lines, from the first line to the
33+
// line under indentation.
34+
std::vector<const Token*> LineStarts;
35+
const Token *getLineStarter(unsigned idx = 0) const {
36+
auto it = LineStarts.rbegin() + idx;
37+
return it < LineStarts.rend() ? *it : nullptr;
38+
}
39+
operator bool() { return LineStarts.size() > 1; }
40+
bool isRBraceDotsPattern() const {
41+
for (auto It = LineStarts.rbegin(), end = LineStarts.rend();
42+
It + 1 < end; ++It) {
43+
auto* CurrentLine = *It;
44+
auto* PreviousLine = *(It + 1);
45+
if (CurrentLine->getKind() == tok::period &&
46+
PreviousLine->getKind() == tok::period) {
47+
// If the previous line starts with dot too, move further up.
48+
continue;
49+
} else if (CurrentLine->getKind() == tok::period &&
50+
PreviousLine->getKind() == tok::r_brace &&
51+
PreviousLine + 1 == CurrentLine) {
52+
// Check if the previous line starts with '}' and the period of the
53+
// current line is immediately after the '}'
54+
return true;
55+
} else {
56+
return false;
57+
}
58+
}
59+
return false;
60+
}
4061
};
4162

4263
using StringBuilder = llvm::SmallString<64>;
@@ -285,17 +306,16 @@ class FormatContext {
285306
return false;
286307

287308
if (TInfo) {
288-
if (TInfo.StartOfLineTarget->getKind() == tok::l_brace &&
289-
isKeywordPossibleDeclStart(*TInfo.StartOfLineBeforeTarget) &&
290-
TInfo.StartOfLineBeforeTarget->isKeyword())
309+
if (TInfo.getLineStarter()->getKind() == tok::l_brace &&
310+
isKeywordPossibleDeclStart(*TInfo.getLineStarter(1)) &&
311+
TInfo.getLineStarter(1)->isKeyword())
291312
return false;
292313
// VStack {
293314
// ...
294315
// }
295316
// .onAppear { <---- No indentation here.
296-
if (TInfo.StartOfLineTarget->getKind() == tok::period &&
297-
TInfo.StartOfLineBeforeTarget->getKind() == tok::r_brace &&
298-
TInfo.StartOfLineBeforeTarget + 1 == TInfo.StartOfLineTarget) {
317+
// .onAppear1 { <---- No indentation here.
318+
if (TInfo.isRBraceDotsPattern()) {
299319
return false;
300320
}
301321
}
@@ -365,7 +385,7 @@ class FormatContext {
365385
SignatureEnd = SD->getSignatureSourceRange().End;
366386
}
367387
if (SignatureEnd.isValid() && TInfo &&
368-
TInfo.StartOfLineTarget->getLoc() == SignatureEnd) {
388+
TInfo.getLineStarter()->getLoc() == SignatureEnd) {
369389
return false;
370390
}
371391

@@ -862,7 +882,7 @@ class CodeFormatter {
862882

863883
// If having sibling locs to align with, respect siblings.
864884
auto isClosingSquare =
865-
ToInfo && ToInfo.StartOfLineTarget->getKind() == tok::r_square;
885+
ToInfo && ToInfo.getLineStarter()->getKind() == tok::r_square;
866886
if (!isClosingSquare && FC.HasSibling()) {
867887
StringRef Line = swift::ide::getTextForLine(LineIndex, Text, /*Trim*/true);
868888
StringBuilder Builder;
@@ -940,33 +960,37 @@ class TokenInfoCollector {
940960
SourceManager &SM;
941961
ArrayRef<Token> Tokens;
942962
unsigned Line;
943-
944-
struct Comparator {
945-
SourceManager &SM;
946-
Comparator(SourceManager &SM) : SM(SM) {}
947-
bool operator()(const Token &T, unsigned Line) const {
948-
return SM.getLineNumber(T.getLoc()) < Line;
949-
}
950-
bool operator()(unsigned Line, const Token &T) const {
951-
return Line < SM.getLineNumber(T.getLoc());
952-
}
953-
};
954-
963+
// The location of the end of the line under indentation, we don't need to
964+
// collect tokens after this location.
965+
SourceLoc EndLimit;
955966
public:
956-
TokenInfoCollector(SourceManager &SM, ArrayRef<Token> Tokens,
957-
unsigned Line) : SM(SM), Tokens(Tokens), Line(Line) {}
967+
TokenInfoCollector(SourceManager &SM,
968+
unsigned BufferId,
969+
ArrayRef<Token> Tokens, unsigned Line):
970+
SM(SM), Tokens(Tokens), Line(Line) {
971+
if (auto Offset = SM.resolveOffsetForEndOfLine(BufferId, Line)) {
972+
EndLimit = SM.getLocForOffset(BufferId, *Offset);
973+
}
974+
}
958975

959976
TokenInfo collect() {
960-
if (Line == 0)
977+
if (EndLimit.isInvalid()) {
961978
return TokenInfo();
962-
Comparator Comp(SM);
963-
auto LineMatch = [this] (const Token* T, unsigned Line) {
964-
return T != Tokens.end() && SM.getLineNumber(T->getLoc()) == Line;
965-
};
966-
auto TargetIt = std::lower_bound(Tokens.begin(), Tokens.end(), Line, Comp);
967-
auto LineBefore = std::lower_bound(Tokens.begin(), TargetIt, Line - 1, Comp);
968-
if (LineMatch(TargetIt, Line) && LineMatch(LineBefore, Line - 1))
969-
return TokenInfo(TargetIt, LineBefore);
979+
}
980+
TokenInfo Result;
981+
for(auto &T: Tokens) {
982+
if (!T.isAtStartOfLine())
983+
continue;
984+
if (SM.isBeforeInBuffer(EndLimit, T.getLoc())) {
985+
if (!Result.LineStarts.empty()) {
986+
if (SM.getLineNumber(Result.getLineStarter()->getLoc()) == Line) {
987+
return Result;
988+
}
989+
}
990+
return TokenInfo();
991+
}
992+
Result.LineStarts.push_back(&T);
993+
}
970994
return TokenInfo();
971995
}
972996
};
@@ -1051,7 +1075,8 @@ std::pair<LineRange, std::string> swift::ide::reformat(LineRange Range,
10511075
FormatContext FC = walker.walkToLocation(Loc);
10521076
CodeFormatter CF(Options);
10531077
unsigned Line = Range.startLine();
1054-
return CF.indent(Line, FC, Text, TokenInfoCollector(SM, walker.getTokens(),
1078+
return CF.indent(Line, FC, Text, TokenInfoCollector(SM, SourceBufferID,
1079+
walker.getTokens(),
10551080
Line).collect());
10561081
}
10571082

branches/rxwei-patch-1/lib/IDE/SyntaxModel.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,10 +1080,13 @@ bool ModelASTWalker::handleAttrRanges(ArrayRef<DeclAttributeAndRange> DeclRanges
10801080

10811081
SmallVector<DeclAttributeAndRange, 4> SortedRanges(DeclRanges.begin(),
10821082
DeclRanges.end());
1083-
std::sort(SortedRanges.begin(), SortedRanges.end(),
1084-
[&](DeclAttributeAndRange LHS, DeclAttributeAndRange RHS) {
1085-
return SM.isBeforeInBuffer(LHS.second.Start, RHS.second.End);
1086-
});
1083+
std::sort(
1084+
SortedRanges.begin(), SortedRanges.end(),
1085+
[&](DeclAttributeAndRange LHS, DeclAttributeAndRange RHS) {
1086+
// Since attributes don't overlap it's safe to compare just by the
1087+
// range's Start
1088+
return SM.isBeforeInBuffer(LHS.second.Start, RHS.second.Start);
1089+
});
10871090
// Handle duplicate synthesized attributes due to * in @available
10881091
auto NewEnd = std::unique(SortedRanges.begin(), SortedRanges.end(),
10891092
[&](DeclAttributeAndRange LHS, DeclAttributeAndRange RHS) {

branches/rxwei-patch-1/lib/Sema/CSGen.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3299,8 +3299,6 @@ namespace {
32993299
// Remove any semantic expression injected by typechecking.
33003300
if (auto ISLE = dyn_cast<InterpolatedStringLiteralExpr>(expr)) {
33013301
ISLE->setSemanticExpr(nullptr);
3302-
} else if (auto OLE = dyn_cast<ObjectLiteralExpr>(expr)) {
3303-
OLE->setSemanticExpr(nullptr);
33043302
} else if (auto EPE = dyn_cast<EditorPlaceholderExpr>(expr)) {
33053303
EPE->setSemanticExpr(nullptr);
33063304
}

branches/rxwei-patch-1/stdlib/public/Darwin/Compression/Compression.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import Foundation
1515
@_exported import Compression
1616

1717
/// Compression algorithms, wraps the C API constants.
18-
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
18+
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *)
1919
public enum Algorithm: CaseIterable, RawRepresentable {
2020

2121
/// LZFSE
@@ -51,7 +51,7 @@ public enum Algorithm: CaseIterable, RawRepresentable {
5151
}
5252

5353
/// Compression filter direction of operation, compress/decompress
54-
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
54+
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *)
5555
public enum FilterOperation: RawRepresentable {
5656

5757
/// Compress raw data to a compressed payload
@@ -77,7 +77,7 @@ public enum FilterOperation: RawRepresentable {
7777
}
7878

7979
/// Compression errors
80-
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
80+
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *)
8181
public enum FilterError: Error {
8282

8383
/// Filter failed to initialize,
@@ -90,7 +90,7 @@ public enum FilterError: Error {
9090
case invalidData
9191
}
9292

93-
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
93+
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *)
9494
extension compression_stream {
9595

9696
/// Initialize a compression_stream struct
@@ -112,7 +112,7 @@ extension compression_stream {
112112
}
113113
}
114114

115-
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
115+
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *)
116116
public class OutputFilter {
117117
private var _stream: compression_stream
118118
private var _buf: UnsafeMutablePointer<UInt8>
@@ -226,7 +226,7 @@ public class OutputFilter {
226226

227227
}
228228

229-
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
229+
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *)
230230
public class InputFilter<D: DataProtocol> {
231231

232232
// Internal buffer to read bytes from a DataProtocol implementation

0 commit comments

Comments
 (0)