Commit Graph

6196 Commits

Author SHA1 Message Date
Gábor Horváth
568fa14b14 Merge pull request #77617 from swiftlang/gaborh/support-lifetime-capture-by
[cxx-interop] Support lifetime_capture_by in ClangImporter
2024-12-18 13:53:16 +00:00
Gábor Horváth
4ee8e0df26 Merge pull request #78115 from swiftlang/gaborh/cpp-span-unsafe
[cxx-interop] Make sure C++ span is imported as @unsafe
2024-12-18 13:20:41 +00:00
Gabor Horvath
8399971f06 [cxx-interop] Support lifetime_capture_by in ClangImporter
Import it as lifetime dependencies.

rdar://137671377
2024-12-18 10:05:43 +00:00
John Hui
796075ab88 [cxx-interop] Fix spurious ambiguous member lookup (#78132)
Nested calls to importBaseMemberDecl() subvert its cache and compromise its idempotence, causing the semantic checker to spuriously report ambiguous member lookups when multiple ClangRecordMemberLookup requests are made (e.g., because of an unrelated missing member lookup).

One such scenario is documented as a test case: test/Interop/Cxx/class/inheritance/inherited-lookup-typechecker.swift fails without this patch because of the expected error from the missing member. Meanwhile, test/Interop/Cxx/class/inheritance/inherited-lookup-executable.swift works because it does not attempt to access a missing member.

This patch fixes the issue by only calling importBaseMemberDecl() in the most derived class (where the ClangRecordMemberLookup originated, i.e., not in recursive requests).

As a consequence of my patch, synthesized member accessors in the derived class directly invoke the member from the base class where the member is inherited from, rather than incurring an indirection at each level of inheritance. As such, the synthesized symbol names are different (and shorter). I've taken this opportunity to update the relevant tests to // CHECK for more of the mangled symbol, rather than only the synthesized symbol prefix, for more precise testing and slightly better readability.

rdar://141069984
2024-12-17 11:40:18 -08:00
Gabor Horvath
985c3a44f8 [cxx-interop] Make sure C++ span is imported as @unsafe
The C++ span should be a non-escapable type but is imported as escapable
for backward compatibility reason. This is inherently unsafe, so make
sure std::span is imported as such. In the future, we plan to generate
safe overloads using Swift's Span and that will be the preferred way of
using the API.
2024-12-16 17:11:22 +00:00
Steven Wu
90176b3f5a Merge pull request #78138 from cachemeifyoucan/eng/PR-141284501
[ClangImporter] Share CASOptions when cloning CompilerInstance
2024-12-13 09:23:31 -08:00
Steven Wu
3cc9524bba [ClangImporter] Share CASOptions when cloning CompilerInstance
When cloning the clang instance in ClangImporter to perform tasks like
PCM/PCH compilation, make two compiler instance to share the same
CASOptions so they can share the CAS ObjectStore and life time.

This fixes a case where clang emits a diagnostics in a source buffer that
gets mapped in via CAS, and mapped into swift source manager. While CAS has
the ownship from CompilerInvocation -> CASOptions -> CAS, if the
CompilerInvocation is deleted when the cloned instance is deleted, it
left an invalid buffer in the swift source manager.

rdar://141284501
2024-12-12 13:31:34 -08:00
Kuba Mracek
a02586f1f2 [embedded] Include and use cxxshims in the embedded/ resource dir 2024-12-12 12:12:11 -08:00
Henrik G. Olsson
ec8ea94fb9 Infer @PointerBounds macro from clang __counted_by parameters (#77387)
This results in an automatic wrapper function with safe pointer types
when the imported function has bounds attributes. This exercises similar
pathways as the recently added functionality for specifying macros from
swift_attr. The new functionality is guarded by the experimental
language feature SafeInteropWrappers.

rdar://97942270
2024-12-11 13:36:56 -08:00
Egor Zhdan
282f3b127b [cxx-interop] Support CxxStdlib overlay for libc++ on Linux
This teaches Swift to rebuild the CxxStdlib overlay module from its interface when using a C++ standard library that is not the platform default, specifically libc++ on Linux.

rdar://138838506
2024-12-10 14:19:59 +00:00
Egor Zhdan
01aa141b6a Merge pull request #77987 from swiftlang/egorzhdan/no-cxx-stdlib
[cxx-interop] Avoid "libstdc++ not found" warning when `-nostdinc++` is passed
2024-12-06 14:29:13 +00:00
Gábor Horváth
745d9b16be Merge pull request #77829 from swiftlang/gaborh/escapability-annotate-STL
[cxx-interop] Inject escapability for the C++ standard library
2024-12-06 15:05:17 +01:00
Doug Gregor
41073a881c Merge pull request #77837 from lhoward/lhoward/retain-return-self
[cxx-interop] allow shared ref retain function to return self
2024-12-05 11:25:31 -08:00
Egor Zhdan
9472c4ca08 [cxx-interop] Avoid "libstdc++ not found" warning when -nostdinc++ is passed
When explicitly asked not to load the C++ standard library, Swift should not emit warnings for missing libstdc++.

This fixes a compiler warning when building the Cxx module on Linux.
2024-12-05 17:51:30 +00:00
Egor Zhdan
70ce8c67f5 Merge pull request #77932 from swiftlang/egorzhdan/spurious-lifetime-diags
[cxx-interop] Do not emit spurious lifetime diagnostics for C++ types
2024-12-05 17:17:12 +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
Doug Gregor
0c91a3409c Formalize the notion of "can clone" so we don't try to clone an attribute that won't work 2024-12-04 15:25:13 -08:00
Doug Gregor
ac448b865b [Clang importer] Don't cache swift_attr source files that have CustomAttrs with arguments
Since we can't do a proper "deep" clone of expression nodes, cloning
such a CustomAttr is necessarily shallow. In such cases, don't cache
the swift_attr source files at all, so we get fresh attribute nodes
for each such usage.
2024-12-04 15:24:00 -08:00
Egor Zhdan
8202dfdecd [cxx-interop] Do not emit spurious lifetime diagnostics for C++ types
In rare scenarios, Swift was emitting diagnostics that looked like this:
```
warning: 'import_owned' swift attribute ignored on type 'basic_string': type is not copyable or destructible
```

This change makes sure the compiler does not emit these (incorrect) warnings. See the inline comment for more details.
2024-12-04 16:10:08 +00:00
Yeoul Na
66321f7bee [ClangImporter] Do not import DynamicRangePointerType and ValueTerminatedType (#77910)
DynamicRangePointerType and ValueTerminatedType are new Clang
types for -fbounds-safety, annotated  with the 'ended_by' and the
'terminated_by' attributes. This adds visitors for these types in
ClangImporter so Swift still builds with Clang that has these new
types.
2024-12-04 00:43:40 -08:00
fahadnayyar
4bab2a8419 Merge pull request #77397 from fahadnayyar/frt-return-unannotated-warning-improve
[cxx-interop] Improve the warnings for unannotated c++ APIs returning SWIFT_SHARED_REFERENCE types
2024-12-04 00:26:03 -08:00
fahadnayyar
2e501754dd [cxx-interop] Improve the warnings for unannotated c++ APIs returning SWIFT_SHARED_REFERENCE types 2024-12-03 18:26:13 -08:00
Steven Wu
04f09d6d1d [Modules] Soft reset diagnostics when clang module import failed
Swift compiler can try to import clang modules which might fail to load.
In this case, the clang diagnostic engine is reset to ignore the errors,
but the hard reset also clears out the states, including the diagnostics
options and current states. This will affect the future clang module
imports and diagnostics. Use a soft reset that only clears the errors
but not the other states.

rdar://139723218
2024-12-03 10:32:36 -08:00
Gábor Horváth
b744793716 Merge pull request #77878 from swiftlang/gaborh/import-rval-ref
[cxx-interop] Import rvalue references as consuming parameters
2024-12-03 16:14:02 +00:00
Kuba (Brecka) Mracek
8792efedf0 Merge pull request #77115 from kubamracek/embedded-mangling-prefix
[Mangling] [NFC] Prepare for a new mangling prefix for Embedded Swift: $e
2024-12-03 08:10:49 -08:00
Hamish Knight
0fdb038fc9 Merge pull request #77896 from hamishknight/functionref-split
[AST] Split out "is compound" bit on FunctionRefKind
2024-12-03 09:53:37 +00:00
Luke Howard
da23bcf1c6 [cxx-interop] allow shared ref retain function to return self
Many existing C APIs for retaining references, including Apple's own, return
the reference. Support this pattern, along with the existing void return
signature, with when importing reference types from C++.
2024-12-03 11:45:29 +11:00
Luke Howard
51fd394065 [cxx-interop] fix typo in RetainReleaseOperationKind enum 2024-12-03 11:45:29 +11:00
Kuba Mracek
6f4ae28520 [ASTMangler] Pass ASTContext to all instantiations of ASTMangler 2024-12-02 15:01:04 -08:00
Allan Shortlidge
5143382265 AST: Introduce Decl::isUnavailableInCurrentSwiftVersion(). 2024-12-02 07:35:58 -08:00
Allan Shortlidge
2358712870 AST/Sema: Remove DeclAttr::isUnavailable().
Update callers to use `Decl::isUnavailable()` instead.
2024-12-02 07:35:58 -08:00
Allan Shortlidge
669930e5d7 Merge pull request #77818 from tshortli/renamed-decl-requestification 2024-12-02 07:33:05 -08:00
Hamish Knight
73fb36f371 [AST] Split out "is compound" bit on FunctionRefInfo
FunctionRefKind was originally designed to represent
the handling needed for argument labels on function
references, in which the unapplied and compound cases
are effectively the same. However it has since been
adopted in a bunch of other places where the
spelling of the function reference is entirely
orthogonal to the application level.

Split out the application level from the
"is compound" bit. Should be NFC. I've left some
FIXMEs for non-NFC changes that I'll address in a
follow-up.
2024-12-02 14:11:33 +00:00
Hamish Knight
a4d51419ba [AST] NFC: Rename FunctionRefKind -> FunctionRefInfo 2024-12-02 14:11:32 +00:00
Gabor Horvath
1601564342 [cxx-interop] Import rvalue references as consuming parameters
Unfortunately, importing them as is results in ambiguous call sites.
E.g., std::vector::push_back has overloads for lvalue reference and
rvalue reference and we have no way to distinguish them at the call site
in Swift. To overcome this issue, functions with rvalue reference
parameters are imported with 'consuming:' argument labels.

Note that, in general, move only types and consuming is not properly
supported in Swift yet. We do not invoke the dtor for the moved-from
objects. This is a preexisting problem that can be observed with move
only types before this PR, so the fix will be done in a separate PR.
Fortunately, for most types, the moved-from objects do not require
additional cleanups.

rdar://125816354
2024-12-02 13:09:21 +00:00
Allan Shortlidge
cd13d7d777 AST: Remove AvailableAttr::RenameDecl.
The renamed decl is now stored exclusively in the split request evaluator
storage, which is more efficient since most availability attributes do not
specify a renamed decl.
2024-11-29 10:35:02 -05:00
Allan Shortlidge
5de7211984 AST: Rename createForAlternative() to createForAsyncAlternative(). 2024-11-22 14:35:47 -08:00
Gabor Horvath
751bcfd952 [cxx-interop] Support parameter packs in escapability annotations
rdar://140271527
2024-11-22 12:32:51 +00:00
Hamish Knight
23e3f5f5de Merge pull request #77666 from hamishknight/lets-try-this-again
[AST] Remove `ModuleDecl::addFile`
2024-11-21 20:15:58 +00:00
Gábor Horváth
8a78496368 Merge pull request #77769 from swiftlang/gaborh/nonescapable-enabled
[cxx-interop] Use the new lifetime dependence language feature flag
2024-11-21 17:09:32 +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
Pavel Yaskevich
a8a8eafc7e Merge pull request #77706 from xedin/rdar-102564592
[ClangImporter] Correctly set parent type when importing ObjC pointers
2024-11-20 09:09:46 -08: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
Pavel Yaskevich
f4595923ba [ClangImporter] Correctly set parent type when importing ObjC pointers
Fixes an issue where parent type wasn't set for qualified ObjC
pointers which leads to crashes during Sema because non-pointer
uses are imported correctly.

Resolves: rdar://102564592
2024-11-19 11:15:22 -08:00
Gabor Horvath
ad4bfef762 [cxx-interop] Support nested templates for conditional escapability
rdar://140115862
2024-11-18 14:16:40 +00:00
Egor Zhdan
004ef749be Merge pull request #77646 from swiftlang/egorzhdan/reland-copy-ctor
Re-land "[cxx-interop] Check the presence of copy constructor correctly"
2024-11-18 12:50:27 +00:00
Hamish Knight
4946c799af [AST] Remove ModuleDecl::addFile
Rather than exposing an `addFile` member on
ModuleDecl, have the `create` members take a
lambda that populates the files for the module.
Once module construction has finished, the files
are immutable.
2024-11-17 14:17:20 +00:00
Doug Gregor
c5de02f60e Merge pull request #77628 from DougGregor/clang-importer-parse-request
[Clang importer] Use ParseSourceFileRequest for parsing swift_attr attributes
2024-11-16 01:12:27 -08:00
Gábor Horváth
5b2f3b7441 Merge pull request #77588 from swiftlang/gaborh/conditional-escapability
[cxx-interop] Support conditional escapability
2024-11-15 18:26:17 +00:00
Doug Gregor
24a12ebc34 Renable GeneratedSourceInfo::Attribute to GeneratedSourceInfo::AttributeFromClang 2024-11-15 09:02:49 -08:00