Commit Graph

386 Commits

Author SHA1 Message Date
Jordan Rose
2b229aa9c7 [PrintAsObjC] Fix infinite loop on typedefs of CFTypeRef.
Swift SVN r31427
2015-08-24 17:48:29 +00:00
Jordan Rose
f2ad7be511 [PrintAsObjC] Add PrettyStackTraces. NFC.
Swift SVN r31314
2015-08-18 22:05:28 +00:00
Jordan Rose
fa2211d834 [PrintAsObjC] Print 'strong' on properties with class type.
...so that our headers can be imported into MRR code.

rdar://problem/17214904

Swift SVN r31230
2015-08-13 22:14:57 +00:00
Jordan Rose
bca4b12f60 [PrintAsObjC] Handle blocks whose parameters come from a typealias.
...instead of crashing.

rdar://problem/21974146

Swift SVN r30753
2015-07-29 04:06:17 +00:00
Jordan Rose
177588d1a8 Only allow collections to contain @objc types in @objc methods and properties.
We allow any array of bridgeable types to be converted to NSArray (and
similar for Dictionary and Set), but to be part of an API is a little
stricter. Previously, '[MySwiftObject]' as a parameter would get exposed
to Objective-C as 'NSArray *', but that's not type-safe at all---and in
corner cases, crashd in the ObjC printer. Now we just don't allow that.

On the plus side, '[Int]' is now exposed as 'NSArray<NSNumber *> *',
which is a fair amount better than just 'NSArray *'.

rdar://problem/19787270

Swift SVN r30719
2015-07-28 18:46:07 +00:00
Jordan Rose
fdc927e8d7 [PrintAsObjC] Add missing SWIFT_COMPILE_NAME for classes renamed with @objc.
This could prevent mixed-source frameworks from being properly imported
into Swift.

rdar://problem/21930630

Swift SVN r30541
2015-07-23 17:28:20 +00:00
Jordan Rose
df93e366f1 [PrintAsObjC] Make sure to use a class's custom name when extended or subclassed.
Otherwise, we end up with an invalid generated header.

rdar://problem/21929752

Swift SVN r30474
2015-07-21 23:56:35 +00:00
Jordan Rose
5f4ad8722f Unmanaged<T> is ObjC-compatible if T is an Objective-C-compatible object type.
rdar://problem/16832080

Swift SVN r30079
2015-07-10 19:05:21 +00:00
Jordan Rose
0b5428fcd3 Import DarwinBoolean as Bool in fully-bridgeable contexts.
These are contexts where we have enough information to bridge /back/
properly; that is, where we can distinguish CBool, ObjCBool, and
DarwinBoolean. In cases where we can't, we keep the three separate;
only CBool is really the same type as Bool.

This also affects current import behavior for ObjCBool, which was previously
incorrectly conflated with CBool in certain cases.

More rdar://problem/19013551

Swift SVN r30051
2015-07-10 01:11:30 +00:00
Jordan Rose
e1ffbbbcf5 Import MacTypes.Boolean as a dedicated DarwinBoolean type.
Like ObjCBool is a legitimate boolean type rather than a typealias for Int8,
DarwinBoolean is better than a typealias for UInt8. It's a BooleanType
(meaning you can use it directly in if/while/?:) and BooleanLiteralConvertible
(meaning you can use 'true' and 'false').

The next commit goes even further, so that you only have to deal with
DarwinBoolean when ABI is important. At all other times it should be
bridged with Bool, just like ObjCBool.

rdar://problem/19013551

Swift SVN r30050
2015-07-10 01:11:25 +00:00
Slava Pestov
f21b67ffe9 Rip out usages of CFunctionPointer in the frontend, NFC
Swift SVN r29991
2015-07-08 20:24:06 +00:00
John McCall
d190ee0767 Honor the swift_error attribute during import.
Add a new convention to describe what happens with
nonzero_result on a type that isn't imported as Bool.
This isn't really a safe convention to implement, but
calls are fine.

Implements <rdar://21715350>.

Swift SVN r29953
2015-07-08 00:57:27 +00:00
Jordan Rose
b4d6a47899 [PrintAsObjC] Use @objc for compile-time names of classes and protocols.
This is half of rdar://problem/17469485. The other half will be
recognizing in the importer that the Objective-C declaration references
a Swift type; see next commit.

Swift SVN r29743
2015-06-26 18:28:48 +00:00
Jordan Rose
f05670bdaa [PrintAsObjC] Avoid using C/C++ keywords in methods and properties.
This very simply avoids printing properties and method arguments whose
names match /any/ keyword recognized by Clang, in any language mode.
That's a bit overkill, but it's easiest to implement. If someone /does/
name their property or argument using a keyword, a single underscore is
appended. That's suboptimal for properties, but better than the "header
fails to parse" alternative.

