Commit Graph

1342 Commits

Author SHA1 Message Date
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
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
Pavel Yaskevich
4132aa04f9 [Tests] NFC: Update all of the test-cases improved by changes to generic argument mismatch handling 2025-06-03 00:49:06 -07:00
Michael Gottesman
3ed4059a60 [sema] Change non-sendable -> non-Sendable in diagnostics.
This matches send non sendable but importantly also makes it clear that we are
talking about something that doesn't conform to the Sendable protocol which is
capitalized.

rdar://151802975
2025-05-22 11:37:58 -07:00
finagolfin
35ee368bb9 [android][test] Fix or disable the remaining failing tests on the Android CI (#81398)
Also, fix and enable `IRGen/lto_autolink` for all non-Wasm targets and
`IRGen/static_initializer` for aarch64.


This should get [the community Android
CI](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-24.04-android-build/)
green
[again](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-24.04-android-arm64/).
2025-05-17 13:27:33 +05:30
Kuba Mracek
1ecdb17fcc [ClangImporter] Fix enum conversion type when importing global values (unwrap if needed) 2025-05-13 16:02:15 -07:00
Robert Widmann
edcde7c55c [ClangImporter] Import 'swift_attr("sending")' As a Type Attribute
Previously, `__attribute__((swift_attr("sending")))` would only be
resolved when attached to declarations. This patch expands it to be
a type attribute as well, which enables it to occur in the result and
parameter positions for blocks, function pointers, and lambdas.

Resolves rdar://148435359
2025-05-07 18:19:38 +01:00
Anthony Latsis
4517a6e26b Merge pull request #81279 from AnthonyLatsis/fix-rebranch-on-main
Fix some rebranch test failures on main
2025-05-06 22:20:09 +01:00
Allan Shortlidge
24fa9c8703 ClangImporter: Introduce the #ClangDeclarationImport diagnostic group.
The warnings that ClangImporter emits about issues it encounters while
importing declarations from Clang modules should all belong to a diagnostic
group so that users of `-warnings-as-errors` can control their behavior using
the compiler flags introduce with SE-0443. It's especially important that these
diagnostics be controllable since they are often caused by external
dependencies and therefore the developer may not have any control over whether
they are emitted.

The `#ClangDeclarationImport` diagnostic group is intentionally broad so that
developers have a way to control all of these diagnostics with a single
`-Wwarning` flag. I fully expect that we'll introduce finer-grained diagnostic
groups for some of these diagnostics in the future, but those groups should be
hierarchically nested under `#ClangDeclarationImport`, which is supported by
SE-0443.

Resolves rdar://150524204.
2025-05-05 14:16:53 -07:00
Anthony Latsis
17fc00f8a7 [test] IRGen: Adjust FileCheck patterns for new nuw attribute in upstream LLVM
This attribute was introduced in
7eca38ce76d5d1915f4ab7e665964062c0b37697 (llvm-project).

Match it using a wildcard regex, since it is not relevant to these
tests.

This is intended to reduce future conflicts with rebranch.
2025-05-04 03:28:56 +01:00
Pavel Yaskevich
b0792d4eb7 [Tests] RegionBasedIsolation: Switch actor isolated to actor-isolated in a few error messages 2025-04-25 15:15:26 -07:00
Michael Gottesman
6cf9ee5ebf Merge pull request #81014 from gottesmm/pr-af452b4f8348d8c3dc39d9a1682b01910a7c3194
[silgen] When emitting a foreign async completion handler for a method, use merge isolation region to tie self and the block storage into the same region.
2025-04-24 10:17:36 -07:00
Michael Gottesman
227ab376cf [silgen] When emitting a foreign async completion handler for a method, use merge isolation region to tie self and the block storage into the same region.
This is an extension of a similar problem that I had fixed earlier where due to
the usage of intermediate Sendable types we do not propagate regions correctly.

The previous issue I fixed was that we were not properly tieing the result of a
foreign async completion handler to the block storage since we used an
intervening UnsafeContinuation (which is Sendable) to propagate the result into
the block storage. I fixed this by changing SILGen to insert a
merge_isolation_region that explicitly ties the result to the block storage.

This new issue is that the block that we create and then pass as the completion
handler is an @Sendable block. Thus when we call the actual objc_method, the
block storage and self are not viewed as being in the same region. In this PR, I
change it so that we add a merge_isolation_region from self onto the block
storage.

The end result of this is that we have that self, the result of the call, and
the block storage are all in the same region meaning that we properly diagnose
that returning an NSObject from the imported Objective-C function is task
isolated and thus we cannot return it as a sending result.

rdar://131422332
2025-04-23 10:01:24 -07:00
Anthony Latsis
9a98784a96 Merge pull request #80593 from AnthonyLatsis/collybia-nuda
AST: Quote attributes more consistently in diagnostics
2025-04-23 16:50:26 +01:00
Anthony Latsis
2cd90bdd69 AST: Quote attributes more consistently in DiagnosticsSema.def 2025-04-22 18:23:36 +01:00
Kuba Mracek
af9fc448a6 [ClangImporter] Mark test/ClangImporter/const_values_objc.swift as REQUIRES: objc_interop 2025-04-20 21:18:41 -07:00
Kuba Mracek
f0094c24e4 [ClangImporter] Don't import accessors of constants as 'open' if they're static 2025-04-20 19:57:54 -07:00
Kuba Mracek
0319aa4686 [ClangImporter] Relax expectations in ClangImporter/const_values.swift to fix Windows CI test failure 2025-04-16 10:18:48 -07:00
Kuba Mracek
26cc36b8b0 [ClangImporter] Handle swift_wrapper annotated typedefs, skip CGFloats when importing const values 2025-04-14 15:03:18 -07:00
Kuba Mracek
8e6071ecbc [ClangImporter] Skip value importing on partial/dependent C++ decls, adjust C++ lit tests 2025-04-14 13:20:51 -07:00
Kuba Mracek
dc6577346e [ClangImporter] Add more const values importing tests cases 2025-04-14 10:01:23 -07:00
Kuba Mracek
936e91130a [ClangImporter] Fix importing values for constant globals of enum types 2025-04-14 10:01:23 -07:00
Kuba Mracek
ec24b7421a [ClangImporter] Add more test coverage in ClangImporter/const_values.swift + ClangImporter/const_values_cxx.swift 2025-04-14 10:01:23 -07:00
Kuba Mracek
a39f60b9ad [ClangImporter] Import constant values for 'const' globals 2025-04-14 10:01:23 -07:00
Becca Royal-Gordon
1445b819d0 Merge pull request #80476 from beccadax/implement-this
Stub fix-its for missing objcImpl requirements
2025-04-10 16:55:19 -07:00
Allan Shortlidge
94a8526526 Merge pull request #80616 from tshortli/availability-domain-serialization
Serialization: Encode custom availability domains
2025-04-08 22:39:03 -07:00
Ahmed Bougacha
1b5a94e219 [ClangImporter] Let clang pick default target CPU. (#80451)
Currently, ClangImporter has some logic to pick the default arm64
target CPU (when -target-cpu isn't passed) based on the target OS
and arch variant.

This was originally done long ago in 3cf3f42e98, and later
maintained through 49a6c8eb7b, because it was necessary when
clang (targeting darwin) relied on -arch to set this sort of default.

Clang has migrated to full -target triples for a while now, and has
sophisticated logic for picking default target CPUs and features based
on the target triple.

Currently, we override that by passing our -mcpu explicitly.
Instead, allow clang to pick its defaults, and only pass -mcpu
when asked via -target-cpu.

This is visible in the test, with arm64 macOS now defaulting to M1.
The same applies to simulators, per Triple::isTargetMachineMac.

rdar://148377686
2025-04-08 17:34:23 -07:00
Allan Shortlidge
abac42b759 Serialization: Encode custom availability domains.
When serializing `@available` attributes, if the attribute applies to a custom
domain include enough information to deserialize the reference to that domain.

Resolves rdar://138441265.
2025-04-08 08:53:42 -07:00
Allan Shortlidge
6527a068eb ClangImporter: Remove custom AvailabilityDomain serialization.
Partially revert https://github.com/swiftlang/swift/pull/80035 now that Clang
has its own APIs for querying serialized modules for the decl representing the
availability domain with a given name.
2025-04-08 08:53:06 -07:00
Becca Royal-Gordon
93188f81cc Stub fix-its for missing objcImpl requirements
Changes the diagnostics emitted when an `@objc @implementation` extension is missing some of the members required by the extension:

• We now emit one error on the extension, plus a note for each missing member.
• Where possible, we also emit a note with a fix-it adding stubs.

For example:

```
  9 | @objc @implementation extension ObjCClass {
    |                       |- error: extension for main class interface does not provide all required implementations
    |                       |- note: missing instance method 'method(fromHeader3:)'
    |                       |- note: missing instance method 'method(fromHeader4:)'
    |                       |- note: missing property 'propertyFromHeader7'
    |                       |- note: missing property 'propertyFromHeader8'
    |                       |- note: missing property 'propertyFromHeader9'
    |                       |- note: missing instance method 'extensionMethod(fromHeader2:)'
    |                       `- note: add stubs for missing '@implementation' requirements
```

With a fix-it on the last note to insert the following after the open brace:

```

  @objc(methodFromHeader3:)
  open func method(fromHeader3 param: Int32) {
      <#code#>
  }

  @objc(methodFromHeader4:)
  open func method(fromHeader4 param: Int32) {
      <#code#>
  }

  @objc(propertyFromHeader7)
  open var propertyFromHeader7: Int32 {
      get {
          <#code#>
      }
      set {
          <#code#>
      }
  }

  @objc(propertyFromHeader8)
  open var propertyFromHeader8: Int32 {
      get {
          <#code#>
      }
      set {
          <#code#>
      }
  }

  @objc(propertyFromHeader9)
  open var propertyFromHeader9: Int32 {
      get {
          <#code#>
      }
      set {
          <#code#>
      }
  }

  @objc(extensionMethodFromHeader2:)
  open func extensionMethod(fromHeader2 param: Int32) {
      <#code#>
  }

```

Fixes rdar://130038221.
2025-04-07 17:53:15 -07:00
Becca Royal-Gordon
274c4d9d22 Merge pull request #80557 from beccadax/the-case-of-the-missing-member
[ClangImporter] Fix import of aliased enum cases
2025-04-07 16:25:53 -07:00
Becca Royal-Gordon
86704e35e1 [ClangImporter] Fix import of aliased enum cases
When a C enum has multiple constants with the same value, ClangImporter selects one of them to import as an `EnumElementDecl` and imports the others as `VarDecl` “aliases” of that one. This helps preserve the invariant that each case of an enum has a unique raw value and is distinct for exhaustiveness checking.

However, a bug in that logic could sometimes cause the canonical case to be imported *twice*—once as an `EnumElementDecl` and again as a `VarDecl` alias. In this situation, the `EnumElementDecl` was not added to the enum’s member list, resulting in a malformed AST. This bug has apparently been present since early 2017 (!), but it seems to have been harmless until recently, when the `ComputeSideEffects` SIL pass recently became sensitive to it (probably because of either #79872 or #80263).

Correct this problem by modifying the memoization logic to retrieve the canonical case’s clang-side constant so the subsequent check will succeed. Additionally change a variable name and add comments to help clarify this code for future maintainers.

In lieu of adding new unit tests, this commit adds a (slightly expensive) conditional assertion to catch this kind of AST malformation. There are actually about twenty tests that will fail with just the assertion and not the fix, but I’ve updated one of them to enable the assertion even in release mode.

Fixes rdar://148213237. Followup to #80487, which added related assertions to the SIL layer.
2025-04-04 18:54:36 -07:00
Allan Shortlidge
a200cf518e Tests: Use #include instead of #import for compatibility on Windows.
The `#import` directive is not supported by Clang in MSVC compatibility mode,
so use `#include` instead for compatibility in the ClangImporter tests for
custom availability domains.

Resolves rdar://147122406.
2025-04-04 07:53:55 -07:00
Artem Chikin
c9ba79c8da [Dependency Scanning] Always record best version of discovered 'canImport'-ed modules
Suppose module 'Foo' exists in the search paths and specifies user module version '1.0'.

If the first encountered 'canImport' query is unversioned:
...

Followed by a versioned one:
...

The success of the first check will record an unversioned successful canImport, which will cause the second check to evaluate to 'true', which is incorrect.

This change causes even unversioned 'canImport' checks to track and record the discovered user module version.
2025-04-01 14:55:37 -07:00
John McCall
4da795fd61 Merge pull request #80297 from rjmccall/zero-objc-async-result-on-error-path
Pass a zero normal result to ObjC async completion handlers on the error path
2025-03-26 12:42:38 -04:00
John McCall
3fe70968cc Remove the substitution map from zeroInitializer builtin in SIL.
This is a value operation that can work just fine on lowered types,
so there's no need to carry along a formal type. Make the value/address
duality clearer, and enforce it in the verifier.
2025-03-26 00:34:15 -04:00
Hamish Knight
738c70e8c8 [AST] Always walk folded SequenceExpr if available
Expand the special-cased ASTWalker behavior for folded SequenceExprs
such that we always walk the folded expression when available. This
ensures that we don't attempt to add the same node multiple times
when expanding ASTScopes during pre-checking.

rdar://147751795
2025-03-24 20:18:34 +00:00
Allan Shortlidge
41be6eba9c Tests: Disable ClangImporter/availability_custom_domains.swift on Android.
Unblocks Windows CI, which apparently tests Android. The underlying issue is tracked by
https://github.com/swiftlang/swift/issues/80058.
2025-03-17 10:01:41 -07:00
Allan Shortlidge
e96b44be31 ClangImporter: Import clang::DomainAvailabilityAttr.
Import `__attribute__((availability(domain:MyDomain, ...)))` as
`@available(SomeDomain, ...)`.

Resolves rdar://138441266.
2025-03-15 07:44:37 -07:00
Allan Shortlidge
72c821e2a7 ClangImporter: Look up availability domains in Clang modules.
In addition to tracking availability domains in SwiftLookupTable, also
serialize and deserialize the mapping from domain name to `clang::VarDecl`.
Ideally this serialization and lookup infrastructure would be entirely handled
by Clang, since it also needs to look up availability domains in serialized
modules, but the implementation for that is not ready yet.

Part of rdar://138441266.
2025-03-15 07:44:37 -07:00
Allan Shortlidge
017dae382e ClangImporter: Look up availability domains defined in bridging headers.
This is very brittle in this first iteration. For now we require the
declaration representing the availability domain be deserialized before it can
be looked up by name since Clang does not have a lookup table for availabilty
domains in its module representation. As a result, it only works for bridging
headers that are not precompiled.

Part of rdar://138441266.
2025-03-15 07:44:37 -07:00
Tony Allevato
2b0f9aa765 Allow module aliases to use escaped identifiers as the alias name.
The original module names themselves must still be valid unescaped identifiers; most of the serialization logic in the compiler depends on the name of a module matching its name on the file system, and it would be very complex to turn escaped identifiers into file-safe names.
2025-03-11 17:18:43 -04:00
Tony Allevato
329261593e Add a test importing a Clang module with non-identifier characters.
This requires no additional work beyond just parsing the identifier because Clang module maps already support such names in quotes.
2025-03-11 17:18:43 -04:00
Becca Royal-Gordon
d8c8f6577b Merge pull request #79206 from beccadax/this-name-is-not-constructive
Diagnose and forbid invalid Swift names on inits
2025-02-17 20:17:56 -08:00
Becca Royal-Gordon
2b2252b6a6 Gracefully handle incorrect SwiftName arg count
…at least in the specific case of initializers.

Normally, clang validates that a SwiftNameAttr’s specified name seems to have the right number of argument labels for the declaration it’s applied to; if it doesn’t, it diagnoses and drops the attribute. However, this checking isn’t perfect because clang doesn’t know all of Clang Importer’s throwing rules. The upshot is that it’s possible to get a mismatched SwiftNameAttr into Clang Importer if the last parameter looks like an out parameter. This trips an assertion in asserts compilers, but release compilers get past that and don’t seem to notice the mismatch at all.

Add code to the compiler to tolerate this condition, at least in initializers, by modifying the Swift name to have the correct number of argument labels and deprecating the declaration with a message explaining the problem.

Fixes rdar://141124373.
2025-02-11 17:37:25 -08:00
Becca Royal-Gordon
12d0458eb2 Diagnose and forbid invalid Swift names on inits
Initializers should always have Swift names that have the special `DeclBaseName::createConstructor()` base name. Although there is an assertion to this effect in the constructor for ConstructorDecl, ClangImporter did not actually reject custom Swift names for initializers that violated this rule. This meant that asserts compilers would crash if they encountered code with an invalid `swift_name` attribute, while release compilers would silently accept them (while excluding these decls from certain checks since lookups that were supposed to find all initializers didn’t find them).

Modify ClangImporter to diagnose this condition and ignore the custom Swift name.
2025-02-11 12:05:17 -08:00
Adrian Prantl
91b6162f25 [Debug info] Emit bound generic class type parameters when emitting AST types
This relands commit 45d4648bdb while ensuring that
sanityCheckCachedType uses the exact same condition (now factored into a helper
function) as createType() to determine whether a type is sized or not.

rdar://143833326
2025-02-01 10:07:45 -08:00
Adrian Prantl
45d4648bdb Revert "[Debug info] Emit bound generic class type parameters when emitting AST types"
This reverts commit f2132890db
it triggers the debug info sanity check when running the source compatibility testsuite.
2025-01-30 17:27:39 -08:00
Adrian Prantl
a5dddcee0f Merge pull request #78901 from adrian-prantl/143595521
[Debug info] Retain all type aliases in asttypes mode
2025-01-29 08:27:46 -08:00
Anthony Latsis
eeb991122a [NFC] Switch from backticks to quotes in several diagnostics 2025-01-29 07:49:27 +00:00