Commit Graph

2523 Commits

Author SHA1 Message Date
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
Doug Gregor
f52c6789db Track the minimum deployment target and use it for 'unavailable' computations.
Swift SVN r20955
2014-08-02 18:05:45 +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
a627411b43 [ClangImporter] Imported NS_OPTIONS structs should not conform to BooleanType.
In general, RawOptionSetType no longer inherits from BooleanType.

Swift SVN r20846
2014-07-31 19:23:08 +00:00
Jordan Rose
904264544d [ClangImporter] Preserve all of Clang's availability attribute information.
This completes <rdar://problem/17024498>, except that we don't yet do
anything with 'deprecated' or 'obsoleted'. The former is covered by
<rdar://problem/17406050>, and I filed <rdar://problem/17873422> for the
latter.

Swift SVN r20845
2014-07-31 18:58:18 +00:00
Jordan Rose
5257550f13 [ClangImporter] Don't mark generated 'unavailable' attributes as implicit.
Nearly all of them come from some annotation written explicitly in the
Objective-C header, and all of them should be shown in the generated
interface for an imported module.

Part of <rdar://problem/17024498>

Swift SVN r20841
2014-07-31 18:58:14 +00:00
Doug Gregor
ba040d9f21 Maintain the DeclContext of a NormalProtocolConformance as the type declaration or extension.
Previously, we only retained the module in which a normal protocol
conformance occurred, which meant we either had to go searching for
the appropriate extension (yuck) or do without that information. This
is part of the separating-extension-archetypes work.

Swift SVN r20793
2014-07-31 01:00:30 +00:00
Doug Gregor
a0bc9274db Change parsing and representation of extensions to accommodate generic parameters.
The eventual goal for extensions of generic types is to require them
to specify their generic parameters, e.g.,

  extension Array<T> { ... }

rather than today's

  extension Array { ... }

Start parsing (optional) generic parameters here, and update the
representation of ExtensionDecl to accomodate this new grammar
production. Aside from the parser changes, there's no intended
functionality change here.

Swift SVN r20682
2014-07-29 19:17:00 +00:00
Doug Gregor
ac332429d9 Give extensions generic parameters and signatures within the AST.
This adds generic parameters and generic signatures to extension
declarations. The actual generic parameters just mirror what is
available on the extended type; however, it is filled in via extension
validation, which is handled lazily.

This is a NFC step toward decoupling the archetypes of extensions from
the archetypes of the extended types <rdar://problem/16974298>.

Swift SVN r20675
2014-07-29 16:20:56 +00:00
Jordan Rose
798814e1d9 [ClangImporter] Import typedefs of other CF types as typealiases.
...rather than distinct classes. This is a bit more complicated than just
making a second typealias because we still want to strip off the "Ref".

<rdar://problem/17686069>

Swift SVN r20652
2014-07-28 22:43:29 +00:00
Jordan Rose
ee176e7269 [ClangImporter] Give NS_OPTIONS structs a static 'allZeros' property.
This will allow RawOptionSet to conform to BitwiseOperations.

<rdar://problem/17815538>

Swift SVN r20600
2014-07-27 00:47:41 +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
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
Chris Lattner
6d0934d33d Introduce a new 'renamed' modifier on unavailable attributes. This allows Xcode
to emit fixit's when we rename something, e.g.:

t.swift:6:9: error: 'float' has been renamed to Float
var y : float
        ^~~~~
        Float

Adopt this in the stdlib.



Swift SVN r20549
2014-07-25 18:00:37 +00:00
Doug Gregor
24be396fd7 Cope with null witnesses
Swift SVN r20520
2014-07-24 21:48:53 +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
Jordan Rose
00b6a5cb08 Import Objective-C properties marked weak/copy as weak/@NSCopying.
...and 'assign' and 'unsafe_unretained' as 'unowned(unsafe)', if the
property is a class type.

This isn't important for the compiler, but it is documentation for users
when they look at the generated interface for an Objective-C module.

Note that this actually produces a decl users can't yet write:

  unowned(unsafe) var foo: UIView!

That's <rdar://problem/17277899> unowned pointers can't be optional.

<rdar://problem/17245555>

Swift SVN r20433
2014-07-23 22:29:01 +00:00
Doug Gregor
070ee7713a Treat imported initializers from Objective-C protocols as 'required'.
Initializers for non-final classes will soon need to be 'required' to
conform to an initializer requirement in a protocol, so start
marking imported initializers from Objective-C protocols as
'required'. This is part of <rdar://problem/17408284> and
<rdar://problem/17415607>.

Swift SVN r20428
2014-07-23 22:16:35 +00:00
Jordan Rose
a0d3d31cc1 [ClangImporter] Make the 'value' field of plain C enums public again.
If an enum has a name but isn't declared with NS_ENUM or NS_OPTIONS, we
don't know how it's intended to be used, so we import it as a struct with
each enumerator as a value. The raw value of the enum used to be accessible
as the 'value' field, but that was mistakenly marked Private in the Great
Access Control Update.

