Skip to content

Commit 9af6dbe

Browse files
authored
Merge pull request #4361 from moiseev/se-0137-ccc
[swift-3.0-branch] Implementing SE-0137
2 parents f6fef03 + 280c20d commit 9af6dbe

14 files changed

+33
-18
lines changed

lib/Frontend/CompilerInvocation.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,8 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
727727
}
728728

729729
static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
730-
DiagnosticEngine &Diags, bool isImmediate) {
730+
DiagnosticEngine &Diags,
731+
const FrontendOptions &FrontendOpts) {
731732
using namespace options;
732733

733734
Opts.AttachCommentsToDecls |= Args.hasArg(OPT_dump_api_path);
@@ -745,6 +746,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
745746

746747
Opts.DisableAvailabilityChecking |=
747748
Args.hasArg(OPT_disable_availability_checking);
749+
if (FrontendOpts.InputKind == InputFileKind::IFK_SIL)
750+
Opts.DisableAvailabilityChecking = true;
748751

749752
if (auto A = Args.getLastArg(OPT_enable_access_control,
750753
OPT_disable_access_control)) {
@@ -1327,8 +1330,7 @@ bool CompilerInvocation::parseArgs(ArrayRef<const char *> Args,
13271330
return true;
13281331
}
13291332

1330-
if (ParseLangArgs(LangOpts, ParsedArgs, Diags,
1331-
FrontendOpts.actionIsImmediate())) {
1333+
if (ParseLangArgs(LangOpts, ParsedArgs, Diags, FrontendOpts)) {
13321334
return true;
13331335
}
13341336

lib/Sema/MiscDiagnostics.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,9 +2040,6 @@ bool AvailabilityWalker::diagAvailability(const ValueDecl *D, SourceRange R,
20402040
TC.diagnoseDeprecated(R, DC, Attr, D->getFullName(), call);
20412041
}
20422042

2043-
if (TC.getLangOpts().DisableAvailabilityChecking)
2044-
return false;
2045-
20462043
// Diagnose for potential unavailability
20472044
auto maybeUnavail = TC.checkDeclarationAvailability(D, R.Start, DC);
20482045
if (maybeUnavail.hasValue()) {
@@ -3574,7 +3571,8 @@ void swift::performSyntacticExprDiagnostics(TypeChecker &TC, const Expr *E,
35743571
diagSyntacticUseRestrictions(TC, E, DC, isExprStmt);
35753572
diagRecursivePropertyAccess(TC, E, DC);
35763573
diagnoseImplicitSelfUseInClosure(TC, E, DC);
3577-
diagAvailability(TC, E, const_cast<DeclContext*>(DC));
3574+
if (!TC.getLangOpts().DisableAvailabilityChecking)
3575+
diagAvailability(TC, E, const_cast<DeclContext*>(DC));
35783576
if (TC.Context.LangOpts.EnableObjCInterop)
35793577
diagDeprecatedObjCSelectors(TC, DC, E);
35803578
}

lib/Sema/TypeCheckType.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,8 +1441,8 @@ Type TypeChecker::resolveIdentifierType(
14411441
bool AllowPotentiallyUnavailableProtocol =
14421442
options.contains(TR_InheritanceClause);
14431443

1444-
// Check the availability of the type. Skip checking for SIL.
1445-
if (!(options & TR_SILType) && !(options & TR_AllowUnavailable) &&
1444+
// Check the availability of the type.
1445+
if (!(options & TR_AllowUnavailable) &&
14461446
diagnoseAvailability(result, IdType,
14471447
Components.back()->getIdLoc(), DC, *this,
14481448
AllowPotentiallyUnavailableProtocol)) {
@@ -1664,6 +1664,9 @@ Type TypeResolver::resolveType(TypeRepr *repr, TypeResolutionOptions options) {
16641664
options -= TR_FunctionInput;
16651665
}
16661666

1667+
if (Context.LangOpts.DisableAvailabilityChecking)
1668+
options |= TR_AllowUnavailable;
1669+
16671670
switch (repr->getKind()) {
16681671
case TypeReprKind::Error:
16691672
return ErrorType::get(Context);
@@ -1768,9 +1771,8 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
17681771

17691772
if (base) {
17701773
Optional<MetatypeRepresentation> storedRepr;
1771-
// The instance type is not a SIL type. We still want to allow
1772-
// unavailable references, though.
1773-
auto instanceOptions = options - TR_SILType | TR_AllowUnavailable;
1774+
// The instance type is not a SIL type.
1775+
auto instanceOptions = options - TR_SILType;
17741776
auto instanceTy = resolveType(base, instanceOptions);
17751777
if (!instanceTy || instanceTy->is<ErrorType>())
17761778
return instanceTy;

stdlib/public/core/BidirectionalCollection.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
/// In most cases, it's best to ignore this protocol and use the
1717
/// `BidirectionalCollection` protocol instead, because it has a more complete
1818
/// interface.
19+
@available(*, deprecated, message: "it will be removed in Swift 4.0. Please use 'BidirectionalCollection' instead")
1920
public protocol BidirectionalIndexable : Indexable {
2021
// FIXME(ABI)(compiler limitation): there is no reason for this protocol
2122
// to exist apart from missing compiler features that we emulate with it.

stdlib/public/core/Collection.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
///
1616
/// In most cases, it's best to ignore this protocol and use the `Collection`
1717
/// protocol instead, because it has a more complete interface.
18+
@available(*, deprecated, message: "it will be removed in Swift 4.0. Please use 'Collection' instead")
1819
public protocol IndexableBase {
1920
// FIXME(ABI)(compiler limitation): there is no reason for this protocol
2021
// to exist apart from missing compiler features that we emulate with it.
@@ -156,6 +157,7 @@ public protocol IndexableBase {
156157
///
157158
/// In most cases, it's best to ignore this protocol and use the `Collection`
158159
/// protocol instead, because it has a more complete interface.
160+
@available(*, deprecated, message: "it will be removed in Swift 4.0. Please use 'Collection' instead")
159161
public protocol Indexable : IndexableBase {
160162
/// A type used to represent the number of steps between two indices, where
161163
/// one value is reachable from the other.
@@ -1727,3 +1729,4 @@ extension Collection where Iterator.Element : Equatable {
17271729

17281730
@available(*, unavailable, message: "PermutationGenerator has been removed in Swift 3")
17291731
public struct PermutationGenerator<C : Collection, Indices : Sequence> {}
1732+

stdlib/public/core/CompilerProtocols.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ public protocol ExpressibleByDictionaryLiteral {
613613
/// String(stringInterpolationSegment: " cookies: $"),
614614
/// String(stringInterpolationSegment: price * number),
615615
/// String(stringInterpolationSegment: "."))
616+
@available(*, deprecated, message: "it will be replaced or redesigned in Swift 4.0. Instead of conforming to 'ExpressibleByStringInterpolation', consider adding an 'init(_:String)'")
616617
public protocol ExpressibleByStringInterpolation {
617618
/// Creates an instance by concatenating the given values.
618619
///
@@ -736,7 +737,7 @@ public typealias ArrayLiteralConvertible
736737
@available(*, deprecated, renamed: "ExpressibleByDictionaryLiteral")
737738
public typealias DictionaryLiteralConvertible
738739
= ExpressibleByDictionaryLiteral
739-
@available(*, deprecated, renamed: "ExpressibleByStringInterpolation")
740+
@available(*, deprecated, message: "it will be replaced or redesigned in Swift 4.0. Instead of conforming to 'StringInterpolationConvertible', consider adding an 'init(_:String)'")
740741
public typealias StringInterpolationConvertible
741742
= ExpressibleByStringInterpolation
742743
@available(*, deprecated, renamed: "_ExpressibleByColorLiteral")

stdlib/public/core/MutableCollection.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
/// In most cases, it's best to ignore this protocol and use the
1616
/// `MutableCollection` protocol instead, because it has a more complete
1717
/// interface.
18+
@available(*, deprecated, message: "it will be removed in Swift 4.0. Please use 'MutableCollection' instead")
1819
public protocol MutableIndexable : Indexable {
1920
// FIXME(ABI)(compiler limitation): there is no reason for this protocol
2021
// to exist apart from missing compiler features that we emulate with it.

stdlib/public/core/RandomAccessCollection.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
/// In most cases, it's best to ignore this protocol and use the
1616
/// `RandomAccessCollection` protocol instead, because it has a more complete
1717
/// interface.
18+
@available(*, deprecated, message: "it will be removed in Swift 4.0. Please use 'RandomAccessCollection' instead")
1819
public protocol RandomAccessIndexable : BidirectionalIndexable {
1920
// FIXME(ABI)(compiler limitation): there is no reason for this protocol
2021
// to exist apart from missing compiler features that we emulate with it.

stdlib/public/core/RangeReplaceableCollection.swift.gyb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
/// In most cases, it's best to ignore this protocol and use the
2323
/// `RangeReplaceableCollection` protocol instead, because it has a more
2424
/// complete interface.
25+
@available(*, deprecated, message: "it will be removed in Swift 4.0. Please use 'RandomAccessCollection' instead")
2526
public protocol RangeReplaceableIndexable : Indexable {
2627
// FIXME(ABI)(compiler limitation): there is no reason for this protocol
2728
// to exist apart from missing compiler features that we emulate with it.

test/Sema/availability_versions.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,15 +1068,12 @@ func functionWithUnavailableInDeadBranch() {
10681068

10691069
localFuncAvailableOn10_51() // no-warning
10701070

1071-
// We still want to error on references to explicitly unavailable symbols
1072-
// CHECK:error: 'explicitlyUnavailable()' is unavailable
10731071
explicitlyUnavailable() // expected-error {{'explicitlyUnavailable()' is unavailable}}
10741072
}
10751073

10761074
guard #available(iOS 8.0, *) else {
10771075
_ = globalFuncAvailableOn10_51() // no-warning
10781076

1079-
// CHECK:error: 'explicitlyUnavailable()' is unavailable
10801077
explicitlyUnavailable() // expected-error {{'explicitlyUnavailable()' is unavailable}}
10811078
}
10821079
}
@@ -1624,6 +1621,5 @@ func useShortFormAvailable() {
16241621
// expected-note@-1 {{add @available attribute to enclosing global function}}
16251622
// expected-note@-2 {{add 'if #available' version check}}
16261623

1627-
// CHECK:error: 'unavailableWins()' is unavailable
16281624
unavailableWins() // expected-error {{'unavailableWins()' is unavailable}}
16291625
}

tools/sil-extract/SILExtract.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ int main(int argc, char **argv) {
163163
Invocation.setRuntimeResourcePath(ResourceDir);
164164
Invocation.getClangImporterOptions().ModuleCachePath = ModuleCachePath;
165165
Invocation.setParseStdlib();
166+
Invocation.getLangOptions().DisableAvailabilityChecking = true;
166167
Invocation.getLangOptions().EnableAccessControl = false;
167168
Invocation.getLangOptions().EnableObjCAttrRequiresFoundation = false;
168169

tools/sil-opt/SILOpt.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ int main(int argc, char **argv) {
210210
// cache.
211211
Invocation.getClangImporterOptions().ModuleCachePath = ModuleCachePath;
212212
Invocation.setParseStdlib();
213+
Invocation.getLangOptions().DisableAvailabilityChecking = true;
213214
Invocation.getLangOptions().EnableAccessControl = false;
214215
Invocation.getLangOptions().EnableObjCAttrRequiresFoundation = false;
215216

validation-test/stdlib/BoolDiagnostics_Dataflow.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,5 @@ func test_constantFoldOr4() -> Int {
5555
}
5656
} // expected-error {{missing return in a function expected to return 'Int'}}
5757

58+
// expected-warning@+1 {{'ExpressibleByStringInterpolation' is deprecated: it will be replaced or redesigned in Swift 4.0. Instead of conforming to 'ExpressibleByStringInterpolation', consider adding an 'init(_:String)'}}
59+
typealias X = ExpressibleByStringInterpolation

validation-test/stdlib/CollectionDiagnostics.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ func sortResultIgnored<
5454
array.sorted { $0 < $1 } // expected-warning {{result of call to 'sorted(by:)' is unused}}
5555
}
5656

57-
struct GoodIndexable : Indexable {
57+
// expected-warning@+1 {{'Indexable' is deprecated: it will be removed in Swift 4.0. Please use 'Collection' instead}}
58+
struct GoodIndexable : Indexable {
5859
func index(after i: Int) -> Int { return i + 1 }
5960
var startIndex: Int { return 0 }
6061
var endIndex: Int { return 0 }
@@ -64,6 +65,7 @@ struct GoodIndexable : Indexable {
6465
}
6566

6667

68+
// expected-warning@+2 {{'Indexable' is deprecated: it will be removed in Swift 4.0. Please use 'Collection' instead}}
6769
// expected-error@+1 {{type 'BadIndexable1' does not conform to protocol 'IndexableBase'}}
6870
struct BadIndexable1 : Indexable {
6971
func index(after i: Int) -> Int { return i + 1 }
@@ -75,6 +77,7 @@ struct BadIndexable1 : Indexable {
7577
// Missing 'subscript(_:) -> SubSequence'.
7678
}
7779

80+
// expected-warning@+2 {{'Indexable' is deprecated: it will be removed in Swift 4.0. Please use 'Collection' instead}}
7881
// expected-error@+1 {{type 'BadIndexable2' does not conform to protocol 'IndexableBase'}}
7982
struct BadIndexable2 : Indexable {
8083
var startIndex: Int { return 0 }
@@ -85,6 +88,7 @@ struct BadIndexable2 : Indexable {
8588
// Missing index(after:) -> Int
8689
}
8790

91+
// expected-warning@+1 {{'BidirectionalIndexable' is deprecated: it will be removed in Swift 4.0. Please use 'BidirectionalCollection' instead}}
8892
struct GoodBidirectionalIndexable1 : BidirectionalIndexable {
8993
var startIndex: Int { return 0 }
9094
var endIndex: Int { return 0 }
@@ -97,6 +101,7 @@ struct GoodBidirectionalIndexable1 : BidirectionalIndexable {
97101

98102
// We'd like to see: {{type 'BadBidirectionalIndexable' does not conform to protocol 'BidirectionalIndexable'}}
99103
// But the compiler doesn't generate that error.
104+
// expected-warning@+1 {{'BidirectionalIndexable' is deprecated: it will be removed in Swift 4.0. Please use 'BidirectionalCollection' instead}}
100105
struct BadBidirectionalIndexable : BidirectionalIndexable {
101106
var startIndex: Int { return 0 }
102107
var endIndex: Int { return 0 }

0 commit comments

Comments
 (0)