Commit Graph

138 Commits

Author SHA1 Message Date
Henrik G. Olsson
c541666b21 Merge pull request #85023 from hnrklssn/swiftify-bridging-header
[ClangImporter] add implicit import of `Swift` for `__ObjC` module
2025-10-31 18:08:47 -07:00
John Hui
be3e118f8d [c-interop] Add test for SWIFT_RETURNS_RETAINED annotations in C interop mode
rdar://144976203
2025-10-22 14:53:11 -07:00
Henrik G. Olsson
314d3d520b add required feature 2025-10-21 13:50:06 -07:00
Henrik G. Olsson
c9a62660f3 [ClangImporter] add implicit import of Swift for __ObjC module
Any safe wrapper expansion originating in a bridging header would fail
typechecking because the `__ObjC` module doesn't import the standard
implicit imports. This is because the main module is not available to
inherit implicit imports from when the `__ObjC` module is created. We
don't need all of the implicit modules for safe wrappers, so import
`Swift` specifically.

rdar://163078116
2025-10-20 18:02:28 -07:00
Henrik G. Olsson
634084bc37 [MacrosOnImports] Don't import !swift modules
Inheriting a clang import marked `requires: !swift` will always result
in an error. This skips such imports, which *may* result in name lookup
errors instead, but also may not, depending on the module.

rdar://161795145
2025-10-15 14:25:06 -07:00
Henrik G. Olsson
3bc17bdd2f Merge pull request #84722 from hnrklssn/conditional-span-module-map
Move `span` to conditional header in libstdc++ module map
2025-10-06 22:09:07 -07:00
Henrik G. Olsson
5519be8b7c Move span to conditional header in libstdc++ module map
`span` is not available in all versions of libstd++, so make it a
conditional header. Also adds other missing c++20 headers.

Fixing this triggered an assert when importing a constant initialized
`wchar_t` variable, so that is also fixed. The reason is that `wchar_t`
is mapped to `Unicode.Scalar`, which cannot be directly initialized by
integer literals in Swift, triggering an assert when looking up the
protocol conformance for `_ExpressibleByBuiltinIntegerLiteral`.

rdar://162074714
2025-10-06 16:02:35 -07:00
Hamish Knight
99f6f60e8f [test] Fix availability in import-as-instance-method.swift
This test can run with non-macOS targets, update the availability
condition to be platform agnostic.
2025-10-06 11:47:16 +01:00
Henrik G. Olsson
ed4f058c01 Merge pull request #84507 from hnrklssn/swiftify-import-as-method
[Swiftify] Add support for free functions imported as instance methods
2025-10-04 00:40:00 -07:00
Henrik G. Olsson
0c3db50e3d fix -verify-additional-file path on windows 2025-10-03 15:25:06 -07:00
Mishal Shah
03a599c5be Merge pull request #84606 from swiftlang/rebranch
Merge clang 21.x rebranch into main
2025-10-02 20:17:05 -07:00
Henrik G. Olsson
bfe96dd84b [Swiftify] Reorder RUN lines (NFC)
Since the compiler invokation performing the macro expansion dump
redirects its stderr output, any errors are not displayed by default.
This is extra problematic for test failures in CI. By performing the
compiler invokation with -verify first, errors are shown.
2025-10-02 16:37:44 -07:00
Henrik G. Olsson
439b9e437b use swift/bridging in test 2025-10-02 16:37:43 -07:00
Henrik G. Olsson
748ef20c8c fix tests in CI 2025-10-02 16:37:42 -07:00
Henrik G. Olsson
87642d499a [Swiftify] Add support for free functions imported as instance methods
This adds support for attaching safe interop wrappers to functions
explicitly imported as instance methods using swift_name.

