Commit Graph

514 Commits

Author SHA1 Message Date
Alex Lorenz
60902cbfa0 [interop] restructure Swift -> C++ interop tests
We will place tests that test the semantics and runtime of the generated
C++ code into Interop/SwiftToCxx. PrintCxx test directory will only be
used to test high level flow without concerning itself about the C++ semantics.
2022-01-24 10:51:52 -08:00
Miguel Salinas
8f9871a5fe invert fallback logic 2022-01-21 00:04:27 -08:00
salinas-miguel
0251836591 rebuild modules without -DCGFLOAT_IN_COREFOUNDATION after test 2022-01-20 12:24:58 -08:00
salinas-miguel
6d269e5670 refactor and add test 2022-01-19 13:00:03 -08:00
Tony Allevato
f9ea748604 [PrintAsObjC] Import/fwd-declare types used in @_cdecl functions.
When a `@_cdecl` function is printed to a generated header, the types
it uses in its signature are not forward declared or imported, so the
header isn't usable unless you also add another Objective-C declaration
to the module (like a class or protocol) that uses the types to force
it.
2021-11-15 08:33:15 -08:00
Tony Allevato
7afb475279 Merge pull request #38682 from bdash/cdecl-extern-C
Prefix @_cdecl functions with `extern "C"` in -Swift.h headers
2021-11-11 16:04:01 -08:00
Ben Barham
7b807d52e3 [PrintAsObjC] Do not output invalid decls when allowing errors
We still want the ObjectiveC header when allowing errors, but make sure
to skip printing out any invalid declarations that may be caused because
of those errors.

In particular, duplicate declarations were causing a crash when sorting
declarations where various assumptions would end up casting a
non-ExtensionDecl to an ExtensionDecl.

Resolves rdar://78023656
2021-08-19 08:45:48 +10:00
Mark Rowe
7a64bf7aa7 Prefix @_cdecl functions with extern "C" in -Swift.h headers
This ensures that the function uses the appropriate mangling if the header is imported and the function is used from Objective-C++ code.
2021-07-28 15:59:52 -07:00
Becca Royal-Gordon
b3d6424101 Merge pull request #38595 from beccadax/incompletion-handler
[PrintAsObjC] Make async completions _Nonnull
2021-07-27 16:36:54 -07:00
Doug Gregor
eeeea49764 Remove -enable-experimental-concurrency almost everywhere. 2021-07-26 21:24:43 -07:00
Becca Royal-Gordon
c306843781 [PrintAsObjC] Make async completions _Nonnull
When we printed `async` methods, we did not print a nullability annotation on the `completionHandler` parameter. This commit adds `_Nonnull`, which matches the generated SIL.

Fixes rdar://80989714.
2021-07-22 17:09:08 -07:00
Doug Gregor
1e2012d816 Disable availability checking in tests that use concurrency 2021-07-20 12:46:26 -07:00
Tony Allevato
607fd9f04c [PrintAsObjc] Import/fwd-declare the unbridged type for known types.
For non-Clang types that conform to `_ObjectiveCBridgeable` but have
type mappings defined in `getKnownTypeInfo`, always use the Clang type
in the mapping to determine which module to import.

`CGFloat` is a rare case of an `_ObjectiveCBridgeable` type that is
a native Swift `struct` declared in an overlay instead of extending
the original Clang decl with the conformance. Since `hasClangNode`
returns false in this case, it fell through to the rest of the logic
for `getObjCBridgedClass` and would forward declare `@class NSNumber`
instead of `@import CoreGraphics`. Thus, in some cases (e.g., the
header only defines APIs that use `CGFloat`), the header would be
invalid.

Fixes SR-14266.
2021-05-17 09:05:35 -07:00
Ben Barham
b34b9826c6 [Gardening] Remove invalid RUN lines that were accidentally merged
ab5a42160c added a new test case with
invalid RUN lines - they were a copy paste from a different file, not
intended to be committed.
2021-03-27 17:52:27 +10:00
Ben Barham
54006fd17c Merge pull request #36581 from bnbarham/emit-post-when-allowing-errors
[Frontend] Always output (some) additional files when allowing errors
2021-03-27 09:36:55 +10:00
Erik Eckstein
78ec15cf38 tests: remove some unused FileCheck prefix options
Such tests would fail with the -allow-unused-prefixes FileCheck option.