We could consider making plain enums RawRepresentable (and just convert
to and from their raw type without checking anything), but that's something
to do later.

<rdar://problem/17753237>

Swift SVN r20355
2014-07-23 00:25:55 +00:00
Dmitri Hrybenko
d14f17beef Change 'getLogicValue()' into a property 'boolValue'; change
'getArrayBoundValue()' into a property 'arrayBoundValue'.

rdar://17156123


Swift SVN r20304
2014-07-22 12:08:10 +00:00
Jordan Rose
ce1e02c6c0 [ClangImporter] Remove hack for non-property 'description' and 'hash'.
...and 'debugDescription'. All SDKs now have the updated NSObject.h.

<rdar://problem/17719783>

Swift SVN r20291
2014-07-22 02:38:58 +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
Chris Lattner
48687380b7 now that DeclAttributes is a single word, there is no reason to deal with
it indirectly through another pointer from Decl, just embed DeclAttributes
directly into Decl and get rid of the "getMutableAttrs" nonsense.



Swift SVN r20216
2014-07-20 04:09:42 +00:00
Doug Gregor
422fc4b00a API notes: factor 'unavailable' into a common base for methods/classes/properties.
Now that we have this, move the ban on NSInvocation into
KnownObjCMethods.def so that it's enforced via API notes.

Swift SVN r20190
2014-07-18 23:25:37 +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
Chris Lattner
2825b9f5f8 move @transparent and @requires_stored_property_inits to the new attribute model.
All that is left is unowned(unsafe) & weak.



Swift SVN r20012
2014-07-16 06:14:19 +00:00
Joe Groff
e41678c583 ClangImporter: Set clang nodes on implicitly-propertized imports.
This lets us recognize "description" and other implicitly-propertized methods as foreign methods.

Swift SVN r20001
2014-07-16 03:04:01 +00:00
Anna Zaks
eab2792cd8 Disallow [NSArray makeObjectsPerformSelector:]
Addresses radar://17559678

Swift SVN r19958
2014-07-14 22:42:37 +00:00
Dave Abrahams
6d1095f44e Protocol names end in "Type," "ible," or "able"
Mechanically add "Type" to the end of any protocol names that don't end
in "Type," "ible," or "able."  Also, drop "Type" from the end of any
associated type names, except for those of the *LiteralConvertible
protocols.

There are obvious improvements to make in some of these names, which can
be handled with separate commits.

Fixes <rdar://problem/17165920> Protocols `Integer` etc should get
uglier names.

Swift SVN r19883
2014-07-12 17:29:57 +00:00
Chris Lattner
35dcc3aa10 Move the @optional attribute to being a SIMPLE_DECL_ATTR, which
simplifies a bunch of code, makes them more consistent with the
other attributes, and is generally the newfangled way to do things.



Swift SVN r19779
2014-07-10 04:34:00 +00:00
Jordan Rose
c99b417a59 [ClangImporter] Handle underscore-punctuated enum names (used by CoreMedia).
<rdar://problem/17594425>

Swift SVN r19732
2014-07-09 18:44:43 +00:00
Joe Groff
c1228c774d ClangImporter: Track when structs have unreferenceable storage.
SIL SROA needs to know when a struct's visible fields actually completely make up the struct value, which becomes an issue if we start importing structs with yet-unrepresentable unions and bitfields. Track this in the ClangImporter, and add an 'aggregateHasUnreferenceableStorage' predicate to SILType to make it easy for passes to query. Part of <rdar://problem/17555966>.

Swift SVN r19720
2014-07-09 03:52:15 +00:00
Jordan Rose
c249599d17 [ClangImporter] Don't crash when a decl is definitively not in a module.
<rdar://problem/17583088>

Swift SVN r19716
2014-07-09 00:35:55 +00:00
Chris Lattner
02999cac51 Reinstate the @ on the @objc attribute. This is largely a revert of r19555 with a few tweaks.
Swift SVN r19706
2014-07-08 21:50:34 +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
Chris Lattner
7a56499d61 Start making @objc not start with an @ sign:
- Change the parser to accept "objc" without an @ sign as a contextual
   keyword, including the dance to handle the general parenthesized case.
 - Update all comments to refer to "objc" instead of "@objc".
 - Update all diagnostics accordingly.
 - Update all tests that fail due to the diagnostics change.
 - Switch the stdlib to use the new syntax.

This does not switch all tests to use the new syntax, nor does it warn about
the old syntax yet.  That will be forthcoming.  Also, this needs a bit of 
refactoring, which will be coming up.



Swift SVN r19555
2014-07-04 05:57:57 +00:00
Anna Zaks
c1537fdcdd Reject explicit uses of CFRetain/CFRelease/CFAutorelease
Ban use of CFRetain, CFRelease, CFAutorelease used for manual memory management as well as a bunch of other similar APIs, such as CGColorRelease.
Addresses radar://16892185

