Commit Graph

1877 Commits

Author SHA1 Message Date
Steven Wu
ed8032cbc3 [ClangImporter] Allow direct explicit load when implicit module is enabled
Improve clang importor so it can directly load explicit module even
implicit module is enabled. This is a special configuration used by lldb
because lldb sometimes need to load additional modules when binding
external types. This provide the path in clang importer that can load
explicit module without locating the clang module map, while fallback to
module map lookup when implicit module is needed.
2024-11-08 15:34:55 -08:00
Egor Zhdan
dcdcd13036 [cxx-interop] Workaround build error in SwiftCompilerSources
Certain build configurations of SwiftCompilerSources now incorrectly treat `BridgedSwiftObject` as a non-copyable type, causing compiler errors. This is a short-term workaround for these errors.

rdar://138924133
2024-11-08 21:27:37 +00:00
Rintaro Ishizaki
d4db99ce9d [Parse] Remove unnecessary dependencies to Parser.h
C++ swift::Parser is going to be replaced with SwiftParser+ASTGen.
Direct dependencies to it should be removed. Before that, remove
unnecessary '#include "swift/Parse/Parser.h"' to clarify what actually
depends on 'swift::Parser'.

Split 'swift::parseDeclName()' et al. into the dedicated files.
2024-11-02 01:23:59 -07:00
fahadnayyar
f430088616 Merge pull request #76798 from fahadnayyar/frt-return-unannotated-warning
[cxx-interop] Warning unannotated C++ APIs returning SWIFT_SHARED_REF…
2024-10-31 17:40:12 -07: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
Egor Zhdan
ffb22d7287 Merge pull request #73297 from swiftlang/egorzhdan/correct-check-for-copy-ctor
[cxx-interop] Check the presence of copy constructor correctly
2024-10-29 17:22:49 +00:00
Egor Zhdan
fbbec48c76 [cxx-interop] Check the presence of copy constructor correctly
This removes a longstanding workaround in the import logic for C++ structs:
Swift assumed that if a C++ struct has no copy constructor that is explicitly deleted, then the struct is copyable. This is not actually correct. This replaces the workaround with a proper check for the presence of a C++ copy constructor.

rdar://136838485
2024-10-28 20:05:57 +00:00
swift-ci
72676c2c4a Merge remote-tracking branch 'origin/main' into rebranch 2024-10-08 15:43:57 -07:00
Doug Gregor
f53670be08 Move _SWIFT_ATTR_SUPPORTS_MACROS to the right place 2024-10-08 11:25:46 -07:00
Doug Gregor
688dd234b4 Define __SWIFT_ATTR_SUPPORTS_MACROS when the MacrosOnImports features is available 2024-10-08 11:12:55 -07:00
Doug Gregor
cdcabd05bd Allow attached macros to be applied to imported C declarations
The Clang importer maps arbitrary attributes spelled with `swift_attr("...")`
over to Swift attributes, using the Swift parser to process those attributes.
Extend this mechanism to allow `swift_attr` to refer to an attached macro,
expanding that macro as needed.

When a macro is applied to an imported declaration, that declaration is
pretty-printed (from the C++ AST) to provide to the macro implementation.
There are a few games we need to place to resolve the macro, and a few more
to lazily perform pretty-printing and adjust source locations to get the
right information to the macro, but this demonstrates that we could
take this path.

