Skip to content

Commit fe4a7b9

Browse files
committed
---
yaml --- r: 294367 b: refs/heads/tensorflow c: d332d21 h: refs/heads/master i: 294365: e7d5f75 294363: a25e2a6 294359: 6ef7dad 294351: 2fb189a 294335: f716bd5
1 parent 3b2547c commit fe4a7b9

File tree

18 files changed

+604
-943
lines changed

18 files changed

+604
-943
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-04-25-a: 22f738a831d43aff2b9c9773bcb65
816816
refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-05-08-a: 7d98cc16689baba5c8a3b90a9329bdcc1a12b4e9
817817
refs/heads/cherr42: a566ad54b073c2c56ac0a705d0a5bed9743135a5
818818
"refs/heads/codable_test_comment_fix": fc8f6824f7f347e1e8db55bff62db385c5728b5a
819-
refs/heads/tensorflow: e43a9f5475fc7ed3efbcf552e66b7f4c3a6c38d3
819+
refs/heads/tensorflow: d332d21056b1cb95e1b5f5cfe7df6dbaa455f540
820820
refs/tags/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-05-11-a: 8126fd7a652e2f70ad6d76505239e34fb2ef3e1a
821821
refs/tags/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-05-12-a: b3fd3dd84df6717f2e2e9df58c6d7e99fed57086
822822
refs/tags/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-05-13-a: 71135119579039dc321c5f65d870050fe36efda2

