Commit Graph

258 Commits

Author SHA1 Message Date
Doug Gregor
4f05186b88 [PrintAsObjC] Don't use take an ArrayRef into temporary storage.
ObjCSelector::getSelectorPieces() can return a pointer to *this, so
don't use it on a temporary. Fixes an ASan-detected
stack-use-after-scope, rdar://problem/31837593.
2017-04-26 22:36:23 -07:00
Argyrios Kyrtzidis
28b15852d8 Fix tests due to clang namespacing USR changes 2017-04-24 17:42:36 -07:00
Argyrios Kyrtzidis
093e826f92 [index] Use a #pragma to apply module namespacing for exported ObjC header and match Swift namespaced USRs with the clang side 2017-04-24 14:02:16 -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
Jordan Rose
a03c40cb2c [ClangImporter] Classify enums using flag_enum and enum_extensibility (#8910)
These new Clang attributes identify whether an enum is intended to
represent an option set or not, and whether the set of cases listed in
the enum declaration is exhaustive. (Swift doesn't currently have a
closed/open distinction for enums, so treat any C enum with
enum_extensibility as a proper closed Swift enum, like we do with
NS_ENUM.)

Enums with neither attribute will continue to be imported as unique
types.

rdar://problem/28476618
2017-04-21 08:57:27 -07:00
Slava Pestov
d58f049608 AST: Introduce ASTContext::getAnyObjectType()
This replaces a number of usages of KnownProtocolKind::AnyObject,
which is soon going away.
2017-04-13 21:17:05 -07:00
Slava Pestov
dc1e681ca4 PrintAsObjC: Support for subclass existentials 2017-04-12 22:24:21 -07:00
Slava Pestov
547a4d4af5 PrintAsObjC: Tighten some screws 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
Slava Pestov
4d5e509ed2 PrintAsObjC: We don't need to print metatypes of non-@objc classes
At least, none of the existing tests hit this case.
2017-04-12 22:24:13 -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
Xi Ge
75e191f5ac AST: Summarize a commonly used call chain in AbstractFunctionDecl. NFC (#8424) 2017-03-30 10:51:10 -07:00
practicalswift
430e8d4a62 [gardening] Use "foo && isa<C>(foo)" instead of "dyn_cast_or_null<C>(foo)" when the result is unused 2017-03-28 21:48:53 +02:00
Hugh Bellamy
d9879522fb Fix top of tree Clang unused lambda capture warnings 2017-03-21 19:15:08 +07:00
Slava Pestov
162b2d252e AST: Include gardening to minimize dependencies on Expr.h
A lot of files transitively include Expr.h, because it was
included from SILInstruction.h, SILLocation.h and SILDeclRef.h.

However in reality most of these files don't do anything
with Exprs, especially not anything in IRGen or the SILOptimizer.

Now we're down to 171 files in the frontend which depend on
Expr.h, which is still a lot but much better than before.
2017-03-12 22:26:56 -07:00
Caleb Davenport
f0f3cc4436 Switch from std::copy_if to std::any_of. 2017-03-06 16:30:44 -05:00
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
Michael Gottesman
8437819b5a [CMake] Revert recent changes.
These changes caused a number of issues:

1. No debug info is emitted when a release-debug info compiler is built.
2. OS X deployment target specification is broken.
3. Swift options were broken without any attempt any recreating that
functionality. The specific option in question is --force-optimized-typechecker.

Such refactorings should be done in a fashion that does not break existing
users and use cases.

This reverts commit e6ce2ff388.
This reverts commit e8645f3750.
This reverts commit 89b038ea7e.
This reverts commit 497cac64d9.
This reverts commit 953ad094da.
This reverts commit e096d1c033.

rdar://30549345
2017-02-15 22:26:06 -08:00
Slava Pestov
13d6b183c0 Merge pull request #7370 from llvm-beanz/simplify-add_swift_library
[CMake] Simplify add_swift_library
2017-02-14 19:16:59 -08:00
Xi Ge
143c5a5d82 Address @jrose-apple's code review comments (#7474) 2017-02-14 18:41:21 -08:00
Chris Bieneman
e096d1c033 [CMake] Simplify add_swift_library
This patch splits add_swift_library into two functions one which handles
the simple case of adding a library that is part of the compiler being
built and the second handling the more complicated case of "target"
libraries, which may need to build for one or more targets.

The new add_swift_library is built using llvm_add_library, which re-uses
LLVM's CMake modules. In adapting to use LLVM's modules some of
add_swift_library's named parameters have been removed and
LINK_LIBRARIES has changed to LINK_LIBS, and LLVM_LINK_COMPONENTS
changed to LINK_COMPONENTS.

This patch also cleans up libswiftBasic's handling of UUID library and
headers, and how it interfaces with gyb sources.

add_swift_library also no longer has the FILE_DEPENDS parameter, which
doesn't matter because llvm_add_library's DEPENDS parameter has the same
behavior.
2017-02-14 14:28:10 -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