Commit Graph

386 Commits

Author SHA1 Message Date
Caleb Davenport
f203c372c1 Change conditions under which an extension is considered empty.
- Empty extensions add no Objective-C compatible members or protocols
2017-03-06 15:48:54 -05:00
Caleb Davenport
47e698e519 Restore empty extensions when they add protocol conformances. 2017-03-05 23:12:13 -05:00
Caleb Davenport
a4749a2f1a Remove empty extensions from Swift compatibility headers. 2017-03-05 23:12:00 -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
Nathan Hawes
444775f58a Merge pull request #7670 from nathawes/rdar16271632
Use clang-style USRs for swift decls that are exposed to Objective C
2017-02-21 17:00:28 -08:00
Nathan Hawes
c9758c2c0f Use clang-style USRs for swift decls that are exposed to Objective C 2017-02-21 09:42:33 -08:00
Doug Gregor
042e6510c3 [AST] Drop ProtocolDecl's "inherited protocols" list.
The list of directly inherited protocols of a ProtocolDecl is already
encoded in the requirement signature, as conformance constraints where
the subject is Self. Gather the list from there rather than separately
computing/storing the list of "inherited protocols".
2017-02-20 09:41:00 -08:00
Xi Ge
03a17e1f06 Cleanup: Move Swift to ObjC name translation API to libAST to allow larger audience body. NFC (#7586) 2017-02-17 22:09:25 -08:00
Xi Ge
143c5a5d82 Address @jrose-apple's code review comments (#7474) 2017-02-14 18:41:21 -08:00
Xi Ge
055da1fbfb [SourceKit] Teach name translation request to translate Swift names to ObjC ones (by using PrintAsObjC). (#7449) 2017-02-14 14:25:52 -08:00
Slava Pestov
a16faae73b AST: Move ProtocolConformance::getTypeWitnessByName() to ProtocolConformanceRef
I need to move some #includes around ("include what you use") to
break circularities for an upcoming refactoring.
2017-02-08 15:33:46 -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
Slava Pestov
c86b5ae427 AST: Header file gardening - include what you use 2017-01-19 20:07:06 -08:00
Brian Gesiak
663b92ece9 [AST] Completely replace Module with ModuleDecl
The typedef `swift::Module` was a temporary solution that allowed
`swift::Module` to be renamed to `swift::ModuleDecl` without requiring
every single callsite to be modified.

Modify all the callsites, and get rid of the typedef.
2017-01-08 00:36:08 -05:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
practicalswift
89c3514be8 [gardening] NULL → nullptr 2017-01-06 16:37:34 +01: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
Jordan Rose
b1c793e086 [PrintAsObjC] Special-case <os/object.h> types, like Dispatch. (#6544)
These have historically been defined as protocols in Objective-C
(under a pile of macros), but when imported into Swift they're classes
instead. Reverse this bit of magic by hard-coding the prefix "OS_" and
the header <os/object.h>, and emitting the classic 'foo_bar_t'-style
type names.

rdar://problem/29790636
2017-01-04 08:37:03 -08:00
Slava Pestov
2c7aae4128 Sema: 'Never'-returning functions can be represented in Objective-C
Fixes <https://bugs.swift.org/browse/SR-3203>.
2017-01-03 20:13:42 -08:00
Kevin Ballard
2a8a70b1af [PrintAsObjC] Add SWIFT_METHOD_FAMILY(init) when required
Initializers that don't look like init methods to ARC need to have
`SWIFT_METHOD_FAMILY(init)`.

Also tighten up the check for init-like methods to not consider e.g.
`initializeFoo` to be an init-like method.
2016-12-21 17:50:49 -08:00
practicalswift
38be6125e5 [gardening] C++ gardening: Terminate namespaces, fix argument names, ...
Changes:
* Terminate all namespaces with the correct closing comment.
* Make sure argument names in comments match the corresponding parameter name.
* Remove redundant get() calls on smart pointers.
* Prefer using "override" or "final" instead of "virtual". Remove "virtual" where appropriate.
2016-12-17 00:32:42 +01:00
Slava Pestov
2c6b9f71b6 AST: Change TypeAliasDecls to store an interface type as their underlying type
- TypeAliasDecl::getAliasType() is gone. Now, getDeclaredInterfaceType()
  always returns the NameAliasType.

- NameAliasTypes now always desugar to the underlying type as an
  interface type.

- The NameAliasType of a generic type alias no longer desugars to an
  UnboundGenericType; call TypeAliasDecl::getUnboundGenericType() if you
  want that.

- The "lazy mapTypeOutOfContext()" hack for deserialized TypeAliasDecls
  is gone.

- The process of constructing a synthesized TypeAliasDecl is much simpler
  now; instead of calling computeType(), setInterfaceType() and then
  setting the recursive properties in the right order, just call
  setUnderlyingType(), passing it either an interface type or a
  contextual type.

  In particular, many places weren't setting the recursive properties,
  such as the ClangImporter and deserialization. This meant that queries
  such as hasArchetype() or hasTypeParameter() would return incorrect
  results on NameAliasTypes, which caused various subtle problems.

- Finally, add some more tests for generic typealiases, most of which
  fail because they're still pretty broken.
2016-12-15 22:46:15 -08:00
Slava Pestov
a384b2a677 Don't call VarDecl::getType() on deserialized VarDecls 2016-12-15 22:46:15 -08:00
Tim Bodeit
260aa33317 [PrintAsObjC] Emit non @discardableResult methods as warn_unused_result
* Add `SWIFT_WARN_UNUSED_RESULT` macro to prologue.
  Evaluates to `__attribute__((warn_unused_result))` where supported.
* Emit `SWIFT_WARN_UNUSED_RESULT` attribute in generated ObjC headers
  for all non-void methods, that don't have an @discardableResult
  attribute.
  Attribute is not emitted for initializers. Attribute is also not
  emitted where the error convention leads to a return value for an
  otherwise void returning method.
2016-12-09 23:38:17 +01:00
Slava Pestov
f3c72d8941 AST: Remove SubstitutedType 2016-12-07 17:03:07 -08:00
Hugh Bellamy
9fd55c7d0b Fix errors and warnings building swift/PrintAsObjc on Windows using MSVC 2016-12-02 14:04:34 +00:00
Slava Pestov
2d83a79c2c AST: Remove TypeDecl::getDeclaredType()
A pointless use of polymorphism -- the result values are not
interchangeable in any practical sense:

- For GenericTypeParamDecls, this returned getDeclaredInterfaceType(),
  which is an interface type.

- For AssociatedTypeDecls, this returned the sugared AssociatedTypeType,
  which desugars to an archetype.

- For TypeAliasDecls, this returned TypeAliasDecl::getAliasType(),
  which desugars to a type containing archetypes.

- For NominalTypeDecls, this returned NominalTypeDecl::getDeclaredType(),
  which is the unbound generic type, a special case used for inferring
  generic arguments when they're not written in source.
2016-12-01 13:00:18 -08:00
Slava Pestov
f875aa5fcf PrintAsObjC: getType() => getInterfaceType() 2016-11-29 03:05:27 -07:00
Slava Pestov
f6e692198c AST: Remove FuncDecl::getResultType() 2016-11-29 03:05:23 -07:00
Graydon Hoare
7c1dc18b64 Revert "Give all declarations an explicit interface type" 2016-11-24 09:55:27 -08:00
Slava Pestov
5b8524a9d1 AST: Remove FuncDecl::getResultType() 2016-11-24 02:35:35 -05:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Doug Gregor
e045429471 [Type Checker] Improve interface to TypeChecker::conformsToProtocol().
This function had a weird, pre-ProtocolConformanceRef interface that
returned true when the type conformed to the protocol, then had a
separate indirect return value for the concrete conformance (if there
is one). Refactor this API, and the similar
TypeChecker::containsProtocol(), to produce an optional
ProtocolConformanceRef, which is far more idiomatic and easier to
use. Push ProtocolConformanceRef into a few more places. Should be NFC
2016-11-14 16:00:58 -08:00
Jordan Rose
7add05fa38 [PrintAsObjC] Use of imported generics require the full definition. (#5518)
I'm not sure why this didn't occur to me in 8282160d: of course if you
see a generic type with arguments, you need to see the @interface for
that type in order to supply the arguments. Maybe I was thinking the
generated interface would automatically import anything the module
itself imports, but that hasn't ever been true.

rdar://problem/28738008
2016-10-31 10:34:25 -07:00
Graydon Hoare
8970d44675 Add "-swift-version <n>" that sets LangOpts.EffectiveLanguageVersion.
This flag switches the "effective language version" of the compiler,
at least to any version supported (as of this change: "3" or "3.0").

At the moment nothing uses it except the language version build
configuration statements (#if swift(...)) and various other places
that report, encode, or otherwise check version numbers.

In the future, it's intended as scaffolding for backwards compatibility.

Fixes SR-2582
2016-09-20 15:11:37 -07:00
Jacob Bandes-Storch
89d0d62bd6 [PrintAsObjC] print __attribute__((noescape)) in Obj-C headers (#4438)
https://bugs.swift.org/browse/SR-2406
2016-08-31 09:27:59 -07:00
Doug Gregor
51529ae888 Eliminate the -enable-id-as-any flag; it's always on now anyway.
Simplify e.g., ASTContext::getBridgedToObjC(), which no longer needs
the optional return.

Eliminate the now-unused constraint kind for checking bridging to
Objective-C.
2016-08-19 21:17:09 -07:00
Slava Pestov
677e72a9c4 AST: Remove GenericParamList::getPrimaryArchetypes(), NFC 2016-08-18 18:43:41 -07:00
Jordan Rose
ea4d110146 [PrintAsObjC] Handle typealiases in ObjC generics.
More specifically, don't try to emit a definition for them. Just fall
through to what we do for forward-declarations...which also needed some
fixing, to make sure we don't use a Swift typealias as its underlying
type but never import the underlying type.

https://bugs.swift.org/browse/SR-2352
2016-08-16 11:09:49 -07:00
Jordan Rose
5e06eb28df [PrintAsObjC] Assert on types we don't expect in @objc methods.
No intended functionality change, because we shouldn't see any of
these types. Should help prevent errors like the previous commit.
2016-08-10 19:45:51 -07:00
Jordan Rose
ca009b7604 [PrintAsObjC] Handle forward-declarations for 'Class <SomeProto>'.
rdar://problem/27746149
2016-08-10 19:45:51 -07:00
Jordan Rose
8282160de8 [PrintAsObjC] Handle circularities introduced by ObjC generics.
Like Swift generics, Objective-C generics may have constraints; unlike
Swift generics, Objective-C doesn't do separate parsing and
type-checking passes. This means that any generic arguments for
constrained generic parameters must be fully-defined, in order to
check that they satisfy the constraints.

This commit addresses this problem with three different mechanisms,
one for each kind of declaration that might run into this issue:

- For classes, if a member references a type with constrained generic
  parameter, and the corresponding argument type hasn't been printed
  yet, that member is "delayed", which means it is put into a category
  at the end of the file.

- Protocols cannot have categories, so for protocols we instead see if
  we can print the definition of the other type first. To break
  circular dependencies, the printer will not attempt this if both the
  type and the protocol are already being depended on. This isn't
  perfect (see below).

- Rather than delaying members of extensions, we just delay them
  wholesale. This keeps related members together, but also has
  problems (see below).

These approaches solve the most common cases while still not crashing
in the uncommon ones. However, there are still a number of problems:

- The protocol heuristic is overly negative, which means we may generate
  an invalid header even when there's a reasonable ordering. For example,
  a single class might inherit from a class A and conform to protocol P,
  and protocol P depends on class A as a generic argument. In this case,
  defining class A first is the right thing to do, but it's possible for
  the printer to decide that there's circularity here and just forward-
  declare A instead.

- Protocols really can be circular. This can be fixed by printing a
  forward-declared protocol alongside the generic constraints, i.e.
  'id <MoreThanNSCopying, NSCopying>' instead of just
  'id <MoreThanNSCopying>'.

- Extensions can introduce protocols as well. This is not modeled at
  all; if a member depends on a protocol conformance, it's assumed
  that simply printing the class would be sufficient. This could be
  fixed by checking how a generic argument satisfies its constraints,
  possibly delaying individual members from extensions in order to
  print them sooner.

- More cases I haven't thought about.

Test cases for some of these problems are in the new
circularity-errors.swift file, mostly to make sure the ObjC printer
doesn't crash when it encounters them.

rdar://problem/27109377
2016-08-09 10:41:09 -07:00
Jordan Rose
02d2517866 [PrintAsObjC] Hack: Assume all option sets have typedefs. (#3851)
...because otherwise option sets that get imported as members using
NS_SWIFT_NAME are printed with an 'enum' tag, and the definition of
NS_OPTIONS only declares the typedef under C++.

We should come back and figure out something more principled for this
later, but for now this solves an issue with generated headers
imported into C++ translation units.

rdar://problem/27130343
2016-08-03 13:03:50 -07:00
Mishal Shah
8d854d24b5 Merge pull request #3918 from jckarter/printasobjc-crash
PrintAsObjC: Handle new upper bounds of Array/Dictionary/Set correctly.
2016-08-02 15:14:38 -07:00
Doug Gregor
6575877124 [@objc checking] Only 'Error' is representable in Objective-C (as 'NSError').
Don't allow types conforming to 'Error' or protocol compositions
involving 'Error' to be reflected in Objective-C. We still allow
bridging conversions, but they are not statically bridged. Fixes
SR-2249/rdar://problem/27658940.
2016-08-02 10:13:54 -07:00
Joe Groff
cfcb6ea50e PrintAsObjC: Handle new upper bounds of Array/Dictionary/Set correctly.
We would crash because 'Any' doesn't have a corresponding bridged type through the normal bridging mechanism. Handle this correctly, and correctly recognize 'AnyHashable' and 'Any' as the upper bounds of Dictionary, Set, and Array so we present the unqualified NS types in the generated header.
2016-08-02 09:54:22 -07:00
Kevin Ballard
0473e99988 [PrintAsObjC] Add unavailable attribute to unavailable obj-c initializers (#3852)
* [PrintAsObjC] Add unavailable attribute to non-inherited initializers

Initializers that aren't inherited by subclasses cannot be called, so we
should make this visible to Obj-C.

Due to SR-2211, non-inherited convenience initializers do not get this
same treatment.

* [PrintAsObjC] Add unavailable initializers for private overrides

When a public initializer is overridden with a private one, we need to
mark these as unavailable to Obj-C as they're not supposed to be
callable even though they do exist.
2016-08-01 10:06:51 -07:00
Andrew Trick
a18d490d6a Migrate from UnsafePointer<Void> to UnsafeRawPointer. (#3773)
* Migrate from `UnsafePointer<Void>` to `UnsafeRawPointer`.

As proposed in SE-0107: UnsafeRawPointer.

`void*` imports as `UnsafeMutableRawPointer`.
`const void*` imports as `UnsafeRawPointer`.

Occurrences of `UnsafePointer<Void>` are replaced with UnsafeRawPointer.

* Migrate overlays from UnsafePointer<Void> to UnsafeRawPointer.

This requires explicit memory binding in several places,
particularly in NSData and CoreAudio.

* Fix a bunch of test cases for Void->Raw migration.

* qsort takes IUO values

* Bridge `Unsafe[Mutable]RawPointer as `void [const] *`.

* Parse #dsohandle as UnsafeMutableRawPointer

* Update a bunch of test cases for Void->Raw migration.

* Trivial fix for the SceneKit test case.

* Add an UnsafeRawPointer self initializer.

This is unfortunately necessary for assignment between types imported from C.

* Tiny simplification of the initializer.
2016-07-26 14:21:15 -07:00