Commit Graph

2546 Commits

Author SHA1 Message Date
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
Joe Groff
4d4a324497 Import Protocol as a foreign class.
In modern ObjC Protocol's object-ness is vestigial, and its class object isn't even visible from newer runtimes, so we can't use it as type metadata. Import it as a foreign class so that we make our own artificial metadata. Fixes <rdar://problem/17303759>.

Swift SVN r18882
2014-06-13 23:07:10 +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
Jordan Rose
577f16c48a [ClangImporter] Import constant globals using 'let' instead of 'var'.
Previously, we considered all imported globals to be mutable, which would
cause problems if you actually tried to change them.

<rdar://problem/17020952>

Swift SVN r18663
2014-05-29 23:04:26 +00:00
Jordan Rose
3ba8808a6f [ClangImporter] When remapping an init method's name, change the selector too.
This is what we use to drop the variadic parameter on UIActionSheet and
UIAlertView's initializers, along with secretly adding a category to each
to provide the one-fewer-parameter init method implementation. However,
we haven't been using the Swift name for the method to generate Objective-C
calls for a while now--we use the @objc attribute. And that was still using
the original selector, and so we crashed.

Fixed by passing the new selector to the @objc attribute.

<rdar://problem/17012323>

Swift SVN r18582
2014-05-23 01:56:56 +00:00
Doug Gregor
67ca1c9ea1 Implement the new casting syntaxes "as" and "as?".
There's a bit of a reshuffle of the ExplicitCastExpr subclasses:
  - The existing ConditionalCheckedCastExpr expression node now represents
"as?". 
  - A new ForcedCheckedCastExpr node represents "as" when it is a
  downcast.
  - CoerceExpr represents "as" when it is a coercion.
  - A new UnresolvedCheckedCastExpr node describes "as" before it has
  been type-checked down to ForcedCheckedCastExpr or CoerceExpr. This
  wasn't a strictly necessary change, but it helps us detangle what's
  going on.

There are a few new diagnostics to help users avoid getting bitten by
as/as? mistakes:
  - Custom errors when a forced downcast (as) is used as the operand
  of postfix '!' or '?', with Fix-Its to remove the '!' or make the
  downcast conditional (with as?), respectively.
  - A warning when a forced downcast is injected into an optional,
  with a suggestion to use a conditional downcast.
  - A new error when the postfix '!' is used for a contextual
  downcast, with a Fix-It to replace it with "as T" with the
  contextual type T.

Lots of test updates, none of which felt like regressions. The new
tests are in test/expr/cast/optionals.swift. 

Addresses <rdar://problem/17000058>


Swift SVN r18556
2014-05-22 06:15:29 +00:00
Argyrios Kyrtzidis
5d2d762cd3 [ClangImporter] A typedef to a typedef should get imported as a typealias.
Swift SVN r18328
2014-05-18 16:08:56 +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
Jordan Rose
3a8208ec17 [ClangImporter] Drop support for @partial_interface.
We're not going to ship this feature.

Swift SVN r18168
2014-05-16 03:49: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
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
7bedd5ca22 Recognize colliding imported constructors properly.
I had gotten the type computation incorrect, causing the
deserialization crashes seen on the buildbot.

Swift SVN r18032
2014-05-13 22:30:19 +00:00
Doug Gregor
d5a9c2ab94 Only supersede initializers with other imported initializers when the types match.
This fixes a case where the Swift-variadic and C-varargs versions of
various initializers were superseding each other
<rdar://problem/16801456>.

It also uncovered some more cases where we weren't getting quite the
right semantics for factory-methods-as-initializers, which are also
fixed here.

Swift SVN r18010
2014-05-13 16:49:39 +00:00
Doug Gregor
9ecb07409b Make the "superseded" diagnostic better.
Users shouldn't actually see this diagnostic, but if it does show up,
it should at least be useful:

error: 'init' is unavailable: superseded by import of
    -[NSArray(NSArrayCreation) initWithObjects:]

Swift SVN r18009
2014-05-13 16:49:36 +00:00
Jordan Rose
5d2ad6c4d9 [ClangImporter] Import known property accessors with consistent types.
Previously, the getter and setter for a property could disagree on what the
"type of the property" was: Unmanaged<CFType> vs. CFType, or COpaquePointer
vs. CMutableVoidPointer. Now, we treat property accessors as distinct from
normal methods when importing their parameter and result types, and have
those types follow the same rules as they would for the property itself.

