Commit Graph

514 Commits

Author SHA1 Message Date
Robert Widmann
e15e293eed Don't flatten input types in ObjC representation check
Arguments of tuple type are not representable in Objective-C but the
old check was looking specifically for them.
2018-06-12 15:13:13 -07:00
Jordan Rose
d734ce800c [PrintAsObjC] Sort imports alphabetically. (#15899)
This ensures that 'Foo' always gets imported before 'Foo_Private'.
This shouldn't strictly be necessary but does end up with more
reliable results in practice.

rdar://problem/36159006
2018-04-12 20:57:42 -07:00
Jordan Rose
1b1a4cb22e [PrintAsObjC] Use enum_extensibility to represent @_frozen
Previously (a03c40cb2c) we assumed all Swift enums were non-frozen in
ObjC, a weird choice in retrospect. Now that we actually distinguish
frozen and non-frozen enums in Swift, we can use the
'enum_extensibility' attribute to mark them as open or closed in ObjC.

Note that this only matters for Swift libraries compiled with
-enable-resilience, i.e. those that might get a new implementation at
runtime. Everyone else is now declaring a "closed" enum, matching the
behavior in Swift.
2018-03-20 14:49:11 -07:00
Jordan Rose
520d6b9b91 Make NS_TYPED_ENUMS ObjectiveCBridgeable when they wrap an object (#15270)
This allows them to be used in generic arguments for NSArray et al.
We already do this for the ones that wrap bridged values (like
NSString/String), but failed to do it for objects that /weren't/
bridged to Swift values (class instances and protocol compositions),
or for Error-which-is-special.

In addition to this being a sensible thing to do, /not/ doing this led
to IRGen getting very confused (i.e. crashing) when we imported a
Objective-C protocol that actually used an NS_TYPED_ENUM in this way.

(We actually shouldn't be using Swift's IRGen logic to emit protocol
descriptors for imported protocols at all, because it's possible we
weren't able to import all the requirements. But that's a separate
issue.)

https://bugs.swift.org/browse/SR-6844
2018-03-15 16:17:38 -07:00
Doug Gregor
02f3c1626e Allow ownership keywords on properties in @objc protocols.
Ownership keywords (weak/unmanaged) in @objc protocols do have an
effect on the generated header, because they get reflected as
weak/assign in the Objective-C `@property`. Therefore, allow these
keywords (again) on properties of @objc protocols.

Fixes SR-7182 / rdar://problem/38418112.
2018-03-15 11:28:01 -07:00
Sho Ikeda
b68be20e9d [test][gardening] Prefer os(macOS) over os(OSX) 2018-03-11 10:58:58 +09:00
Saleem Abdulrasool
b67d5f0cf7 test: convert rm -rf && mkdir -p into %empty-directory
This converts the instances of the pattern for which we have a proper
substitution in lit.  This will make it easier to replace it
appropriately with Windows equivalents.
2018-03-06 14:30:54 -08:00
Stephan Tolksdorf
2a5135b4fc [PrintAsObjC] Test that SWIFT_METHOD_FAMILY is not printed for non-initializer methods with inferable method families 2018-02-25 17:13:06 +01:00
Tapan Thaker
bb6db49f80 [PrintAsObjC] Fixes [SR-6884]. Prints availability information for properties. (#14561) 2018-02-13 18:09:29 -08:00
Mark Lacey
5b7ebd7c4f IUO: Updates to PrintAsObjC to use the decl attribute for IUO.
Use the attribute to update the OptionalTypeKind used for various
decls that we print.

I added test cases to make sure we were exercising all the modified
code paths.
2018-01-11 23:48:32 -08:00
Jordan Rose
9a9ea6915f [PrintAsObjC] Downgrade +new unavailability to deprecation in Swift 4
The general policy has been that even if something crashes at run
time, we don't make it a hard error in Swift 4 mode (or Swift 3 mode!)
if it wasn't a hard error in Swift 4.0 (3.0). In this case, we thought
we could get away with it, and then it turns out it actually caused
some problems. (And as 2bc010681 shows, we can still make mistakes.)

This change isn't perfect because the diagnostic appears in /clients/
rather than in the module that's being compiled as Swift 4 (instead of
Swift 5). But it still means that someone who hasn't changed
/anything/ from a valid Swift 4.0 project will be able to compile
without any changes, even if they were relying on being able to call
+new when -init was unavailable for some reason.

More rdar://problem/35942058
2017-12-13 17:59:55 -08:00
Jordan Rose
7493eccaa9 [PrintAsObjC] Include a message when making +new unavailable
Another follow-up to 49c65facc9. We've seen a few people run into
this and not know what changed.

rdar://problem/35942058
2017-12-13 17:59:55 -08:00
Jordan Rose
2bc0106810 [PrintAsObjC] Reintroduce +new when reintroducing -init. (#13320)
Follow-up to 49c65facc9 to account for subclasses. An unavailable
-init makes +new unavailable, but reintroducing it in a subclass
should reintroduce +new if the root class is NSObject (where +new is
implemented).

rdar://problem/35914080
2017-12-07 15:15:43 -08:00
Jordan Rose
34e602b93a [PrintAsObjC] Don't define char{16,32}_t in C++-pre-11 (#12537)
Turns out libc++ already defines compatibility typedefs in this case,
and we don't care about any other C++ stdlibs on Apple platforms at
the moment.

rdar://problem/34861807
2017-10-23 10:46:01 -07:00
Jordan Rose
01add3aec1 [PrintAsObjC] Defend against macros named 'any' (#12396)
SourceKit uses a clever pragma to automatically attach an attribute to
every declaration in the file. However, the form of this pragma (clang
attribute push) uses a parenthesized list marked with 'any', which turns
out to be a name that people sometimes use for macros. Guard against this
using the push_macro pragma (originally from MSVC), under the assumption
that anyone who supports the highly-use-specific 'external_source_symbol'
attribute probably implements this more common extension. This does make
the generated header a little uglier, but it's not like it was really
pretty to begin with.

rdar://problem/34168022
2017-10-12 13:39:07 -07:00
Javier Soto
49c65facc9 [PrintAsObjC] Attempt at fixing SR-5018: marking +new unavailable when -init is unavailable.
Currently a loop-hole exists by which one could end up invoking an unavailable -init initializer from Obj-C
when it is unavailable by using +new (which itself calls -init)

https://bugs.swift.org/browse/SR-5018
2017-10-05 16:54:55 -07:00
Jordan Rose
0a2e8eb452 [PrintAsObjC] Include messages for platform always-unavailable decls.
A misplaced brace left the messages in empty space. Noticed by
inspection.
2017-08-08 17:25:04 -07:00
Jordan Rose
191e2767ab [PrintAsObjC] Print availability on classes, protocols, and categories
Now that Clang has availability diagnostics too
(-Wpartial-availability and friends) we need to get this correct, or
people will get warnings in the generated header!

rdar://problem/33313703
2017-08-08 17:25:04 -07:00
Rintaro Ishizaki
3337d0330f [test] Add missing ':' for FileCheck directives (#10572)
In FileCheck tests, check prefixes must be immediately followed by ':'.
2017-06-27 07:25:07 +09:00
Jordan Rose
bd0cb3de8a [PrintAsObjC] Silence -Wnullability for the generated declarations. (#10247)
Since Swift 3 and Swift 4 might have different views of an Objective-C
API's nullability, we can end up with incompatible overrides,
including with inherited initializers. This is unfortunate but also
realistic; the Swift 3 code is /not/ set up to handle the new nullability
used by Swift 4 and Objective-C. Just silence the warning.

(It would be nice to not print inherited initializers at all, but that
would mean making sure there are no convenience initializers we have
to print as well. Otherwise the class would get mistaken for one
without explicit designated initializers.)

rdar://problem/32571301
2017-06-14 13:50:06 -07:00
Robert Widmann
71bf312a25 Migrate the rest of the tests to %empty-directory 2017-06-04 11:08:39 -07:00
Dmitri Gribenko
984210aa53 tests: replace '// RUN: rm -rf' '// RUN: mkdir' pairs with '%empty-directory(...)'
These changes were made using a script.
2017-06-04 11:08:39 -07:00
Dmitri Gribenko
486cab447d tests: replace 'rm -rf %t && mkdir -p %t' with '%empty-directory(%t)'
These changes were made using a script.
2017-06-04 11:08:39 -07:00
Jordan Rose
eb9f047ad8 [PrintAsObjC] Handle the importer's compatibility typealiases. (#10042)
These are TypeAliasDecls whose Clang nodes are not TypedefNameDecls.
This worked all right for classes, but dropped the tag keyword
(e.g. 'struct') for tag decls with names of their own, and didn't
print any name at all for C types that used the
typedef-for-anonymous-tag pattern.

rdar://problem/32514335
2017-06-01 15:28:44 -07:00
Doug Gregor
1063b4b5fc [SE-0160] [PrintAsObjC] Adopt Clang's new diagnose_if attribute.
When available, use Clang's new diagnose_if attribute to mark
Objective-C methods/properties that were generated based on the @objc
inference rules that have been removed from Swift 4. The diagnose_if
warnings aren't likely to be accidentally disabled or hidden by other
deprecated code.

Fixes rdar://problem/32370734.
2017-05-23 22:08:11 -07:00
Doug Gregor
b610a509fc [PrintAsObjC] Handle typealiases to non-type Clang declarations.
For historic reasons, Clang's representation of an Objective-C class
declaration ObjCInterfaceDecl) and compatibility alias
(ObjCCompatibleAliasDecl) are not actually Clang TypeDecl nodes. Cope
with this in Objective-C printing, fixing rdar://problem/32308192.
2017-05-19 21:57:41 -07:00
Jordan Rose
2e47272ad3 [PrintAsObjC] Don't warn about inferred '@objc' in Swift 3 mode. (#9756)
Only do so in modes where '@objc' /is/ inferred but we're supposed to
warn about it. Neither plain old Swift 3 nor plain old Swift 4 are in
this state, but we have frontend options that allow us to set that up
for migration purposes.

rdar://problem/32284936
2017-05-19 07:33:13 -07:00
Huon Wilson
1c82b7d3f5 [ClangImporter] Don't resugar NSPointer for the error out parameter of throws functions.
This breaks a cycle with a function in Foundation, but isn't a complete
fix: it will be similarly problematic if a function that can't have the
throws conversion is added.
2017-05-18 17:51:03 -07:00
Slava Pestov
e3b68e7bdd Remove -enable-experimental-subclass-existentials staging flag 2017-04-27 20:46:37 -07:00
Argyrios Kyrtzidis
28b15852d8 Fix tests due to clang namespacing USR changes 2017-04-24 17:42:36 -07:00
Argyrios Kyrtzidis
0efba5f0e9 [PrintAsObjC] Make sure the preprocessor checks work in a compiler different than clang
The C preprocessor rules don't short-circuit so "#if defined(__has_feature) && __has_feature(modules)" will always fail if '__has_feature' is not defined.
2017-04-21 12:00:21 -07:00
Slava Pestov
dc1e681ca4 PrintAsObjC: Support for subclass existentials 2017-04-12 22:24:21 -07:00
Slava Pestov
75190c7060 PrintAsObjC: Drop redundant protocols from inheritance clauses
There was a FIXME for that. Seems easy enough to address,
please shout if this breaks anything.
2017-04-12 22:24:20 -07:00
Doug Gregor
6d1bc9cf03 [SE-0160] Add “deprecated” attributes to the generated headers for Swift 3 inferred @objc.
When Swift 3 infers @objc using one of the rules deprecated in Swift 4, add a “deprecated” attribute to the declarations generated Objective-C header so that Objective-C gets warnings for uses of these APIs.
2017-03-31 21:22:15 -07:00
Doug Gregor
80e9491fe3 Make Swift-3-inferred @objc explicit in test cases 2017-03-31 21:22:15 -07:00
Caleb Davenport
5e5b1540eb Restore test to ensure an extended imported class is not redefined. 2017-03-06 16:46:31 -05:00
Caleb Davenport
617167ad96 Remove redundant protocol conformance test.
This test was designed to ensure that extensions that only add a
non-objc-compatible protocol are not printed in a compatibility header.
That case is already covered by the `extension NSString : NotObjC {}`
test in `PrintAsObjC/protocols.swift`.
2017-03-06 16:37:27 -05:00
Caleb Davenport
46475c8257 Add a few more failing tests.
- Extension that only contains non-objc-compatible members
- Extensions that only add non-objc-compatible protocol conformances
2017-03-06 15:46:48 -05:00
Caleb Davenport
cf420e4012 Add failing tests. 2017-03-05 18:22:43 -05:00
Jordan Rose
79b5ea022d [PrintAsObjC] Handle generic parameters in extensions. (#7818)
Most of the time, "generics" means "cannot be exposed to Objective-C"
and certainly "cannot be exposed in the generated header", but there
is one exception: imported Objective-C parameterized types, and their
extensions. We were previously dropping this on the floor and printing
`Foo</* BarType */>` in the generated header, which is nonsense.

https://bugs.swift.org/browse/SR-3480
2017-02-28 12:52:10 -08:00
Xi Ge
143c5a5d82 Address @jrose-apple's code review comments (#7474) 2017-02-14 18:41:21 -08:00
Rintaro Ishizaki
f02c155864 [PrintAsObjC] Add return type related attributes to '_cdecl' global functions
Additionally, Print '(void)' instead '()' for functions that takes no arguments.
2017-01-30 13:56:19 +09:00
Rintaro Ishizaki
4f51f7535f [PrintAsObjC] Add '__attribute__((return))' for 'Never' return methods
* Add 'SWIFT_NORETURN' macro to the prologue. This macro is evaluated to
  '__attribute__((noreturn))' where supported.
* Apply 'SWIFT_NORETURN' to 'isUninhabited()' methods.
2017-01-30 13:40:46 +09:00
Rintaro Ishizaki
dd8531e37b Merge pull request #5542 from danielmartin/fix-SR-2860
[SR-2860] Change the way comments are exported to Doxygen
2017-01-16 23:11:11 +09:00
Daniel Martín
d510793566 Fix SR-2860 2017-01-16 09:39:36 +01:00
Jordan Rose
33ed767933 [ClangImporter] Preserve the names of imported ObjC properties. (#6182)
This is necessary for proper working of #keyPath, as well as improving
the experience of PrintAsObjC.

rdar://problem/28543037
2017-01-10 13:37:12 -08:00
Daniel Martín
4ce3070133 Add test case that reproduces bug SR-2860 2017-01-07 18:09:21 +01:00
Christopher Rogers
a33aed0180 [PrintAsObjC] Inline code segments in documentation should remain inline. (#6625)
Fixes <https://bugs.swift.org/browse/SR-3163>.
2017-01-06 17:21:59 -08:00
Kevin Ballard
1b5adb7568 Merge pull request #6480 from kballard/objc-availability-attributes
[PrintAsObjC] Add availability attributes to Obj-C declarations
2017-01-04 14:07:13 -08:00
Kevin Ballard
0aa751d228 [PrintAsObjC] Add availability attributes to Obj-C declarations 2017-01-04 11:43:00 -08:00