Commit Graph

53 Commits

Author SHA1 Message Date
Becca Royal-Gordon
da07ff577c [PrintAsClang] Warn about unstable decl order
PrintAsClang is supposed to emit declarations in the same order regardless of the compiler’s internal state, but we have repeatedly found that our current criteria are inadequate, resulting in non-functionality-affecting changes to generated header content. Add a diagnostic that’s emitted when this happens soliciting a bug report.

Since there *should* be no cases where the compiler fails to order declarations, this diagnostic is never actually emitted. Instead, we test this change by enabling `-verify` on nearly all PrintAsClang tests to make sure they are unaffected.

This did demonstrate a missing criterion that only mattered in C++ mode: extensions that varied only in their generic signature were not sorted stably. Add a sort criterion for this.
2025-02-14 21:41:36 -08:00
Karl Wagner
ab4f80ed95 [SE-0404] Allow protocols to be nested in non-generic contexts 2023-10-06 21:04:03 +02:00
Becca Royal-Gordon
8a8e71ea09 Ignore Sendable conformances in PrintAsClang
PrintAsClang previously tried to print Sendable conformances, which tripped an assertion and failed. Skip them instead.

Fixes rdar://95241184.
2022-06-23 13:16:41 -07:00
Becca Royal-Gordon
5459737239 Don’t declare async methods with alternatives in headers
If Swift sees this pattern of methods in an @objc protocol:

```
    func hello() async -> Int

    @available(*, renamed: “hello()”)
    func hello(completion: @escaping (Int) -> Void)
```

Then PrintAsClang will print only the completion-handler-based method, not the async one, into a generated header, on the assumption that the completion-handler method may have greater availability.

Fixes rdar://94175167.
2022-06-16 18:27:12 -07:00
Jordan Rose
0bcf355bc8 [PrintAsObjC] Use 'unsafe_unretained' to print 'unowned', not 'assign'
The ObjC generator previously preserved a subtle difference between
'unowned' and 'unowned(unsafe)' / Unmanaged by printing the former as
'assign' and the latter as 'unsafe_unretained'. Upstream Clang,
however, has gotten a new warning to discourage the use of 'assign'
with reference-countable types at all. Since it was always a subtle
distinction, just go with the new convention and print
'unsafe_unretained' for 'unowned' properties as well.

rdar://problem/44290715
2018-09-10 14:32:32 -07:00
Doug Gregor
f39fe1a755 [Tests] Put NSObject Equatable/Hashable back in the ObjectiveC module.
Technically, these operations belong in the ObjectiveC module, where NSObject
is defined. Keep them there. However, we need to build the mock ObjectiveC
overlay with `-disable-objc-attr-requires-foundation-module` now.
2018-08-01 09:25:28 -07:00
Slava Pestov
5964c00091 Migrate PrintAsObjC tests to Swift 4
I didn't migrate test/PrintAsObjC/versioned.swift, because it
explicitly checks the Swift 3 projection of some APIs.
2018-06-26 16:57:04 -07:00
Slava Pestov
5d2752f7d2 Run tests with -swift-version 4 by default
Some test now fail, so add an explicit -swift-version 3.
2018-06-19 23:24:19 -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
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
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
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
Slava Pestov
e3b68e7bdd Remove -enable-experimental-subclass-existentials staging flag 2017-04-27 20:46:37 -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
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
David Farler
b7d17b25ba Rename -parse flag to -typecheck
A parse-only option is needed for parse performance tracking and the
current option also includes semantic analysis.
2016-11-28 10:50:55 -08:00
Dmitri Gribenko
55864d10cb Tests: use 'mkdir -p' 2016-09-02 21:36:45 -07:00
Dmitri Gribenko
d175b3b66d Migrate FileCheck to %FileCheck in tests 2016-08-10 23:52:02 -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
Joe
a6dad0091b [SE-0095] Initial parsing implementation for '&' composition syntax
This commit defines the ‘Any’ keyword, implements parsing for composing
types with an infix ‘&’, and provides a fixit to convert ‘protocol<>’

