Commit Graph

41 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
Doug Gregor
d6d21892f3 Handle output file maps that use the key "objc-header".
This anachronously-named key is nonetheless still important to accept,
or else we'll fail to emit the generated header.

Fixes rdar://90900115.
2022-03-28 10:06:59 -07:00
Jordan Rose
a3942059bf Make sure to allow '@objc' on enum elements
Previously they were ignored by the checking of '@objc', but in the
refactoring to a request the attribute started getting marked as
invalid without a diagnostic.

rdar://problem/43401047
2018-08-22 15:29:27 -07:00
Mani Ramezan
9df5adb150 Move mock Foundation framework into clang shared folder 2018-07-11 02:32:59 -04: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
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
Daniel Martín
d510793566 Fix SR-2860 2017-01-16 09:39:36 +01:00
Tim Bodeit
96c964ee0d [test/PrintAsObjc] Adjust existing test cases for SWIFT_WARN_UNUSED_RESULT 2016-12-10 01:48:49 +01: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
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
Jordan Rose
b5aca663bc [ClangImporter] Remove importer-based NS stripping. (#3880)
* [ClangImporter] Remove importer-based NS stripping.

As Tony puts it, in the end we wound up with more Foundation
declarations imported as members or keeping "NS" than those that
dropped it, and any further decisions will be made on a case-by-case
basis. Move all of the existing cases of prefix-stripping into
Foundation's API notes and drop the logic from the compiler.

Tested by dumping the generated interface for Foundation and its
submodules for both macOS and the iOS simulator, and comparing the
results. A few cases did slip through here because of the interaction
between "SwiftName" and "Availability: nonswift".

The next commit will re-add "NS" to some stragglers that we missed.

rdar://problem/26880017

* APINotes: Add "NS" back to a few types.

NSKeyedUnarchiverDelegate
NSKeyedArchiverDelegate
NSTextCheckingTypes
NSBinarySearchingOptions
NSEnumerationOptions
NSSortOptions

More rdar://problem/26880017

* Remove now-redundant SwiftNames from API notes.

No change observed in the generated interface of Foundation and its
submodules.

Finishes rdar://problem/26880017.
2016-08-01 20:54:26 -07:00
Doug Gregor
823c24b355 [SE-0112] Rename ErrorProtocol to Error.
This is bullet (5) of the proposed solution in SE-0112, and the last
major piece to be implemented.
2016-07-12 10:53:52 -07:00
Mishal Shah
87b7bcfd3e Update master to build with Xcode 8 beta 1, OS X 10.12, iOS 10, tvOS 10, and watchOS 3 SDKs. 2016-06-14 14:53:55 -07:00
David Farler
4d8b33e5ba Markup: Move Doxygen converter into a proper MarkupASTNode visitor
Enclose the entire doc comment in /** */ to ensure that newlines
don't cause comments to leak out and get parsed as C.

rdar://problem/24923076
2016-05-03 16:44:31 -07: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
Saleem Abdulrasool
89d37bc694 test: ignore unused options in some tests
These tests explicitly disable the use of modules.  However, the lit
configuration is such that the module cache path will be passed unconditionally
to the clang invocation.  Squelch the unused option warning (error).
2016-04-05 10:00:37 -07:00
Drew Crawford
aa5cf2b842 [Serialization] Don't serialize non-public documentation
Let's say I am a good citizen and document my private symbols:

    /** My TOP SECRET DOCUMENTATION */
    private class Foo {
    }

When I go to distribute the compiled binary, I find out my private
documentation is distributed as well:

    $ swiftc test.swift -emit-module -module-name "test"
    $ strings test.swiftdoc
    My TOP SECRET DOCUMENTATION
    /** My TOP SECRET DOCUMENTATION */

If a client can't use a symbol (e.g. it's private [or internal and not
-enable-testing]) don't emit the documentation for a symbol in the
swiftdoc.

Fixes: SR-762, rdar://21453624

