Skip to content

Commit c3cbc8b

Browse files
authored
---
yaml --- r: 349228 b: refs/heads/master-next c: 777d557 h: refs/heads/master
1 parent c99a67f commit c3cbc8b

16 files changed

+300
-55
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 3574c513bbc5578dd9346b4ea9ab5995c5927bb5
3-
refs/heads/master-next: e2b6a3d98287176606b8a9b3a43c6c4d399c4d62
3+
refs/heads/master-next: 777d557d392d8c0842098e81046924db071c5bac
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea
66
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-b: 66d897bfcf64a82cb9a87f5e663d889189d06d07

branches/master-next/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,7 @@ if(SWIFT_NEED_EXPLICIT_LIBDISPATCH)
996996
-DCMAKE_CXX_COMPILER=${SWIFT_LIBDISPATCH_CXX_COMPILER}
997997
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
998998
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
999+
-DCMAKE_INSTALL_LIBDIR=lib
9991000
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
10001001
-DCMAKE_LINKER=${CMAKE_LINKER}
10011002
-DCMAKE_RANLIB=${CMAKE_RANLIB}

branches/master-next/lib/Sema/TypeCheckDecl.cpp

Lines changed: 60 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,55 +1431,57 @@ static LiteralExpr *getAutomaticRawValueExpr(TypeChecker &TC,
14311431
llvm_unreachable("Unhandled AutomaticEnumValueKind in switch.");
14321432
}
14331433

