Skip to content
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
693 changes: 249 additions & 444 deletions apinotes/Foundation.apinotes

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions include/swift/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,6 @@ enum class KnownFoundationEntity {
/// entity name.
Optional<KnownFoundationEntity> getKnownFoundationEntity(StringRef name);

/// Determine with the non-prefixed name of the given known Foundation
/// entity conflicts with the Swift standard library.
bool nameConflictsWithStandardLibrary(KnownFoundationEntity entity);

/// Callback function used when referring to a type member of a given
/// type variable.
typedef std::function<Type(TypeVariableType *, AssociatedTypeDecl *)>
Expand Down
1 change: 0 additions & 1 deletion include/swift/AST/KnownFoundationEntities.def
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ FOUNDATION_ENTITY(NSObject)
FOUNDATION_ENTITY(NSRange)
FOUNDATION_ENTITY(NSSet)
FOUNDATION_ENTITY(NSString)
FOUNDATION_ENTITY(NSStringEncoding)
FOUNDATION_ENTITY(NSUInteger)
FOUNDATION_ENTITY(NSURL)
FOUNDATION_ENTITY(NSZone)
Expand Down
3 changes: 0 additions & 3 deletions include/swift/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,6 @@ namespace swift {
/// and methods.
bool InferImportAsMember = false;

/// Whether we are stripping the "NS" prefix from Foundation et al.
bool StripNSPrefix = true;

/// Should 'id' in Objective-C be imported as 'Any' in Swift?
bool EnableIdAsAny = true;

Expand Down
4 changes: 0 additions & 4 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,6 @@ def enable_swift_newtype :
Flag<["-"], "enable-swift-newtype">,
HelpText<"Enable the swift_newtype attribute">;

def enable_strip_ns_prefix :
Flag<["-"], "enable-strip-ns-prefix">,
HelpText<"Strip 'NS' prefix from Foundation entities">;

def swift3_migration :
Flag<["-"], "swift3-migration">,
HelpText<"Enable Fix-It based migration aids for Swift 3">;
Expand Down
30 changes: 0 additions & 30 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2578,29 +2578,6 @@ Optional<KnownFoundationEntity> swift::getKnownFoundationEntity(StringRef name){
.Default(None);
}

bool swift::nameConflictsWithStandardLibrary(KnownFoundationEntity entity) {
switch (entity) {
case KnownFoundationEntity::NSArray:
case KnownFoundationEntity::NSDictionary:
case KnownFoundationEntity::NSInteger:
case KnownFoundationEntity::NSRange:
case KnownFoundationEntity::NSSet:
case KnownFoundationEntity::NSString:
case KnownFoundationEntity::NSCopying:
case KnownFoundationEntity::NSError:
case KnownFoundationEntity::NSErrorPointer:
case KnownFoundationEntity::NSNumber:
case KnownFoundationEntity::NSObject:
case KnownFoundationEntity::NSUInteger:
case KnownFoundationEntity::NSURL:
case KnownFoundationEntity::NSZone:
return true;

case KnownFoundationEntity::NSStringEncoding:
return false;
}
}

StringRef ASTContext::getSwiftName(KnownFoundationEntity kind) {
StringRef objcName;
switch (kind) {
Expand All @@ -2610,13 +2587,6 @@ StringRef ASTContext::getSwiftName(KnownFoundationEntity kind) {
#include "swift/AST/KnownFoundationEntities.def"
}

// If we're omitting needless words and the name won't conflict with
// something in the standard library, strip the prefix off the Swift
// name.
if (LangOpts.StripNSPrefix &&
!nameConflictsWithStandardLibrary(kind))
return objcName.substr(2);

return objcName;
}

Expand Down
11 changes: 1 addition & 10 deletions lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1309,13 +1309,6 @@ ClangImporter::Implementation::Implementation(ASTContext &ctx,
DeprecatedAsUnavailableMessage =
"APIs deprecated as of OS X 10.9 and earlier are unavailable in Swift";
}

// Prepopulate the set of module prefixes.
// FIXME: Hard-coded list should move into the module map language.
if (ctx.LangOpts.StripNSPrefix) {
ModulePrefixes["Foundation"] = "NS";
ModulePrefixes["ObjectiveC"] = "NS";
}
}


Expand Down Expand Up @@ -1817,8 +1810,7 @@ static unsigned stripModulePrefixLength(
// Check whether this is a known Foundation entity that conflicts with the
// standard library.
if (auto known = getKnownFoundationEntity(baseName))
if (nameConflictsWithStandardLibrary(*known))
return 0;
return 0;

// If the character following the prefix is a '_', eat that, too.
unsigned prefixLen = prefixPos->second.size();
Expand Down Expand Up @@ -4436,7 +4428,6 @@ ClangImporter::Implementation::SwiftNameLookupExtension::hashExtension(
SWIFT_LOOKUP_TABLE_VERSION_MAJOR,
SWIFT_LOOKUP_TABLE_VERSION_MINOR,
Impl.InferImportAsMember,
Impl.SwiftContext.LangOpts.StripNSPrefix,
Impl.HonorSwiftNewtypeAttr);
}

Expand Down
4 changes: 1 addition & 3 deletions lib/ClangImporter/MappedTypes.def
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,7 @@ MAP_STDLIB_TYPE("CFIndex", SignedWord, 0, "Int", false, DefineAndUse)

// Foundation types.
// FIXME: <rdar://problem/16074941> NSStringEncoding doesn't work on 32-bit
MAP_STDLIB_TYPE(
Impl.SwiftContext.getSwiftName(KnownFoundationEntity::NSStringEncoding),
UnsignedWord, 0, "UInt", false, DoNothing)
MAP_STDLIB_TYPE("NSStringEncoding", UnsignedWord, 0, "UInt", false, DoNothing)

#undef MAP_STDLIB_TYPE
#undef MAP_TYPE
1 change: 0 additions & 1 deletion lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
Opts.Playground |= Args.hasArg(OPT_playground);
Opts.Swift3Migration |= Args.hasArg(OPT_swift3_migration);
Opts.WarnOmitNeedlessWords = Args.hasArg(OPT_warn_omit_needless_words);
Opts.StripNSPrefix |= Args.hasArg(OPT_enable_strip_ns_prefix);
Opts.InferImportAsMember |= Args.hasArg(OPT_enable_infer_import_as_member);

Opts.EnableThrowWithoutTry |= Args.hasArg(OPT_enable_throw_without_try);
Expand Down
3 changes: 1 addition & 2 deletions lib/Serialization/Deserialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1100,13 +1100,12 @@ Decl *ModuleFile::resolveCrossReference(Module *M, uint32_t pathLen) {
// has to go through this path, but it's an option we toggle for
// testing.
if (values.empty() && !retrying &&
getContext().LangOpts.StripNSPrefix &&
(M->getName().str() == "ObjectiveC" ||
M->getName().str() == "Foundation")) {
if (name.str().startswith("NS")) {
if (name.str().size() > 2 && name.str() != "NSCocoaError") {
auto known = getKnownFoundationEntity(name.str());
if (!known || !nameConflictsWithStandardLibrary(*known)) {
if (!known) {
name = getContext().getIdentifier(name.str().substr(2));
retrying = true;
goto retry;
Expand Down
4 changes: 2 additions & 2 deletions test/ClangModules/availability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,6 @@ func testImportAsMember() {
}

func testUnavailableRenamedEnum() {
_ = ClothingStyle.hipster
_ = NSClothingStyleOfficeCasual // expected-error{{'NSClothingStyleOfficeCasual' has been renamed to 'ClothingStyle.semiFormal'}} {{7-34=ClothingStyle.semiFormal}}
_ = NSClothingStyle.hipster
_ = NSClothingStyleOfficeCasual // expected-error{{'NSClothingStyleOfficeCasual' has been renamed to 'NSClothingStyle.semiFormal'}} {{7-34=NSClothingStyle.semiFormal}}
}
18 changes: 9 additions & 9 deletions test/ClangModules/availability_implicit_macosx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ func useClassThatTriggersImportOfDeprecatedEnum() {
// when importing deprecated enums do not themselves trigger deprecation
// warnings in the synthesized code.

_ = ClassWithDeprecatedOptionsInMethodSignature.sharedInstance()
_ = NSClassWithDeprecatedOptionsInMethodSignature.sharedInstance()
}

func useClassThatTriggersImportOExplicitlyUnavailableOptions() {
_ = ClassWithPotentiallyUnavailableOptionsInMethodSignature.sharedInstance()
_ = NSClassWithPotentiallyUnavailableOptionsInMethodSignature.sharedInstance()
}

func useClassThatTriggersImportOfPotentiallyUnavailableOptions() {
_ = ClassWithExplicitlyUnavailableOptionsInMethodSignature.sharedInstance()
_ = NSClassWithExplicitlyUnavailableOptionsInMethodSignature.sharedInstance()
}

func directUseShouldStillTriggerDeprecationWarning() {
_ = DeprecatedOptions.first // expected-warning {{'DeprecatedOptions' was deprecated in OS X 10.51: Use a different API}}
_ = DeprecatedEnum.first // expected-warning {{'DeprecatedEnum' was deprecated in OS X 10.51: Use a different API}}
_ = NSDeprecatedOptions.first // expected-warning {{'NSDeprecatedOptions' was deprecated in OS X 10.51: Use a different API}}
_ = NSDeprecatedEnum.first // expected-warning {{'NSDeprecatedEnum' was deprecated in OS X 10.51: Use a different API}}
}

func useInSignature(_ options: DeprecatedOptions) { // expected-warning {{'DeprecatedOptions' was deprecated in OS X 10.51: Use a different API}}
func useInSignature(_ options: NSDeprecatedOptions) { // expected-warning {{'NSDeprecatedOptions' was deprecated in OS X 10.51: Use a different API}}
}

class SuperClassWithDeprecatedInitializer {
Expand All @@ -53,11 +53,11 @@ func callImplicitInitializerOnSubClassWithSynthesizedDesignedInitializerOverride
}

@available(OSX, introduced: 10.9, deprecated: 10.51)
class DeprecatedSuperClass {
class NSDeprecatedSuperClass {
var i : Int = 7 // Causes initializer to be synthesized
}

class NotDeprecatedSubClassOfDeprecatedSuperClass : DeprecatedSuperClass { // expected-warning {{'DeprecatedSuperClass' was deprecated in OS X 10.51}}
class NotDeprecatedSubClassOfDeprecatedSuperClass : NSDeprecatedSuperClass { // expected-warning {{'NSDeprecatedSuperClass' was deprecated in OS X 10.51}}
}

func callImplicitInitializerOnNotDeprecatedSubClassOfDeprecatedSuperClass() {
Expand All @@ -68,7 +68,7 @@ func callImplicitInitializerOnNotDeprecatedSubClassOfDeprecatedSuperClass() {
}

@available(OSX, introduced: 10.9, deprecated: 10.51)
class DeprecatedSubClassOfDeprecatedSuperClass : DeprecatedSuperClass {
class NSDeprecatedSubClassOfDeprecatedSuperClass : NSDeprecatedSuperClass {
}

// Tests synthesis of materializeForSet
Expand Down
2 changes: 1 addition & 1 deletion test/ClangModules/enum-dataflow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import Foundation
import user_objc

let aliasOriginal = AliasesEnum.byName
let aliasOriginal = NSAliasesEnum.byName

switch aliasOriginal {
case .original:
Expand Down
2 changes: 1 addition & 1 deletion test/ClangModules/enum-with-target.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import user_objc
let calendarUnits: NSCalendar.Unit = [.era, .year, .calendar]
let calendarUnits2: NSCalendar.Unit = [.NSMonthCalendarUnit, .NSYearCalendarUnit] // expected-error 2 {{unavailable}}
// ...unless they're all deprecated.
let calendarUnitsDep: CalendarUnitDeprecated = [.eraCalendarUnitDeprecated, .yearCalendarUnitDeprecated] // expected-error 2 {{unavailable}}
let calendarUnitsDep: NSCalendarUnitDeprecated = [.eraCalendarUnitDeprecated, .yearCalendarUnitDeprecated] // expected-error 2 {{unavailable}}

// rdar://problem/21081557
func pokeRawValue(_ random: SomeRandomEnum) {
Expand Down
Loading