Commit Graph

6196 Commits

Author SHA1 Message Date
Henrik G. Olsson
374658aae0 [Swiftify] Don't import counted_by with suffixed integer literals (#82469)
Integer literal expressions with types that are not of type `int` are
printed with a suffix to indicate the type (e.g. `123U` or `456L` for
`unsigned` and `long`). This is not valid syntax for integer literals in
Swift, so until we fully translate the count expr syntax to Swift we
need to avoid importing these count expressions.

Also fixes some -Werror related stuff in test cases.

rdar://154141719
2025-06-27 09:27:50 -07:00
Egor Zhdan
f8664adbad Merge pull request #82496 from swiftlang/egorzhdan/allow-qual-swift-name
[cxx-interop] Allow import-as-member for types in namespaces
2025-06-27 13:22:25 +01:00
Anthony Latsis
1f89bb6a94 Merge pull request #82452 from swiftlang/jepa2
Sema: Fix the insertion location for conformances attributes
2025-06-26 21:38:41 +01:00
Pavel Yaskevich
32a0d80b60 Merge pull request #82085 from xedin/rdar-149811049
[ClangImporter] SE-0463: Implement `@Sendable` inference exception for global actor isolated functions
2025-06-26 09:26:28 -07:00
Egor Zhdan
e95f6a3ce9 [cxx-interop] Allow import-as-member for types in namespaces
This adds support for `swift_name` attribute being used with C++ types that are declared within namespaces, e.g.
```
__attribute__((swift_name("MyNamespace.MyType.my_method()")))
```

Previously import-as-member would only accept a top-level unqualified type name.

