Commit Graph

425 Commits

Author SHA1 Message Date
Dmitri Hrybenko
e6f53a38cc stdlib: remove swift_createDate
It was added for testing and it is actually never used now.

Swift SVN r26195
2015-03-16 22:25:27 +00:00
Jordan Rose
edf3bb460d [ClangImporter] Ignore deprecated enum constants when computing prefixes.
This fixes the import of enums like NSCalendarUnit, which changed from
NSXXXCalendarUnit to NSCalendarUnitXXX, as has been the guideline in
recent years. Now even when the old names are present, we can still
prefix-strip based on the new names. If /all/ options are deprecated,
though, we'll prefix-strip as we did before.

Note that we /don't/ check the current deployment target for this,
because we want to use the "nice" names as soon as we have an SDK where
they're available, not when the deployment target matches such an SDK.

rdar://problem/17686122

Swift SVN r26184
2015-03-16 18:01:45 +00:00
Devin Coughlin
1e5daf7557 [Sema] Suppress deprecation warnings inside implicit functions
This commit suppresses deprecation warnings for references to deprecated symbols
by climbing the DeclContext hierarchy to determine if the warning location is
inside an implicit function.

This is a quick fix to get rid of spurious warnings for deprecated enums whose
nil literal conformance is synthesized by the importer. These warnings would
occur even when user code made no apparent reference to the enum in question and
instead only referred to an imported class that itself referred to the enum in a
method signature. This quick fix intentionally drops some valid warnings
(for example, for a synthesized call to a deprecated initializer in a super
class). rdar://problem/20024980 tracks adding these special purpose warnings
back.

rdar://problem/20007266

Swift SVN r25720
2015-03-03 21:16:01 +00:00
Jordan Rose
a493410402 [ClangImporter] Map MacTypes.h's ItemCount and ByteCount to Swift.Int.
typedef unsigned long ByteCount;
  typedef unsigned long ItemCount;

Both of these are still in use by CoreMIDI, but we don't have a reason to
keep them distinct in Swift.

rdar://problem/19939552

