Commit Graph

514 Commits

Author SHA1 Message Date
Jordan Rose
042569a3be Optional: Replace uses of Nothing with None.
llvm::Optional (like Swift.Optional!) uses None as its placeholder value,
not Nothing.

Swift SVN r22476
2014-10-02 18:51:42 +00:00
Doug Gregor
e0afb13abb Remove the APINotes library; it lives in Clang, now.
Swift SVN r22286
2014-09-25 18:48:43 +00:00
Doug Gregor
6559392293 Start re-namespacing APINotes and its dependencies.
FixNum.h and BCRecordLayout.h will move down into LLVM, APINotes
will move into Clang. Get the namespaces right before we start to move
files around.

Swift SVN r22218
2014-09-23 17:52:17 +00:00
Doug Gregor
c1399cf229 Allow SDK overlays to add 'required' initializers.
Removes the initWithBool: hack from the Clang importer. We can now
express NSNumber's conformance to the BooleanLiteralConvertible
protocol in the overlay.

Swift SVN r21976
2014-09-16 17:09:58 +00:00
Doug Gregor
d93eaed9f7 Switch BooleanLiteralConvertible over to an initializer requirement.
Conforming to BooleanLiteralConvertible now requires

  init(booleanLiteral: Bool)

rather than

  static func convertFromBooleanLiteral(value: Bool) -> Self

This posed a problem for NSNumber's conformance to
BooleanLiteralConvertible. A class needs a required initializer to
satisfy an initializer requirement, but one cannot add a required
initializer via an extension. To that end, we hack the Clang importer
to import NSNumber's initWithBool with the name

  init(booleanLiteral:)

and add back the expected init(bool:) initializer in the
overlay. These tricks make NSNumber even harder to subclass, but we
don't really care: it's nearly impossible to do well anyway, and is
generally a Bad Idea.

Part of rdar://problem/18154091.

Swift SVN r21961
2014-09-15 23:59:30 +00:00
Jordan Rose
8eb7bf2c31 Re-apply "Don't force-load Foundation under ImportForwardDeclarations."
This re-applies r21857, which was reverted r21871, fixing a use-of-
uninitialized-memory error that only showed up in optimized builds.

Swift SVN r21933
2014-09-13 00:56:12 +00:00
Dmitri Hrybenko
6c4c5492b1 Revert r21857 to fix the build
Swift SVN r21871
2014-09-11 13:54:49 +00:00
Jordan Rose
f1ccae6721 [ClangImporter] Don't force-load Foundation under ImportForwardDeclarations.
When we print the ObjectiveC module, we really shouldn't see extensions that
come from Foundation. Admittedly, we don't see them correctly in Foundation
either, but that's a separate issue.

There is one slightly unsafe hack here: we still import NSString as String,
by name alone, even when Foundation isn't present. This is because NSString
shows up in the ObjectiveC module, but we want people to be using String
when interacting with NSObject in real life.

Swift SVN r21857
2014-09-10 23:49:13 +00:00
Jordan Rose
7b6a0dd185 [ClangImporter] Add a mode where @class decls are imported as empty classes.
This can be used by SourceKit's interface printer to display modules with
forward declarations of classes in dependent modules, e.g. ObjectiveC
forward-declaring Foundation's NSString for use in NSObject. We can consider
doing something similar for C tag types (structs and enums).

Part of rdar://problem/18273845

Swift SVN r21828
2014-09-10 02:32:53 +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
Doug Gregor
b6248c8342 Remove the -enable-objc-failable-initializers option.
As part of this, failable initializers get enabled by default for
swift-ide-test.


Swift SVN r21704
2014-09-04 15:31:02 +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
a6c5547c81 [ClangImporter] When importing attributes for a class, use the @interface.
i.e. don't look for attributes on an @class somewhere.

Also do this for tag decls, whose attributes propagate forwards until there's
a definition.

<rdar://problem/17986861>

