Commit Graph

2523 Commits

Author SHA1 Message Date
Gábor Horváth
217b450a39 Merge pull request #77294 from swiftlang/gaborh/import-return-independent-as-immortal
[cxx-interop] SWIFT_RETURNS_INDEPENDENT_VALUE implies immortal lifetime
2024-10-31 14:53:46 +00:00
Gábor Horváth
09c89fb983 Merge pull request #77204 from swiftlang/gaborh/diagnostic-location
[cxx-interop] Import more C++ source locations into Swift
2024-10-31 11:06:11 +00:00
Tony Allevato
97186b0738 Merge pull request #69460 from dylansturg/indexstore
Enable indexing for refs to implicit declarations.
2024-10-30 16:38:37 -04:00
Gabor Horvath
17ef2f66fe [cxx-interop] Make SWIFT_RETURNS_INDEPENDENT_VALUE imply immortal lifetime
The semantics of returning independent value already matches what
immortal lifetimes are within Swift. This patch makes sure this
annotation works as expected with non-escapable types.

rdar://137671642
2024-10-30 15:35:33 +00:00
Gabor Horvath
86e708a39b [cxx-interop] Import more C++ source locations into Swift
Occasionally, when the Swift compiler emits a diagnostic for a construct
that was imported from C++ we get a diagnostic with unknown location.
This is a bad user experience. It is particularly bad with the
borrow-checker related diagnostics. This patch extends the source
location importing to declarations in ClangImporter. There are some
invariants enforced by the Swift compile, e.g., a source range is
comprised of two valid source locations or two invalid ones. As a
result, this patch adds approximate source locations to some separators
like braces or parens that are not maintained by Clang. Having slightly
incorrect ranges in this case is better than emitting unknown source
locations.
2024-10-30 10:58:26 +00:00
fahadnayyar
e640ed637d [cxx-interop] Warning unannotated C++ APIs returning SWIFT_SHARED_REFERENCE types 2024-10-29 17:31:15 -07:00
Ben Barham
f59b2f19e6 Merge branch 'main' into 2024-rebranch-to-main 2024-10-28 13:03:35 -07:00
Dylan Sturgeon
a1e888785d Enable indexing for refs to synthesized declarations.
Based on feedback in PR https://github.com/swiftlang/swift/pull/69460, enabling indexing for synthesized decls because they are usable by users and make sense to appear in the indexstore.

Sets `synthesized` on some additional decls:

  - derived `hashInto(...)`
  - Objc properties and methods derived from Objc protocols

https://github.com/apple/swift/issues/67446
2024-10-28 10:07:27 -07:00
Egor Zhdan
81c7fb015a [cxx-interop] Ensure that C++ structs are fully defined
Swift should never try to import C++ structs that are not fully defined. This is because Clang can't synthesize implicit members of such types, which might be necessary for Swift, e.g. a copy constructor.

This adds an assertion that makes sure that C++ structs are considered to be fully defined by Clang. This condition should already be satisfied.
2024-10-28 12:54:13 +00:00
swift-ci
ed4836f5b1 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-18 12:22:36 -07:00
Egor Zhdan
9c5519a74a Merge pull request #77098 from swiftlang/egorzhdan/chrono-linux-cxx23
[cxx-interop] Do not import `std::chrono::time_zone`
2024-10-18 20:52:02 +02:00
Egor Zhdan
c530d3c0db [cxx-interop] Do not import std::chrono::time_zone
This type is non-copyable and non-moveable despite having a defaulted move constructor. It cannot currently be expressed in Swift. Let's not try to import it into Swift.

