Commit Graph

1358 Commits

Author SHA1 Message Date
Alexis Laferrière
0107f38384 InternalBridgingHeader: Test with vs without library-evolution 2026-01-22 14:59:28 -08:00
Alexis Laferrière
81cff6d4b5 InternalBridgingHeader: Don't warn on use without library-evolution 2026-01-22 14:59:14 -08:00
Hiroshi Yamauchi
867bd732b2 Fix swift tests for Windows ARM64 (#86558) 2026-01-21 16:08:58 -08:00
Alexis Laferrière
0ce07f1cd7 Merge pull request #86565 from xymus/exportability-internal-header
Sema: Enforce non-library-evolution exportability checking with the internal bridging header
2026-01-15 16:06:22 -08:00
Alexis Laferrière
251f0a266c Sema: Fix missing diagnostics with internal bridging headers
rdar://166322874
2026-01-14 13:24:47 -08:00
Steven Wu
a9aa57ee0b Reapply "[DependencyScan] Correct setup clang VFS for dependency scanning"
This reverts commit e60ae24052 and fix
non-deterministic failures introduced by the commit.

Fix two issues when attempting to testing parallel scanning using
`swift-scan-test` tools:
* Make sure the BumpPtrAllocator in ScanningService is thread-safe so
  there are no race condition when a new slab is allocated.
* Make sure the output of `swift-scan-test` only written from one
  thread. This prevents some race conditions when writing to the same
  raw_fd_ostream.

rdar://167760262
2026-01-08 14:14:22 -08:00
Steven Wu
e60ae24052 Revert "[DependencyScan] Correct setup clang VFS for dependency scanning"
This reverts commit e0e69f7ac0. This
causes flaky tests ScanDependencies/scanner_api_working_dir.swift.

rdar://167742034
2026-01-08 08:14:23 -08:00
Steven Wu
4490c656c0 Merge pull request #86104 from cachemeifyoucan/eng/PR-clang-importer-vfs
[DependencyScan] Correct setup clang VFS for dependency scanning
2026-01-07 15:26:03 -08:00
Steven Wu
e0e69f7ac0 [DependencyScan] Correct setup clang VFS for dependency scanning
Currently, dependency scanner is not reporting the redirecting files
that are baked inside swift-frontend for platform support. This causes
dependency scanner returns virtual path for those files, and
swift-driver/build-system will not be able to correct validate the files
on incremental build, causing incremental build to be almost clean
builds.

This behavior issue is caused by the dependency scanning file system
layer inside clang dependency scanner that caches stats. If the
redirecting files are created underneath the layer, the real path is
lost. This fixes the issue by moving the redirecting files above the
caching layer using `-ivfsoverlay` option.

In addition to that, this commit also unifies how clang importer and
clang dependency scanner initiate the VFS, making the logic much
simpler.
2026-01-07 10:00:25 -08:00
Doug Gregor
50ac566cca Use pure C headers with newtype 2026-01-05 17:53:29 -08:00
Doug Gregor
c9da4abd4d Split out the Objective-C parts of the newtype conformance test 2026-01-05 15:39:09 -08:00
Doug Gregor
cac9b9d398 Fix _SwiftNewtypeWrapper when not using the Objective-C runtime
When Objective-C interoperability was disabled, we were not including
the default implementations of _ObjectiveCBridgeable for
_SwiftNewtypeWrapper-conforming types in the standard library. This
meant that the _ObjectiveCBridgeable conformance of newtype'd imported
types was broken.

Enable those implementations by dropping the `#if _runtime(_ObjC)`
check and drop the Objective-C interop requirement for the
corresponding test.

Fixes rdar://167570178.
2026-01-05 13:33:34 -08:00
Erik Eckstein
ccc19e0b73 SemanticARCOpts: remove the BorrowScope optimization because this is now covered by SimplifyBeginBorrow 2025-12-19 17:43:58 +01:00
John Hui
f1e2b7a07f Merge pull request #85723 from an0/my-branch
[ClangImporter] Fix NS_CLOSED_ENUM to validate raw values
2025-12-09 13:35:30 -08:00
Ling Wang
c3f4e5aff9 [ClangImporter] Add tests for NS_CLOSED_ENUM raw value validation
Add execution tests verifying that NS_CLOSED_ENUM (imported as @frozen)
properly validates raw values in init?(rawValue:), returning nil for
invalid values instead of creating poison enum instances.

These tests currently fail, demonstrating issue #85701 where invalid
raw values are accepted and later crash in switch statements.
2025-11-27 14:36:43 -06:00
Hamish Knight
7bca421d51 [ClangImporter] Add check for Bool in importNumericLiteral
I somehow missed this in my original patch, make sure we also handle
the bool case here.

rdar://164916048
2025-11-24 12:02:31 +00:00
John Hui
f830b1c665 [ClangImporter] Do not import enum when already imported via DeclContext (#85424)
If we try to import this in ObjC interop mode:

```objc
typedef CF_OPTIONS(uint32_t, MyFlags) {
  ...
} CF_SWIFT_NAME(MyCtx.Flags);

struct MyStruct {
  MyFlags flags;
  ...
} CF_SWIFT_NAME(MyCtx);
```

ClangImporter tries to import `MyCtx/MyStruct` before it imports
`MyFlags` (via `importDeclContextOf()`), which in turn tries to import
`MyFlags` again due to the `flags` field. The existing cycle-breaking
mechanism prevents us from looping infinitely, but leads us to import
two copies of the Swift `EnumDecl`, which can cause errors later during
CodeGen.

~~This patch adds an assertion to catch such issues earlier, and breaks
the cycle by checking the cache again.~~ This patch no longer does so
because that caused issues beyond the scope of this patch.

rdar://162317760
2025-11-17 13:18:59 -08:00
Hamish Knight
cdffd55d12 [ClangImporter] Check for builtin conformance in importNumericLiteral
Make sure the destination type actually conforms to the corresponding
builtin literal protocol before attempting to import it. We may want
to consider allowing any type that conforms to the non-builtin literal
protocol, but I want to keep this patch low risk and just ensure we at
least don't crash for now.

rdar://156524292
2025-11-10 15:57:33 +00:00
Erik Eckstein
62786b01e2 Optimizer: add the mandatory destroy hoisting pass
It hoists `destroy_value` instructions for non-lexical values.

```
  %1 = some_ownedValue
  ...
  last_use(%1)
  ... // other instructions
  destroy_value %1
```
->
```
  %1 = some_ownedValue
  ...
  last_use(%1)
  destroy_value %1    // <- moved after the last use
  ... // other instructions
```

In contrast to non-mandatory optimization passes, this is the only pass which hoists destroys over deinit-barriers.
This ensures consistent behavior in -Onone and optimized builds.
2025-11-06 21:00:44 +01:00
Doug Gregor
f267f62f65 [SILGen] Consistently use SIL asmname for foreign function/variable references
Whenever we have a reference to a foreign function/variable in SIL, use
a mangled name at the SIL level with the C name in the asmname
attribute. The expands the use of asmname to three kinds of cases that
it hadn't been used in yet:

* Declarations imported from C headers/modules
* @_cdecl @implementation of C headers/modules
* @_cdecl functions in general

Some code within the SIL pipeline makes assumptions that the C names of
various runtime functions are reflected at the SIL level. For example,
the linking of Embedded Swift runtime functions is done by-name, and
some of those names refer to C functions (like `swift_retain`) and
others refer to Swift functions that use `@_silgen_name` (like
`swift_getDefaultExecutor`). Extend the serialized module format to
include a table that maps from the asmname of functions/variables over
to their mangled names, so we can look up functions by asmname if we
want. These tables could also be used for checking for declarations
that conflict on their asmname in the future. Right now, we leave it
up to LLVM or the linker to do the checking.

`@_silgen_name` is not affected by these changes, nor should it be:
that hidden feature is specifically meant to affect the name at the
SIL level.

The vast majority of test changes are SIL tests where we had expected
to see the C/C++/Objective-C names in the tests for references to
foreign entities, and now we see Swift mangled names (ending in To).
The SIL declarations themselves will have a corresponding asmname.

Notably, the IRGen tests have *not* changed, because we generally the
same IR as before. It's only the modeling at the SIL lever that has
changed.

Another part of rdar://137014448.
2025-10-29 19:35:55 -07:00
finagolfin
32913de8c1 Android: disable new @available test until we get NDK 28 or newer in the CI (#85069)
This test was only run with NDK 28 locally, so we didn't realize this
feature won't work with Bionic in LTS NDK 27, which is what the CI uses.
We will re-enable this with the next LTS NDK release, when we switch the
Android CI to use that next LTS NDK.
2025-10-22 17:21:52 -07:00
Alexis Laferrière
4c9a9ca9ad Merge pull request #85039 from xymus/exportability-var-diag
Sema: Custom diagnostic for var decls referencing a restricted type
2025-10-22 10:01:09 -07:00
Alexis Laferrière
2d339c1260 Sema: Custom diagnostic for var decls referencing a restricted type
Replace the `here` part of the generic exportability diagnostic for
variables with: `in a property declaration marked public or in a
'@frozen' or '@usableFromInline' context`.

The full diagnostic now looks like:
```
error: cannot use struct 'ImportedType' in a property declaration marked
public or in a '@frozen' or '@usableFromInline' context;
'HiddenDependency' has been imported as implementation-only
```

This should be improved further to support implicitly exported memory
layouts in non-library-evolution and embedded.
2025-10-21 11:30:52 -07:00
Mads Odgaard
c92e5b47f3 Merge pull request #84574 from madsodgaard/android-availability 2025-10-20 10:40:37 +09:00
Allan Shortlidge
d1991f01ae Merge pull request #84982 from tshortli/clang-importer-ios-availability-test
Tests: Fix `ClangImporter/availability_ios.swift` expected diagnostics
2025-10-17 13:41:19 -07:00
Allan Shortlidge
cccc86ea8c Tests: Fix ClangImporter/availability_ios.swift expected diagnostics.
Resolves rdar://162439072.
2025-10-17 08:09:13 -07:00
Allan Shortlidge
62371b908b Tests: Upstream missing contents of ClangImporter/availability_ios.swift. 2025-10-17 08:09:05 -07:00
Anthony Latsis
71067ea6cc [test] Fix 2 tests after https://github.com/swiftlang/swift/pull/84685
rdar://162273295
2025-10-16 18:42:07 +01:00
Egor Zhdan
de4354b769 [cxx-interop] Quote identifiers more consistently in Clang diagnostics
This is a tiny improvement to the diagnostic messages emitted by Swift. Conventionally we wrap identifiers, such as module names, in single quotes in the diagnostic messages.

rdar://138812125
2025-10-14 15:26:01 +01:00
Alejandro Alonso
18feebaf3a Few more tests 2025-10-07 13:22:34 -07:00
Michael Gottesman
4da340a30d Merge pull request #84728 from gottesmm/pr-c10808b54e513cf6f212aa5f01ede2a97d5a32a6
[concurrency] Import getters with completion handlers as nonisolated(nonsending).
2025-10-07 04:57:53 -07:00
Michael Gottesman
08f108c23b [concurrency] Import getters with completion handlers as nonisolated(nonsending).
Specifically, this means importing getters defined via swift_async_name. This
just ensures that they are treated just like any other imported objc async
function with completion handler.

rdar://156985950
2025-10-06 19:57:01 -07:00
Henrik G. Olsson
1ed646efd6 add -verify-ignore-unrelated to some more tests 2025-10-05 14:01:44 -07:00
Henrik G. Olsson
cbc0ec3b88 Add -verify-ignore-unrelated where necessary (NFC)
These are tests that fail in the next commit without this flag. This
does not add -verify-ignore-unrelated to all tests with -verify, only
the ones that would fail without it. This is NFC since this flag is
currently a no-op.
2025-10-04 14:19:52 -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
Ramon Asuncion
d8591f3f45 [Test][ClangImporter] Split grouped touch commands into individual lines 2025-10-01 11:33:24 -07:00
swift-ci
0632073367 Merge remote-tracking branch 'origin/main' into rebranch 2025-09-23 08:23:10 -07:00
Allan Shortlidge
d505527ff2 Merge pull request #84454 from tshortli/deprecated-custom-availability-domain-fix-its 2025-09-23 07:44:11 -07:00
swift-ci
9372966674 Merge remote-tracking branch 'origin/main' into rebranch 2025-09-22 23:16:05 -07:00
Allan Shortlidge
8a1338dfb2 AST/Sema: Diagnose references to permanently enabled availability domains
A "permanently enabled" availability domain is one that has been declared
always available and is also simultaneously has either an attribute that
makes it deprecated or universally unavailable.

Emit fix-its that remove (or update) `@available` attributes that restrict
availability in a permanently enabled domain. Also, emit warnings about
`if #available` queries that always return true because they check a
permanently enabled domain.

Resolves rdar://157601761.
2025-09-22 17:48:55 -07:00
Doug Gregor
67a9fe09d6 Temporarily disable on Windows 2025-09-22 17:09:16 -07:00
Doug Gregor
a1bc577720 Ensure that -internal-import-bridging-header doesn't show up in a textual interface 2025-09-22 17:09:16 -07:00
Doug Gregor
b7a83495fa Expand DisallowedOriginKind with an explicit entry for internal bridging headers 2025-09-22 11:08:51 -07:00
Doug Gregor
d04e6dd881 Add #include guards around bridging header 2025-09-19 20:09:59 -07:00
Doug Gregor
7bc02d6a70 Improve some diagnostic with @_implementationOnly violations from internal bridging headers 2025-09-19 16:49:24 -07:00
Doug Gregor
30bdb6b37a [Serialization] Don't serialize an internally-imported bridging header
Internally-imported bridging headers must not leak outside of the Swift
module. Don't serialize their contents, and make sure we can still
import the module even if the bridging header has been removed.
2025-09-19 16:49:22 -07:00
Doug Gregor
b9f00ef923 Warn about the use of internal bridging headers without library evolution
It's very, very easy to make a mistake that will cause broken
serialized modules. Until that's no longer true, at least tell folks
that they are heading into uncharted waters, as we do with
`@_implementationOnly` imports.
2025-09-19 16:49:22 -07:00
Doug Gregor
903937a78f Exempt C++ namespaces from internal-import checking
C++ namespaces always get imported into the bridging header's module
for Reasons. Exempt them from internal-import checking, since we get
checking for the namespace members that are actually used.
2025-09-19 16:49:20 -07:00
Doug Gregor
b13c2aeccd Treat internally-imported bridging headers as internally-imported
When using an internal import for a bridging header, semantically treat
the contents of the bridging header, and anything that it imports, as
if they were imported internally. This is the actual semantic behavior
we wanted from internally-imported bridging headers.

This is the main semantic checking bit for rdar://74011750.
2025-09-19 16:49:17 -07:00
Doug Gregor
2383d7ab2d Introduce "-internal" variant of bridging header import flags
The flags "-import-bridging-header" and "-import-pch" import a bridging
header, treating the contents as a public import. Introduce
"internal-" variants of both flags that provide the same semantics,
but are intended to treat the imported contents as if they came in
through an internal import. This is just plumbing of the options for
the moment.
2025-09-19 16:49:11 -07:00