If you've named your /type/ something that conflicts with C, you deserve
what you get. Mark the thing @nonobjc. (We could actually check this in
Sema, but it's rare enough that I'm going to punt on doing that for now.)

rdar://problem/21060399

Swift SVN r29473
2015-06-18 03:53:07 +00:00
Dmitri Hrybenko
15b0520f4a Remove support for Clang without Objective-C generics
Swift SVN r29074
2015-05-27 20:47:11 +00:00
Jordan Rose
1b8741dc7d Remove references to C{Const,Mutable}VoidPointer and CString.
These types have long since been removed. No functionality change.

Swift SVN r28945
2015-05-23 01:56:15 +00:00
Doug Gregor
b8ad66eb18 PrintAsObjC: Print property getter/setter names when they differ from the defaults.
We were printing getter/setter names when the property came from
Objective-C initially, which is incorrect: we should print them when
the names differ from what Objective-C would compute by default. This
finishes rdar://problem/19408726, which was mostly in place a while
ago.

Swift SVN r28783
2015-05-19 20:38:48 +00:00
Doug Gregor
a6fa12aa79 PrintAsObjC: use getObjCPropertyName() consistently for property name
This is NFC, because we were already properly using
getObjCPropertyName() for the general case. Only the
imported-from-an-NSUInteger property case remained, which will
currently have getName() == getObjCPropertyName(). But, be consistent
to be more future-proof, if renaming of @properties should come.

Swift SVN r28782
2015-05-19 20:38:45 +00:00
Doug Gregor
dd08b8c5ed PrintAsObjC: Stop avoiding using parameterized Foundation collections.
The macro hackery here was staging while we waited for Foundation's
parameterized collections to percolate through the system, then I
forgot about it. Eliminate the hackery so the Objective-C view of
Swift APIs actually produces specialized types such as
NSArray<NSString *> *.

Be a bit more careful when printing parameterized Foundation
collections, to ensure that we only print the type arguments if
they're guaranteed to be printed as object types.

Fixes rdar://problem/20984336.

Swift SVN r28677
2015-05-17 04:35:20 +00:00
Doug Gregor
1bd917e83c Revert "PrintAsObjC: Stop avoiding using parameterized Foundation collections."
This reverts r28650; I've run out of time to fix it tonight.

Swift SVN r28663
2015-05-16 05:54:33 +00:00
Jordan Rose
5eaea5d278 [PrintAsObjC] Expose the domain for @objc enums conforming to ErrorType.
We just use a static string constant for now, which isn't at all resilient.
But it works! Credit to JoeG for coming up with this solution.

Part of rdar://problem/20577517

Swift SVN r28662
2015-05-16 05:35:21 +00:00
Doug Gregor
149ccd1cbe PrintAsObjC: Stop avoiding using parameterized Foundation collections.
The macro hackery here was staging while we waited for Foundation's
parameterized collections to percolate through the system, then I
forgot about it. Eliminate the hackery so the Objective-C view of
Swift APIs actually produces specialized types such as
NSArray<NSString *> *.

Fixes rdar://problem/20984336.

Swift SVN r28650
2015-05-15 23:46:49 +00:00
Doug Gregor
75617df37d PrintAsObjC: Stop printing SWIFT_NULLABILITY(keyword).
Everyone's Clang should support nullability qualifiers now.

Swift SVN r28649
2015-05-15 23:46:46 +00:00
Joe Groff
cef754de45 Update ClangImporter to map SIMD types to their C-like Swift counterparts.
Swift SVN r28386
2015-05-09 23:03:39 +00:00
Joe Groff
95d1cf5e6d Revert "ClangImporter etc.: Remap C vector types to nested BaseType.VectorN types."
Reverts r28087. We're going back to the C++ interface for SIMD, and the changes in this patch are needless complication for that design.

Swift SVN r28384
2015-05-09 23:03:33 +00:00
Doug Gregor
b8995b0aa3 Transform the Module class into ModuleDecl.
Modules occupy a weird space in the AST now: they can be treated like
types (Swift.Int), which is captured by ModuleType. They can be
treated like values for disambiguation (Swift.print), which is
captured by ModuleExpr. And we jump through hoops in various places to
store "either a module or a decl".

Start cleaning this up by transforming Module into ModuleDecl, a
TypeDecl that's implicitly created to describe a module. Subsequent
changes will start folding away the special cases (ModuleExpr ->
DeclRefExpr, name lookup results stop having a separate Module case,
etc.).

Note that the Module -> ModuleDecl typedef is there to limit the
changes needed. Much of this patch is actually dealing with the fact
that Module used to have Ctx and Name public members that now need to
be accessed via getASTContext() and getName(), respectively.