diff --git a/test/lit.cfg b/test/lit.cfg
-run_filecheck = '%s %s --sanitize BUILD_DIR=%s --sanitize SOURCE_DIR=%s --use-filecheck %s %s' % (
+run_filecheck = '%s %s --sanitize BUILD_DIR=%s --sanitize SOURCE_DIR=%s --use-filecheck %s %s -allow-unused-prefixes=false' % (

It helps avoiding some wrong CHECK patterns.
I just looked briefly at some of the fails. TODO: fix remaining tests, too.

rdar://74189761
2021-03-25 15:19:30 +01:00
Ben Barham
ab5a42160c [Frontend] Always emit generated ObjectiveC header when allowing errors
Resolves rdar://75754282
2021-03-25 16:19:09 +10:00
Andrew Trick
0a020815ad PrintAsObjC test is broken. Add comments. 2021-03-02 22:20:13 -08:00
Andrew Trick
b689b1dabe Rename GuaranteedARCOpts to MandatoryARCOpts.
This bleeds into the implementation where "guaranteed" is used
everywhere to talk about optimization of guaranteed values. We need to
use mandatory to indicate we're talking about the pass pipeline.
2021-03-02 22:20:13 -08:00
John McCall
a8464dcaf1 Implicitly import _Concurrency under -enable-experimental-concurrency 2020-10-22 00:53:15 -04:00
Doug Gregor
daf9e2df7e [Concurrency] Print @objc async declarations as Objective-C declarations.
@objc async declarations are mapping into completion-handler-based
methods in Objective-C, so ensure that the result type, parameters,
and attributes reflect that.
2020-09-08 10:15:24 -07:00
Brent Royal-Gordon
9d4281b46b Support generic @compatibility_alias in PrintAsObjC
When @compatibility_alias is used with an ObjC generic class, this ends up importing as a generic typealias. PrintAsObjC previously didn’t handle declarations involving these types correctly; it would fail an assertion in asserts compilers, and potentially print an incorrect compatibility header in non-asserts compilers.

This PR makes it so that PrintAsObjC can now correctly use generic typealiases imported from Objective-C modules. It is, of course, still not possible to declare a generic typealias in Swift that will be printed into the Objective-C header.

Fixes rdar://67256866.
2020-08-20 16:21:50 -07:00
Brent Royal-Gordon
a60aad89a7 [PrintAsObjC] Forward-declare bridged types
The initial pass through a type’s members to forward-declare or import anything needed by them did not account for _ObjectiveCBridgeable conformances; instead, it would examine the Swift type being bridged from, either tripping an assertion or just failing to do anything. Treat these as references to the bridged type instead.

Fixes rdar://67263753.
2020-08-19 13:53:06 -07:00
Mishal Shah
60d996f060 [Apple Silicon] Add support for triple and availability canonicalization 2020-07-02 19:26:25 -07:00
Robert Widmann
cddf73ecdb [Gardening] Clean Up OS-Test Patterns Across The Codebase
Clean up a few general patterns that are now obviated by canImport

This aligns more generally with the cleanup that the Swift Package
Manager has already done in their automated XCTest-plumbing tool in
apple/swift-package-manager#1826.
2020-06-30 22:55:58 -07:00
Mishal Shah
272c466e47 Update master to build with Xcode 12 beta 2020-06-22 15:43:20 -07:00
Michael Gottesman
702c1bc5e8 [arc] Change guaranteed arc opts to be based on SemanticARCOpts and move from Diagnostic pipeline -> Onone pipeline.
The pass is already not being run during normal compilation scenarios today
since it bails on OSSA except in certain bit-rot situations where a test wasn't
updated and so was inadvertently invoking the pass. I discovered these while
originally just trying to eliminate the pass from the diagnostic pipeline. The
reason why I am doing this in one larger change is that I found there were a
bunch of sil tests inadvertently relying on guaranteed arc opts to eliminate
copy traffic. So, if I just removed this and did this in two steps, I would
basically be unoptimizing then re-optimizing the tests.

Some notes:

1. The new guaranteed arc opts is based off of SemanticARCOpts and runs only on
   ossa. Specifically, in this new pass, we just perform simple
   canonicalizations that do not involve any significant analysis. Some
   examples: a copy_value all of whose uses are destroys. This will do what the
   original pass did and more without more compile time. I did a conservative
   first approximation, but we can probably tune this a bit.

2. the reason why I am doing this now is that I was trying to eliminate the
   enable-ownership-stripping-after-serialization flag and discovered that the
   test opaque_value_mandatory implicitly depends on this since sil-opt by
   default was the only place left in the compiler with that option set to false
   by default. So I am eliminating that dependency before I land the larger
   change.
2020-06-15 17:00:18 -07:00
Slava Pestov
14cc7dd9bd PrintAsObjC: Fix crash when printing typedef that was imported inside an Objective-C generic class
The assertion here is too strict. The TypeAliasDecl will inherit a
generic signature from the outer context even if it does not have
generic parameters of its own. Instead, let's just assert that the
TypeAliasDecl does not have its own generic parameters.

Fixes <rdar://problem/63188938>.
2020-05-21 17:35:49 -04:00
David Zarzycki
5dcc32f98f Remove all uses of -force-single-frontend-invocation
The `-force-single-frontend-invocation` flag predates WMO and is now an
alias for `-whole-module-optimization`. We should use the latter and let
the former fade into history.
2020-05-08 06:37:41 -04:00
Alexis Laferrière
e078a86f0b [PrintAsObjC] Test that we don't leak extended implementationOnly types 2020-04-20 16:37:13 -07:00
Doug Gregor
091f987e28 Revert "[PrintAsObjC] Test that we don't leak extended implementationOnly types"
This reverts commit 4e8867e021.
2020-04-13 13:58:07 -07:00
Doug Gregor
bf99f31d75 Revert "PrintAsObjc: expand module @imports to header #imports if modules are not supported"
This reverts commit a2534fa234.
2020-03-27 21:02:44 -07:00
Doug Gregor
ab97d50b0f Revert "PrintAsObjC: use header path relative to usr/include when importing non-framework headers"
This reverts commit ebe0a45583.
2020-03-27 21:00:51 -07:00
Xi Ge
ebe0a45583 PrintAsObjC: use header path relative to usr/include when importing non-framework headers
We could assume usr/include belongs to header search paths. If a header
is located in a deeper location inside this directory, we need to print
the additional path components.

rdar://60857172
2020-03-25 23:30:28 -07:00
Xi Ge
df0493c288 PrintAsObjC: allow users to specify bridging header relative path for printing
Compatibility header may #import bridging header if specified with -import-underlying-module.
How these two headers are relative to each other is subject to project setting. To accommodate
this, we should allow users to specify bridging header directory for header generating purposes.

rdar://59110975
2020-03-11 17:09:53 -07:00
Alexis Laferrière
4e8867e021 [PrintAsObjC] Test that we don't leak extended implementationOnly types 2020-03-09 14:11:06 -07:00
Xi Ge
a2534fa234 PrintAsObjc: expand module @imports to header #imports if modules are not supported
rdar://58284119
2020-03-03 11:54:14 -08:00
Xi Ge
fa659ede76 [PrintAsObjc] add macro guard against potential recursive definitions 2020-02-05 12:37:01 -08:00
Slava Pestov
eef1428a2b PrintAsObjC: Support for blocks with __owned parameters 2019-12-02 18:41:27 -05:00
Jordan Rose
bb83722113 Merge pull request #5252 from JGiola/SR-2405
SR-2405 Print IB_DESIGNABLE and IBInspectable in the generated ObjC header
2019-10-21 09:44:09 -07:00
Jacopo Andrea Giola
5902a477d4 Print IB_DESIGNABLE and IBInspectable in the generated ObjC header
Add support for @IBDesignable and @IBInspectable attribute to the
generated ObjC headers
2019-10-16 20:18:50 +02:00
Brent Royal-Gordon
f1e8ad9348 Reenable PrintAsObjC/extensions.swift
This test was disabled to work around a bug in the ObjC generics implementation in clang. That bug was corrected by https://reviews.llvm.org/D66696, so we should now be able to turn the Swift test back on.
2019-10-16 10:10:01 -07:00
Varun Gandhi
04ce7bf779 Merge pull request #27557 from varungandhi-apple/vg-fix-selector-names
Use the accessor names as written in Objective-C.
2019-10-08 10:08:13 -07:00
Varun Gandhi
3b9dbd57c4 [AST] Get the ObjC accessor name, not the one parsed from Swift.
Fixes rdar://problem/55519276.
2019-10-06 06:57:50 -07:00
Varun Gandhi
d4bafdf9fa Add minimal test case for rdar://problem/55519276.
We are dropping the getter and setter names we get from Objective-C.
This leads to a runtime crash. Oops.
2019-10-06 06:57:50 -07:00
Brent Royal-Gordon
f696ebdae5 XFAIL PrintAsObjC/extensions.swift
rdar://problem/54414986
2019-08-16 17:41:00 -07:00
Jordan Rose
406a9d9cf1 Add the notion of @_implementationOnly overrides
When an @_implementationOnly import includes Objective-C categories
for existing types, it's useful to be able to override the members
provided in those categories without exposing them to clients of the
framework being built. Allow this as long as the overriding
declaration is marked as @_implementationOnly itself, with an
additional check that the type of the declaration does not change.
(Normally overrides are allowed to change in covariant ways.)

Part of rdar://50827914
2019-06-17 17:48:40 -07:00
mishal_shah
1e38fc3030 Update master to build with Xcode 11 beta, macOS 10.15, iOS 13, tvOS 13, and watchOS 6 SDKs 2019-06-03 22:50:02 -07:00
Ben Cohen
e9d4687e31 De-underscore @frozen, apply it to structs (#24185)
* De-underscore @frozen for enums

* Add @frozen for structs, deprecate @_fixed_layout for them

* Switch usage from _fixed_layout to frozen
2019-05-30 17:55:37 -07:00
Slava Pestov
6363961e90 Split up a couple more tests into stable and pre-stable ABI deployment target versions 2019-05-21 17:30:13 -04:00