As an example, we use this mechanism to add an `async` version of a C
function that delivers its result via completion handler, using the
`@AddAsync` example macro implementation from the swift-syntax
repository.
2024-10-08 11:12:50 -07:00
Steven Wu
ab219d246e [ClangImporter] Update the error condition when delayed inputs are used
Return error only when no inputs are available, instead of relying on
checking no errors occured in diagnostics.
2024-10-03 11:23:16 -07:00
swift-ci
fa8b276b48 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-03 07:54:56 -07:00
Egor Zhdan
c874e6f84c Merge pull request #76119 from finagolfin/droid
[test] Check that the C/C++ module maps are looked for in `-resource-dir` before `-sdk`
2024-10-03 15:36:35 +01:00
Steven Wu
8d2d92a96f [ClangImporter][CAS] Add delay init CAS inputs in clang importer
Handle the special clang instance usage in clang importer to make sure
the inputs from CAS are initialized before perform frontend actions.
2024-10-01 11:33:43 -07:00
swift-ci
c4877a5680 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-01 10:54:18 -07:00
Alastair Houghton
ac750a6aec Merge pull request #76545 from al45tair/eng/PR-115918181
[ClangImporter][ModuleWrap] Turn off libc warnings.
2024-10-01 18:46:06 +01:00
Alastair Houghton
bace89ffbd [ClangImporter] Just turn off the warning, not the actual overlays.
We should still try adding the overlays, even if we're asked not to
generate a diagnostic while doing so.  That's slightly safer because
it means that we're less likely to find ourselves in a situation
where `swift-modulewrap` wants to use types from the C/C++ library
and can't.

rdar://115918181
2024-09-30 17:02:41 +01: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
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
Alastair Houghton
6e48b1d781 [ClangImporter][ModuleWrap] Turn off libc warnings.
`swift-modulewrap` uses the `ClangImporter` to obtain a module loader,
but it doesn't take an SDK argument (nor does anything bother to pass
one), which means that when cross-compiling you get warnings about not
being able to find the C library.

Suppress the warning by telling the `ClangImporter` that we don't care
about the C library here.

rdar://115918181
2024-09-18 13:56:53 +01: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
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
fahadnayyar
f3f4e1913b Fixed diagnostics for incorrect signature of retain/release functions of SWIFT_SHARED_REFERENCE C++ types. 2024-09-10 16:15:07 -07:00
Alexis Laferrière
839f99ec40 Sema: Register clang's export_as in ModuleDecl::getExportAsModule
This service on ModuleDecl wasn't actually used before this PR. The main
client in ASTPrinter calls direclty the underlying logic in FileUnit.
Let's update it for our needs.
2024-09-09 16:57:46 -07:00
swift-ci
189d9fd1e3 Merge remote-tracking branch 'origin/main' into rebranch 2024-09-05 14:54:27 -07:00
Saleem Abdulrasool
a8f47b3ef5 ClangImporter: support SDK for APINotes
Honour the SDK for APINotes to augment the system libraries. This allows
us to distribute APINotes with the Swift SDK and impact the system
without having to map the APINotes into the filesystem.
2024-09-04 15:59:57 -07:00
swift-ci
f1877410ef Merge remote-tracking branch 'origin/main' into rebranch 2024-09-03 02:53:13 -07:00
Gábor Horváth
54efb012f9 Merge pull request #76209 from swiftlang/gaborh/nonescapable-attr
[cxx-interop] Add a SWIFT_NONESCAPABLE attribute to the bridging header
2024-09-03 10:48:55 +01:00
Gabor Horvath
1842867de2 [cxx-interop][NFC] Fix some clang-tidy warnings
Mostly remove redundant includes, adding missing namespace end comments
and using isa_and_nonnull.
2024-09-02 15:24:47 +01:00
Gabor Horvath
738b4c6d8d [cxx-interop] Add a SWIFT_NONESCAPABLE attribute to the bridging header
This makes it easier to experiment with noescapable types in interop.
Moreover, we always wanted to have this annotation for completeness,
similar to SWIFT_NONCOPYABLE.
2024-09-02 14:51:27 +01:00
Finagolfin
d5bd790d05 [test] Check that the C/C++ module maps are looked for in -resource-dir before -sdk, as changed in #74814
Also, dump the module map paths when `-Xfrontend -dump-clang-diagnostics` is
passed in, both so we can check that manually and in these tests, and fix
another Frontend test to be more specific now that this other output trips it up.
2024-08-30 02:37:57 +05:30
swift-ci
50587cd751 Merge remote-tracking branch 'origin/main' into rebranch 2024-08-24 08:34:45 -07:00
Steven Wu
7ed9a52633 [PrefixMap] Remap clang cc1 args when building swift interfaces
Fix a bug that swift clang importer is not setup correctly when prefix
map is used. There are two separate issues:
* CC1 args used to setup clang import when building swift (interface and
  sources) are not correctly remapped.
