Skip to content

Commit 7e99354

Browse files
authored
---
yaml --- r: 274939 b: refs/heads/master c: 041eda1 h: refs/heads/master i: 274937: 5bffffe 274935: 3ff73c1
1 parent 62f512a commit 7e99354

Some content is hidden

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

50 files changed

+1205
-797
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 52c6e03c44114dd7bf37e4db2972b458e291233a
2+
refs/heads/master: 041eda1f276550b60d3d1e727e871b735f54648f
33
refs/heads/master-next: 75552d2b66023907022c17dfd899aae8b198add5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/include/swift/AST/Decl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4549,6 +4549,9 @@ class AbstractStorageDecl : public ValueDecl {
45494549
/// other modules.
45504550
bool exportsPropertyDescriptor() const;
45514551

4552+
/// True if any of the accessors to the storage is private or fileprivate.
4553+
bool hasPrivateAccessor() const;
4554+
45524555
// Implement isa/cast/dyncast/etc.
45534556
static bool classof(const Decl *D) {
45544557
return D->getKind() >= DeclKind::First_AbstractStorageDecl &&

trunk/include/swift/SIL/DynamicCasts.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#ifndef SWIFT_SIL_DYNAMICCASTS_H
1919
#define SWIFT_SIL_DYNAMICCASTS_H
2020

21+
#include "swift/AST/Module.h"
2122
#include "swift/Basic/ProfileCounter.h"
2223
#include "swift/SIL/SILInstruction.h"
2324
#include "swift/SIL/SILModule.h"
@@ -420,10 +421,33 @@ struct SILDynamicCastInst {
420421
// Bridging casts cannot be further simplified.
421422
auto TargetIsBridgeable = getTargetType()->isBridgeableObjectType();
422423
auto SourceIsBridgeable = getSourceType()->isBridgeableObjectType();
423-
424424
return TargetIsBridgeable != SourceIsBridgeable;
425425
}
426426

427+
/// If getSourceType() is a Swift type that can bridge to an ObjC type, return
428+
/// the ObjC type it bridges to. If the source type is an objc type, an empty
429+
/// CanType() is returned.
430+
CanType getBridgedSourceType() const {
431+
SILModule &mod = getModule();
432+
Type t = mod.getASTContext().getBridgedToObjC(mod.getSwiftModule(),
433+
getSourceType());
434+
if (!t)
435+
return CanType();
436+
return t->getCanonicalType();
437+
}
438+
439+
/// If getTargetType() is a Swift type that can bridge to an ObjC type, return
440+
/// the ObjC type it bridges to. If the target type is an objc type, an empty
441+
/// CanType() is returned.
442+
CanType getBridgedTargetType() const {
443+
SILModule &mod = getModule();
444+
Type t = mod.getASTContext().getBridgedToObjC(mod.getSwiftModule(),
445+
getTargetType());
446+
if (!t)
447+
return CanType();
448+
return t->getCanonicalType();
449+
}
450+
427451
bool isConditional() const {
428452
switch (getKind()) {
429453
case SILDynamicCastKind::CheckedCastAddrBranchInst: {

trunk/include/swift/SIL/SILBuilder.h

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,18 +2257,45 @@ class SILBuilderWithScope : public SILBuilder {
22572257
};
22582258

22592259
class SavedInsertionPointRAII {
2260-
SILBuilder &Builder;
2261-
PointerUnion<SILInstruction *, SILBasicBlock *> SavedIP;
2260+
SILBuilder &builder;
2261+
PointerUnion<SILInstruction *, SILBasicBlock *> savedInsertionPoint;
22622262

22632263
public:
2264-
SavedInsertionPointRAII(SILBuilder &B, SILInstruction *NewIP)
2265-
: Builder(B), SavedIP(&*B.getInsertionPoint()) {
2266-
Builder.setInsertionPoint(NewIP);
2264+
/// Constructor that saves a Builder's insertion point without changing the
2265+
/// builder's underlying insertion point.
2266+
SavedInsertionPointRAII(SILBuilder &B) : builder(B), savedInsertionPoint() {
2267+
// If our builder does not have a valid insertion point, just put nullptr
2268+
// into SavedIP.
2269+
if (!builder.hasValidInsertionPoint()) {
2270+
savedInsertionPoint = static_cast<SILBasicBlock *>(nullptr);
2271+
return;
2272+
}
2273+
2274+
// If we are inserting into the end of the block, stash the insertion block.
2275+
if (builder.insertingAtEndOfBlock()) {
2276+
savedInsertionPoint = builder.getInsertionBB();
2277+
return;
2278+
}
2279+
2280+
// Otherwise, stash the instruction.
2281+
SILInstruction *i = &*builder.getInsertionPoint();
2282+
savedInsertionPoint = i;
2283+
}
2284+
2285+
SavedInsertionPointRAII(SILBuilder &b, SILInstruction *insertionPoint)
2286+
: SavedInsertionPointRAII(b) {
2287+
builder.setInsertionPoint(insertionPoint);
2288+
}
2289+
2290+
SavedInsertionPointRAII(SILBuilder &b, SILBasicBlock *block,
2291+
SILBasicBlock::iterator iter)
2292+
: SavedInsertionPointRAII(b) {
2293+
builder.setInsertionPoint(block, iter);
22672294
}
22682295

2269-
SavedInsertionPointRAII(SILBuilder &B, SILBasicBlock *NewIP)
2270-
: Builder(B), SavedIP(B.getInsertionBB()) {
2271-
Builder.setInsertionPoint(NewIP);
2296+
SavedInsertionPointRAII(SILBuilder &b, SILBasicBlock *insertionBlock)
2297+
: SavedInsertionPointRAII(b) {
2298+
builder.setInsertionPoint(insertionBlock);
22722299
}
22732300

22742301
SavedInsertionPointRAII(const SavedInsertionPointRAII &) = delete;
@@ -2277,12 +2304,12 @@ class SavedInsertionPointRAII {
22772304
SavedInsertionPointRAII &operator=(SavedInsertionPointRAII &&) = delete;
22782305

22792306
~SavedInsertionPointRAII() {
2280-
if (SavedIP.isNull()) {
2281-
Builder.clearInsertionPoint();
2282-
} else if (SavedIP.is<SILInstruction *>()) {
2283-
Builder.setInsertionPoint(SavedIP.get<SILInstruction *>());
2307+
if (savedInsertionPoint.isNull()) {
2308+
builder.clearInsertionPoint();
2309+
} else if (savedInsertionPoint.is<SILInstruction *>()) {
2310+
builder.setInsertionPoint(savedInsertionPoint.get<SILInstruction *>());
22842311
} else {
2285-
Builder.setInsertionPoint(SavedIP.get<SILBasicBlock *>());
2312+
builder.setInsertionPoint(savedInsertionPoint.get<SILBasicBlock *>());
22862313
}
22872314
}
22882315
};

trunk/include/swift/SIL/TypeLowering.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,14 @@ class TypeConverter {
792792
return ti.getLoweredType();
793793
}
794794

795+
CanType getLoweredRValueType(Type t) {
796+
return getLoweredType(t).getASTType();
797+
}
798+
799+
CanType getLoweredRValueType(AbstractionPattern origType, Type substType) {
800+
return getLoweredType(origType, substType).getASTType();
801+
}
802+
795803
AbstractionPattern getAbstractionPattern(AbstractStorageDecl *storage,
796804
bool isNonObjC = false);
797805
AbstractionPattern getAbstractionPattern(VarDecl *var,
@@ -800,7 +808,7 @@ class TypeConverter {
800808
bool isNonObjC = false);
801809
AbstractionPattern getAbstractionPattern(EnumElementDecl *element);
802810

803-
SILType getLoweredTypeOfGlobal(VarDecl *var);
811+
CanType getLoweredTypeOfGlobal(VarDecl *var);
804812

805813
/// Return the SILFunctionType for a native function value of the
806814
/// given type.
@@ -1001,7 +1009,8 @@ class TypeConverter {
10011009
EnumElementDecl *elt);
10021010

10031011
private:
1004-
CanType getLoweredRValueType(AbstractionPattern origType, CanType substType);
1012+
CanType computeLoweredRValueType(AbstractionPattern origType,
1013+
CanType substType);
10051014

10061015
Type getLoweredCBridgedType(AbstractionPattern pattern, Type t,
10071016
Bridgeability bridging,

trunk/include/swift/SILOptimizer/Utils/CastOptimizer.h

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,24 +63,6 @@ class CastOptimizer {
6363
/// that a cast will fail.
6464
std::function<void()> WillFailAction;
6565

66-
/// Optimize a cast from a bridged ObjC type into
67-
/// a corresponding Swift type implementing _ObjectiveCBridgeable.
68-
SILInstruction *optimizeBridgedObjCToSwiftCast(
69-
SILInstruction *Inst, bool isConditional, SILValue Src, SILValue Dest,
70-
CanType Source, CanType Target, Type BridgedSourceTy,
71-
Type BridgedTargetTy, SILBasicBlock *SuccessBB, SILBasicBlock *FailureBB);
72-
73-
/// Optimize a cast from a Swift type implementing _ObjectiveCBridgeable
74-
/// into a bridged ObjC type.
75-
SILInstruction *optimizeBridgedSwiftToObjCCast(
76-
SILInstruction *Inst, CastConsumptionKind ConsumptionKind,
77-
bool isConditional, SILValue Src, SILValue Dest, CanType Source,
78-
CanType Target, Type BridgedSourceTy, Type BridgedTargetTy,
79-
SILBasicBlock *SuccessBB, SILBasicBlock *FailureBB);
80-
81-
void deleteInstructionsAfterUnreachable(SILInstruction *UnreachableInst,
82-
SILInstruction *TrapInst);
83-
8466
public:
8567
CastOptimizer(SILOptFunctionBuilder &FunctionBuilder,
8668
SILBuilderContext *BuilderContext,
@@ -149,6 +131,19 @@ class CastOptimizer {
149131
/// May change the control flow.
150132
SILInstruction *optimizeBridgedCasts(SILDynamicCastInst cast);
151133

134+
/// Optimize a cast from a bridged ObjC type into
135+
/// a corresponding Swift type implementing _ObjectiveCBridgeable.
136+
SILInstruction *
137+
optimizeBridgedObjCToSwiftCast(SILDynamicCastInst dynamicCast);
138+
139+
/// Optimize a cast from a Swift type implementing _ObjectiveCBridgeable
140+
/// into a bridged ObjC type.
141+
SILInstruction *
142+
optimizeBridgedSwiftToObjCCast(SILDynamicCastInst dynamicCast);
143+
144+
void deleteInstructionsAfterUnreachable(SILInstruction *UnreachableInst,
145+
SILInstruction *TrapInst);
146+
152147
SILValue optimizeMetatypeConversion(ConversionInst *mci,
153148
MetatypeRepresentation representation);
154149
};

trunk/lib/AST/Decl.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4419,6 +4419,14 @@ void AbstractStorageDecl::overwriteImplInfo(StorageImplInfo implInfo) {
44194419
Accessors.getPointer()->overwriteImplInfo(implInfo);
44204420
}
44214421

4422+
bool AbstractStorageDecl::hasPrivateAccessor() const {
4423+
for (auto accessor : getAllAccessors()) {
4424+
if (hasPrivateOrFilePrivateFormalAccess(accessor))
4425+
return true;
4426+
}
4427+
return false;
4428+
}
4429+
44224430
void AbstractStorageDecl::setAccessors(StorageImplInfo implInfo,
44234431
SourceLoc lbraceLoc,
44244432
ArrayRef<AccessorDecl *> accessors,

trunk/lib/ClangImporter/ClangAdapter.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -718,19 +718,17 @@ bool importer::isUnavailableInSwift(
718718
if (attr->getPlatform()->getName() == "swift")
719719
return true;
720720

721-
if (platformAvailability.filter &&
722-
!platformAvailability.filter(attr->getPlatform()->getName())) {
721+
if (!platformAvailability.isPlatformRelevant(
722+
attr->getPlatform()->getName())) {
723723
continue;
724724
}
725725

726-
if (platformAvailability.deprecatedAsUnavailableFilter) {
727-
llvm::VersionTuple version = attr->getDeprecated();
728-
if (version.empty())
729-
continue;
730-
if (platformAvailability.deprecatedAsUnavailableFilter(
731-
version.getMajor(), version.getMinor())) {
732-
return true;
733-
}
726+
727+
llvm::VersionTuple version = attr->getDeprecated();
728+
if (version.empty())
729+
continue;
730+
if (platformAvailability.treatDeprecatedAsUnavailable(decl, version)) {
731+
return true;
734732
}
735733
}
736734

trunk/lib/ClangImporter/ClangImporter.cpp

Lines changed: 78 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,65 +1684,88 @@ ModuleDecl *ClangImporter::getImportedHeaderModule() const {
16841684
return Impl.ImportedHeaderUnit->getParentModule();
16851685
}
16861686

1687-
PlatformAvailability::PlatformAvailability(LangOptions &langOpts) {
1688-
// Add filters to determine if a Clang availability attribute
1689-
// applies in Swift, and if so, what is the cutoff for deprecated
1690-
// declarations that are now considered unavailable in Swift.
1691-
1692-
if (langOpts.Target.isiOS() && !langOpts.Target.isTvOS()) {
1693-
if (!langOpts.EnableAppExtensionRestrictions) {
1694-
filter = [](StringRef Platform) { return Platform == "ios"; };
1695-
} else {
1696-
filter = [](StringRef Platform) {
1697-
return Platform == "ios" || Platform == "ios_app_extension";
1698-
};
1699-
}
1700-
// Anything deprecated in iOS 7.x and earlier is unavailable in Swift.
1701-
deprecatedAsUnavailableFilter = [](
1702-
unsigned major, llvm::Optional<unsigned> minor) { return major <= 7; };
1687+
PlatformAvailability::PlatformAvailability(LangOptions &langOpts)
1688+
: platformKind(targetPlatform(langOpts)) {
1689+
switch (platformKind) {
1690+
case PlatformKind::iOS:
1691+
case PlatformKind::iOSApplicationExtension:
1692+
case PlatformKind::tvOS:
1693+
case PlatformKind::tvOSApplicationExtension:
17031694
deprecatedAsUnavailableMessage =
17041695
"APIs deprecated as of iOS 7 and earlier are unavailable in Swift";
1705-
} else if (langOpts.Target.isTvOS()) {
1706-
if (!langOpts.EnableAppExtensionRestrictions) {
1707-
filter = [](StringRef Platform) { return Platform == "tvos"; };
1708-
} else {
1709-
filter = [](StringRef Platform) {
1710-
return Platform == "tvos" || Platform == "tvos_app_extension";
1711-
};
1712-
}
1713-
// Anything deprecated in iOS 7.x and earlier is unavailable in Swift.
1714-
deprecatedAsUnavailableFilter = [](
1715-
unsigned major, llvm::Optional<unsigned> minor) { return major <= 7; };
1716-
deprecatedAsUnavailableMessage =
1717-
"APIs deprecated as of iOS 7 and earlier are unavailable in Swift";
1718-
} else if (langOpts.Target.isWatchOS()) {
1719-
if (!langOpts.EnableAppExtensionRestrictions) {
1720-
filter = [](StringRef Platform) { return Platform == "watchos"; };
1721-
} else {
1722-
filter = [](StringRef Platform) {
1723-
return Platform == "watchos" || Platform == "watchos_app_extension";
1724-
};
1725-
}
1726-
// No deprecation filter on watchOS
1727-
deprecatedAsUnavailableFilter = [](
1728-
unsigned major, llvm::Optional<unsigned> minor) { return false; };
1696+
break;
1697+
1698+
case PlatformKind::watchOS:
1699+
case PlatformKind::watchOSApplicationExtension:
17291700
deprecatedAsUnavailableMessage = "";
1730-
} else if (langOpts.Target.isMacOSX()) {
1731-
if (!langOpts.EnableAppExtensionRestrictions) {
1732-
filter = [](StringRef Platform) { return Platform == "macos"; };
1733-
} else {
1734-
filter = [](StringRef Platform) {
1735-
return Platform == "macos" || Platform == "macos_app_extension";
1736-
};
1737-
}
1738-
// Anything deprecated in OSX 10.9.x and earlier is unavailable in Swift.
1739-
deprecatedAsUnavailableFilter = [](unsigned major,
1740-
llvm::Optional<unsigned> minor) {
1741-
return major < 10 ||
1742-
(major == 10 && (!minor.hasValue() || minor.getValue() <= 9));
1743-
};
1701+
break;
1702+
1703+
case PlatformKind::OSX:
1704+
case PlatformKind::OSXApplicationExtension:
17441705
deprecatedAsUnavailableMessage =
1745-
"APIs deprecated as of OS X 10.9 and earlier are unavailable in Swift";
1706+
"APIs deprecated as of macOS 10.9 and earlier are unavailable in Swift";
1707+
break;
1708+
1709+
default:
1710+
break;
1711+
}
1712+
}
1713+
1714+
bool PlatformAvailability::isPlatformRelevant(StringRef name) const {
1715+
switch (platformKind) {
1716+
case PlatformKind::OSX:
1717+
return name == "macos";
1718+
case PlatformKind::OSXApplicationExtension:
1719+
return name == "macos" || name == "macos_app_extension";
1720+
1721+
case PlatformKind::iOS:
1722+
return name == "ios";
1723+
case PlatformKind::iOSApplicationExtension:
1724+
return name == "ios" || name == "ios_app_extension";
1725+
1726+
case PlatformKind::tvOS:
1727+
return name == "tvos";
1728+
case PlatformKind::tvOSApplicationExtension:
1729+
return name == "tvos" || name == "tvos_app_extension";
1730+
1731+
case PlatformKind::watchOS:
1732+
return name == "watchos";
1733+
case PlatformKind::watchOSApplicationExtension:
1734+
return name == "watchos" || name == "watchos_app_extension";
1735+
1736+
case PlatformKind::none:
1737+
return false;
1738+
}
1739+
1740+
llvm_unreachable("Unexpected platform");
1741+
}
1742+
1743+
bool PlatformAvailability::treatDeprecatedAsUnavailable(
1744+
const clang::Decl *clangDecl, const llvm::VersionTuple &version) const {
1745+
assert(!version.empty() && "Must provide version when deprecated");
1746+
unsigned major = version.getMajor();
1747+
Optional<unsigned> minor = version.getMinor();
1748+
1749+
switch (platformKind) {
1750+
case PlatformKind::OSX:
1751+
// Anything deprecated in OSX 10.9.x and earlier is unavailable in Swift.
1752+
return major < 10 ||
1753+
(major == 10 && (!minor.hasValue() || minor.getValue() <= 9));
1754+
1755+
case PlatformKind::iOS:
1756+
case PlatformKind::iOSApplicationExtension:
1757+
case PlatformKind::tvOS:
1758+
case PlatformKind::tvOSApplicationExtension:
1759+
// Anything deprecated in iOS 7.x and earlier is unavailable in Swift.
1760+
return major <= 7;
1761+
1762+
case PlatformKind::watchOS:
1763+
case PlatformKind::watchOSApplicationExtension:
1764+
// No deprecation filter on watchOS
1765+
return false;
1766+
1767+
default:
1768+
return false;
17461769
}
17471770
}
17481771

0 commit comments

Comments
 (0)