Swift SVN r21223
2014-08-15 03:26:24 +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
Jordan Rose
5c1e9d7d36 [Accessibility] Store setter accessibility explicitly.
Previously, we were just storing setter accessibility via the accessibility
level on the setter function. However, some Stored properties never actually
have a setter synthesized, which led to the compiler dropping the setter
accessibility at serialization time. Rather than try to hack up something
clever, just store the setter accessibility explicitly in every
AbstractStorageDecl. (We still only serialize it for VarDecls, because
settable SubscriptDecls always have setter functions.)

<rdar://problem/17816530>

Swift SVN r20598
2014-07-26 22:43:54 +00:00
Jordan Rose
aae4a3d731 [ClangImporter] Pass through diagnostic locations for imports.
If importing a Clang module fails, we should report that at the location of
the import statement. This doesn't do that fully because it isn't transitive
(if Swift module Foo imports Swift module Bar, which fails to import Clang
module Baz, we don't get an error in user source), but it's a step forward
for the simple cases.

Swift SVN r20575
2014-07-25 23:01:51 +00:00
Jordan Rose
d8077fc540 [ClangImporter] Print notes for macro expansions and include locations.
(for errors in the bridging header or in modules)

<rdar://problem/17573187>

Swift SVN r20573
2014-07-25 23:01:47 +00:00
Anna Zaks
071291003b APINotes: Use the property's notes to set the accessor's types.
Fixes the crashes due to the property and its setter and getter being out of sync.

Swift SVN r20570
2014-07-25 22:49:36 +00:00
Doug Gregor
5b3a3bdbaa An imported initializer is required if it is used to conform to a protocol requirement.
This replaces my egregious -initWithCoder:-specific hack with a more
reasonable general solution.

Replace my initWithCoder: hack with a proper

Swift SVN r20562
2014-07-25 21:01:36 +00:00
Doug Gregor
ec6016040e Clang importer: try harder to mark initializers from protocols as required.
There is an egregious hack here that special-cases -initWithCoder:. We
need to completely revisit how we handle 'required' checking.

Swift SVN r20516
2014-07-24 21:29:05 +00:00
Doug Gregor
0ad6ad65c8 API notes: add a "Required" field for Objective-C methods.
This allows us to express required initializers in the API notes. Use
it to smooth over NSString differences in the various SDKs even more.

Swift SVN r20511
2014-07-24 20:14:48 +00:00
Dave Abrahams
21669b3aee [stdlib] Add "Mutable" to [Autoreleasing]UnsafePointer
UnsafePointer becomes UnsafeMutablePointer
AutoreleasingUnsafePointer becomes AutoreleasingUnsafeMutablePointer

Swift SVN r20316
2014-07-22 16:56:23 +00:00
Doug Gregor
2faeb84e0c Rename ObjCClassInfo to ObjCContextInfo, to also cover protocols.
Swift SVN r20262
2014-07-21 17:30:16 +00:00
Jordan Rose
a419138a7a [PrintAsObjC] Print 'struct Foo' or 'enum Foo' instead of 'Foo' when necessary.
To do this, we keep track of decls with superfluous typedefs (rather than
just the typedefs), and check for that. Tag decls without typedefs are
printed with the tag.

<rdar://problem/17569385>

Swift SVN r20221
2014-07-20 17:26:20 +00:00
Doug Gregor
076d310132 Remove -import-tighter-objc-types option; we're turning it on by default.
Swift SVN r20191
2014-07-18 23:25:38 +00:00
Doug Gregor
fb9beed4cd Clang importer: clean up handling of Objective-C property API notes.
What we had was specific to optionality and had a different flow than
for methods; simplify the approach to match methods.

Swift SVN r20172
2014-07-18 18:48:10 +00:00
Doug Gregor
d1cfab0943 Remove redundant FactoryAsInitKind definition. NFC
Swift SVN r20170
2014-07-18 18:48:05 +00:00
Jordan Rose
fce31decdc Serialize bridging headers into the merged module file.
We do this so that the swiftmodule file contains all info necessary to
reconstruct the AST for debugging purposes. If the swiftmodule file is copied
into a dSYM bundle, it can (in theory) be used to debug a built app months
later. The header is processed with -frewrite-includes so that it includes
any non-modular content; the user will not have to recreate their project
structure and header maps to reload the AST.

There is some extra complexity here: a target with a bridging header
(such as a unit test target) may depend on another target with a bridging
header (such as an app target). This is a rare case, but one we'd like to
still keep working. However, if both bridging headers import some common.h,
we have a problem, because -frewrite-includes will lose the once-ness
of #import. Therefore, we /also/ store the path, size, and mtime of a
bridging header in the swiftmodule, and prefer to use a regular parse from
the original file if it can be located and hasn't been changed.

<rdar://problem/17688408>

Swift SVN r20128
2014-07-18 00:22:53 +00:00
Doug Gregor
dab7ece3bf API notes: which the Clang importer over to API notes completely.
The Clang importer no longer depends on built-in knowledge from
KnownObjCMethods.def.

Swift SVN r20120
2014-07-17 23:16:42 +00:00
Doug Gregor
533a94a5a0 Use API notes for Objective-C class/protocol nullability defaults.
Swift SVN r20113
2014-07-17 21:08:06 +00:00
Doug Gregor
b2220fc503 API notes: use API notes for property nullability information.
Swift SVN r20100
2014-07-17 17:00:19 +00:00
Doug Gregor
08db87ca35 Clang importer: load API notes whenever we load a Clang module.
We're not using this for anything, yet, so there aren't any checked-in
tests. Also note that I'm using ".apinotesc" for the binary form of
API notes.

Swift SVN r20096
2014-07-17 16:11:39 +00:00
Doug Gregor
9e2b68c4f9 Introduce CGFloat as a distinct struct type.
CGFloat is 32-bit on 32-bit architectures and 64-bit on 64-bit
architectures for historical reasons. Rather than having it alias
either Float (32-bit) or Double (64-bit), introduce a distinct struct
type for CGFloat. CGFloat provides a complete set of comparisons and
arithmetic operators (including tgmath functions), initializers allows
explicit conversion between it an Int, UInt, Float, and Double, as
well as conforming to all of the protocols that Float/Double do.

This formulation of CGFloat makes use of CGFloat
architecture-independent, although it still requires a number of casts.
Fixes <rdar://problem/17224725>

Swift SVN r19689
2014-07-08 19:00:18 +00:00
Anna Zaks
8cb6d45efb Only remap NSUInteger to Int in system frameworks
Makes NSUInteger come in as Uint from user declarations (and as Int from system modules).
Addresses radar://17473606

Swift SVN r19536
2014-07-03 21:46:47 +00:00
Ted Kremenek
a3b704ec42 Mark all imported APIs deprecated in iOS 7 (or earlier) or OS 10.9 (or earlier) as unavailable.
This patch takes care that synthesized initializers are created
when overriding unavailable initializers (thanks Doug).

Swift SVN r19202
2014-06-26 00:50:46 +00:00
Jordan Rose
6cca3529eb Compute accessibility for all ValueDecls, and serialize it properly.
No validation is done yet on whether the user-specified access control makes
sense in context, but all ValueDecls should at least /have/ accessibility now.

/Still/ no tests yet. They will be much easier to write once we're actually
enforcing access control and/or printing access control.

Swift SVN r19143
2014-06-24 21:32:13 +00:00
Jordan Rose
db3914e94b Disallow conforming to ObjC protocols with requirements that can't be imported.
For example, variadic ObjC method requirements.

<rdar://problem/17366999>

Swift SVN r19121
2014-06-24 01:23:06 +00:00
Anna Zaks
a7fefdb561 Known ObjC types sidecar: add ability to annotate properties.
Add a simple option that allows to pass along information about properties.

Swift SVN r19110
2014-06-23 23:53:37 +00:00
Anna Zaks
50178f649e Add audited APIs to sidecart for NSView.
From NSView.h, NSRuler.h, NSLayoutConstraint.h.

Swift SVN r19109
2014-06-23 23:53:36 +00:00
Anna Zaks
5f61494928 Add OBJC_CONTEXT(ClassName, Options) to KnownObjCMethods.
This allows to specify the method options most common for the methods in a
given audited class or protocol.

Swift SVN r19108
2014-06-23 23:53:34 +00:00
Anna Zaks
9f122e56b7 Add initial support for importing with tighter Objective C pointer types.
Add the ability to store optionality of the ObjC method parameters and return
type in a sidecar. This hardcoded info is then used to import Objective C
object pointer types as either optional or none, instead of implicitly
unwrapped optionals.

The feature is enabled with -import-with-tighter-objc-types=true.

Swift SVN r19048
2014-06-20 19:19:43 +00:00
Jordan Rose
a4ea927426 [ClangImporter] If a protocol and a class have the same name, add "Protocol".
.../if/ the protocol and the class are from the same top-level Clang module.
If not, the protocol is /not/ renamed, and users will have to disambiguate
with module qualification.

This kills our hardcoded "RenamedProtocols" list; it turns out this pattern
is more common than we thought /and/ leads to cross-referencing issues.

<rdar://problem/16206627>

Swift SVN r18809
2014-06-11 23:00:00 +00:00
Chris Lattner
4dbff38780 Change NULL/Nil/nil and various other macros to be imported as an unavailable decl,
instead of importing them as _Nil (which will be going away when nil becomes an expr).

You now get an error saying:
error: 'NULL' is unavailable: use 'nil' instead of this imported macro

This is pretty cool all around, except for the GCD macros that need to be fixed, I'll
handle that as a follow-up.


Swift SVN r18747
2014-06-09 17:08:11 +00:00
Doug Gregor
f338c9f9bf Extend ObjC methods whitelist to support adding an "unavailable" attribute.
Use this for -class and +class, to make them less ad hoc. More to follow.

As part of this, actually mark imported unavailable declarations in a
protocol as "optional", because nobody should have to implement an
unavailable declaration.

Swift SVN r18262
2014-05-17 19:18:02 +00:00
Doug Gregor
d640eb4083 Introduce support for blacklisting factory-methods-as-inits.
Some fcactory methods shouldn't come in as initializers, per
<rdar://problem/16908950>.


Swift SVN r18101
2014-05-15 07:04:46 +00:00
Doug Gregor
3210f19411 Clang importer: replace the designated-initializer whitelist with a general method whitelist.
... which only handles designated initializers, for now at least.


Swift SVN r18100
2014-05-15 06:22:44 +00:00
John McCall
a3fb501114 Recognize the objc_bridge and objc_bridge_mutable
attributes and create implicit conversions for them.

Also, when generating Clang modules for import, set the
appropriate macro to make CoreFoundation actually apply
those attributes to its typedefs.

Also, give shared linkage to imported class method
definitions.

The net effect is that CFString now automatically
converts to NSString and vice-versa.

Depends on Clang r208756 in order to preserve attributes
applied to tag types in multiple typedef declarations.

Swift SVN r18069
2014-05-14 08:19:39 +00:00
Doug Gregor
63edc38d0a Use a bit to avoid performing early declaration attribute validation more than once.
Attribute validation is not naturally idempotent, and we shouldn’t need to make it so. Rather, we should only do the validation once. This fixes an immediate issue with @NSManaged in multi-file situations (<rdar://problem/16879162>) and avoids some redundant work.

Longer term, we have a ton of redundant visitation that needs to be addressed <rdar://problem/16905199>.

Swift SVN r18039
2014-05-13 23:36:09 +00:00