Commit Graph

18 Commits

Author SHA1 Message Date
Andrew Trick
6cc1a8d880 Diagnostic message: suppress printing "requires LifetimeDependence"
Adopters of the new Span and MutableSpan types should not encounter information
about an experimental feature when they attempt to use these types in
unsupported ways, such as simply returning them from a function.

Fixes rdar://151788740 (Diagnostic message: suppress printing "requires
'-enable-experimental-feature LifetimeDependence'")
2025-05-21 22:56:57 -07:00
Allan Shortlidge
24fa9c8703 ClangImporter: Introduce the #ClangDeclarationImport diagnostic group.
The warnings that ClangImporter emits about issues it encounters while
importing declarations from Clang modules should all belong to a diagnostic
group so that users of `-warnings-as-errors` can control their behavior using
the compiler flags introduce with SE-0443. It's especially important that these
diagnostics be controllable since they are often caused by external
dependencies and therefore the developer may not have any control over whether
they are emitted.

The `#ClangDeclarationImport` diagnostic group is intentionally broad so that
developers have a way to control all of these diagnostics with a single
`-Wwarning` flag. I fully expect that we'll introduce finer-grained diagnostic
groups for some of these diagnostics in the future, but those groups should be
hierarchically nested under `#ClangDeclarationImport`, which is supported by
SE-0443.

Resolves rdar://150524204.
2025-05-05 14:16:53 -07:00
Gabor Horvath
e0a431ec98 [cxx-interop] Diagnose Escapable C++ types with non-escapable fields
rdar://148899224
2025-04-09 13:01:31 +01:00
Andrew Trick
8432d2e788 Fix C++ interop tests using swift_attr("~Escapable")) 2025-03-19 11:59:05 -07:00
Gabor Horvath
6b24af65f0 [cxx-interop] Always import the lifetime annotations
Importing these annotations were behind the LifetimeDependence
experimental flag. However, this feature flag is intended to guard the
use of @lifetime annotations on the Swift side and lifetime inference.
The checking of imported lifetime contracts should work even when this
flag is off. Removing the flag from the importer caused some fallout.
This was mostly due to calling getInterfaceType functions before the
import of some Swift declarations were fully done so the code was
slightly improved to make decisions only based on the C++ types.
There was also a crash when on-member functions imported as methods into
Swift. That is worked around in this PR.

There is one last feature check that we cannot remove yet, we generate
@lifetime annotations in the SwiftifyImport macro.
2025-03-05 15:36:59 +00:00
Gabor Horvath
d0c167762c [cxx-importer] Do not import pointers to non-escapable types
Unfortunately, Unsafe*Pointer types do not support non-escapable
pointees so we do not really have anything to map these types to at the
moment. Previously, importing such code resulted in crashes.

rdar://145800679
2025-03-04 12:27:34 +00:00
Gabor Horvath
9027edd430 [cxx-interop] Inject escapability for the C++ standard library
We only add conditional annotations because those do not break backward
compatibility (we might import span and similar view types as
non-escapable in the future). We inject these annotations in the
importer to make sure we have consistent behavior acress the different
standard library implementations. Once we can ship APINotes for the STL
and we have conditional escapability support in APINotes we can migrate
to that solution. But it is not possible as of today and Clang already
has precedent of injecting information for the STL with lifetimebound.

rdar://139065558
2024-12-05 16:27:34 +01:00
Gabor Horvath
751bcfd952 [cxx-interop] Support parameter packs in escapability annotations
rdar://140271527
2024-11-22 12:32:51 +00:00
Gabor Horvath
51e92d9db4 [cxx-interop] Use the new lifetime dependence language feature flag
Non-escapable types are now enabled by default. Use the new lifetime
dependence feature flag to gate interpreting lifetime annotations on the
C++ side and add tests to make sure we get the expected diagnostics when
the feaature flag is off.
2024-11-21 13:13:16 +00:00
Gábor Horváth
d3064c5fc6 Merge pull request #77678 from swiftlang/gaborh/conditional-escapability
[cxx-interop] Support nested templates for conditional escapability
2024-11-20 13:59:00 +00:00
Meghana Gupta
e8abd59da5 Update tests 2024-11-18 18:09:19 -08:00
Gabor Horvath
ad4bfef762 [cxx-interop] Support nested templates for conditional escapability
rdar://140115862
2024-11-18 14:16:40 +00:00
Gabor Horvath
558380f6f8 [cxx-interop] Support conditional escapability
This PR adds a variadic macro that builds a SwiftAttr string containing
the names of the template type parameters that need to be escapable for
the type to be considered escapable. It also adds logic to interpret
this annotation.

rdar://139065437
2024-11-15 14:27:54 +00:00
Gábor Horváth
88c2269e69 Merge pull request #77323 from swiftlang/gaborh/use-imported-locs
[cxx-interop] Use the locations imported from C++
2024-11-07 17:44:07 +00:00
Daniel Rodríguez Troitiño
ba68faaed5 [test] Mark tests that use experimental/upcoming features as such
Find all the usages of `--enable-experimental-feature` or
`--enable-upcoming-feature` in the tests and replace some of the
`REQUIRES: asserts` to use `REQUIRES: swift-feature-Foo` instead, which
should correctly apply to depending on the asserts/noasserts mode of the
toolchain for each feature.

Remove some comments that talked about enabling asserts since they don't
apply anymore (but I might had miss some).

All this was done with an automated script, so some formatting weirdness
might happen, but I hope I fixed most of those.

There might be some tests that were `REQUIRES: asserts` that might run
in `noasserts` toolchains now. This will normally be because their
feature went from experimental to upcoming/base and the tests were not
updated.
2024-11-02 11:46:46 -07:00
Gabor Horvath
6d24c52b80 [cxx-interop] Use the locations imported from C++
A recent PR (#77204) started to import C++ source locations into Swift.
This PR flips a switch so these locations are actually used more widely.
Now some of the diagnostic locations are changed, but they generally
improved the quality of the diagnostics, pointing out conformances
imported from Obj-C code right when they are declared.
2024-11-01 13:49:09 +00:00
Gabor Horvath
e86cf185e2 [cxx-interop] Diagnose misuses of escapability and lifetimebound
When a type is explicitly annotated as escapable or non-escapable it has
requirements about the lifetime annotations. This patch introduces
diagnostics to detect that.
2024-10-17 15:35:55 +01:00
Gabor Horvath
16e012bb5e [cxx-interop] Teach importer to interpret lifetimebound annotations
The lifetimebound annotations are now imported as lifetime dependencies.
This works for basic cases but there are still some parts missing:
* Support lifeitmebound annotations on constructors
* A way to represent immortal/static lifetimes on the C++ side
2024-09-18 10:51:05 +01:00