Skip to content

Commit 4358d63

Browse files
committed
---
yaml --- r: 294878 b: refs/heads/swift-5.1-branch c: 9e39efb h: refs/heads/master
1 parent 3fb01bd commit 4358d63

File tree

21 files changed

+1466
-135
lines changed

21 files changed

+1466
-135
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ refs/heads/marcrasi-astverifier-disable: 3fac766a23a77ebd0640296bfd7fc116ea60a4e
12421242
refs/heads/revert-22227-a-tall-white-fountain-played: adfce60b2eaa54903ea189bed8a783bca609fa53
12431243
refs/heads/revert-22300-revert-22227-a-tall-white-fountain-played: 5f92040224df7dd4e618fdfb367349df64d8acad
12441244
refs/heads/swift-5.1-old-llvm-branch: 9cef8175146f25b72806154b8a0f4a3f52e3e400
1245-
refs/heads/swift-5.1-branch: 43fd43732248650a139972506428fd4b0cb01bd8
1245+
refs/heads/swift-5.1-branch: 9e39efb56d905f4aa81e02901265a86e82bef09e
12461246
refs/tags/swift-4.2.2-RELEASE: e429d1f1aaf59e69d38207a96e56265c7f6fccec
12471247
refs/tags/swift-5.0-DEVELOPMENT-SNAPSHOT-2019-02-02-a: 3e5a03d32ff3b1e9af90d6c1198c14f938379a6e
12481248
refs/tags/swift-5.0-DEVELOPMENT-SNAPSHOT-2019-02-03-a: 4591c933063ddcb0d6cd6d0cdd01086b2f9b244d