* When loading SDKInfo from SDK path, the SDKSettings.json is not
  loading from VFS, thus the file cannot be loaded from remapped path.

rdar://134458611
2024-08-23 10:32:20 -07:00
Ben Barham
467e528200 Merge remote-tracking branch 'origin/main' into manual-rebranch-merge
Conflicts:
  - `lib/Serialization/ModuleFormat.h` bumped version to account for
    differences between main and rebranch.
2024-08-09 15:22:39 -07:00
Egor Zhdan
bfe72b4be9 Merge pull request #75589 from swiftlang/egorzhdan/linux-libcxx-interop
[cxx-interop] Allow compiling with libc++ on Linux
2024-08-09 13:42:29 +01:00
Egor Zhdan
059f0f97d1 [cxx-interop] Allow compiling with libc++ on Linux
This makes sure that Swift respects `-Xcc -stdlib=libc++` flags.

Clang already has existing logic to discover the system-wide libc++ installation on Linux. We rely on that logic here.

Importing a Swift module that was built with a different C++ stdlib is not supported and emits an error.

The Cxx module can be imported when compiling with any C++ stdlib. The synthesized conformances, e.g. to CxxRandomAccessCollection also work. However, CxxStdlib currently cannot be imported when compiling with libc++, since on Linux it refers to symbols from libstdc++ which have different mangled names in libc++.

rdar://118357548 / https://github.com/swiftlang/swift/issues/69825
2024-08-08 16:24:58 +01:00
swift-ci
1bb450833a Merge remote-tracking branch 'origin/main' into rebranch 2024-07-30 09:36:41 -07:00
Steven Wu
193b886951 Merge pull request #75443 from cachemeifyoucan/eng/PR-13225588
[Caching] Avoid using clang CAS options in the command-line
2024-07-30 09:33:01 -07:00
swift-ci
b24dc98148 Merge remote-tracking branch 'origin/main' into rebranch 2024-07-24 15:55:32 -07:00
Steven Wu
3f64d99a56 Merge pull request #75357 from cachemeifyoucan/eng/PR-132046247
[ExplicitModule] Include `-Xcc -D` into module hash
2024-07-24 15:50:02 -07:00
swift-ci
f1ea924a51 Merge remote-tracking branch 'origin/main' into rebranch 2024-07-24 10:14:18 -07:00
Allan Shortlidge
66e2f972ab Merge pull request #75432 from tshortli/maccatalyst-upstream
Upstream missing macCatalyst support
2024-07-24 09:58:04 -07:00
swift-ci
5365e57beb Merge remote-tracking branch 'origin/main' into rebranch 2024-07-24 09:53:08 -07:00
Steven Wu
23b0d80d7c [Caching] Avoid using clang CAS options in the command-line
Avoid constructing tasks with `-Xcc` options that references clang
CASOptions. This is going to make the cache hit/miss to be dependent on
CAS location/configuraitons.

Instead, only give swift CASOptions to constructed tasks and propagate
the configurations to underlying clang importer.

rdar://132255889
2024-07-24 09:20:22 -07:00
Egor Zhdan
e9c5f412dd [cxx-interop] Add stack trace entry for the safety heuristic
To better investigate reports of an infinite recursion in `hasPointerInSubobjects`, let's add a pretty stack trace entry to get more readable crash reports.

rdar://131366982
2024-07-24 14:02:38 +01:00
Allan Shortlidge
bb8a837dcf IRGen: Honor -target-variant flag for zippered macCatalyst binaries. 2024-07-23 17:00:10 -07:00