This will need a bit of cleanup work once we're importing implicit properties
everywhere, but this handles the crashes and unfortunate limitations we were
seeing for WWDC.

<rdar://problem/16544938>

Swift SVN r17987
2014-05-13 01:32:12 +00:00
Doug Gregor
73528dc0e0 Enable importing factory methods as initializers by default.
Finishes <rdar://problem/16509024>.

Swift SVN r17972
2014-05-12 23:01:20 +00:00
Doug Gregor
2702c943aa When determining whether an imported initializer is a designated initializer, use the context it's being imported into.
Previously, we were using the context where the initializer was declared in Objective-C, rather than where it was being imported. This meant that we wouldn't treat an inherited designated initializer as a designated initializer if (for example) the designated-initializer marking came from our internal table of DIs. Fixes <rdar://problem/16838515>.

Swift SVN r17968
2014-05-12 22:47:38 +00:00
Ted Kremenek
6e83fde849 Suggest ".self", not ".Type" (the old name) for +class remapping.
Swift SVN r17884
2014-05-11 20:28:48 +00:00
Ted Kremenek
4479eb85c0 Import +class and -class as unavailable, suggesting ".type" and ".dynamicType" instead.
Implements <rdar://problem/16871007>.

Swift SVN r17883
2014-05-11 20:22:53 +00:00
Joe Groff
3dda4c9cf5 SILGen: Reference ObjC initializers and factories through foreign-to-native thunks.
Eliminate the duplicate half-broken bridging logic in emitClassConstructorAllocator by referencing foreign initializers through their foreign-to-native thunks, which SILGen knows how to emit already. Do the same thing for factory initializers by suppressing their normal allocating initializer codegen and just referencing the usual foreign-to-native thunk for them. This fixes <rdar://problem/16853205> because we get the ownership thunking right now.

Swift SVN r17840
2014-05-10 20:18:53 +00:00
Argyrios Kyrtzidis
19aeaf94fc Fully embrace ParamDecls instead of AnyPattern at function creation time, thus removing the need to create param decls at SILGen or Sema.
Swift SVN r17829
2014-05-10 18:23:50 +00:00
Doug Gregor
d1e8be50be Turn -implicit-objc-with on by default <rdar://problem/16795899>.
Swift SVN r17796
2014-05-09 20:17:42 +00:00
John McCall
03d3cf9c40 Import the formal type of a property as audited if the
corresponding getter method is audited.

There are a host of other potential consistency problems
here, but this should fix a particular egregious one
that was preventing use of NSColor's CGColor property.

rdar://16846555

Swift SVN r17667
2014-05-08 01:32:25 +00:00
John McCall
c03b705dd0 Recognize CF "subclasses" and require CFTypeRef to specifically
be 'const void *', not just any 'void*'.

Swift SVN r17659
2014-05-08 00:51:27 +00:00
Joe Pamer
d22ffa8cb8 Re-lazify the addition of equatable conformances to imported enum types. (rdar://problem/16808612)
Rather than force conformances to Equatable to be added to all imported enumeration types outright, change them back to being lazily added. We can then handle situations where new overloads of '==' are introduced during constraint generation by re-writing the relevant overload disjunction constraint to include the newly forced declarations as bind options.

Swift SVN r17557
2014-05-06 19:56:29 +00:00
John McCall
cbd662632b Import CFTypeRef as AnyObject, but wrap it in Unmanaged<>
in all the situations that we would wrap e.g. CFStringRef.

Swift SVN r17546
2014-05-06 09:34:24 +00:00
John McCall
a83e5740de Import CF types as managed pointers when they are:
- the type of a const global variable
  - the type of a parameter, always
  - the return type of a function that has been audited
    or has an explicit retained/not-retained attribute
  - the return type of an ObjC method that has an explicit
    retain/not-retained/inner-pointer attribute

Additionally, choose the correct conventions for all
these cases during SIL type lowering.

All this importing logic is still only enabled under
-Xfrontend -import-cf-types.

Swift SVN r17543
2014-05-06 08:29:44 +00:00