branches/swift-5.1-branch/cmake/modules/SwiftSource.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ function(_compile_swift_files
265265

266266
# Force swift 4 compatibility mode for overlays.
267267
if (SWIFTFILE_IS_SDK_OVERLAY)
268-
list(APPEND swift_flags "-swift-version" "5")
268+
list(APPEND swift_flags "-swift-version" "4")
269269
endif()
270270

271271
if(SWIFTFILE_IS_SDK_OVERLAY)

branches/swift-5.1-branch/include/swift/AST/Decl.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,8 @@ class alignas(1 << DeclAlignInBits) Decl {
400400
/// The ResilienceExpansion to use for default arguments.
401401
DefaultArgumentResilienceExpansion : 1
402402
);
403-
404-
SWIFT_INLINE_BITFIELD(AbstractFunctionDecl, ValueDecl, 3+8+1+1+1+1+1+1+1,
403+
404+
SWIFT_INLINE_BITFIELD(AbstractFunctionDecl, ValueDecl, 3+8+1+1+1+1+1+1+1+1,
405405
/// \see AbstractFunctionDecl::BodyKind
406406
BodyKind : 3,
407407

@@ -428,7 +428,10 @@ class alignas(1 << DeclAlignInBits) Decl {
428428

429429
/// Whether this member was synthesized as part of a derived
430430
/// protocol conformance.
431-
Synthesized : 1
431+
Synthesized : 1,
432+
433+
/// Whether this member's body consists of a single expression.
434+
HasSingleExpressionBody : 1
432435
);
433436

434437
SWIFT_INLINE_BITFIELD(FuncDecl, AbstractFunctionDecl, 1+2+1+1+2,
@@ -5433,13 +5436,25 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
54335436
Bits.AbstractFunctionDecl.DefaultArgumentResilienceExpansion =
54345437
unsigned(ResilienceExpansion::Maximal);
54355438
Bits.AbstractFunctionDecl.Synthesized = false;
5439+
Bits.AbstractFunctionDecl.HasSingleExpressionBody = false;
54365440
}
54375441

54385442
void setBodyKind(BodyKind K) {
54395443
Bits.AbstractFunctionDecl.BodyKind = unsigned(K);
54405444
}
54415445

54425446
public:
5447+
void setHasSingleExpressionBody(bool Has = true) {
5448+
Bits.AbstractFunctionDecl.HasSingleExpressionBody = Has;
5449+
}
5450+
5451+
bool hasSingleExpressionBody() const {
5452+
return Bits.AbstractFunctionDecl.HasSingleExpressionBody;
5453+
}
5454+
5455+
Expr *getSingleExpressionBody() const;
5456+
void setSingleExpressionBody(Expr *NewBody);
5457+
54435458
/// Returns the string for the base name, or "_" if this is unnamed.
54445459
StringRef getNameStr() const {
54455460
assert(!getFullName().isSpecial() && "Cannot get string for special names");

branches/swift-5.1-branch/include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ NOTE(implicit_member_declared_here,none,
5151
"%1 '%0' is implicitly declared", (StringRef, StringRef))
5252
NOTE(extended_type_declared_here,none,
5353
"extended type declared here", ())
54-
NOTE(opaque_return_type_declared_here,none,
55-
"opaque return type declared here", ())
5654

5755
//------------------------------------------------------------------------------
5856
// MARK: Constraint solver diagnostics
@@ -1587,9 +1585,6 @@ ERROR(type_does_not_conform_in_decl_ref,none,
15871585
ERROR(type_does_not_conform_decl_owner,none,
15881586
"%0 %1 requires that %2 conform to %3",
15891587
(DescriptiveDeclKind, DeclName, Type, Type))
1590-
ERROR(type_does_not_conform_in_opaque_return,none,
1591-
"return type of %0 %1 requires that %2 conform to %3",
1592-
(DescriptiveDeclKind, DeclName, Type, Type))
15931588
ERROR(types_not_equal_decl,none,
15941589
"%0 %1 requires the types %2 and %3 be equivalent",
15951590
(DescriptiveDeclKind, DeclName, Type, Type))

branches/swift-5.1-branch/lib/AST/ASTDumper.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,10 @@ namespace {
10691069
Indent -= 2;
10701070
}
10711071
}
1072-
if (auto Body = D->getBody(/*canSynthesize=*/false)) {
1072+
if (D->hasSingleExpressionBody()) {
1073+
OS << '\n';
1074+
printRec(D->getSingleExpressionBody());
1075+
} else if (auto Body = D->getBody(/*canSynthesize=*/false)) {
10731076
OS << '\n';
10741077
printRec(Body, D->getASTContext());
10751078
}

branches/swift-5.1-branch/lib/AST/ASTWalker.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,15 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
339339
}
340340
}
341341

342+
// FIXME: FIXME_NOW: DETERMINE: Is this or something like it needed? Right
343+
// now it's causing assertion failures during AST verification.
344+
//
345+
// if (AFD->hasSingleExpressionBody()) {
346+
// if (Expr *body = doIt(AFD->getSingleExpressionBody()))
347+
// AFD->setSingleExpressionBody(body);
348+
// else
349+
// return true;
350+
// }
342351
if (AFD->getBody(/*canSynthesize=*/false)) {
343352
AbstractFunctionDecl::BodyKind PreservedKind = AFD->getBodyKind();
344353
if (BraceStmt *S = cast_or_null<BraceStmt>(doIt(AFD->getBody())))

branches/swift-5.1-branch/lib/AST/Decl.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,26 @@ case DeclKind::ID: return cast<ID##Decl>(this)->getLoc();
461461
llvm_unreachable("Unknown decl kind");
462462
}
463463

464+
Expr *AbstractFunctionDecl::getSingleExpressionBody() const {
465+
assert(hasSingleExpressionBody() && "Not a single-expression body");
466+
auto braceStmt = getBody();
467+
assert(braceStmt != nullptr && "No body currently available.");
468+
auto body = getBody()->getElement(0);
469+
if (body.is<Stmt *>())
470+
return cast<ReturnStmt>(body.get<Stmt *>())->getResult();
471+
return body.get<Expr *>();
472+
}
473+
474+
void AbstractFunctionDecl::setSingleExpressionBody(Expr *NewBody) {
475+
assert(hasSingleExpressionBody() && "Not a single-expression body");
476+
auto body = getBody()->getElement(0);
477+
if (body.is<Stmt *>()) {
478+
cast<ReturnStmt>(body.get<Stmt *>())->setResult(NewBody);
479+
return;
480+
}
481+
getBody()->setElement(0, NewBody);
482+
}
483+
464484
bool AbstractStorageDecl::isTransparent() const {
465485
return getAttrs().hasAttribute<TransparentAttr>();
466486
}

branches/swift-5.1-branch/lib/Parse/ParseDecl.cpp

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5636,8 +5636,56 @@ void Parser::parseAbstractFunctionBody(AbstractFunctionDecl *AFD) {
56365636
Context.Stats->getFrontendCounters().NumFunctionsParsed++;
56375637

56385638
ParserResult<BraceStmt> Body = parseBraceItemList(diag::invalid_diagnostic);
5639-
if (!Body.isNull())
5640-
AFD->setBody(Body.get());
5639+
if (!Body.isNull()) {
5640+
// If the body consists of a single expression, turn it into a return
5641+
// statement.
5642+
BraceStmt * BS = Body.get();
5643+
AFD->setBody(BS);
5644+
// FIXME: FIXME_NOW: DETERMINE: Do we need to handle the code completion
5645+
// case here? It is being handled for closure
5646+
// (Parser::parseExprClosure).
5647+
if (BS->getNumElements() == 1) {
5648+
auto Element = BS->getElement(0);
5649+
// FIXME: FIXME_NOW: DETERMINE: Do we need to do this? It's being done
5650+
// for closures (Parser::parseExprClosure) but it may not be
5651+
// relevant here.
5652+
//
5653+
// if (Element.is<Stmt *>()) {
5654+
// if (auto returnStmt =
5655+
// dyn_cast_or_null<ReturnStmt>(Element.get<Stmt*>())) {
5656+
//
5657+
// if (!returnStmt->hasResult()) {
5658+
// Expr *returnExpr = TupleExpr::createEmpty(Context,
5659+
// SourceLoc(),
5660+
// SourceLoc(),
5661+
// /*implicit*/true);
5662+
//
5663+
// returnStmt->setResult(returnExpr);
5664+
// AFD->setHasSingleExpressionBody();
5665+
// AFD->setSingleExpressionBody(returnExpr);
5666+
// }
5667+
// }
5668+
// } else
5669+
if (Element.is<Expr *>()) {
5670+
auto E = Element.get<Expr *>();
5671+
if (auto F = dyn_cast_or_null<FuncDecl>(AFD)) {
5672+
auto RS = new (Context) ReturnStmt(SourceLoc(), E);
5673+
BS->setElement(0, RS);
5674+
AFD->setHasSingleExpressionBody();
5675+
AFD->setSingleExpressionBody(E);
5676+
} else if (auto F = dyn_cast_or_null<ConstructorDecl>(AFD)) {
5677+
if (F->getFailability() != OTK_None && isa<NilLiteralExpr>(E)) {
5678+
// If it's a nil literal, just insert return. This is the only
5679+
// legal thing to return.
5680+
auto RS = new (Context) ReturnStmt(E->getStartLoc(), E);
5681+
BS->setElement(0, RS);
5682+
AFD->setHasSingleExpressionBody();
5683+
AFD->setSingleExpressionBody(E);
5684+
}
5685+
}
5686+
}
5687+
}
5688+
}
56415689
}
56425690

56435691
bool Parser::parseAbstractFunctionBodyDelayed(AbstractFunctionDecl *AFD) {

branches/swift-5.1-branch/lib/Sema/CSDiagnostics.cpp

Lines changed: 10 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -155,25 +155,12 @@ ValueDecl *RequirementFailure::getDeclRef() const {
155155
auto *anchor = getRawAnchor();
156156
auto *locator = cs.getConstraintLocator(anchor);
157157

158-
// Get a declaration associated with given type (if any).
159-
// This is used to retrieve affected declaration when
160-
// failure is in any way contextual, and declaration can't
161-
// be fetched directly from constraint system.
162-
auto getAffectedDeclFromType = [](Type type) -> ValueDecl * {
158+
if (isFromContextualType()) {
159+
auto type = cs.getContextualType();
163160
assert(type);
164-
// If problem is related to a typealias, let's point this
165-
// diagnostic directly to its declaration without desugaring.
166-
if (auto *alias = dyn_cast<TypeAliasType>(type.getPointer()))
167-
return alias->getDecl();
168-
169-
if (auto *opaque = type->getAs<OpaqueTypeArchetypeType>())
170-
return opaque->getDecl();
171-
172-
return type->getAnyGeneric();
173-
};
174-
175-
if (isFromContextualType())
176-
return getAffectedDeclFromType(cs.getContextualType());
161+
auto *alias = dyn_cast<TypeAliasType>(type.getPointer());
162+
return alias ? alias->getDecl() : type->getAnyGeneric();
163+
}
177164

178165
if (auto *AE = dyn_cast<CallExpr>(anchor)) {
179166
// NOTE: In valid code, the function can only be a TypeExpr
@@ -209,7 +196,11 @@ ValueDecl *RequirementFailure::getDeclRef() const {
209196
if (overload)
210197
return overload->choice.getDecl();
211198

212-
return getAffectedDeclFromType(getOwnerType());
199+
auto ownerType = getOwnerType();
200+
if (auto *NA = dyn_cast<TypeAliasType>(ownerType.getPointer()))
201+
return NA->getDecl();
202+
203+
return ownerType->getAnyGeneric();
213204
}
214205

215206
GenericSignature *RequirementFailure::getSignature(ConstraintLocator *locator) {
@@ -272,28 +263,6 @@ bool RequirementFailure::diagnoseAsError() {
272263
auto lhs = resolveType(getLHS());
273264
auto rhs = resolveType(getRHS());
274265

275-
if (auto *OTD = dyn_cast<OpaqueTypeDecl>(AffectedDecl)) {
276-
auto *namingDecl = OTD->getNamingDecl();
277-
emitDiagnostic(
278-
anchor->getLoc(), diag::type_does_not_conform_in_opaque_return,
279-
namingDecl->getDescriptiveKind(), namingDecl->getFullName(), lhs, rhs);
280-
281-
TypeLoc returnLoc;
282-
if (auto *VD = dyn_cast<VarDecl>(namingDecl)) {
283-
returnLoc = VD->getTypeLoc();
284-
} else if (auto *FD = dyn_cast<FuncDecl>(namingDecl)) {
285-
returnLoc = FD->getBodyResultTypeLoc();
286-
} else if (auto *SD = dyn_cast<SubscriptDecl>(namingDecl)) {
287-
returnLoc = SD->getElementTypeLoc();
288-
}
289-
290-
if (returnLoc.hasLocation()) {
291-
emitDiagnostic(returnLoc.getLoc(), diag::opaque_return_type_declared_here)
292-
.highlight(returnLoc.getSourceRange());
293-
}
294-
return true;
295-
}
296-
297266
if (genericCtx != reqDC && (genericCtx->isChildContextOf(reqDC) ||
298267
isStaticOrInstanceMember(AffectedDecl))) {
299268
auto *NTD = reqDC->getSelfNominalTypeDecl();

branches/swift-5.1-branch/lib/Sema/MiscDiagnostics.cpp

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,9 +2257,6 @@ class OpaqueUnderlyingTypeChecker : public ASTWalker {
22572257
AbstractFunctionDecl *Implementation;
22582258
OpaqueTypeDecl *OpaqueDecl;
22592259
SmallVector<std::pair<Expr*, Type>, 4> Candidates;
2260-
2261-
bool HasInvalidReturn = false;
2262-
22632260
public:
22642261
OpaqueUnderlyingTypeChecker(TypeChecker &TC,
22652262
AbstractFunctionDecl *Implementation,
@@ -2273,13 +2270,7 @@ class OpaqueUnderlyingTypeChecker : public ASTWalker {
22732270

22742271
void check() {
22752272
Implementation->getBody()->walk(*this);
2276-
2277-
// If given function has any invalid returns in the body
2278-
// let's not try to validate the types, since it wouldn't
2279-
// be accurate.
2280-
if (HasInvalidReturn)
2281-
return;
2282-
2273+
22832274
// If there are no candidates, then the body has no return statements, and
22842275
// we have nothing to infer the underlying type from.
22852276
if (Candidates.empty()) {
@@ -2358,20 +2349,6 @@ class OpaqueUnderlyingTypeChecker : public ASTWalker {
23582349
}
23592350
return std::make_pair(false, E);
23602351
}
2361-
2362-
std::pair<bool, Stmt *> walkToStmtPre(Stmt *S) override {
2363-
if (auto *RS = dyn_cast<ReturnStmt>(S)) {
2364-
if (RS->hasResult()) {
2365-
auto resultTy = RS->getResult()->getType();
2366-
// If expression associated with return statement doesn't have
2367-
// a type or type has an error, checking opaque types is going
2368-
// to produce incorrect diagnostics.
2369-
HasInvalidReturn |= resultTy.isNull() || resultTy->hasError();
2370-
}
2371-
}
2372-
2373-
return {true, S};
2374-
}
23752352
};
23762353

23772354
} // end anonymous namespace

branches/swift-5.1-branch/lib/Sema/TypeCheckStmt.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,6 +1920,48 @@ bool TypeChecker::typeCheckFunctionBodyUntil(FuncDecl *FD,
19201920
BraceStmt *BS = FD->getBody();
19211921
assert(BS && "Should have a body");
19221922

1923+
// FIXME: FIXME_NOW: DETERMINE: What is the appropriate place for this code to
1924+
// live?
1925+
if (FD->hasSingleExpressionBody()) {
1926+
auto fnType = FD->getBodyResultTypeLoc().getType();
1927+
auto returnStmt = cast<ReturnStmt>(BS->getElement(0).get<Stmt *>());
1928+
auto E = returnStmt->getResult();
1929+
1930+
// FIXME: FIXME_NOW: DETERMINE: Does this actually need to be here? It's
1931+
// being done for closures, but there may be a reason that applies
1932+
// there but not here.
1933+
//
1934+
// if (E != FD->getSingleExpressionBody()) {
1935+
// FD->setSingleExpressionBody(E);
1936+
// }
1937+
1938+
if (FD->getBodyResultTypeLoc().isNull() || fnType->isVoid()) {
1939+
auto voidExpr = TupleExpr::createEmpty(Context,
1940+
E->getStartLoc(),
1941+
E->getEndLoc(),
1942+
/*implicit*/true);
1943+
returnStmt->setResult(voidExpr);
1944+
BS = BraceStmt::create(Context,
1945+
BS->getStartLoc(),
1946+
{ E, returnStmt },
1947+
BS->getEndLoc(),
1948+
/*implicit=*/true);
1949+
} else {
1950+
// FIXME: FIXME_NOW: DETERMINE: Is this the appropriate mechanism to use
1951+
// to divine the type of E?
1952+
auto exprTy = typeCheckExpression(E, FD, TypeLoc(),
1953+
CTP_ReturnStmt);
1954+
if (!exprTy.isNull() && exprTy->isUninhabited() &&
1955+
exprTy->getCanonicalType() != fnType->getCanonicalType()) {
1956+
BS = BraceStmt::create(Context,
1957+
BS->getStartLoc(),
1958+
{ E },
1959+
BS->getEndLoc(),
1960+
/*implicit=*/true);
1961+
}
1962+
}
1963+
}
1964+
19231965
StmtChecker SC(*this, static_cast<AbstractFunctionDecl *>(FD));
19241966
SC.EndTypeCheckLoc = EndTypeCheckLoc;
19251967
bool HadError = SC.typeCheckBody(BS);

branches/swift-5.1-branch/stdlib/public/Darwin/AppKit/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ add_swift_target_library(swiftAppKit ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS
99
NSGraphics.swift
1010
NSOpenGL.swift
1111

12-
SWIFT_COMPILE_FLAGS ${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}
12+
SWIFT_COMPILE_FLAGS ${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS} -swift-version 4
1313
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
1414
TARGET_SDKS OSX
1515
SWIFT_MODULE_DEPENDS_OSX Darwin CoreData CoreGraphics CoreImage Dispatch Foundation IOKit ObjectiveC QuartzCore XPC # auto-updated

branches/swift-5.1-branch/stdlib/public/Darwin/CloudKit/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ add_swift_target_library(swiftCloudKit ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES}
1616
CKRecordValue.swift
1717
DefaultParameters.swift
1818

19-
SWIFT_COMPILE_FLAGS "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
19+
SWIFT_COMPILE_FLAGS "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}" "-swift-version" "4.2"
2020
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
2121
TARGET_SDKS OSX IOS IOS_SIMULATOR TVOS TVOS_SIMULATOR WATCHOS WATCHOS_SIMULATOR
2222

branches/swift-5.1-branch/stdlib/public/Darwin/CoreImage/CoreImage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ extension CIFilter {
3838
for (key, value) in elements {
3939
dict[key] = value
4040
}
41-
self.init(name: name, parameters: dict)
41+
self.init(name: name, withInputParameters: dict)
4242
}
4343
}
4444

0 commit comments

Comments
 (0)