branches/tensorflow/cmake/modules/StandaloneOverlay.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ set(SWIFT_APPLE_PLATFORMS
8484
set(BUILD_STANDALONE TRUE)
8585
set(SWIFT_BUILD_STANDALONE_OVERLAY TRUE)
8686

87-
set(SWIFT_STDLIB_LIBRARY_BUILD_TYPES "SHARED")
8887
set(SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES "SHARED")
8988

9089

branches/tensorflow/lib/AST/Decl.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6856,13 +6856,7 @@ Type ConstructorDecl::getInitializerInterfaceType() {
68566856
return InitializerInterfaceType;
68576857

68586858
// Lazily calculate initializer type.
6859-
auto allocatorTy = getInterfaceType();
6860-
if (!allocatorTy->is<AnyFunctionType>()) {
6861-
InitializerInterfaceType = ErrorType::get(getASTContext());
6862-
return InitializerInterfaceType;
6863-
}
6864-
6865-
auto funcTy = allocatorTy->castTo<AnyFunctionType>()->getResult();
6859+
auto funcTy = getInterfaceType()->castTo<AnyFunctionType>()->getResult();
68666860
assert(funcTy->is<FunctionType>());
68676861

68686862
// Constructors have an initializer type that takes an instance

branches/tensorflow/lib/Frontend/ParseableInterfaceSupport.cpp

Lines changed: 29 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "swift/AST/ASTContext.h"
14-
#include "swift/AST/ASTPrinter.h"
1514
#include "swift/AST/Decl.h"
1615
#include "swift/AST/DiagnosticsFrontend.h"
1716
#include "swift/AST/DiagnosticsSema.h"
@@ -164,69 +163,47 @@ namespace {
164163
class InheritedProtocolCollector {
165164
static const StringLiteral DummyProtocolName;
166165

167-
using AvailableAttrList = TinyPtrVector<const AvailableAttr *>;
168-
using ProtocolAndAvailability =
169-
std::pair<ProtocolDecl *, AvailableAttrList>;
170-
171166
/// Protocols that will be included by the ASTPrinter without any extra work.
172167
SmallVector<ProtocolDecl *, 8> IncludedProtocols;
173-
/// Protocols that will not be printed by the ASTPrinter, along with the
174-
/// availability they were declared with.
175-
SmallVector<ProtocolAndAvailability, 8> ExtraProtocols;
168+
/// Protocols that will not be printed by the ASTPrinter.
169+
SmallVector<ProtocolDecl *, 8> ExtraProtocols;
176170
/// Protocols that can be printed, but whose conformances are constrained with
177171
/// something that \e can't be printed.
178172
SmallVector<const ProtocolType *, 8> ConditionalConformanceProtocols;
179173

180-
/// Helper to extract the `@available` attributes on a decl.
181-
AvailableAttrList getAvailabilityAttrs(const Decl *D) {
182-
AvailableAttrList result;
183-
auto attrRange = D->getAttrs().getAttributes<AvailableAttr>();
184-
result.insert(result.begin(), attrRange.begin(), attrRange.end());
185-
return result;
186-
}
187-
188174
/// For each type in \p directlyInherited, classify the protocols it refers to
189175
/// as included for printing or not, and record them in the appropriate
190176
/// vectors.
191-
void recordProtocols(ArrayRef<TypeLoc> directlyInherited, const Decl *D) {
192-
Optional<AvailableAttrList> availableAttrs;
193-
177+
void recordProtocols(ArrayRef<TypeLoc> directlyInherited) {
194178
for (TypeLoc inherited : directlyInherited) {
195179
Type inheritedTy = inherited.getType();
196180
if (!inheritedTy || !inheritedTy->isExistentialType())
197181
continue;
198182

199183
bool canPrintNormally = isPublicOrUsableFromInline(inheritedTy);
200-
if (!canPrintNormally && !availableAttrs.hasValue())
201-
availableAttrs = getAvailabilityAttrs(D);
184+
SmallVectorImpl<ProtocolDecl *> &whichProtocols =
185+
canPrintNormally ? IncludedProtocols : ExtraProtocols;
202186

203187
ExistentialLayout layout = inheritedTy->getExistentialLayout();
204-
for (ProtocolType *protoTy : layout.getProtocols()) {
205-
if (canPrintNormally)
206-
IncludedProtocols.push_back(protoTy->getDecl());
207-
else
208-
ExtraProtocols.push_back({protoTy->getDecl(),
209-
availableAttrs.getValue()});
210-
}
188+
for (ProtocolType *protoTy : layout.getProtocols())
189+
whichProtocols.push_back(protoTy->getDecl());
211190
// FIXME: This ignores layout constraints, but currently we don't support
212191
// any of those besides 'AnyObject'.
213192
}
214193
}
215194

216-
/// For each type directly inherited by \p extension, record any protocols
217-
/// that we would have printed in ConditionalConformanceProtocols.
218-
void recordConditionalConformances(const ExtensionDecl *extension) {
219-
for (TypeLoc inherited : extension->getInherited()) {
195+
/// For each type in \p directlyInherited, record any protocols that we would
196+
/// have printed in ConditionalConformanceProtocols.
197+
void recordConditionalConformances(ArrayRef<TypeLoc> directlyInherited) {
198+
for (TypeLoc inherited : directlyInherited) {
220199
Type inheritedTy = inherited.getType();
221200
if (!inheritedTy || !inheritedTy->isExistentialType())
222201
continue;
223202

224203
ExistentialLayout layout = inheritedTy->getExistentialLayout();
225-
for (ProtocolType *protoTy : layout.getProtocols()) {
226-
if (!isPublicOrUsableFromInline(protoTy))
227-
continue;
228-
ConditionalConformanceProtocols.push_back(protoTy);
229-
}
204+
for (ProtocolType *protoTy : layout.getProtocols())
205+
if (isPublicOrUsableFromInline(protoTy))
206+
ConditionalConformanceProtocols.push_back(protoTy);
230207
// FIXME: This ignores layout constraints, but currently we don't support
231208
// any of those besides 'AnyObject'.
232209
}
@@ -266,7 +243,7 @@ class InheritedProtocolCollector {
266243
if (!isPublicOrUsableFromInline(nominal))
267244
return;
268245

269-
map[nominal].recordProtocols(directlyInherited, D);
246+
map[nominal].recordProtocols(directlyInherited);
270247

271248
// Recurse to find any nested types.
272249
for (const Decl *member : memberContext->getMembers())
@@ -287,7 +264,7 @@ class InheritedProtocolCollector {
287264
if (!isPublicOrUsableFromInline(nominal))
288265
return;
289266

290-
map[nominal].recordConditionalConformances(extension);
267+
map[nominal].recordConditionalConformances(extension->getInherited());
291268
// No recursion here because extensions are never nested.
292269
}
293270

@@ -330,19 +307,16 @@ class InheritedProtocolCollector {
330307
// Note: We could do this in one pass, but the logic is easier to
331308
// understand if we build up the list and then print it, even if it takes
332309
// a bit more memory.
333-
// FIXME: This will pick the availability attributes from the first sight
334-
// of a protocol rather than the maximally available case.
335-
SmallVector<std::pair<ProtocolDecl *, AvailableAttrList>, 16>
336-
protocolsToPrint;
337-
for (const auto &protoAndAvailability : ExtraProtocols) {
338-
protoAndAvailability.first->walkInheritedProtocols(
310+
SmallVector<ProtocolDecl *, 16> protocolsToPrint;
311+
for (ProtocolDecl *proto : ExtraProtocols) {
312+
proto->walkInheritedProtocols(
339313
[&](ProtocolDecl *inherited) -> TypeWalker::Action {
340314
if (!handledProtocols.insert(inherited).second)
341315
return TypeWalker::Action::SkipChildren;
342316

343317
if (isPublicOrUsableFromInline(inherited) &&
344318
conformanceDeclaredInModule(M, nominal, inherited)) {
345-
protocolsToPrint.push_back({inherited, protoAndAvailability.second});
319+
protocolsToPrint.push_back(inherited);
346320
return TypeWalker::Action::SkipChildren;
347321
}
348322

@@ -352,20 +326,14 @@ class InheritedProtocolCollector {
352326
if (protocolsToPrint.empty())
353327
return;
354328

355-
for (const auto &protoAndAvailability : protocolsToPrint) {
356-
StreamPrinter printer(out);
357-
for (const AvailableAttr *attr : protoAndAvailability.second)
358-
attr->print(printer, printOptions);
359-
360-
printer << "extension ";
361-
nominal->getDeclaredType().print(printer, printOptions);
362-
printer << " : ";
363-
364-
ProtocolDecl *proto = protoAndAvailability.first;
365-
proto->getDeclaredType()->print(printer, printOptions);
366-
367-
printer << " {}\n";
368-
}
329+
out << "extension ";
330+
nominal->getDeclaredType().print(out, printOptions);
331+
out << " : ";
332+
swift::interleave(protocolsToPrint,
333+
[&out, &printOptions](ProtocolDecl *proto) {
334+
proto->getDeclaredType()->print(out, printOptions);
335+
}, [&out] { out << ", "; });
336+
out << " {}\n";
369337
}
370338

371339
/// If there were any conditional conformances that couldn't be printed,
@@ -378,7 +346,7 @@ class InheritedProtocolCollector {
378346
return false;
379347
assert(nominal->isGenericContext());
380348

381-
out << "@available(*, unavailable)\nextension ";
349+
out << "extension ";
382350
nominal->getDeclaredType().print(out, printOptions);
383351
out << " : ";
384352
swift::interleave(ConditionalConformanceProtocols,

branches/tensorflow/lib/SILGen/SILGenExpr.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -931,25 +931,6 @@ RValue RValueEmitter::visitOtherConstructorDeclRefExpr(
931931
}
932932

933933
RValue RValueEmitter::visitNilLiteralExpr(NilLiteralExpr *E, SGFContext C) {
934-
// Peephole away the call to Optional<T>(nilLiteral: ()).
935-
if (E->getType()->getOptionalObjectType()) {
936-
auto *noneDecl = SGF.getASTContext().getOptionalNoneDecl();
937-
auto enumTy = SGF.getLoweredType(E->getType());
938-
939-
ManagedValue noneValue;
940-
if (enumTy.isLoadable(SGF.F) || !SGF.silConv.useLoweredAddresses()) {
941-
noneValue = ManagedValue::forUnmanaged(
942-
SGF.B.createEnum(E, SILValue(), noneDecl, enumTy));
943-
} else {
944-
noneValue =
945-
SGF.B.bufferForExpr(E, enumTy, SGF.getTypeLowering(enumTy), C,
946-
[&](SILValue newAddr) {
947-
SGF.B.createInjectEnumAddr(E, newAddr, noneDecl);
948-
});
949-
}
950-
return RValue(SGF, E, noneValue);
951-
}
952-
953934
return SGF.emitLiteral(E, C);
954935
}
955936

branches/tensorflow/lib/Sema/CSApply.cpp

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,27 +1912,57 @@ namespace {
19121912
}
19131913

19141914
Expr *visitNilLiteralExpr(NilLiteralExpr *expr) {
1915-
auto type = simplifyType(cs.getType(expr));
1916-
1917-
// By far the most common 'nil' literal is for Optional<T>.none.
1918-
// We don't have to look up the witness in this case since SILGen
1919-
// knows how to lower it directly.
1920-
if (auto objectType = type->getOptionalObjectType()) {
1921-
cs.setType(expr, type);
1922-
return expr;
1923-
}
1924-
19251915
auto &tc = cs.getTypeChecker();
19261916
auto *protocol = tc.getProtocol(expr->getLoc(),
19271917
KnownProtocolKind::ExpressibleByNilLiteral);
19281918

19291919
// For type-sugar reasons, prefer the spelling of the default literal
19301920
// type.
1921+
auto type = simplifyType(cs.getType(expr));
19311922
if (auto defaultType = tc.getDefaultType(protocol, dc)) {
19321923
if (defaultType->isEqual(type))
19331924
type = defaultType;
19341925
}
19351926

1927+
// By far the most common 'nil' literal is for Optional<T>.none.
1928+
//
1929+
// Emit this case directly instead of calling Optional.init(nilLiteral:),
1930+
// since this generates more efficient SIL.
1931+
if (auto objectType = type->getOptionalObjectType()) {
1932+
auto *nilDecl = tc.Context.getOptionalNoneDecl();
1933+
tc.validateDecl(nilDecl);
1934+
if (!nilDecl->hasInterfaceType())
1935+
return nullptr;
1936+
1937+
auto genericSig =
1938+
nilDecl->getDeclContext()->getGenericSignatureOfContext();
1939+
SubstitutionMap subs =
1940+
SubstitutionMap::get(genericSig, llvm::makeArrayRef(objectType),
1941+
{ });
1942+
ConcreteDeclRef concreteDeclRef(nilDecl, subs);
1943+
1944+
auto nilType = FunctionType::get(
1945+
{FunctionType::Param(MetatypeType::get(type))}, type);
1946+
auto *nilRefExpr = new (tc.Context) DeclRefExpr(
1947+
concreteDeclRef, DeclNameLoc(expr->getLoc()),
1948+
/*implicit=*/true, AccessSemantics::Ordinary,
1949+
nilType);
1950+
cs.cacheType(nilRefExpr);
1951+
1952+
auto *typeExpr = TypeExpr::createImplicitHack(
1953+
expr->getLoc(),
1954+
type,
1955+
tc.Context);
1956+
cs.cacheType(typeExpr);
1957+
1958+
auto *callExpr = new (tc.Context) DotSyntaxCallExpr(
1959+
nilRefExpr, expr->getLoc(), typeExpr, type);
1960+
callExpr->setImplicit(true);
1961+
cs.cacheType(callExpr);
1962+
1963+
return callExpr;
1964+
}
1965+
19361966
DeclName initName(tc.Context, DeclBaseName::createConstructor(),
19371967
{ tc.Context.Id_nilLiteral });
19381968
return convertLiteralInPlace(expr, type, protocol,

0 commit comments

Comments
 (0)