Commit Graph

1343 Commits

Author SHA1 Message Date
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
swift-ci
91e5e65d11 Merge remote-tracking branch 'origin/main' into rebranch 2025-09-12 16:28:53 -07:00
Egor Zhdan
61db98855b Merge pull request #84260 from egorzhdan/egorzhdan/macro-out-of-date
[cxx-interop] Import complex macros consistently in C++ language mode
2025-09-13 00:07:44 +01:00
Egor Zhdan
3c82042633 [cxx-interop] Import complex macros consistently in C++ language mode
This is similar to ced4cb06.

Clang stores macro information for each identifier inside of `IdentifierInfo`, which can sometimes get outdated. Clang solves this by updating the identifier info if necessary in `getLeafModuleMacros`. Let's do the same in Swift.

This makes sure that macros that reference other macros are correctly imported with C++ interop enabled.

rdar://145584369
rdar://110071334
2025-09-12 17:43:42 +01:00
swift-ci
66c8ef9205 Merge remote-tracking branch 'origin/main' into rebranch 2025-09-11 20:55:58 -07:00
Allan Shortlidge
d2682f7c32 AST: Import "always enabled" availability domains from Clang.
Resolves rdar://157593409.
2025-09-11 14:39:18 -07:00
swift-ci
b467918d69 Merge remote-tracking branch 'origin/main' into rebranch 2025-09-03 09:17:14 -07:00
Allan Shortlidge
91ddf93d0f Sema: Introduce an ExportabilityReason for availability attributes.
This allows diagnostics to be more precise and will also support logic that
allows for special cases for `@available` attributes in exportability checking.

Also fixes a bug where the exportability of `@available` attributes attached to
extensions were diagnosed twice for slightly differing reasons.
2025-09-02 23:13:08 -07:00
swift-ci
4904de156e Merge remote-tracking branch 'origin/main' into rebranch 2025-09-02 06:54:21 -07:00
Yuta Saito
3f96cef3a4 [wasm] Add support for __builtin_va_list type mapping (#84029)
Cover all va_list family of types just aliased by __builtin_va_list, including __isoc_va_list from wasi-libc. This enables proper C interop for variable argument functions on WASI targets.

Close https://github.com/swiftlang/swift/issues/72398
2025-09-02 14:36:33 +01:00
swift-ci
8c5816adbc Merge remote-tracking branch 'origin/main' into rebranch 2025-08-30 06:17:37 -07:00
Hamish Knight
28772234bc [CS] Allow contextual types with errors
Previously we would skip type-checking the result expression of a
`return` or the initialization expression of a binding if the contextual
type had an error, but that misses out on useful diagnostics and
prevents code completion and cursor info from working. Change the logic
such that we open ErrorTypes as holes and continue to type-check.
2025-08-29 15:04:20 +01:00
swift-ci
81fa849eae Merge remote-tracking branch 'origin/main' into rebranch 2025-08-26 17:19:55 -07:00
Allan Shortlidge
0b5d510713 Tests: Adopt Clang availability domain declaration macros.
NFC.
2025-08-26 08:20:12 -07:00
Allan Shortlidge
7ac68cecb1 Sema: Check access, availability, and exportability of availability domains.
Teach Sema to diagnose the access level, exportability, and availability of
availability domains that are referenced by `@available` attributes and
`if #available` statements.

Resolves rdar://159147207.
2025-08-26 08:20:12 -07:00
Allan Shortlidge
9de88624b2 Sema: Diagnose availability of availability domains in if #available queries.
When emitting statement diagnostics for `if #available` queries, diagnose the
availability of the decls representing the referenced availability domains.
Among other things, this checks that the domains are sufficiently visible to be
used in the containing function body context.
2025-08-26 08:20:12 -07:00