Swift SVN r19552
2014-07-04 02:29:05 +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
Joe Groff
ce9802c5a5 ClangImporter: Allow unions and structs with bitfields to be imported.
We still don't import the fields of unions or bitfields, but we want to at least be able to represent the types so that APIs using the types can be used from Swift. IRGen should be able to produce the correct layout for these types even if all of their fields don't get reflected into Swift.

Swift SVN r19529
2014-07-03 21:15:29 +00:00
Ted Kremenek
04095fb5aa *Start* importing more availability information from the SDK.
This is a WIP.  This patch includes:

- Adds version tuple information for 'introduced', 'deprecated',
  and 'obsoleted' to the 'availability' attribute.

- Add Clang importer support to import __attribute__((availability))
  version tuples into Swift as pieces of the 'availability'
  attribute.

- Add serialization support for the 'availability' attribute with
  this extra information.  This is not tested other than the
  tests currently passing.  This is not expected to be
  really exercised (with interesting versions) until
  parsing support is added for the version tuples.  However,
  existing @availability attributes in the test suite are being
  serialized, which should just include "empty" version information.

What's not in this patch:

- Parsing support in Swift for 'deprecated', 'introduced', or
  'obsoleted'.  All of this information is currently being pulled
  in from the Clang Importer.

- Warning support for using deprecated declarations based on the
  availability information and the minimum deployment target.

- Some harmony reconciling the 'IsUnavailable' field in
  AvailabilityAttr, which attempts to eagerly compute if something
  is unavailable so we don't have to replicate the checking logic
  elsewhere.  The idea is that when we either import availability
  information or lazily deserialize it we can compute whether or
  not something is conditionally unavailable or deprecated right
  there, and not have to have all clients within the frontend
  of the availability information need to pass the minimum
  deployment target.  Right now 'IsUnavailable' is also used
  to encode if the attribute represents unconditional unavailability,
  e.g. @availability(*, unavailable).

This patch, however, should contain enough information to start
looking at implementing weak linking support.

NOTE: the serialization of the attribute is a bit ugly.  I wasn't
certain if Jordan's serialization meta-programming supported
serializing values that decomposed into multiple values in a record,
so this ugly macro-based implementation is in place which compacts
all the version tuple information for an availability attribute
into a single record.

Swift SVN r19487
2014-07-02 23:13:14 +00:00
Ted Kremenek
5ecbad667a Instead of defining __swift__, rely on the 'annotate' attribute to define custom unavailability in Swift (v1).
Swift SVN r19482
2014-07-02 20:59:14 +00:00
Jordan Rose
1b7a384252 Fix a multitude of issues with extensions exposed to Objective-C (r19116).
- Category names weren't unique.
- We were using an attribute to detect if something was a Swift category,
  but attributes can't be used on categories.
- The test that this was all working was failing in a way that wasn't caught.

To solve these problems:

- We're using a macro to generate category names based on __LINE__ in addition
  to the current module.
- The importer uses the macro to detect that the category comes from Swift
  (no attribute needed).
- The test now has a deliberate error for -verify to catch.

<rdar://problem/17342287&17538553>

Swift SVN r19479
2014-07-02 20:35:25 +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
Jordan Rose
347f330d15 Don't import the ObjC representation of Swift extensions in frameworks.
Because extensions don't have any identity we can check against, we can't
tell when we see an Objective-C category if it came from a Swift extension.
Change PrintAsObjC to mark all such categories with SWIFT_EXTENSION, and
just skip them unilaterally when importing Objective-C code.

Also, actually give Swift extensions a name when writing them as Objective-C
categories. Previously, they were nameless categories ("class extensions"),
but methods in a class extension are supposed to be implemented in the class's
main @implementation, so people were getting unexpected warnings about missing
implementations.

<rdar://problem/17342287>

Swift SVN r19116
2014-06-24 01:23:00 +00:00
Joe Pamer
cc6e3e8d03 Fix some issues with type checking indirectly recursive protocol requirements
These changes prevent a certain class of bogus errors, as well as several crashers. Unfortunately, though, they don't quite get us to the point where we can broadly use recursively defined protocol requirements, in the standard library.  (To do so would require significant changes across the entire stack.)

Swift SVN r19019
2014-06-20 00:06:14 +00:00
Chris Lattner
60fc0e6cd2 Implement <rdar://problem/16951729> nil should be a literal type
This is all goodness, and eliminates a major source of implicit conversions.
One thing this regresses on though, is that we now reject "x == nil" where
x is an option type and the element of the optional is not Equtatable.  If
this is important, there are ways to enable this, but directly testing it as
a logic value is more straight-forward.

This does not include support for pattern matching against nil, that will be
a follow on patch.



Swift SVN r18918
2014-06-15 22:59:03 +00:00