rdar://156288883
2025-10-02 16:37:40 -07:00
susmonteiro
f114a7bda0 [cxx-interop] Re-merge tests failing on Windows 2025-09-30 16:17:56 +01:00
swift-ci
2b9632fde3 Merge remote-tracking branch 'origin/main' into rebranch 2025-09-30 07:55:22 -07:00
susmonteiro
7e14a8ea40 [cxx-interop] SWIFT_NONCOPYABLE overlooked in some cases 2025-09-30 09:28:58 +01:00
Henrik G. Olsson
472644e335 [Interop] Fix tests relying on transitive module imports (NFC) 2025-09-22 14:58:47 -07:00
swift-ci
ce0f17aeac Merge remote-tracking branch 'origin/main' into rebranch 2025-09-19 21:35:40 -07:00
Henrik G. Olsson
33634becd8 [ImportResolution] Remove redundant "Swift" module import
Import resolution now adds the Swift module to the list of imports, so
we no longer need to add it manually.
2025-09-16 21:10:06 -07:00
Henrik G. Olsson
0ea5677aa1 [ImportResolution] Deduplicate top-level clang modules from import list
Importing clang submodules results in an implicit import of the
top-level module as well. This can result in the same TLM being imported
many different times, if multiple submodules are imported from the same
module. This deduplicates these imports.

Other imports are not expected to be duplicated, so care is taken to
only deduplicate clang TLM imports.
2025-09-16 21:10:05 -07:00
Henrik G. Olsson
369fc18c01 [ClangImporter] Only import explicit submodules to the current module
Non-explicit submodules don't need to be explicitly added to the list of
imports to be visible, since their decls are implicitly exported. Skip
these modules even when present in the list of imports. Explicit
submodules are imported *regardless* of whether another module
imports them however.
2025-09-16 21:10:04 -07:00
Henrik G. Olsson
928cc6c83e [ClangImporter] Deduplicate imports copied from submodule to TLM
The imported top-level module inherits the imports of all its
(transitive) submodules. Since multiple submodules can import the same
modules these need to be deduplicated to avoid redundant work.
2025-09-16 21:10:03 -07:00
Henrik G. Olsson
17c0e564e8 Add hidden --dump-source-file-imports flag
This flag dumps all imports for each SourceFile after it's gone through
import resolution. It is only intended for testing purposes.
There are other ways to print imports, but they don't correspond 1:1 to
the imports actually resolved, which is a bit problematic when testing
implicit clang module imports.
2025-09-16 21:09:59 -07:00
Henrik G. Olsson
ef1af64f40 [SwiftifyImport] Add various submodule import test cases
Updates to these test cases will make it easier to follow the effects of
the next commits.
2025-09-08 17:25:37 -07:00
Henrik G. Olsson
3e1358b208 test cxx mode in clang-includes tests 2025-09-08 17:25:36 -07:00
Henrik G. Olsson
13b1faf471 [ClangImporter] Add submodules as implicit imports of wrapper module
Decls in Swift wrapper module may not originate in the top-level clang
module with the same name, since decls in clang submodules are dumped
into the top-level module. This is because Swift has no concept of
submodules. To make sure that any imported decl has access to the same
symbols as the original clang decl had, all transitive submodules, and
their imports, are added as implicit imports of the wrapper module. This
is necessary in the case where a submodule is marked `explicit`.

The content in explicit submodules isn't normally made visible when
importing the parent module. Decls from explicit submodules still
end up in the top-level wrapper module however, so in Swift they do
still need to be visible from the top-level module. This is relevant
for macro expansions, so that they can refer to the same types as the
original decl.
2025-09-08 17:25:35 -07:00
Henrik G. Olsson
9dd52eedc5 fix tests after rebase 2025-09-08 17:25:33 -07:00
Henrik G. Olsson
a43c8474bc [ClangImporter] Add clang module imports to Swift wrapper module
When macros like _SwiftifyImport are added to a wrapper module for a
clang module, they may need to refer to symbols declared in another
clang module that the wrapped module imports (e.g. because they are used
in the original signature). This adds all the imported clang modules as
implicit imports to the wrapper module.

rdar://151611573
2025-09-08 17:25:26 -07:00
swift-ci
4925d9287e Merge remote-tracking branch 'origin/main' into rebranch 2025-09-08 15:34:33 -07:00
Henrik G. Olsson
5ea84522fa update Interop/C/swiftify-import/counted-by-noescape.swift 2025-09-07 12:10:23 -07:00
swift-ci
d493d6e35f Merge remote-tracking branch 'origin/main' into rebranch 2025-08-21 01:57:52 -07:00
Egor Zhdan
ed70a1bb1a Merge pull request #83802 from egorzhdan/egorzhdan/frt-windows
[cxx-interop] Enable reference-counted types on Windows
2025-08-21 09:56:41 +01:00
Egor Zhdan
b440c4ff70 [cxx-interop] Enable reference-counted types on Windows
This enables the use of reference-counted foreign reference types on Windows. As it turns out, the assertion that was failing on Windows previously was unnecessary. This also enabled many of the tests on Windows.