rdar://138934888
2025-06-26 12:39:50 +01:00
Argyrios Kyrtzidis
d385e8c87a Merge pull request #81792 from sina-mahdavi/sina-mahdavi/fix-llvm-prefix-mapping-calls
fix calls to llvm prefix mapping functions to use space-separated opt…
2025-06-25 13:19:21 -07:00
Artem Chikin
705b1a667f Merge pull request #82429 from artemcm/ScannerInvalidBinaryModuleRefactor
[Dependency Scanning] Refactor the scanner to simplify layering
2025-06-25 09:03:18 -07:00
Sina Mahdavi
7090b7e145 fix calls to llvm prefix mapping functions to use space-separated option format 2025-06-24 13:32:55 -07:00
Anthony Latsis
ad8c52237c Sema: Fix the insertion location for conformances attributes 2025-06-24 14:49:03 +01:00
Artem Chikin
39c096c388 [Dependency Scanning] Refactor 'ModuleDependenciesCache' to not hold a reference to the global 'SwiftDependencyScanningService'
While this made sense in the distant past where the scanning service provided backing storage for the dependency cache, it no longer does so and now makes for awkard layering where clients get at the service via the cache. Now the cache is a simple data structure while all the clients that need access to the scanning service will get it explicitly.
2025-06-23 13:39:43 -07:00
Artem Chikin
68883a1014 [Dependency Scanning] Refactor Swift Scanner loader to be standalone
- 'SwiftModuleScanner' will now be owned directly by the 'ModuleDependencyScanningWorker' and will contain all the necessary custom logic, instead of being instantiated by the module interface loader for each query
- Moves ownership over module output path and sdk module output path directly into the scanning worker, instead of the cache
2025-06-23 13:39:36 -07:00
Egor Zhdan
4911078437 [cxx-interop] NFC: Remove unused function 2025-06-23 15:25:00 +01:00
John Hui
a0d3ad7bd0 Merge pull request #82006 from j-hui/jump-to-def-for-macro-expanded-clang-imports
[SourceKit] Support location info for macro-expanded Clang imports
2025-06-19 02:01:40 -07:00
michael-yuji
cf2f7154a5 Merge pull request #77836 from michael-yuji/mchiu/freebsd
[FreeBSD] Adding FreeBSD support
2025-06-18 19:59:48 -07:00
(null)
aaf283258b Merge branch 'main' into mchiu/freebsd 2025-06-17 15:41:57 -04:00
(null)
d6811260a9 Merge commit '665515c781999a81094bbe4f8302a7cb1a6a6b39' into mchiu/freebsd 2025-06-17 15:12:23 -04:00
Egor Zhdan
f6e61728c5 Merge pull request #82161 from swiftlang/egorzhdan/template-param-nullability
[cxx-interop] Import nullability of templated function parameters correctly
2025-06-17 16:51:47 +01:00
Gábor Horváth
304d558f43 Merge pull request #82203 from swiftlang/gaborh/shared-references-are-safe
[cxx-interop] Shared references are considered safe
2025-06-17 16:12:59 +01:00
Cyndy Ishida
64168edbf5 [Modules] Allow implicit conversions when loading interfaces with invalid os versions (#82228)
Initially, the compiler rejected building dependencies that contained OS
versions in an invalid range. However, this happens to be quite
disruptive, so instead allow it and request that these versions be
implicitly bumped based on what `llvm::Triple::getCanonicalVersionForOS`
computes.

resolves: rdar://153205856
2025-06-16 12:46:32 -07:00
Egor Zhdan
607dd4a7d4 [cxx-interop] Import nullability of templated function parameters correctly
This teaches ClangImporter to respect the `_Nonnull`/`_Nullable` arguments on templated function parameters.

Previously Swift would only import a non-annotated function overload. Using an overload that has either  `_Nonnull` or `_Nullable` would result in a compiler error. The non-annotated overload would get imported with incorrect nullability: Swift would always assume non-null pointers, which was inconsistent with non-templated function parameters, which are mapped to implicitly unwrapped optionals.

With this change all three possible overloads are imported, and all of them get the correct nullability in Swift.

rdar://151939344
2025-06-13 18:15:52 +01:00
Gabor Horvath
ddacdf416d [cxx-interop] Shared references are considered safe
This patch makes sure we don't get warnings in strict memory safe mode
when using shared references. Those types are reference counted so we
are unlikely to run into lifetime errors.

rdar://151039766
2025-06-13 15:41:51 +01:00
John Hui
44aba1382d [SourceKit] Support location info for macro-expanded Clang imports
Currently, when we jump-to-definition for decls that are macro-expanded
from Clang imported decls (e.g., safe overloads generated by
@_SwiftifyImport), setLocationInfo() emits a bongus location pointing to
a generated buffer, leading the IDE to try to jump to a file that does
not exist.

The root cause here is that setLocationInfo() calls getOriginalRange()
(earlier, getOriginalLocation()), which was not written to account for
such cases where a macro is generated from another generated buffer
whose kind is 'AttributeFromClang'.

This patch fixes setLocationInfo() with some refactoring:

-   getOriginalRange() is inlined into setLocationInfo(), so that the
    generated buffer-handling logic is localized to that function. This
    includes how it handles buffers generated for ReplacedFunctionBody.

-   getOriginalLocation() is used in a couple of other places that only
    care about macros expanded from the same buffer (so other generated
    buffers not not relevant). This "macro-chasing" logic is simplified
    and moved from ModuleDecl::getOriginalRange() to a free-standing
    function, getMacroUnexpandedRange() (there is no reason for it to be
    a method of ModuleDecl).

-   GeneratedSourceInfo now carries an extra ClangNode field, which is
    populated by getClangSwiftAttrSourceFile() when constructing
    a generated buffer for an 'AttributeFromClang'. This could probably
    be union'ed with one or more of the other fields in the future.

rdar://151020332
2025-06-12 18:22:06 -07:00
Saleem Abdulrasool
0311223ea4 ClangImporter: work around the inability to adjust the Darwin overlay (#82213)
Explicitly carve out `_stdio.stdin`, `_stdio.stdout`, `_stdio.stderr` as
unaliased as the macros are explicitly imported through the `_stdio`
overlay.
2025-06-12 16:17:52 -07:00
Artem Chikin
1c08abab43 Merge pull request #82169 from artemcm/DepScanImportAccessControl
[Dependency Scanning] Keep track of each imported module's access control
2025-06-12 12:41:51 -07:00
Artem Chikin
6816922dd4 [Dependency Scanning] Keep track of each imported module's access control
Adds an access control field for each imported module identified. When multiple imports of the same module are found, this keeps track of the most "open" access specifier.
2025-06-12 06:56:30 -07:00
Pavel Yaskevich
ab227b401d [ClangImporter] SE-0463: Implement @Sendable inference exception for global actor isolated functions
Functions that are isolated to a global actor don't have completion
handlers imported as `@Sendable`. Main actor isolated functions with
completion handlers that are always called on the main actor is a
very common Objective-C pattern, and this carve out will eliminate
false positive warnings in the cases where the main actor annotation
is missing on the completion handler parameter.

Resolves: rdar://149811049
2025-06-11 23:44:01 -07:00
Slava Pestov
71186eb07f AST: Call setExtendedNominal() instead of cacheOutput(ExtendedNominalRequest...) 2025-06-11 20:07:42 -04:00
Henrik G. Olsson
bd714f57fc [ClangImporter] Look through bounds attributes for template matching
When instantiating templated functions with pointers to the templated
type, the ClangImporter does not strip type sugar. This strips type
sugar for bounds attributes, to make sure that they import the same
regardless of whether they are parsed or not.

rdar://151041990
2025-06-10 18:11:47 +02:00
Qiongsi Wu
1b003b2c51 Revert "[Dependency Scanning] Update Uses of ModuleDeps::ClangModuleDeps #81243" (#81658)
This reverts commit 024dbd040f, reversing
changes made to a08b1cbb1d.

The commit did not solve the fundamental issue we need to handle and is
no longer necessary.

rdar://144794793

<!--
If this pull request is targeting a release branch, please fill out the
following form:

https://github.com/swiftlang/.github/blob/main/PULL_REQUEST_TEMPLATE/release.md?plain=1

Otherwise, replace this comment with a description of your changes and
rationale. Provide links to external references/discussions if
appropriate.
If this pull request resolves any GitHub issues, link them like so:

  Resolves <link to issue>, resolves <link to another issue>.

For more information about linking a pull request to an issue, see:

https://docs.github.com/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue
-->

<!--
Before merging this pull request, you must run the Swift continuous
integration tests.
For information about triggering CI builds via @swift-ci, see:

https://github.com/apple/swift/blob/main/docs/ContinuousIntegration.md#swift-ci

Thank you for your contribution to Swift!
-->
2025-06-09 08:36:35 -07:00
Saleem Abdulrasool
c66d43e1c5 ClangImporter: enhance the importer to alias declarations
Import simple CPP macro aliases as aliases in Swift. Extend the macro
importer to import the following construct:

  ```
  #define alias aliasee
  ```

as the following Swift construct:

  ```
  @_transparent @inline(__always)
  var alias: type(of: aliasee) {
    aliasee
  }
  ```

This improves the QoI for Windows where there is a universal define
(`UNICODE`) which normally is used for translating APIs between ANSI and
Unicode variants, e.g.:

  ```
  #if defined(UNICODE)
  #define MessageBox MessageBoxW
  #else
  #define MessageBox MessageBoxA
  #endif
  ```

Global variables which are non-const also have a setter synthesized:

  ```
  @_transparent @inline(__always)
  var alias: type(of: aliasee) {
    get { return aliasee }
    set { aliasee = newValue }
  }
  ```
2025-06-08 12:45:40 -07:00
Pavel Yaskevich
74471e858b [ClangImporter] Use DefaultsToSendable with completion handler parameter
This lifts the check for the feature flag up into the `importParameterType`
from `importType` and means that completion handler type for `async` variant
is no longer gains `@Sendable` attribute.
2025-06-06 17:08:22 -07:00
Saleem Abdulrasool
083cb114b3 Merge pull request #82065 from compnerd/import-shims
ClangImporter: import SwiftShims properly for static linking
2025-06-06 15:05:04 -07:00
Steven Wu
debdd224d5 Merge pull request #81990 from cachemeifyoucan/eng/PR-152441866
[CAS] Allow uncached job from CAS based dependency scanning
2025-06-06 12:08:21 -07:00
Saleem Abdulrasool
43b2b596fe ClangImporter: import SwiftShims properly for static linking
When building against the static standard library, we should define
`SWIFT_STATIC_STDLIB` to indicate to the shims that the declarations
should be giving hidden visibility and default DLL storage. This is
required to ensure that these symbols are known to be `dso_local` when
compiling to avoid an unnecessary look up through the PLT/GOT or the
indirection through the synthesized `__imp_` symbol and the IAT. This
corrects a number of incorrect code generation cases on Windows with the
static standard library.
2025-06-06 09:35:51 -07:00
Gábor Horváth
296726aa12 Merge pull request #82016 from swiftlang/gaborh/swiftify-private
[cxx-interop] Avoid swiftifying private and protected methods
2025-06-06 17:19:46 +01:00
Gabor Horvath
6eb7057e75 [cxx-interop] Avoid swiftifying private and protected methods
The generated overloads do not get seralized and later on the compiler
crashes due to the missing body of the SILFunction. This PR works this
problem around by not generating these overloads. We plan to address the
serialization issue later.

rdar://152181531
2025-06-06 11:07:01 +01:00
Gabor Horvath
868c85d5f0 [cxx-interop] Only swiftify template instantiations behind type aliases
While I could not trigger a scenario where the generated macro triggers
a compilation error, the generated code is definitely not valid Swift.

rdar://151422108
2025-06-06 10:31:52 +01:00
Steven Wu
8d5d758676 [CAS] Allow uncached job from CAS based dependency scanning
Create a path that swift-frontend can execute an uncached job from
modules built with CAS based explicit module build. The new flag
-import-module-from-cas will allow an uncached build to load module
from CAS, and combined with source file from real file system to build
the current module. This allows quick iterations that bypasses CAS,
without full dependency scanning every time in between.

rdar://152441866
2025-06-05 14:55:42 -07:00
Henrik G. Olsson
89b09a69e4 Merge pull request #81752 from hnrklssn/swiftify-sized-sizedby
[Swiftify] Support __sized_by on byte-sized pointee types
2025-06-05 08:42:42 -07:00
Henrik G. Olsson
114a1a924c address review comments 2025-06-04 11:26:15 -07:00
Gábor Horváth
a8d979e625 Merge pull request #81947 from swiftlang/gaborh/swiftify-initializers
[cxx-interop] Support Swiftifying C++ constructors
2025-06-04 17:41:40 +01:00
Gabor Horvath
d5faddaa9b [cxx-interop] Support Swiftifying C++ constructors
Unfortunately, there is no common abstraction for initializers and
functions in SwiftSyntax, so this PR rolls our own. Alternatively, we
could probably achieve something similar with a new protocol, but we
only needed a handful of fields so this change keeps it simple.

rdar://152112660
2025-06-04 10:06:16 +01:00
Susana Monteiro
e910d9b2f8 Merge pull request #81709 from swiftlang/susmonteiro/ambiguous-use-of-method
[cxx-interop] Fix ambiguous methods in long chains of inheritance
2025-06-03 15:50:28 +01:00
Artem Chikin
4fb4945ab9 Merge pull request #81908 from artemcm/FixImplicitBuildCXXInteropCycle
[C++Interop] Do not query C++ Standard Library Swift overlays when building Swift modules which were built without C++ interop
2025-06-02 23:26:27 -07:00
Artem Chikin
5577df7115 [Implicit Module Builds] Do not query CxxStdlib Swift overlay for textual modules which were not built with c++interop
When the compiler is building a module without a defined formal C++ interop mode (e.g. building a textual interface which specifies it was built without C++ interop enabled), avoid looking up the C++ standard library Swift overlay for it. This is required for the case of the Darwin module, for example, which includes headers which map to C++ stdlib headers when the compiler is operating in C++ interop mode, but the C++ standard library Swift overlay module itself depends on 'Darwin', which results in a cycle. To resolve such situations, we can rely on the fact that Swift textual interfaces of modules which were not built with C++ interop must be able to build without importing the C++ standard library Swift overlay, so we avoid specifying it as a dependency for such modules. The primary source module, as well as Swift textual module dependencies which were built with C++ interop will continue getting a direct depedency of the 'CxxStdlib' Swift module.

This was previously fixed in the dependency scanner for explicitly-built modules in https://github.com/swiftlang/swift/pull/81415.
2025-06-02 12:25:59 -07:00
Michael Chiu
7bbafc599d Merge branch 'main' into mchiu/freebsd 2025-06-02 13:33:18 -04:00
susmonteiro
79227e7a09 [cxx-interop] Fix ambiguous methods in long chains of inheritance 2025-06-02 16:51:58 +01:00
Henrik G. Olsson
ac068c2a6b [ClangImporter] Look through __ended_by and __null_terminated (#81630)
Previously we would not import decls containing these types. This was
not an issue, because they can only occur when -fbounds-safety or
-fexperimental-bounds-safety-attributes is passed to clang. When
SafeInteropWrappers is enabled we pass
-fexperimental-bound-safety-attributes to clang however, so these types
can now occur without the user specifying any -Xcc flags.

rdar://151611718
2025-05-30 22:53:15 -07:00
Kuba (Brecka) Mracek
5ea9b7d357 Merge pull request #81857 from kubamracek/embedded-builtin-float
[embedded] Resolve a circular dependency problem in SwiftShims when using pico-libc
2025-05-30 02:12:01 -07:00
Artem Chikin
74e207b7bb Merge pull request #81713 from artemcm/ClangRemapsForDepScanQueries
[Dependency Scanning] Add ClangImporter's mandatory path remaps to dependency scanning query filesystem
2025-05-29 18:25:30 -07:00