The test coverage implements this truth table:

| visibility | -enable-testing | documentation? |
|------------|-----------------|----------------|
| private    | no              |              |
| internal   | no              |              |
| public     | no              |              |
| private    | yes             |              |
| internal   | yes             |              |
| public     | yes             |              |

Modified the existing comments test coverage to expect non-public
documentation not to be emitted.

Don't rely on existing comment structure

Refuse to emit comments if the decl cannot actually have one.  To
accomplish this, we move `canHaveComment` into the Decl instance.  It
must also be marked `const`, since one of its existing usages operates
on a const pointer.

Perform fewer checks when serializing the standard library.
2016-03-17 17:46:23 -05:00
Max Moiseev
7fe6916bf6 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-03-07 12:10:47 -08:00
Doug Gregor
e16d6898ef [PrintAsObjC] Sentence-case the enum case name when appending it to the enum name.
Otherwise, we cram a conventionally UpperCamelCase thing with a
newly-conventinally-lowerCamelCased thing together and destroy the
word boundaries. Fixes rdar://problem/24947695.
2016-03-04 15:42:22 -08:00
Max Moiseev
3a3984877a Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-15 15:43:34 -08:00
Kevin Ballard
4da629f1be [PrintAsObjC] Use @objc name for enums in enum references
Also make sure the `FooDomain` constant for `ErrorType` enums uses the
correct name.

Fixes SR-693: Custom named @objc enum still exposes original Swift name
in Objective-C
2016-02-09 13:10:47 -08:00
Max Moiseev
08e1e4a043 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-01-11 16:51:11 -08:00
Kevin Ballard
f473851148 [PrintObjC] Support @objc(name) on enum cases 2016-01-06 14:46:06 -08:00
Max Moiseev
f51e708a8f Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-01-04 12:25:25 -08:00
Kevin Ballard
2de24e167f [PrintObjC] Add SWIFT_ENUM_NAMED for enums with custom ObjC names 2015-12-23 15:52:16 -08:00
Dmitri Gribenko
feacbc4433 Rename ErrorType to ErrorProtocol 2015-12-09 17:12: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
cddd26477e [PrintAsObjC] Enum domain string constants are __nonnull.
(And they are '__nonnull' rather than '_Nonnull' for two reasons:
it's a very cheap concession to preserve compatibility with Xcode 6.3,
and the existing code works this way.)

rdar://problem/22805286

Swift SVN r32228
2015-09-25 17:53:37 +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
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
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
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
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
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
Joe Groff
944860adb0 PrintAsObjC: Handle forward declarations of @objc enums.
If enums are used as parameters or returns of @objc methods, we may need to forward declare those enums when printing the class @interface.

Swift SVN r23445
2014-11-19 22:27:48 +00:00
Joe Groff
b8d912c0db PrintAsObjC: Swap SWIFT_ENUM args around to match other *_ENUM macros.
And introduce a SWIFT_ENUM_EXTRA preprocessor hook for the Clang importer to inject its annotations.

Swift SVN r23425
2014-11-19 04:03:10 +00:00
Joe Groff
dc2ad382a2 Serialization: Serialize the raw values of @objc enums.
This is necessary for @objc enums because, for C compatibility, the representations of the cases must match their raw values. We might want to do this for sufficiently fragile Swift enums in the future too, but that can wait. This lets us successfully print the raw values as ObjC.

Swift SVN r23423
2014-11-19 04:03:06 +00:00
Joe Groff
5059bd4366 PrintAsObjC: Print @objc enums.
Predefine a SWIFT_ENUM macro that expands the same as NS_ENUM, but which we can use to recognize Swift-defined @objc enums that are imported back. Print enums as ObjC using this SWIFT_ENUM macro.

We currently don't serialize the raw value exprs of enums, so we fail to correctly bring raw values from the enum declaration to the ObjC version.

Swift SVN r23422
2014-11-19 04:03:05 +00:00