- Updated tests & stdlib for new composition syntax
- Provide errors when compositions used in inheritance.
Any is treated as a contextual keyword. The name ‘Any’
is used emit the empty composition type. We have to
stop user declaring top level types spelled ‘Any’ too.
2016-07-19 12:01:02 -07:00
Jorge Bernal
0a3f913b20 SE-0070: Make Optional Requirements Objective-C-only.
Optional protocol requirements now require an explicit @objc attribute.

Fixes SR-1395
2016-05-06 11:05:52 +02:00
Manav Gabhawala
7928140f79 [SE-0046] Implements consistent function parameter labels by discarding extraneous parameter names and adding _ where necessary 2016-04-06 20:21:58 -04:00
Maxim Moiseev
0e54467bfa Final bulk removal of Type suffix 2015-12-16 17:06:19 -08:00
Kevin Ballard
66369468aa Use new-style _Nullable keywords in obj-c header
Use the keywords `_Nullable`, `_Nonnull`, and `_Null_unspecified`
instead of the older compatibility forms `__nullable`, `__nonnull`, and
`__null_unspecified`.

Part of rdar://problem/23614638
2015-12-05 19:54:27 -08: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
8106a11dac Disallow @objc on non-ObjC-rooted classes.
These classes don't show up well in generated headers (rdar://problem/20855568),
can't actually be allocated from Objective-C (rdar://problem/17184317), and
make the story of "what is exposed to Objective-C" more complicated. Better
to just disallow them.

All classes are still "id-compatible" in that they can be converted to
AnyObject and passed to Objective-C, they secretly implement NSObjectProtocol
(via our SwiftObject root class), and their members can still be individually
exposed to Objective-C.

The frontend flag -disable-objc-attr-requires-foundation-module will disable
this requirement as well, which is still necessary for both the standard
library and a variety of tests I didn't feel like transforming.

Swift SVN r29760
2015-06-27 16:27:56 +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
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
Doug Gregor
5de47e93dd Remove uses of getProtocols() from serialization.
NFC except for having to work around the brokenness of
-enable-source-import in more places.

Swift SVN r27979
2015-04-30 16:13:45 +00:00
Doug Gregor
480b6e9af4 Start using DeclContext::getLocalConformances() to decide which conformances get recorded.
Swift SVN r26320
2015-03-19 22:10:04 +00:00
Dmitri Hrybenko
f43843f25c tests: use the new substitution for the mock SDK
This is required to correctly use the mock SDK when the SDK overlay is
built and tested separately.  (Otherwise, the mock SDK might not get
used, because the overlay SDK options would expand from the
%-substitution, appear first on the command line, and shadow the mock
SDK in the search path).

Swift SVN r25185
2015-02-11 18:57:29 +00:00
Graham Batty
83b4384fac Update test flags for linux failures and support.
Also removed the sdk 'feature' in favour of the more specific
objc_interop.

Swift SVN r24856
2015-01-30 21:31:48 +00:00
Dmitri Hrybenko
3b04d1b013 tests: reorganize tests so that they actually use the target platform
Most tests were using %swift or similar substitutions, which did not
include the target triple and SDK.  The driver was defaulting to the
host OS.  Thus, we could not run the tests when the standard library was
not built for OS X.

Swift SVN r24504
2015-01-19 06:52:49 +00:00
David Farler
87c3d7421f Refine static func and var syntax
rdar://problem/17198298

- Allow 'static' in protocol property and func requirements, but not 'class'.
- Allow 'static' methods in classes - they are 'class final'.
- Only allow 'class' methods in classes (or extensions of classes)
- Remove now unneeded diagnostics related to finding 'static' in previously banned places.
- Update relevant diagnostics to make the new rules clear.

Swift SVN r24260
2015-01-08 03:03:29 +00:00
Dmitri Hrybenko
1eea220932 Use one module cache directory for all the lit tests to speed them up
Doing so is safe even though we have mock SDK.  The include paths for
modules with the same name in the real and mock SDKs are different, and
the module files will be distinct (because they will have a different
hash).

This reduces test runtime on OS X by 30% and brings it under a minute on
a 16-core machine.