rdar://154694125 / resolves https://github.com/swiftlang/swift/issues/82643
2025-08-20 12:35:10 +01:00
Anthony Latsis
44c480e83b Mnually merge main -> rebranch
Conflicts:
* `lib/ClangImporter/ClangModuleDependencyScanner.cpp`:
  https://github.com/swiftlang/swift/commit/5e09125
*	`utils/build.ps1`: https://github.com/swiftlang/swift/pull/83523
2025-08-19 21:51:34 +01:00
Egor Zhdan
c73f528b82 [cxx-interop] Validate C foreign reference types
Swift validates the retain/release operations for foreign reference types to check for obvious errors, e.g. a wrong parameter type or return type.

That logic was only running for C++ foreign reference types. This patch enables it for C foreign reference types as well.

rdar://158609723
2025-08-18 19:18:18 +01:00
swift-ci
fdc5b2bc73 Merge remote-tracking branch 'origin/main' into rebranch 2025-08-14 19:55:30 -07:00
Doug Gregor
75faafede1 Merge pull request #83671 from DougGregor/apinotes-swift-destroy-op
[Interop] Test APINotes support for noncopyable types with SwiftDestroyOp
2025-08-14 14:46:32 -07:00
swift-ci
e93ab979eb Merge remote-tracking branch 'origin/main' into rebranch 2025-08-14 05:15:47 -07:00
Kavon Farvardin
da53b24d76 test: @_inlineable -> @inlinable
The Swift 4 spelling only should remain in specific tests that ensure it's still accepted in that mode.
2025-08-12 14:32:24 -07:00
Doug Gregor
73687c9f5f [Interop] Test APINotes support for noncopyable types with SwiftDestroyOp. 2025-08-12 10:12:38 -07:00
swift-ci
a06b4d6144 Merge remote-tracking branch 'origin/main' into rebranch 2025-08-07 23:17:13 -07:00
Gabor Horvath
402ad33463 [StrictMemorySafety] Check the safety of return types of calls
Previously, we skipped checking the return type of a function for safety
as we expected to warn at the use of the returned value:

  let x = returnsUnsafe()
  usesUnsafe(x) // warn here

Unfortunately, this resulted in missing some unsafe constructs that can
introduce memory safety issues when the use of the return value had a
different shape resulting in false negatives for cases like:

  return returnsUnsafe()

or

  usesUnsafe(returnsUnsafe())

This PR changes the analysis to always take return types of function
calls into account.

rdar://157237301
2025-08-05 12:16:44 +01:00
Anthony Latsis
3f841b515c Merge remote-tracking branch 'origin/main' into jepa-rebranch 2025-07-30 14:31:33 +01:00
Doug Gregor
71b96e9db9 Split out the part of the test that's failing on Windows 2025-07-29 08:05:28 -07:00
Doug Gregor
34545e0df8 Disable part of this test on Windows 2025-07-28 19:10:21 -07:00
Doug Gregor
8680de42e9 Add missing test for newtype'd struct imported as an option set 2025-07-28 15:53:55 -07:00
Doug Gregor
8909f24440 Add SWIFT_NONCOPYABLE_WITH_DESTROY to swift/bridging header
This packages up the ~Copyable and "destroy" attributes in a macro.
2025-07-28 15:51:44 -07:00
Doug Gregor
63135e8929 [Clang importer] Diagnose various issues with the new "destroy:"
When we cannot respect the "destroy:" annotation, mark the type as
deprecated with a message thst says why there is a problem. There are
various potential problems:

* Multiple conflicting destroy functions
* Destroy functions that don't meet the pattern
* Type isn't imported as a move-only type
* Type has a non-trivial destructor (in C++)
2025-07-28 13:52:50 -07:00