rdar://138123064 / resolves https://github.com/swiftlang/swift/issues/76809
2024-10-18 15:25:50 +01:00
swift-ci
848b66dca6 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-17 12:15:00 -07: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
swift-ci
b4107795e1 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-16 04:15:19 -07:00
Gábor Horváth
e4d625cbec Merge pull request #76696 from swiftlang/gaborh/lifetimebound-on-ctors
[cxx-interop] Add test for lifetimebound annotation in ctor
2024-10-16 11:57:26 +01:00
swift-ci
8956a19bd8 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-15 20:34:48 -07:00
John Hui
b58a908082 [cxx-interop] Add Hashable conformance to imported enums (#76940)
* [cxx-interop] Add Hashable conformance to imported enums

Previously, imported enums only conformed to RawRepresentable and Equatable,
so they could not be used as members of a Set or keys of a Dictionary.
This patch adds Hashable conformance to give them that ability,
as well as some test cases to clarify the expected behavior.
Existing test cases are updated to reflect this new conformance.

rdar://129713687
2024-10-15 20:24:35 -07:00
Gabor Horvath
9551e9d9ca [cxx-interop] Add test for lifetimebound annotation in ctor
There was also an off by one error in this case.
2024-10-15 16:29:31 +01:00
swift-ci
fa5fc7948e Merge remote-tracking branch 'origin/main' into rebranch 2024-10-14 21:45:47 -07:00
Allan Shortlidge
7819dd7833 AST/Sema: Remove unnecessary ASTContext parameters from availability APIs.
Many of the methods on `AvailabilityInference` take both a `Decl` and an
`ASTContext`, which is redundant.
2024-10-14 17:46:53 -07:00
swift-ci
72676c2c4a Merge remote-tracking branch 'origin/main' into rebranch 2024-10-08 15:43:57 -07:00
Doug Gregor
ead028bb11 Support applying macros to imported-as-member declarations 2024-10-08 11:12:53 -07:00
swift-ci
b8a5d2d6d7 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-03 01:35:42 -07:00
Konrad `ktoso` Malawski
45b97f146b Merge branch 'main' into wip-experimental-isolated-deinit 2024-09-30 13:47:39 +09:00
swift-ci
21ca39540e Merge remote-tracking branch 'origin/main' into rebranch 2024-09-27 22:54:31 -07:00
fahadnayyar
bd9095e69f Merge pull request #76733 from fahadnayyar/cxx-interop-frt-retain-release-diagnostics-patch-2
[cxx-interop] Add diagnostic notes when retain/release are not import…
2024-09-27 22:37:07 -07:00
fahadnayyar
d1b380ffd6 [cxx-interop] Add diagnostic notes when retain/release are not imported into swift for SWIFT_SHARED_REFERENCE types 2024-09-27 18:57:31 -07:00
swift-ci
59a7eb4710 Merge remote-tracking branch 'origin/main' into rebranch 2024-09-27 06:15:16 -07:00
Gabor Horvath
cbd8cdfe95 [cxx-interop] Add rules to recognize escapability of aggregates
For now, this logic is used for importing fewer unannotated types as
unsafe. In the future, this logic will be used by escapability inference
for other (non-aggregate) types.
2024-09-24 16:41:00 +01:00
swift-ci
2bd533ccda Merge remote-tracking branch 'origin/main' into rebranch 2024-09-24 07:55:58 -07:00
Gabor Horvath
72ce39ce07 [cxx-interop] Fix off-by-one error when importing lifetimebound attrs 2024-09-24 12:01:26 +01:00
Konrad `ktoso` Malawski
d89347bed0 Merge branch 'main' into wip-experimental-isolated-deinit 2024-09-20 18:34:45 +09:00
swift-ci
df338c19a8 Merge remote-tracking branch 'origin/main' into rebranch 2024-09-19 09:34:45 -07:00
Gabor Horvath
929c0ca7d8 [cxx-interop] Introduce a safe C++ interop mode
In this mode all C++ types are imported as unsafe by default. Users
explicitly marking types are escapable or not escapable can make them
imported as safe. In the future, we also want to import unannotated
functions as unsafe and add more logic to infer types that are actually
safe, like agregates of escapable types.
2024-09-19 12:34:07 +01:00
swift-ci
6964118e7e Merge remote-tracking branch 'origin/main' into rebranch 2024-09-18 13:17:04 -07:00
Doug Gregor
3a570e060c Merge pull request #76551 from DougGregor/one-loc-to-file-lookup
Reimplement ModuleDecl::getSourceFileContainingLocation() using SourceManager
2024-09-18 12:55:08 -07:00
swift-ci
5039a2d86c Merge remote-tracking branch 'origin/main' into rebranch 2024-09-18 10:55:29 -07:00
Doug Gregor
da0c70f301 Merge pull request #76512 from DougGregor/sourcefile-nonopt-buffer
Ensure that SourceFiles always have a backing buffer in the SourceManager
2024-09-18 10:54:52 -07:00
Doug Gregor
8febd3fb32 Reimplement ModuleDecl::getSourceFileContainingLocation() using SourceManager
ModuleDecl kept track of all of the source files in the module so that it
could find the source file containing a given location, which relied on
a sorted array all of these source files. SourceManager has its own
similar data structure for a similar query mapping the locations to
buffer IDs.

Replace ModuleDecl's dats structure with a use of the SourceManager's version
with the mapping from buffer IDs to source files.
2024-09-18 07:45:50 -07:00
swift-ci
72a4f929b0 Merge remote-tracking branch 'origin/main' into rebranch 2024-09-18 07:33:29 -07:00
Gábor Horváth
ffa1014c30 Merge pull request #76311 from swiftlang/gaborh/import-lifetimebound
[cxx-interop] Teach importer to interpret lifetimebound annotations
2024-09-18 15:24:32 +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
swift-ci
24e41cb1b0 Merge remote-tracking branch 'origin/main' into rebranch 2024-09-17 09:35:17 -07:00
Egor Zhdan
5981833c17 [cxx-interop] NFC: Remove unused method
`importer::hasUnsafeAPIAttr` is being used instead of this method.
2024-09-17 13:48:53 +01:00
Konrad `ktoso` Malawski
7d1ce789ad Revert "Revert "Isolated synchronous deinit"" 2024-09-17 17:35:38 +09:00
Doug Gregor
4e7fb73b0c Provide the buffer ID for source files created for C swift_attr attributes
When rendering a swift_attr attribute for parsing, we were creating both
the backing buffer and a source file, but not providing the buffer's ID
to the source file, so we couldn't find the source code again. Fix that.

While here, also register the source file with the module, so we can
find the source file again based on location.
2024-09-16 21:45:34 -07:00
Ben Barham
a7b50f357f Merge remote-tracking branch 'origin/main' into manual-main-merge
Conflicts:
  - `lib/Driver/ToolChains.cpp` conflicting with the `addAllArgs` rename
    for multiple options
2024-09-16 13:53:18 -07:00
Allan Shortlidge
02dbb96b94 AST: Rename AvailabilityContext to AvailabilityRange.
The generality of the `AvailabilityContext` name made it seem like it
encapsulates more than it does. Really it just augments `VersionRange` with
additional set algebra operations that are useful for availability
computations. The `AvailabilityContext` name should be reserved for something
pulls together more than just a single version.
2024-09-13 16:25:18 -07:00
fahadnayyar
7753ad0885 Merge pull request #76131 from fahadnayyar/cxx-interop-frt-retain-release-diagnostics
Fixed diagnostics for incorrect parameters of retain/release function…
2024-09-11 10:24:20 -07:00