This also uncovered some problems with some tests -- even when run for
iOS configurations, some tests would still run with macosx triple.  I
fixed the tests where I noticed this issue.

rdar://problem/19125022

Swift SVN r23683
2014-12-04 11:21:48 +00:00
Graham Batty
83f27a8af7 Revert "Mark tests that don't pass on linux as XFAIL."
This reverts commit 2711ca86de7bf6a7885ccea24219a48a590b1e95.

Swift SVN r23577
2014-11-24 17:42:13 +00:00
Graham Batty
198402dcfe Mark tests that don't pass on linux as XFAIL.
Swift SVN r23573
2014-11-24 17:40:37 +00:00
Doug Gregor
267f0ff756 Wrap context-sensitive nullability keywords in SWIFT_NULLABILITY.
Swift SVN r23533
2014-11-21 21:28:17 +00:00
Doug Gregor
07740515c2 Emit nullability context-sensitive keywords for instancetype.
Swift SVN r23486
2014-11-20 21:16:00 +00:00
Doug Gregor
96a9751372 PrintAsObjC: Print nullability type specifiers to capture optionality.
Part of rdar://problem/19005653. There is still some work to do to
produce pretty output here, but the current output is correct.

Swift SVN r23444
2014-11-19 21:08:23 +00:00
Jordan Rose
2f988f48d1 [PrintAsObjC] Don't use OBJC_DESIGNATED_INITIALIZER for protocol initializers.
<rdar://problem/17793674>

Swift SVN r20903
2014-08-01 18:06:33 +00:00
Doug Gregor
1cc28d4f80 An initializer requirement can only be satisfied by a required class initializer in a non-final class.
This is part of eliminating the notion of non-inheritable
conformances. Fixes <rdar://problem/17408284>.

Swift SVN r20430
2014-07-23 22:16:38 +00:00
Doug Gregor
a5c079af59 Replace the class_protocol attribute with a "class" requirement.
This only tackles the protocol case (<rdar://problem/17510790>); it
does not yet generalize to an arbitrary "class" requirement on either
existentials or generics.

Swift SVN r19896
2014-07-13 06:57:48 +00:00
Chris Lattner
fe95f81397 introduce a new 'DeclModifier' flag on attributes, which mark that the
attribute is a "modifier" of a decl, not an "attribute" and thus shouldn't
be spelt with an @ sign.  Teach the parser to parse "@foo" but reject it with
a nice diagnostic and a fixit if "foo" is a decl modifier.

Move 'dynamic' over to this (since it simplifies some code), and switch the
@optional and @required attributes to be declmodifiers (eliminating their @'s).



Swift SVN r19787
2014-07-10 05:49:10 +00:00
Jordan Rose
c90cd11aff [PrintAsObjC] Only include internal decls if we have a bridging header.
The upshot of this is that internal decls in an app target will be in the
generated header but internal decls in a framework target will not. This
is important since the generated header is part of a framework's public
interface. Users always have the option to add members via category to an
internal framework type they need to use from Objective-C, or to write the
@interface themselves if the entire type is missing. Only internal protocols
are left out by this.

The presence of the bridging header isn't a /perfect/ way to decide this,
but it's close enough. In an app target without a bridging header, it's
unlikely that there will be ObjC sources depending on the generated header.

Swift SVN r19763
2014-07-09 23:58:57 +00:00
Jordan Rose
3e994a24cf [PrintAsObjC] Don't print private protocols in the generated header.
Swift SVN r19735
2014-07-09 19:01:34 +00:00
Jordan Rose
cf53b747d0 Don't infer @objc on private members.
You can still mark them @objc explicitly (or @IBOutlet, or anything else that
would require ObjC interop).

Also, don't print private decls in the generated header, whether @objc or not.
not.

Swift SVN r19733
2014-07-09 18:44:46 +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
Jordan Rose
7fc8ecd919 [PrintAsObjC] Mark String, Array, and Dictionary properties as 'copy'.
<rdar://problem/17012159>

Swift SVN r19118
2014-06-24 01:23:03 +00:00