Swift SVN r28284
2015-05-07 21:10:50 +00:00
Joe Groff
d0473756ec ClangImporter etc.: Remap C vector types to nested BaseType.VectorN types.
The design we landed on for SIMD is to define the vector types as nested types of their element, e.g. Float.Vector4, Int32.Vector2, etc. Update the Clang importer and other mapping facilities to match.

Swift SVN r28087
2015-05-02 15:04:43 +00:00
Joe Groff
fbd76737a4 Clang Importer: Rename the special vector type module to "simd".
We want this to act as an overlay/replacement for the C "simd" module.

Swift SVN r28047
2015-05-01 20:11:01 +00:00
David Farler
ca5876a866 swiftMarkup Library
Replace ReST-flavored documentation comments with Markdown.

rdar://problem/20180412

In addition to full Markdown support, the following extensions are
supported. These appear as lists at the top level of the comment's
"document". All of these extensions are matched without regard to
case.

Parameter Outlines
------------------

- Parameters:
  - x: ...
  - y: ...

Separate Parameters
-------------------

- parameter x: ...
- parameter y: ...

- Note:
Parameter documentation may be broken up across the entire comment,
with a mix of parameter documentation kinds - they'll be consolidated
in the end.

Returns
-------

- returns: ...

The following extensions are also list items at the top level, which
will also appear in Xcode QuickHelp as first-class citizens:

- Attention: ...
- Author: ...
- Authors: ...
- Bug: ...
- Complexity: ...
- Copyright: ...
- Date: ...
- Experiment: ...
- Important: ...
- Invariant: ...
- Note: ...
- Postcondition: ...
- Precondition: ...
- Remark: ...
- Remarks: ...
- See: ...
- Since: ...
- Todo: ...
- Version: ...
- Warning: ...

These match most of the extra fields in Doxygen, plus a few more per request.

Other changes
-------------
- Remove use of rawHTML for all markup AST nodes except for those
not representable by the Xcode QuickHelp XSLT - <h>, <hr/>, and of
course inline/block HTML itself.

- Update the doc comment RNG schema to more accurately reflect Xcode
QuickHelp.

- Clean up cmark CMake configuration.

- Rename "FullComment" to "DocComment"

- Update the Swift Standard Documentation (in a follow-up commit)

- Update SourceKit for minor changes and link against cmark
  (in a follow-up commit).

Swift SVN r27727
2015-04-26 00:07:15 +00:00
Joe Groff
58660ec6ba PrintAsObjC: Support for SIMD types.
Splat out a bunch of typedefs for the small vector types we want to support, and map the SIMD.* types to them.

Swift SVN r27385
2015-04-16 22:07:09 +00:00
Doug Gregor
de427fce5d Print throwing @objc methods with the appropriate Objective-C signature.
When printing the Objective-C form of a throwing method, use the
appropriate result type (BOOL, nullable result, etc.) and include the
error parameter. As part of this, refactor the printing loop for
Objective-C method declarations to stop being based on splitting
strings: ObjCSelector has the pieces we need.

Swift SVN r27282
2015-04-14 18:16:18 +00:00
Joe Groff
ec47ebdd3a PrintAsObjC: Handle @convention(c) function types.
Swift SVN r27263
2015-04-13 23:13:14 +00:00
Joe Groff
ad0d20c07a Fold "AbstractCC" into SILFunctionType::Representation.
These aren't really orthogonal concerns--you'll never have a @thick @cc(objc_method), or an @objc_block @cc(witness_method)--and we have gross decision trees all over the codebase that try to hopscotch between the subset of combinations that make sense. Stop the madness by eliminating AbstractCC and folding its states into SILFunctionTypeRepresentation. This cleans up a ton of code across the compiler.

I couldn't quite eliminate AbstractCC's information from AST function types, since SIL type lowering transiently created AnyFunctionTypes with AbstractCCs set, even though these never occur at the source level. To accommodate type lowering, allow AnyFunctionType::ExtInfo to carry a SILFunctionTypeRepresentation, and arrange for the overlapping representations to share raw values.

In order to avoid disturbing test output, AST and SILFunctionTypes are still printed and parsed using the existing @thin/@thick/@objc_block and @cc() attributes, which is kind of gross, but lets me stage in the real source-breaking change separately.

Swift SVN r27095
2015-04-07 21:59:39 +00:00
Doug Gregor
7c4823ec71 Convert PrintAsObjC over to conformance lookup table entrypoints.
Another step toward using the conformance lookup table for
everything. This uncovered a tricky little bug in the conformance
lookup table's filtering logic (when asking for only those
conformances explicitly specified within a particular context) that
would end up dropping non-explicit conformances from the table (rather
than just the result).

Ween a few tests off of -enable-source-import, because they'll break
otherwise.

