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.
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.
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
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.
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.
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.
@objc async declarations are mapping into completion-handler-based
methods in Objective-C, so ensure that the result type, parameters,
and attributes reflect that.
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.
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.
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.
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.
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>.
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.
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
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
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.
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