1434-
static void checkEnumRawValues(TypeChecker &TC, EnumDecl *ED) {
1434+
static Optional<AutomaticEnumValueKind>
1435+
computeAutomaticEnumValueKind(TypeChecker &TC, EnumDecl *ED) {
14351436
Type rawTy = ED->getRawType();
1436-
if (!rawTy) {
1437-
return;
1438-
}
1439-
1437+
assert(rawTy && "Cannot compute value kind without raw type!");
1438+
14401439
if (ED->getGenericEnvironmentOfContext() != nullptr)
14411440
rawTy = ED->mapTypeIntoContext(rawTy);
1442-
if (rawTy->hasError())
1443-
return;
1444-
1445-
AutomaticEnumValueKind valueKind;
1441+
14461442
// Swift enums require that the raw type is convertible from one of the
14471443
// primitive literal protocols.
14481444
auto conformsToProtocol = [&](KnownProtocolKind protoKind) {
1449-
ProtocolDecl *proto = TC.getProtocol(ED->getLoc(), protoKind);
1450-
return TypeChecker::conformsToProtocol(rawTy, proto,
1451-
ED->getDeclContext(), None);
1445+
ProtocolDecl *proto = TC.getProtocol(ED->getLoc(), protoKind);
1446+
return TypeChecker::conformsToProtocol(rawTy, proto,
1447+
ED->getDeclContext(), None);
14521448
};
1453-
1449+
14541450
static auto otherLiteralProtocolKinds = {
14551451
KnownProtocolKind::ExpressibleByFloatLiteral,
14561452
KnownProtocolKind::ExpressibleByUnicodeScalarLiteral,
14571453
KnownProtocolKind::ExpressibleByExtendedGraphemeClusterLiteral,
14581454
};
1459-
1455+
14601456
if (conformsToProtocol(KnownProtocolKind::ExpressibleByIntegerLiteral)) {
1461-
valueKind = AutomaticEnumValueKind::Integer;
1457+
return AutomaticEnumValueKind::Integer;
14621458
} else if (conformsToProtocol(KnownProtocolKind::ExpressibleByStringLiteral)){
1463-
valueKind = AutomaticEnumValueKind::String;
1459+
return AutomaticEnumValueKind::String;
14641460
} else if (std::any_of(otherLiteralProtocolKinds.begin(),
14651461
otherLiteralProtocolKinds.end(),
14661462
conformsToProtocol)) {
1467-
valueKind = AutomaticEnumValueKind::None;
1463+
return AutomaticEnumValueKind::None;
14681464
} else {
1469-
TC.diagnose(ED->getInherited().front().getSourceRange().Start,
1470-
diag::raw_type_not_literal_convertible,
1471-
rawTy);
1472-
ED->getInherited().front().setInvalidType(TC.Context);
1473-
return;
1465+
return None;
14741466
}
1467+
}
14751468

1476-
// We need at least one case to have a raw value.
1477-
if (ED->getAllElements().empty()) {
1478-
TC.diagnose(ED->getInherited().front().getSourceRange().Start,
1479-
diag::empty_enum_raw_type);
1469+
static void checkEnumRawValues(TypeChecker &TC, EnumDecl *ED) {
1470+
Type rawTy = ED->getRawType();
1471+
if (!rawTy) {
14801472
return;
14811473
}
14821474

1475+
if (ED->getGenericEnvironmentOfContext() != nullptr)
1476+
rawTy = ED->mapTypeIntoContext(rawTy);
1477+
if (rawTy->hasError())
1478+
return;
1479+
1480+
// If we don't have a value kind, the decl checker will provide a diagnostic.
1481+
auto valueKind = computeAutomaticEnumValueKind(TC, ED);
1482+
if (!valueKind.hasValue())
1483+
return;
1484+
14831485
// Check the raw values of the cases.
14841486
LiteralExpr *prevValue = nullptr;
14851487
EnumElementDecl *lastExplicitValueElt = nullptr;
@@ -1499,24 +1501,14 @@ static void checkEnumRawValues(TypeChecker &TC, EnumDecl *ED) {
14991501
(void)elt->getInterfaceType();
15001502
if (elt->isInvalid())
15011503
continue;
1502-
1503-
// We don't yet support raw values on payload cases.
1504-
if (elt->hasAssociatedValues()) {
1505-
TC.diagnose(elt->getLoc(),
1506-
diag::enum_with_raw_type_case_with_argument);
1507-
TC.diagnose(ED->getInherited().front().getSourceRange().Start,
1508-
diag::enum_raw_type_here, rawTy);
1509-
elt->setInvalid();
1510-
continue;
1511-
}
15121504

15131505
if (elt->hasRawValueExpr()) {
15141506
lastExplicitValueElt = elt;
15151507
} else {
15161508
// If the enum element has no explicit raw value, try to
15171509
// autoincrement from the previous value, or start from zero if this
15181510
// is the first element.
1519-
auto nextValue = getAutomaticRawValueExpr(TC, valueKind, elt, prevValue);
1511+
auto nextValue = getAutomaticRawValueExpr(TC, *valueKind, elt, prevValue);
15201512
if (!nextValue) {
15211513
elt->setInvalid();
15221514
break;
@@ -2611,11 +2603,26 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
26112603
checkAccessControl(TC, ED);
26122604

26132605
TC.checkPatternBindingCaptures(ED);
2614-
2615-
if (ED->hasRawType() && !ED->isObjC()) {
2606+
2607+
if (auto rawTy = ED->getRawType()) {
2608+
// The raw type must be one of the blessed literal convertible types.
2609+
if (!computeAutomaticEnumValueKind(TC, ED)) {
2610+
TC.diagnose(ED->getInherited().front().getSourceRange().Start,
2611+
diag::raw_type_not_literal_convertible,
2612+
rawTy);
2613+
ED->getInherited().front().setInvalidType(TC.Context);
2614+
}
2615+
2616+
// We need at least one case to have a raw value.
2617+
if (ED->getAllElements().empty()) {
2618+
TC.diagnose(ED->getInherited().front().getSourceRange().Start,
2619+
diag::empty_enum_raw_type);
2620+
}
2621+
26162622
// ObjC enums have already had their raw values checked, but pure Swift
26172623
// enums haven't.
2618-
checkEnumRawValues(TC, ED);
2624+
if (!ED->isObjC())
2625+
checkEnumRawValues(TC, ED);
26192626
}
26202627

26212628
checkExplicitAvailability(ED);
@@ -3089,6 +3096,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
30893096

30903097
void visitEnumElementDecl(EnumElementDecl *EED) {
30913098
(void)EED->getInterfaceType();
3099+
auto *ED = EED->getParentEnum();
30923100

30933101
TC.checkDeclAttributes(EED);
30943102

@@ -3097,8 +3105,19 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
30973105
checkDefaultArguments(TC, PL, EED);
30983106
}
30993107

3108+
// We don't yet support raw values on payload cases.
3109+
if (EED->hasAssociatedValues()) {
3110+
if (auto rawTy = ED->getRawType()) {
3111+
TC.diagnose(EED->getLoc(),
3112+
diag::enum_with_raw_type_case_with_argument);
3113+
TC.diagnose(ED->getInherited().front().getSourceRange().Start,
3114+
diag::enum_raw_type_here, rawTy);
3115+
EED->setInvalid();
3116+
}
3117+
}
3118+
31003119
// Yell if our parent doesn't have a raw type but we have a raw value.
3101-
if (!EED->getParentEnum()->hasRawType() && EED->hasRawValueExpr()) {
3120+
if (EED->hasRawValueExpr() && !ED->hasRawType()) {
31023121
TC.diagnose(EED->getRawValueExpr()->getLoc(),
31033122
diag::enum_raw_value_without_raw_type);
31043123
EED->setInvalid();

branches/master-next/lib/Sema/TypeCheckDeclObjC.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,6 +1372,11 @@ static bool isEnumObjC(EnumDecl *enumDecl) {
13721372
return false;
13731373
}
13741374

1375+
// We need at least one case to have a raw value.
1376+
if (enumDecl->getAllElements().empty()) {
1377+
enumDecl->diagnose(diag::empty_enum_raw_type);
1378+
}
1379+
13751380
return true;
13761381
}
13771382

branches/master-next/stdlib/public/core/BridgeObjectiveC.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,7 @@ public protocol _ObjectiveCBridgeable {
8585

8686
#if _runtime(_ObjC)
8787

88-
@available(macOS, introduced: 9999, deprecated)
89-
@available(iOS, introduced: 9999, deprecated)
90-
@available(watchOS, introduced: 9999, deprecated)
91-
@available(tvOS, introduced: 9999, deprecated)
88+
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
9289
@available(*, deprecated)
9390
@_cdecl("_SwiftCreateBridgedArray")
9491
@usableFromInline
@@ -101,6 +98,19 @@ internal func _SwiftCreateBridgedArray(
10198
return Unmanaged<AnyObject>.passRetained(bridged)
10299
}
103100

101+
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
102+
@available(*, deprecated)
103+
@_cdecl("_SwiftCreateBridgedMutableArray")
104+
@usableFromInline
105+
internal func _SwiftCreateBridgedMutableArray(
106+
values: UnsafePointer<AnyObject>,
107+
numValues: Int
108+
) -> Unmanaged<AnyObject> {
109+
let bufPtr = UnsafeBufferPointer(start: values, count: numValues)
110+
let bridged = _SwiftNSMutableArray(Array(bufPtr))
111+
return Unmanaged<AnyObject>.passRetained(bridged)
112+
}
113+
104114
@_silgen_name("swift_stdlib_connectNSBaseClasses")
105115
internal func _connectNSBaseClasses() -> Bool
106116

branches/master-next/stdlib/public/core/Runtime.swift.gyb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,18 @@ internal class __SwiftNativeNSArray {
276276
deinit {}
277277
}
278278

279+
@_fixed_layout
280+
@usableFromInline
281+
@objc @_swift_native_objc_runtime_base(__SwiftNativeNSMutableArrayBase)
282+
internal class _SwiftNativeNSMutableArray {
283+
@inlinable
284+
@nonobjc
285+
internal init() {}
286+
// @objc public init(coder: AnyObject) {}
287+
@inlinable
288+
deinit {}
289+
}
290+
279291
@_fixed_layout
280292
@usableFromInline
281293
@objc @_swift_native_objc_runtime_base(__SwiftNativeNSDictionaryBase)

0 commit comments

Comments
 (0)