Swift SVN r27021
2015-04-05 13:44:47 +00:00
Doug Gregor
5c8fde3f2e Make PrintAsObjC more tolerant of non-@objc classes within collections.
Swift's bridged collections are allowed to store objects of non-@objc
classes, e.g., an array of (non-@objc) Swift classes is still bridged
to NSArray. Deal with such cases by printing out the type as "NSArray
*", since we cannot name the type in Objective-C to provide a more
specialized NSArray type.

This is a fairly narrow fix for rdar://problem/20392771 that needs
more discussion.

Swift SVN r26905
2015-04-02 21:56:58 +00:00
Chris Lattner
79ed57f9f2 standardize naming of tuples and tuple patterns on "elements".
Previously some parts of the compiler referred to them as "fields",
and most referred to them as "elements".  Use the more generic 'elements'
nomenclature because that's what we refer to other things in the compiler
(e.g. the elements of a bracestmt).

At the same time, make the API better by providing "getElement" consistently
and using it, instead of getElements()[i].

NFC.



Swift SVN r26894
2015-04-02 20:23:49 +00:00
Jordan Rose
f74bc7122c Split getAccessibility() into getFormalAccess() and getEffectiveAccess().
Currently a no-op, but effective access for entities within the current
module will soon need to take testability into account. This declaration:

  internal func foo() {}

has a formal access of 'internal', but an effective access of 'public' if
we're in a testable mode.

Part of rdar://problem/17732115 (testability)

Swift SVN r26472
2015-03-24 02:16:58 +00:00
John McCall
080b7dfabf Remove the default handle-all Decl and DeclAttribute
cases from ASTVisitor and privatize SILGen's statement
emitter.  NFC.

Swift SVN r26402
2015-03-22 03:22:45 +00:00
Doug Gregor
f6e95b0a34 Fix printing of Objective-C @properties for @objc-renamed properties.
Finishes rdar://problem/19963219.

Swift SVN r25624
2015-02-27 22:54:46 +00:00
Doug Gregor
db51abba9a Fix Objective-C printing of init(forFun: ()) initializers.
This is the rest of rdar://problem/19973250, thank you Jordan!

Swift SVN r25623
2015-02-27 22:54:45 +00:00
Doug Gregor
96a2659223 Serialize initializer stub implementations.
Fixes the cross-module initializer inheritance issues implied by
rdar://problem/19794036.

Swift SVN r25336
2015-02-17 00:38:21 +00:00
Jordan Rose
4d7d6bbfc6 [PrintAsObjC] Don't forward-declare @objc enums using typedefs.
That's a C11 feature, and we can't force everyone to enable C11 just yet.
Instead, go back to the old way of using "enum Foo" to refer to @objc enums
defined in Swift. Just don't do it unilaterally for non-@objc enums.

Should unstick the buildbot.

Swift SVN r25161
2015-02-11 03:15:06 +00:00
Jordan Rose
d397a323a3 [PrintAsObjC] Output nullability for CF types and non-retainable pointers.
For pointer types that Swift doesn't currently import using Optional
(see rdar://problem/15189170 and its dups), use __null_unspecified.

rdar://problem/19775335

Swift SVN r25144
2015-02-10 23:52:48 +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
Doug Gregor
883911c767 Define __null_unspecified to nothing when the underlying Clang doesn't support nullability.
Fixes rdar://problem/19730896.

Swift SVN r25000
2015-02-05 17:35:45 +00:00
Jordan Rose
82c8d9b3dc [PrintAsObjC] Preserve NSUInteger in overridden decls when easy to do.
If a property, method, or subscript overrides an imported property, method,
or subscript that was originally declared using NSUInteger as a property,
parameter, or return type, print the subclass's member using "NSUInteger"
in the generated header to prevent override warnings.

This doesn't handle all cases--in particular, it doesn't handle the
NSUInteger being nested inside a larger type--but it does get the easy
ones correct. I think the easiest way to be more correct would be to mark
NSUInteger-as-Int somehow using a distinct type. (Hidden attribute?
Another typealias? Not sure.)

rdar://problem/19321126

Swift SVN r24771
2015-01-28 01:37:04 +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
fe5fe16c46 PrintAsObjC: Start printing __null_unspecified where needed.
Fixes rdar://problem/19499467.

Swift SVN r24643
2015-01-22 19:26:21 +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
Doug Gregor
b642c555be Allow one to change the argument labels of curried function parameters.
Curried function parameters (i.e., those past the first written
parameter list) default to having argument labels (which they always
have), but any attempt to change or remove the argument labels would
fail. Use the fact that we keep both the argument labels and the
parameter names in patterns to generalize our handling of argument
labels to address this problem.

The IDE changes are due to some positive fallout from this change: we
were using the body parameters as labels in code completions for
subscript operations, which was annoying and wrong.

Fixes rdar://problem/17237268.

Swift SVN r24525
2015-01-19 22:15:14 +00:00