Skip to content

Commit 9696184

Browse files
authored
---
yaml --- r: 341740 b: refs/heads/rxwei-patch-1 c: b0f30c8 h: refs/heads/master
1 parent 899f26d commit 9696184

File tree

19 files changed

+182
-196
lines changed

19 files changed

+182
-196
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: d186e9ca913d307350249f26ef8ad8cdf0b29502
1018+
refs/heads/rxwei-patch-1: b0f30c8123414becc6ba24241a66158c97a36452
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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -599,12 +599,6 @@ 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;
608602

609603
static bool classof(const Expr *E) {
610604
return E->getKind() >= ExprKind::First_LiteralExpr &&

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

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -773,103 +773,6 @@ 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-
return res;
843-
}
844-
845-
// Make an exact copy of this AST node.
846-
LiteralExpr *LiteralExpr::shallowClone(
847-
ASTContext &Ctx, llvm::function_ref<void(Expr *, Type)> setType,
848-
llvm::function_ref<Type(const Expr *)> getType) const {
849-
LiteralExpr *Result = nullptr;
850-
switch (getKind()) {
851-
default: llvm_unreachable("Unknown literal type!");
852-
#define DISPATCH_CLONE(KIND) \
853-
case ExprKind::KIND: \
854-
Result = shallowCloneImpl(cast<KIND##Expr>(this), Ctx, getType); \
855-
break;
856-
857-
DISPATCH_CLONE(NilLiteral)
858-
DISPATCH_CLONE(IntegerLiteral)
859-
DISPATCH_CLONE(FloatLiteral)
860-
DISPATCH_CLONE(BooleanLiteral)
861-
DISPATCH_CLONE(StringLiteral)
862-
DISPATCH_CLONE(InterpolatedStringLiteral)
863-
DISPATCH_CLONE(ObjectLiteral)
864-
DISPATCH_CLONE(MagicIdentifierLiteral)
865-
#undef DISPATCH_CLONE
866-
}
867-
868-
setType(Result, getType(this));
869-
Result->setImplicit(isImplicit());
870-
return Result;
871-
}
872-
873776
IntegerLiteralExpr * IntegerLiteralExpr::createFromUnsigned(ASTContext &C, unsigned value) {
874777
llvm::SmallString<8> Scratch;
875778
llvm::APInt(sizeof(unsigned)*8, value).toString(Scratch, 10, /*signed*/ false);

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/Frontend/ParseableInterfaceModuleLoader.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ class swift::ParseableInterfaceBuilder {
504504
// Note that we don't assume cachePath is the same as the Clang
505505
// module cache path at this point.
506506
if (!moduleCachePath.empty())
507-
(void)llvm::sys::fs::create_directory(moduleCachePath);
507+
(void)llvm::sys::fs::create_directories(moduleCachePath);
508508

509509
configureSubInvocationInputsAndOutputs(OutPath);
510510

@@ -1267,6 +1267,10 @@ class ParseableInterfaceModuleLoaderImpl {
12671267
depsAdjustedToMTime.push_back(adjustedDep);
12681268
}
12691269

1270+
// Create the module cache if we haven't created it yet.
1271+
StringRef parentDir = path::parent_path(outputPath);
1272+
(void)llvm::sys::fs::create_directories(parentDir);
1273+
12701274
auto hadError = withOutputFile(diags, outputPath,
12711275
[&](llvm::raw_pwrite_stream &out) {
12721276
llvm::yaml::Output yamlWriter(out);

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/SIL/DynamicCasts.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,16 @@ CanType swift::getNSBridgedClassOfCFClass(ModuleDecl *M, CanType type) {
292292

293293
static bool isCFBridgingConversion(ModuleDecl *M, SILType sourceType,
294294
SILType targetType) {
295-
return (sourceType.getASTType() ==
296-
getNSBridgedClassOfCFClass(M, targetType.getASTType()) ||
297-
targetType.getASTType() ==
298-
getNSBridgedClassOfCFClass(M, sourceType.getASTType()));
295+
if (auto bridgedTarget =
296+
getNSBridgedClassOfCFClass(M, targetType.getASTType())) {
297+
return bridgedTarget->isExactSuperclassOf(sourceType.getASTType());
298+
}
299+
if (auto bridgedSource =
300+
getNSBridgedClassOfCFClass(M, sourceType.getASTType())) {
301+
return targetType.getASTType()->isExactSuperclassOf(bridgedSource);
302+
}
303+
304+
return false;
299305
}
300306

301307
/// Try to classify the dynamic-cast relationship between two types.
@@ -868,7 +874,7 @@ namespace {
868874
value = getOwnedScalar(source, srcTL);
869875
}
870876
auto targetTy = target.LoweredType;
871-
if (isCFBridgingConversion(SwiftModule, targetTy, value->getType())) {
877+
if (isCFBridgingConversion(SwiftModule, value->getType(), targetTy)) {
872878
value = B.createUncheckedRefCast(Loc, value, targetTy.getObjectType());
873879
} else {
874880
value = B.createUpcast(Loc, value, targetTy.getObjectType());

0 commit comments

Comments
 (0)