Skip to content

[swift-3.0-branch] Implementing SE-0137 #4361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,8 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
}

static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
DiagnosticEngine &Diags, bool isImmediate) {
DiagnosticEngine &Diags,
const FrontendOptions &FrontendOpts) {
using namespace options;

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

Opts.DisableAvailabilityChecking |=
Args.hasArg(OPT_disable_availability_checking);
if (FrontendOpts.InputKind == InputFileKind::IFK_SIL)
Opts.DisableAvailabilityChecking = true;

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

if (ParseLangArgs(LangOpts, ParsedArgs, Diags,
FrontendOpts.actionIsImmediate())) {
if (ParseLangArgs(LangOpts, ParsedArgs, Diags, FrontendOpts)) {
return true;
}

Expand Down
6 changes: 2 additions & 4 deletions lib/Sema/MiscDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2040,9 +2040,6 @@ bool AvailabilityWalker::diagAvailability(const ValueDecl *D, SourceRange R,
TC.diagnoseDeprecated(R, DC, Attr, D->getFullName(), call);
}

if (TC.getLangOpts().DisableAvailabilityChecking)
return false;

// Diagnose for potential unavailability
auto maybeUnavail = TC.checkDeclarationAvailability(D, R.Start, DC);
if (maybeUnavail.hasValue()) {
Expand Down Expand Up @@ -3574,7 +3571,8 @@ void swift::performSyntacticExprDiagnostics(TypeChecker &TC, const Expr *E,
diagSyntacticUseRestrictions(TC, E, DC, isExprStmt);
diagRecursivePropertyAccess(TC, E, DC);
diagnoseImplicitSelfUseInClosure(TC, E, DC);
diagAvailability(TC, E, const_cast<DeclContext*>(DC));
if (!TC.getLangOpts().DisableAvailabilityChecking)
diagAvailability(TC, E, const_cast<DeclContext*>(DC));
if (TC.Context.LangOpts.EnableObjCInterop)
diagDeprecatedObjCSelectors(TC, DC, E);
}
Expand Down
12 changes: 7 additions & 5 deletions lib/Sema/TypeCheckType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1441,8 +1441,8 @@ Type TypeChecker::resolveIdentifierType(
bool AllowPotentiallyUnavailableProtocol =
options.contains(TR_InheritanceClause);

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

if (Context.LangOpts.DisableAvailabilityChecking)
options |= TR_AllowUnavailable;

switch (repr->getKind()) {
case TypeReprKind::Error:
return ErrorType::get(Context);
Expand Down Expand Up @@ -1768,9 +1771,8 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,

if (base) {
Optional<MetatypeRepresentation> storedRepr;
// The instance type is not a SIL type. We still want to allow
// unavailable references, though.
auto instanceOptions = options - TR_SILType | TR_AllowUnavailable;
// The instance type is not a SIL type.
auto instanceOptions = options - TR_SILType;
auto instanceTy = resolveType(base, instanceOptions);
if (!instanceTy || instanceTy->is<ErrorType>())
return instanceTy;
Expand Down
1 change: 1 addition & 0 deletions stdlib/public/core/BidirectionalCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
/// In most cases, it's best to ignore this protocol and use the
/// `BidirectionalCollection` protocol instead, because it has a more complete
/// interface.
@available(*, deprecated, message: "it will be removed in Swift 4.0. Please use 'BidirectionalCollection' instead")
public protocol BidirectionalIndexable : Indexable {
// FIXME(ABI)(compiler limitation): there is no reason for this protocol
// to exist apart from missing compiler features that we emulate with it.
Expand Down
3 changes: 3 additions & 0 deletions stdlib/public/core/Collection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
///
/// In most cases, it's best to ignore this protocol and use the `Collection`
/// protocol instead, because it has a more complete interface.
@available(*, deprecated, message: "it will be removed in Swift 4.0. Please use 'Collection' instead")
public protocol IndexableBase {
// FIXME(ABI)(compiler limitation): there is no reason for this protocol
// to exist apart from missing compiler features that we emulate with it.
Expand Down Expand Up @@ -156,6 +157,7 @@ public protocol IndexableBase {
///
/// In most cases, it's best to ignore this protocol and use the `Collection`
/// protocol instead, because it has a more complete interface.
@available(*, deprecated, message: "it will be removed in Swift 4.0. Please use 'Collection' instead")
public protocol Indexable : IndexableBase {
/// A type used to represent the number of steps between two indices, where
/// one value is reachable from the other.
Expand Down Expand Up @@ -1727,3 +1729,4 @@ extension Collection where Iterator.Element : Equatable {

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

3 changes: 2 additions & 1 deletion stdlib/public/core/CompilerProtocols.swift
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ public protocol ExpressibleByDictionaryLiteral {
/// String(stringInterpolationSegment: " cookies: $"),
/// String(stringInterpolationSegment: price * number),
/// String(stringInterpolationSegment: "."))
@available(*, deprecated, message: "it will be replaced or redesigned in Swift 4.0. Instead of conforming to 'ExpressibleByStringInterpolation', consider adding an 'init(_:String)'")
public protocol ExpressibleByStringInterpolation {
/// Creates an instance by concatenating the given values.
///
Expand Down Expand Up @@ -736,7 +737,7 @@ public typealias ArrayLiteralConvertible
@available(*, deprecated, renamed: "ExpressibleByDictionaryLiteral")
public typealias DictionaryLiteralConvertible
= ExpressibleByDictionaryLiteral
@available(*, deprecated, renamed: "ExpressibleByStringInterpolation")
@available(*, deprecated, message: "it will be replaced or redesigned in Swift 4.0. Instead of conforming to 'StringInterpolationConvertible', consider adding an 'init(_:String)'")
public typealias StringInterpolationConvertible
= ExpressibleByStringInterpolation
@available(*, deprecated, renamed: "_ExpressibleByColorLiteral")
Expand Down
1 change: 1 addition & 0 deletions stdlib/public/core/MutableCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
/// In most cases, it's best to ignore this protocol and use the
/// `MutableCollection` protocol instead, because it has a more complete
/// interface.
@available(*, deprecated, message: "it will be removed in Swift 4.0. Please use 'MutableCollection' instead")
public protocol MutableIndexable : Indexable {
// FIXME(ABI)(compiler limitation): there is no reason for this protocol
// to exist apart from missing compiler features that we emulate with it.
Expand Down
1 change: 1 addition & 0 deletions stdlib/public/core/RandomAccessCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
/// In most cases, it's best to ignore this protocol and use the
/// `RandomAccessCollection` protocol instead, because it has a more complete
/// interface.
@available(*, deprecated, message: "it will be removed in Swift 4.0. Please use 'RandomAccessCollection' instead")
public protocol RandomAccessIndexable : BidirectionalIndexable {
// FIXME(ABI)(compiler limitation): there is no reason for this protocol
// to exist apart from missing compiler features that we emulate with it.
Expand Down
1 change: 1 addition & 0 deletions stdlib/public/core/RangeReplaceableCollection.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
/// In most cases, it's best to ignore this protocol and use the
/// `RangeReplaceableCollection` protocol instead, because it has a more
/// complete interface.
@available(*, deprecated, message: "it will be removed in Swift 4.0. Please use 'RandomAccessCollection' instead")
public protocol RangeReplaceableIndexable : Indexable {
// FIXME(ABI)(compiler limitation): there is no reason for this protocol
// to exist apart from missing compiler features that we emulate with it.
Expand Down
4 changes: 0 additions & 4 deletions test/Sema/availability_versions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1068,15 +1068,12 @@ func functionWithUnavailableInDeadBranch() {

localFuncAvailableOn10_51() // no-warning

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

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

// CHECK:error: 'explicitlyUnavailable()' is unavailable
explicitlyUnavailable() // expected-error {{'explicitlyUnavailable()' is unavailable}}
}
}
Expand Down Expand Up @@ -1624,6 +1621,5 @@ func useShortFormAvailable() {
// expected-note@-1 {{add @available attribute to enclosing global function}}
// expected-note@-2 {{add 'if #available' version check}}

// CHECK:error: 'unavailableWins()' is unavailable
unavailableWins() // expected-error {{'unavailableWins()' is unavailable}}
}
1 change: 1 addition & 0 deletions tools/sil-extract/SILExtract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ int main(int argc, char **argv) {
Invocation.setRuntimeResourcePath(ResourceDir);
Invocation.getClangImporterOptions().ModuleCachePath = ModuleCachePath;
Invocation.setParseStdlib();
Invocation.getLangOptions().DisableAvailabilityChecking = true;
Invocation.getLangOptions().EnableAccessControl = false;
Invocation.getLangOptions().EnableObjCAttrRequiresFoundation = false;

Expand Down
1 change: 1 addition & 0 deletions tools/sil-opt/SILOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ int main(int argc, char **argv) {
// cache.
Invocation.getClangImporterOptions().ModuleCachePath = ModuleCachePath;
Invocation.setParseStdlib();
Invocation.getLangOptions().DisableAvailabilityChecking = true;
Invocation.getLangOptions().EnableAccessControl = false;
Invocation.getLangOptions().EnableObjCAttrRequiresFoundation = false;

Expand Down
2 changes: 2 additions & 0 deletions validation-test/stdlib/BoolDiagnostics_Dataflow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,5 @@ func test_constantFoldOr4() -> Int {
}
} // expected-error {{missing return in a function expected to return 'Int'}}

// 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)'}}
typealias X = ExpressibleByStringInterpolation
7 changes: 6 additions & 1 deletion validation-test/stdlib/CollectionDiagnostics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ func sortResultIgnored<
array.sorted { $0 < $1 } // expected-warning {{result of call to 'sorted(by:)' is unused}}
}

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


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

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

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

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