Swift SVN r25529
2015-02-25 05:00:06 +00:00
Jordan Rose
5554cec143 [ClangImporter] Don't inherit initializers as designated...
...even if they were designated in the base class. (Unless they're required,
in which case they're still required.)

This led to Swift subclasses treating convenience initializers as
designated initializers, which (if synthesized) led to properties being
initialized twice.

rdar://problem/19730160

Swift SVN r25410
2015-02-20 02:26:55 +00:00
Doug Gregor
f919dd5248 __attribute__((noescape)) isn't getting imported properly for methods.
Fixes rdar://problem/19818617.

Swift SVN r25256
2015-02-12 22:53:59 +00:00
Joe Groff
a0ecab5b16 ClangImporter: Don't attempt to bridge __unsafe_unretained NSString * fields in structs.
We certainly can't import them as stored properties, and it's too late to try to bridge them as computed property, so restore the old behavior of importing them as unbridged object types. The types still come in as strong managed reference types, which is still wrong, but seems to be right enough for Khan Academy and potentially other existing apps for now, and I don't want to introduce additional source-breaking changes and instability this late in the game. Fixes rdar://problem/19789023, leaving rdar://problem/19790608 to be done when we can afford more churn.

Swift SVN r25158
2015-02-11 01:30:20 +00:00
Jordan Rose
6a50a12bef [PrintAsObjC] Don't assume typedef'd enums have a name themselves.
...and then fix our forward-declaration logic that assumed that they did.

This fixes a rare case where we would end up printing "enum" twice if the
user (benignly) misused NS_ENUM.

rdar://problem/19769964

Swift SVN r25143
2015-02-10 23:52:44 +00:00
Dmitri Hrybenko
1952a103ef ClangImporter: import size_t as Int
Converging APIs to use ``Int`` as the default integer type allows users to
write fewer explicit type conversions.

Importing ``size_t`` as a signed ``Int`` type is not be a problem for 64-bit
platforms.  32-bit platforms are important, but the usecase for an
unsigned ``size_t`` on 32-bit platforms is pretty marginal, and for code
that nevertheless needs to do that there is always the option of doing a
bitcast to ``UInt`` or using C.

rdar://18949559

Swift SVN r25070
2015-02-07 10:39:00 +00:00
Devin Coughlin
2c5f786ffb clang-importer: Always import attributes for accessors
This commit changes the clang importer to always import attributes on property accessors.
Previously, attributes were only imported if the accessor method was declared before the
property but not if the accessor method was declared after it.

Swift SVN r25018
2015-02-05 21:46:45 +00:00
Doug Gregor
e855ae8f58 Clang importer: only consider imported initializers when filtering out duplicates.
Fixes rdar://problem/18500201 and 16 of the crashes in the crash suite.

Swift SVN r24982
2015-02-05 00:07:58 +00:00
Devin Coughlin
af1f02e247 clang-importer: Import attributes on enum elements.
This commit updates the clang importer to import attributes on enum elements. We also
now print these attributes in ASTPrinter.

Swift SVN r24973
2015-02-04 21:17:14 +00:00
Doug Gregor
c362f5962d Add a test for the weird form of __attribute__((nonnull(indices...))).
Test from rdar://problem/19522038, which is actually about something
entirely different.

Swift SVN r24751
2015-01-27 17:06:46 +00:00
Doug Gregor
f0eec4d9d5 Don't rely on overriding nullability in Objective-C; it's banned now.
Fixes rdar://problem/19610107.

Swift SVN r24750
2015-01-27 16:52:03 +00:00
Doug Gregor
896df201e2 Map the Clang 'noescape' attribute to 'noescape' for @objc_block function parameters.
Fixes rdar://problem/19389222.

Swift SVN r24582
2015-01-21 00:48:25 +00:00
Jordan Rose
0c182d73a3 [PrintAsObjC] Prefer the Clang name of imported typedefs.
Previously, when dealing with CF typedefs of other CF types, we would strip
off the "Ref" suffix...and then leave it off when it came time to print the
Objective-C header.

rdar://problem/19446942

Swift SVN r24562
2015-01-20 20:42:01 +00:00
Dmitri Hrybenko
3b04d1b013 tests: reorganize tests so that they actually use the target platform
Most tests were using %swift or similar substitutions, which did not
include the target triple and SDK.  The driver was defaulting to the
host OS.  Thus, we could not run the tests when the standard library was
not built for OS X.

Swift SVN r24504
2015-01-19 06:52:49 +00:00
Jordan Rose
93a89467b8 [ClangImporter] Hide old API from the Carbon days.
This affects the MacTypes.h header in the Darwin module as well as the
CarbonCore and OSServices sub-frameworks of the CoreServices framework.
API hidden in this way can still be accessed through qualified lookup
in case it's really needed, but will not appear in the module interface
or in code completion.

This is a hack, and it would be nice to remove it if/when all of this API
is officially marked as deprecated. I did check with Nick for MacTypes.h
and Chris Linn from CoreServices that this was a reasonable action to take.

rdar://problem/16806148

Swift SVN r24424
2015-01-14 19:27:45 +00:00
Doug Gregor
69e5a3ddda Clean up handling of nullability in the Clang importer.
Handle nullability at the top level of importType, so that it doesn't
break bridging.

Swift SVN r24195
2015-01-06 00:16:38 +00:00
Jordan Rose
7d9e859596 [ClangImporter] Don't drop the first letter of an enum with underscores.
If the common prefix of all enumerators ends with an underscore, but the
enumerators don't have a common prefix with the enum itself, we can't
drop the underscore.

rdar://problem/18730653

Swift SVN r23941
2014-12-15 19:33:45 +00:00
Doug Gregor
671f79483a Properly account for nullability of Objective-C methods with a related result type.
We were losing the nullability of factory methods that turned into
initializers (which should have been mapped to failability), and more
generally, methods with nullability for related result types
(instancetype in Clang, dynamic Self in Swift).

Note that this commit also contains tests for a similar Clang-side fix
where Clang itself wasn't correctly recording that an Objective-C
method with a nullability-qualified instancetype result type in fact
had a related result type.

Found by browsing through the most excellent Swift SDK Analyzer.

Swift SVN r23834
2014-12-10 06:20:23 +00:00
Chris Willmore
36d0f187ec Sema, SILGen, ClangImporter: Add special support for Set<T>
Add the following functionality to the Swift compiler:

* covariant subtyping of Set
* upcasting, downcasting of Set
* automatic bridging between Set and NSSet, including
    * NSSet params/return values in ObjC are imported as Set<NSObject>
    * Set params/return values in Swift are visible to ObjC as NSSet

<rdar://problem/18853078> Implement Set<T> up and downcasting

Swift SVN r23751
2014-12-06 02:52:33 +00:00
Doug Gregor
5524c0a393 Honor the Clang nonnull and returns_nonnull attributes in the importer.
Non-null attributes can indicate non-optionality of pointers. While
these non-null attributes are generally less useful than the
nullability type specifiers, they are occasionally used in the
wild. Addresses rdar://problem/18428099.

Swift SVN r23733
2014-12-05 06:58:54 +00:00
Joe Groff
e6d97e8de7 Clang importer: Add a zeroing default initializer to imported structs.
If an imported C struct has no __nonnull pointer fields, then we can give a default initializer that zeroes all of its fields. This becomes a requirement when working with partially-imported types like NSDecimal. NSDecimal has bitfields Swift can't see yet, so it's impossible to DI, but the Foundation functions that work with NSDecimal all emit their result by out parameter, and without access to its fields it is impossible to initialize an NSDecimal for use with one of these functions. Implement the initializer using a builtin that gets lowered by IRGen; this is also made necessary by the fact that Swift has only a partial view of the struct, so we can't form a complete zero initializer until we have the definitive type layout from Clang.

Swift SVN r23727
2014-12-05 05:31:22 +00:00
Chris Willmore
6d428b8d52 ClangImporter: Import macros of the form '#define FOO CFSTR("bar")'.
rdar://problem/18668528

Swift SVN r23544
2014-11-22 02:33:27 +00:00
Doug Gregor
7b77294cac Improve testing of nullability type specifier importing.
Swift SVN r23457
2014-11-20 00:06:14 +00:00
Doug Gregor
9d9336db97 Importer nullability type specifiers __nonnull/__nullable/__null_unspecified as optional types.
Implements rdar://problem/19005653.

Swift SVN r23416
2014-11-18 23:23:21 +00:00
Jordan Rose
eb3689051e [ClangImporter] Ban useless macro CF_USE_OSBYTEORDER_H.
rdar://problem/18966078

Swift SVN r23395
2014-11-18 01:55:30 +00:00
John McCall
653775077d Dispatch.h -> dispatch.h
We have a module map referring to it as dispatch.h, and
this capitalization matches the system, so let's go with it.

Fixes running test/ClangModules/blocks_parse.swift on
case-sensitive file systems.  Apparently I'm the only
person building on a case-sensitive file system.

Swift SVN r23380
2014-11-17 21:02:17 +00:00
Chris Willmore
f723b05672 Don't remove 'with' from ObjC method arg name if resulting name is keyword.
Also, remove calls to isSwiftReservedName in
ClangImporter::Implementation::importName(), since 'true' and 'false'
are now keywords and rdar://problem/13187570 is no longer a problem.

rdar://problem/18797808

Swift SVN r23244
2014-11-11 19:34:53 +00:00
Chris Willmore
ae5ed11eaa Don't include zero-byte fields in args to struct constructor.
rdar://problem/18510461

Swift SVN r23015
2014-10-30 03:47:45 +00:00
Jordan Rose
657070a637 [ClangImporter] Recognize OBJC_ENUM/OPTIONS along with CF_ENUM/OPTIONS.
rdar://problem/18506964

Swift SVN r22885
2014-10-23 03:28:28 +00:00
Devin Coughlin
f765fc8e29 [Sema] Add tests for version-based availability checking of ObjC imported APIs.
Swift SVN r22706
2014-10-13 18:22:00 +00:00
Anna Zaks
9e5003e668 API Notes: Mark dispatch_retain and dispatch_release as unavailable.
Swift SVN r22091
2014-09-18 18:51:52 +00:00
Anna Zaks
c61280cf35 API Notes: Mark several APIs as unavailable.
- Make NSZone functions unavailable radar://16688847
 - Distributed Objects subsystem should not be imported into Swift radar://16689104
 - NSCalendarDate is available in Swift, but deprecated radar://16689207
 - Do not import NSMethodSignature class and related methods radar://16689329
 - NSInvocationOperation should be unavailble in Swift radar://17921785

Swift SVN r22090
2014-09-18 18:51:51 +00:00
Anna Zaks
7be3363210 Reapply Swift Overlay: Make most common security return codes work with OSStatus
This reverts commit 043dbaafa20f3a1bbb1c71cd748a651ad57ba7b4.

Swift SVN r21794
2014-09-09 01:47:03 +00:00
Anna Zaks
ecf471bbff Revert "Swift Overlay: Make most common security return codes work with OSStatus"
This is causing buildbot breakage while building the Security library.

Swift SVN r21761
2014-09-06 05:30:23 +00:00
Anna Zaks
d51c1736f0 Swift Overlay: Make most common security return codes work with OSStatus
Swift SVN r21759
2014-09-06 00:46:21 +00:00
Anna Zaks
c3c8576ecc Add special handling of accessibility APIs.
This is a hack that allows us to support accessibility APIs in Swift.
It addresses radar://17509751.

A class might conform to both NSAccessibility (containing accessibility
properties) and individual accessibility protocols (containing
accessibility methods with the same names as the properties). This should
not compile (but currently happens to compile). To avoid the problem down
the road, we import setters and getters instead of the accessibility
properties from NSAccessibility.

Swift SVN r21757
2014-09-06 00:46:17 +00:00
Joe Groff
d7c98dcff4 Add an @NSApplicationMain attribute.
This behaves like @UIApplicationMain, except for AppKit. Attach it to your NSApplicationDelegate, and an artificial "main" will be generated that invokes NSApplicationMain() for you. Implements rdar://problem/16904667.

Swift SVN r21697
2014-09-04 05:52:26 +00:00
Doug Gregor
17716524c5 Handle CF <-> Objective-C toll-free-bridged conversions in the type checker.
Introduce an attribute that describes when a given CF type is
toll-free-bridged to an Objective-C class, and which class that
is. Use that information in the type checker to provide the CF <->
Objective-C toll-free-bridged conversions directly, rather than using
the user-defined conversion machinery.

Swift SVN r21376
2014-08-21 21:36:05 +00:00
Doug Gregor
28866251b0 Clang importer SDK: separate out CoreFoundation.h so we can build it up.
Swift SVN r21375
2014-08-21 21:36:02 +00:00
Doug Gregor
fe8213eec3 Cope with leading acronyms when turning factory methods into initializers.
This allows us to properly import, e.g., +[NSURL URLWithString] as the
initializer init(string:). Fixes <rdar://problem/16906469>.

Swift SVN r21366
2014-08-21 17:41:25 +00:00
Doug Gregor
d603db43f2 Make factory methods unavailable when there is already a corresponding initializer.
Depending on visitation order, we would occasionally leave the factory
method available if we had completely imported the initializer
first. Fixes <rdar://problem/17261609>.

Swift SVN r21361
2014-08-21 16:45:17 +00:00
Doug Gregor
5709a86f2f Start importing Objective-C initializers and factory methods using failable initializers.
In this mode, use nullability information on the result type of the
initializer or factory method to determine failability of the
initializer. This is behind the flag
-enable-objc-failable-initializers until we have the SILGen support in
place.



Swift SVN r21341
2014-08-21 04:50:20 +00:00
Jordan Rose
8176e99f5a [ClangImporter] Special-case some known non-CF types whose names end in "Ref".
Without this, we try to bring these in as CF types, and then ARC tries to
manage them, and the program crashes.

<rdar://problem/17211521>

Swift SVN r21081
2014-08-07 01:18:26 +00:00
Jordan Rose
3caaac5b9a [ClangImporter] QoI: Import 'const void *' as 'UnsafePointer<Void>'.
...instead of 'UnsafePointer<()>'.

Swift SVN r21033
2014-08-05 01:55:01 +00:00
Anna Zaks
c17fd1a586 API Notes: Add availability info to global variables and global functions.
Swift SVN r21029
2014-08-04 23:49:14 +00:00
Anna Zaks
782ecab50a API Notes: Teach Clang Importer about nullability of globals and functions
Swift SVN r20941
2014-08-02 01:55:18 +00:00
Jordan Rose
fe8e659667 [ClangImporter] Hack: import selected constants from Security as CFStrings.
This is a step towards making the framework easier to use in Swift; in the
actual headers, these are typed as "CFTypeRef" or "const CFTypeRef", which
is not considered Hashable (and thus cannot be put in a dictionary).
Unfortunately, CFStringRef is also not hashable, so we're not there yet,
but at least this allows a freer conversion to NSString.

Part of <rdar://problem/17162475>

Swift SVN r20931
2014-08-02 00:03:40 +00:00