Skip to content

Commit 2bc1832

Browse files
committed
---
yaml --- r: 316903 b: refs/heads/master-rebranch c: e9ec2ed h: refs/heads/master i: 316901: 0ade4c6 316899: 2638288 316895: 8a1b9d8
1 parent 68ef713 commit 2bc1832

File tree

10 files changed

+140
-28
lines changed

10 files changed

+140
-28
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1457,4 +1457,4 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-02-a: ddd2b2976aa9bfde5f20fe37f6bd2
14571457
refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-03-a: 171cc166f2abeb5ca2a4003700a8a78a108bd300
14581458
refs/heads/benlangmuir-patch-1: baaebaf39d52f3bf36710d4fe40cf212e996b212
14591459
refs/heads/i-do-redeclare: 8c4e6d5de5c1e3f0a2cedccf319df713ea22c48e
1460-
refs/heads/master-rebranch: caec0f909cf2aaffa88daaecf14016a3df02d58e
1460+
refs/heads/master-rebranch: e9ec2ed51f96353f6797eea56174a8c3b0416c84

branches/master-rebranch/include/swift/Basic/Version.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ class Version {
161161
};
162162

163163
bool operator>=(const Version &lhs, const Version &rhs);
164+
bool operator<(const Version &lhs, const Version &rhs);
164165
bool operator==(const Version &lhs, const Version &rhs);
165166
inline bool operator!=(const Version &lhs, const Version &rhs) {
166167
return !(lhs == rhs);

branches/master-rebranch/lib/AST/ASTPrinter.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ void PrintOptions::clearSynthesizedExtension() {
6464
TransformContext.reset();
6565
}
6666

67+
static bool isPublicOrUsableFromInline(const ValueDecl *VD) {
68+
AccessScope scope =
69+
VD->getFormalAccessScope(/*useDC*/nullptr,
70+
/*treatUsableFromInlineAsPublic*/true);
71+
return scope.isPublic();
72+
}
73+
6774
static bool contributesToParentTypeStorage(const AbstractStorageDecl *ASD) {
6875
auto *DC = ASD->getDeclContext()->getAsDecl();
6976
if (!DC) return false;
@@ -96,10 +103,7 @@ PrintOptions PrintOptions::printTextualInterfaceFile() {
96103
bool shouldPrint(const Decl *D, const PrintOptions &options) override {
97104
// Skip anything that isn't 'public' or '@usableFromInline'.
98105
if (auto *VD = dyn_cast<ValueDecl>(D)) {
99-
AccessScope accessScope =
100-
VD->getFormalAccessScope(/*useDC*/nullptr,
101-
/*treatUsableFromInlineAsPublic*/true);
102-
if (!accessScope.isPublic()) {
106+
if (!isPublicOrUsableFromInline(VD)) {
103107
// We do want to print private stored properties, without their
104108
// original names present.
105109
if (auto *ASD = dyn_cast<AbstractStorageDecl>(VD))
@@ -109,6 +113,14 @@ PrintOptions PrintOptions::printTextualInterfaceFile() {
109113
}
110114
}
111115

116+
// Skip extensions that extend things we wouldn't print.
117+
if (auto *ED = dyn_cast<ExtensionDecl>(D)) {
118+
if (!shouldPrint(ED->getExtendedNominal(), options))
119+
return false;
120+
// FIXME: We also need to check the generic signature for constraints
121+
// that we can't reference.
122+
}
123+
112124
// Skip typealiases that just redeclare generic parameters.
113125
if (auto *alias = dyn_cast<TypeAliasDecl>(D)) {
114126
if (alias->isImplicit()) {
@@ -886,7 +898,7 @@ void PrintAST::printPattern(const Pattern *pattern) {
886898
recordDeclLoc(decl, [&]{
887899
if (Options.OmitNameOfInaccessibleProperties &&
888900
contributesToParentTypeStorage(decl) &&
889-
decl->getFormalAccess() < AccessLevel::Public)
901+
!isPublicOrUsableFromInline(decl))
890902
Printer << "_";
891903
else
892904
Printer.printName(named->getBoundName());

branches/master-rebranch/lib/Basic/Version.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,11 @@ bool operator>=(const class Version &lhs,
384384
return true;
385385
}
386386

387+
bool operator<(const class Version &lhs, const class Version &rhs) {
388+
389+
return !(lhs >= rhs);
390+
}
391+
387392
bool operator==(const class Version &lhs,
388393
const class Version &rhs) {
389394
auto n = std::max(lhs.size(), rhs.size());
@@ -446,4 +451,3 @@ std::string getSwiftRevision() {
446451

447452
} // end namespace version
448453
} // end namespace swift
449-

branches/master-rebranch/lib/Parse/ParseIfConfig.cpp

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace {
3636
/// Get PlatformConditionKind from platform condition name.
3737
static
3838
Optional<PlatformConditionKind> getPlatformConditionKind(StringRef Name) {
39-
return llvm::StringSwitch<llvm::Optional<PlatformConditionKind>>(Name)
39+
return llvm::StringSwitch<Optional<PlatformConditionKind>>(Name)
4040
.Case("os", PlatformConditionKind::OS)
4141
.Case("arch", PlatformConditionKind::Arch)
4242
.Case("_endian", PlatformConditionKind::Endianness)
@@ -53,6 +53,20 @@ static StringRef extractExprSource(SourceManager &SM, Expr *E) {
5353
return SM.extractText(Range);
5454
}
5555

56+
static bool isValidPrefixUnaryOperator(Optional<StringRef> UnaryOperator) {
57+
return UnaryOperator != None &&
58+
(UnaryOperator.getValue() == ">=" || UnaryOperator.getValue() == "<");
59+
}
60+
61+
static bool isValidVersion(const version::Version &Version,
62+
const version::Version &ExpectedVersion,
63+
StringRef UnaryOperator) {
64+
if (UnaryOperator == ">=")
65+
return Version >= ExpectedVersion;
66+
if (UnaryOperator == "<")
67+
return Version < ExpectedVersion;
68+
llvm_unreachable("unsupported unary operator");
69+
}
5670

5771
/// The condition validator.
5872
class ValidateIfConfigCondition :
@@ -63,7 +77,7 @@ class ValidateIfConfigCondition :
6377
bool HasError;
6478

6579
/// Get the identifier string of the UnresolvedDeclRefExpr.
66-
llvm::Optional<StringRef> getDeclRefStr(Expr *E, DeclRefKind Kind) {
80+
Optional<StringRef> getDeclRefStr(Expr *E, DeclRefKind Kind) {
6781
auto UDRE = dyn_cast<UnresolvedDeclRefExpr>(E);
6882
if (!UDRE ||
6983
!UDRE->hasName() ||
@@ -85,7 +99,7 @@ class ValidateIfConfigCondition :
8599
Expr *foldSequence(Expr *LHS, ArrayRef<Expr*> &S, bool isRecurse = false) {
86100
assert(!S.empty() && ((S.size() & 1) == 0));
87101

88-
auto getNextOperator = [&]() -> llvm::Optional<StringRef> {
102+
auto getNextOperator = [&]() -> Optional<StringRef> {
89103
assert((S.size() & 1) == 0);
90104
while (!S.empty()) {
91105
auto Name = getDeclRefStr(S[0], DeclRefKind::BinaryOperator);
@@ -109,7 +123,7 @@ class ValidateIfConfigCondition :
109123
// If failed, it's not a sequence anymore.
110124
return LHS;
111125
Expr *Op = S[0];
112-
126+
113127
// We will definitely be consuming at least one operator.
114128
// Pull out the prospective RHS and slice off the first two elements.
115129
Expr *RHS = validate(S[1]);
@@ -216,16 +230,16 @@ class ValidateIfConfigCondition :
216230
return E;
217231
}
218232

219-
// 'swift' '(' '>=' float-literal ( '.' integer-literal )* ')'
220-
// 'compiler' '(' '>=' float-literal ( '.' integer-literal )* ')'
233+
// 'swift' '(' ('>=' | '<') float-literal ( '.' integer-literal )* ')'
234+
// 'compiler' '(' ('>=' | '<') float-literal ( '.' integer-literal )* ')'
221235
if (*KindName == "swift" || *KindName == "compiler") {
222236
auto PUE = dyn_cast<PrefixUnaryExpr>(Arg);
223-
llvm::Optional<StringRef> PrefixName = PUE ?
224-
getDeclRefStr(PUE->getFn(), DeclRefKind::PrefixOperator) : None;
225-
if (!PrefixName || *PrefixName != ">=") {
226-
D.diagnose(Arg->getLoc(),
227-
diag::unsupported_platform_condition_argument,
228-
"a unary comparison, such as '>=2.2'");
237+
Optional<StringRef> PrefixName =
238+
PUE ? getDeclRefStr(PUE->getFn(), DeclRefKind::PrefixOperator) : None;
239+
if (!isValidPrefixUnaryOperator(PrefixName)) {
240+
D.diagnose(
241+
Arg->getLoc(), diag::unsupported_platform_condition_argument,
242+
"a unary comparison '>=' or '<'; for example, '>=2.2' or '<2.2'");
229243
return nullptr;
230244
}
231245
auto versionString = extractExprSource(Ctx.SourceMgr, PUE->getArg());
@@ -382,13 +396,17 @@ class EvaluateIfConfigCondition :
382396
return thisVersion >= Val;
383397
} else if ((KindName == "swift") || (KindName == "compiler")) {
384398
auto PUE = cast<PrefixUnaryExpr>(Arg);
399+
auto PrefixName = getDeclRefStr(PUE->getFn());
385400
auto Str = extractExprSource(Ctx.SourceMgr, PUE->getArg());
386401
auto Val = version::Version::parseVersionString(
387402
Str, SourceLoc(), nullptr).getValue();
388403
if (KindName == "swift") {
389-
return Ctx.LangOpts.EffectiveLanguageVersion >= Val;
404+
return isValidVersion(Ctx.LangOpts.EffectiveLanguageVersion, Val,
405+
PrefixName);
390406
} else if (KindName == "compiler") {
391-
return version::Version::getCurrentLanguageVersion() >= Val;
407+
auto currentLanguageVersion =
408+
version::Version::getCurrentLanguageVersion();
409+
return isValidVersion(currentLanguageVersion, Val, PrefixName);
392410
} else {
393411
llvm_unreachable("unsupported version conditional");
394412
}

branches/master-rebranch/test/ModuleInterface/access-filter.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,12 @@ extension PublicStruct {
102102
// CHECK: public private(set) static var secretlySettable: Int{{$}}
103103
public private(set) static var secretlySettable: Int = 0
104104
} // CHECK: {{^[}]$}}
105+
106+
extension InternalStruct_BAD: PublicProto {
107+
internal static var dummy: Int { return 0 }
108+
}
109+
110+
// CHECK: extension UFIStruct : PublicProto {{[{]$}}
111+
extension UFIStruct: PublicProto {
112+
internal static var dummy: Int { return 0 }
113+
} // CHECK-NEXT: {{^[}]$}}

branches/master-rebranch/test/ModuleInterface/private-stored-member-type-layout.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
// These two appear out-of-order between run lines
1818

1919
// CHECK-DAG: [[MYCLASS:%T20PrivateStoredMembers7MyClassC]] = type opaque
20-
// CHECK-DAG: [[MYSTRUCT:%T20PrivateStoredMembers8MyStructV]] = type <{ %Ts5Int64V, %TSb, [7 x i8], %Ts5Int64V, %TSb, [7 x i8], %Ts5Int64V, %TSb, [7 x i8], %Ts5Int64V }>
20+
// CHECK-DAG: [[MYSTRUCT:%T20PrivateStoredMembers8MyStructV]] = type <{ %Ts5Int64V, %TSb, [7 x i8], %Ts5Int64V, %TSb, [7 x i8], %Ts5Int64V, %TSb, [7 x i8], %Ts5Int64V, %TSb, [7 x i8], %Ts5Int64V }>
2121

22-
// CHECK-MAIN-DAG: [[MYCLASS:%T4main7MyClassC]] = type <{ %swift.refcounted, %Ts5Int64V, %TSb, [7 x i8], %Ts5Int64V, %TSb, [7 x i8], %Ts5Int64V, %TSb, [7 x i8], %Ts5Int64V }>
23-
// CHECK-MAIN-DAG: [[MYSTRUCT:%T4main8MyStructV]] = type <{ %Ts5Int64V, %TSb, [7 x i8], %Ts5Int64V, %TSb, [7 x i8], %Ts5Int64V, %TSb, [7 x i8], %Ts5Int64V }>
22+
// CHECK-MAIN-DAG: [[MYCLASS:%T4main7MyClassC]] = type <{ %swift.refcounted, %Ts5Int64V, %TSb, [7 x i8], %Ts5Int64V, %TSb, [7 x i8], %Ts5Int64V, %TSb, [7 x i8], %Ts5Int64V, %TSb, [7 x i8], %Ts5Int64V }>
23+
// CHECK-MAIN-DAG: [[MYSTRUCT:%T4main8MyStructV]] = type <{ %Ts5Int64V, %TSb, [7 x i8], %Ts5Int64V, %TSb, [7 x i8], %Ts5Int64V, %TSb, [7 x i8], %Ts5Int64V, %TSb, [7 x i8], %Ts5Int64V }>
2424

2525
#if SHOULD_IMPORT
2626
import PrivateStoredMembers
@@ -29,7 +29,7 @@ import PrivateStoredMembers
2929
// CHECK-EXEC: swiftcc void @"$s{{[^ ]+}}8makeUseryyF"() #0 {
3030
public func makeUser() {
3131
let ptr = UnsafeMutablePointer<MyStruct>.allocate(capacity: 1)
32-
// CHECK-EXEC: %.publicEndVar = getelementptr inbounds [[MYSTRUCT]], [[MYSTRUCT]]* %{{[0-9]+}}, i32 0, i32 [[PUBLIC_END_VAR_IDX:9]]
32+
// CHECK-EXEC: %.publicEndVar = getelementptr inbounds [[MYSTRUCT]], [[MYSTRUCT]]* %{{[0-9]+}}, i32 0, i32 [[PUBLIC_END_VAR_IDX:12]]
3333
// CHECK-EXEC: %.publicEndVar._value = getelementptr inbounds %Ts5Int64V, %Ts5Int64V* %.publicEndVar, i32 0, i32 0
3434
// CHECK-EXEC: store i64 4, i64* %.publicEndVar._value
3535
ptr.pointee.publicEndVar = 4

branches/master-rebranch/test/ModuleInterface/private-stored-members.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ public struct MyStruct {
2929
// RESILIENT-NOT: internal let _: [[BOOL]]{{$}}
3030
let internalLet: Bool
3131

32+
// COMMON-NEXT: @usableFromInline
33+
// COMMON-NEXT: internal var ufiVar: [[INT64]]{{$}}
34+
@usableFromInline var ufiVar: Int64
35+
36+
// COMMON-NEXT: @usableFromInline
37+
// COMMON-NEXT: internal let ufiLet: [[BOOL]]{{$}}
38+
@usableFromInline let ufiLet: Bool
39+
3240
// CHECK-NEXT: private var _: [[INT64]]{{$}}
3341
// RESILIENT-NOT: private var _: [[INT64]]{{$}}
3442
private var privateVar: Int64
@@ -69,6 +77,14 @@ public class MyClass {
6977
// RESILIENT-NOT: internal let _: [[BOOL]]{{$}}
7078
let internalLet: Bool = true
7179

80+
// COMMON-NEXT: @usableFromInline
81+
// COMMON-NEXT: internal var ufiVar: [[INT64]]{{$}}
82+
@usableFromInline var ufiVar: Int64 = 0
83+
84+
// COMMON-NEXT: @usableFromInline
85+
// COMMON-NEXT: internal let ufiLet: [[BOOL]]{{$}}
86+
@usableFromInline let ufiLet: Bool = true
87+
7288
// CHECK-NEXT: private var _: [[INT64]]{{$}}
7389
// RESILIENT-NOT: private var _: [[INT64]]{{$}}
7490
private var privateVar: Int64 = 0
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: %target-typecheck-verify-swift
2+
// RUN: %target-typecheck-verify-swift -swift-version 4
3+
4+
#if !compiler(>=4.1)
5+
// There should be no error here.
6+
foo bar
7+
#else
8+
let _: Int = 1
9+
#endif
10+
11+
#if compiler(<4.1)
12+
// There should be no error here.
13+
foo bar
14+
#else
15+
let _: Int = 1
16+
#endif
17+
18+
#if (compiler(>=4.1))
19+
let _: Int = 1
20+
#else
21+
// There should be no error here.
22+
foo bar
23+
#endif
24+
25+
#if !compiler(<4.1)
26+
let _: Int = 1
27+
#else
28+
// There should be no error here.
29+
foo bar
30+
#endif

branches/master-rebranch/test/Parse/ConditionalCompilation/language_version.swift

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@
77
asdf asdf asdf asdf
88
#endif
99

10+
#if swift(<1.2)
11+
#endif
12+
13+
#if swift(<4.2)
14+
let a = 1
15+
#else
16+
let a = 2
17+
#endif
18+
19+
#if swift(<1.0)
20+
// This shouldn't emit any diagnostics.
21+
asdf asdf asdf asdf
22+
#endif
23+
1024
#if swift(>=1.2)
1125

1226
#if os(iOS)
@@ -34,13 +48,21 @@
3448
%#^*&
3549
#endif
3650

37-
#if swift(">=7.1") // expected-error {{unexpected platform condition argument: expected a unary comparison, such as '>=2.2'}}
51+
#if !swift(<1000.0)
52+
// This shouldn't emit any diagnostics.
53+
%#^*&
54+
#endif
55+
56+
#if swift(">=7.1") // expected-error {{unexpected platform condition argument: expected a unary comparison '>=' or '<'; for example, '>=2.2' or '<2.2'}}
57+
#endif
58+
59+
#if swift("<7.1") // expected-error {{unexpected platform condition argument: expected a unary comparison '>=' or '<'; for example, '>=2.2' or '<2.2'}}
3860
#endif
3961

40-
#if swift(">=2n.2") // expected-error {{unexpected platform condition argument: expected a unary comparison, such as '>=2.2'}}
62+
#if swift(">=2n.2") // expected-error {{unexpected platform condition argument: expected a unary comparison '>=' or '<'; for example, '>=2.2' or '<2.2'}}
4163
#endif
4264

43-
#if swift("") // expected-error {{unexpected platform condition argument: expected a unary comparison, such as '>=2.2'}}
65+
#if swift("") // expected-error {{unexpected platform condition argument: expected a unary comparison '>=' or '<'; for example, '>=2.2' or '<2.2'}}
4466
#endif
4567

4668
#if swift(>=2.2.1)

0 commit comments

Comments
 (0)