Commit Graph

28619 Commits

Author SHA1 Message Date
Pavel Yaskevich
087c36c7c1 [ConstraintSystem] Fix getEffectiveOverloadType handling of mutating methods
(cherry picked from commit c767f7aff7)
2025-06-27 23:43:09 -07:00
Pavel Yaskevich
69bd48e2ea [CSSimplify] CGFloat-Double: Rank narrowing correctly when result is injected into an optional
If result of `CGFloat` -> `Double` conversion is injected into an optional
it should be ranked based on depth just like when locator is fully simplified.

For example:

```swift
func test(v: CGFloat?) {
   _ = v ?? 2.0 / 3.0
}
```

In this expression division should be performed on `Double` and result
narrowed down (based on the rule that narrowing conversion should always
be delayed) but `Double` -> `CGFloat?` was given an incorrect score and
instead of picking `?? (_: T?, _: T) -> T` overload, the solver would
use `?? (_: T?, _: T?) -> T?`.

(cherry picked from commit cb876cbd9e)
2025-06-27 23:43:09 -07:00
Pavel Yaskevich
f650c0ac6e [CSBindings] Prevent BindingSet::isViable from dropping viable bindings (v2)
The original attempt to do this was reverted by https://github.com/swiftlang/swift/pull/77653

The problem is that the fix was too broad, I narrowed it down to
non-exact uses of stdlib collections that support upcasts.

(cherry picked from commit b7e7493076)
2025-06-27 23:43:09 -07:00
John McCall
2eee30dfbe [NFC] Encapsulate the parameter index of an ActorIsolation 2025-06-27 19:48:12 -04:00
Alexis Laferrière
81a0f98783 Merge pull request #82194 from xymus/cdecl-parser
Parser: Accept `@cdecl` with an optional identifier for a custom C name
2025-06-27 15:06:11 -07:00
Doug Gregor
aea1084d41 "nonisolated deinit" does not have back-deployment constraints
Fixes rdar://150484159
2025-06-27 14:54:26 -07:00
Slava Pestov
ff26de7eac AST: Better cope with UnboundGenericType in TypeBase::getSuperclass()
Returning the unsubstituted superclass type is not correct,
because it may contain type parameters. Let's form a new
UnboundGenericType instead.

- Fixes https://github.com/swiftlang/swift/issues/82160.
- Fixes rdar://152989888.
2025-06-27 17:12:09 -04:00
Pavel Yaskevich
7c1dffb1f2 Merge pull request #82549 from xedin/rdar-153083848
[CSFix] Fix `getConcurrencyFixBehavior` to account for non-decl overl…
2025-06-27 13:19:47 -07:00
Doug Gregor
ee9f6f8db7 [SE-0466] Don't infer @MainActor on types conforming to Sendable
When the default isolation is main-actor, don't infer @MainActor
for a type that conforms to a protocol P in its primary definition when
P inherits from Sendable. Such types should remain non-isolated
because they're highly unlikely to be able to implement the P
conformance (which cannot be isolated).

Put this feature behind a new experimental flag,
SendableProhibitsMainActorInference.

Implements rdar://151029300
2025-06-27 12:24:38 -07:00
Slava Pestov
34253a8606 Merge pull request #82506 from slavapestov/warn-long-expression-type-checking
Sema: Fix the -warn-long-expression-type-checking flag
2025-06-27 01:10:25 -04:00
Pavel Yaskevich
3ae8d5680f [CSFix] Fix getConcurrencyFixBehavior to account for non-decl overloads
Adjust the downgrade check for static member references to
account for the fact that argument could come of a tuple or
some other reference that doesn't have a declaration associated
with it.

Resolves: rdar://153083848
2025-06-26 15:08:51 -07: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
Doug Gregor
f94159029e Merge pull request #82493 from DougGregor/effects-subst-parameter-packs
[Effects] Ensure that we properly substitute function types in ByClosure checks
2025-06-26 09:41:24 -07:00
Allan Shortlidge
6b05efd087 Sema: Remove unused variable in CSSolver.cpp. 2025-06-25 22:23:47 -07:00
Slava Pestov
487918f07b Sema: Fix -warn-long-expression-type-checking when expression timer is turned off
My change 983b75e1cf broke
-warn-long-expression-type-checking because now the
ExpressionTimer is not instantiated by default and that
entire code path is skipped.

Change it so that if -warn-long-expression-type-checking
is passed in, we still start the timer, we just don't
ever consider it to have 'expired'.

Fixes rdar://problem/152998878.
2025-06-25 22:07:23 -04:00
Slava Pestov
0f00c89b31 Sema: Remove unused variable 2025-06-25 22:07:23 -04:00
Pavel Yaskevich
0999792bf4 Merge pull request #82467 from xedin/swift-testing-troubles
[CSSimplify] Narrow down tuple wrapping for pack expansion matching
2025-06-25 16:03:07 -07:00
Doug Gregor
5391887b01 [Effects] Ensure that we properly substitute function types in ByClosure checks
We weren't substituting generic arguments into function types. In the
presence of parameter packs, this could mean that the parameter and
argument lists no longer match up, which would cause the effects
checker to prematurely bail out after treating this as "invalid" code.
The overall effect is that we would not properly check for throwing
behavior in this case, allowing invalid code (as in the example) and
miscompiling valid code by not treating the call as throwing.

Fixes rdar://153926820.
2025-06-25 10:01:34 -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
Pavel Yaskevich
b41a21a114 Merge pull request #82465 from xedin/rdar-154202375
[Concurrency] Global actor isolated conformances are only allowed to …
2025-06-25 01:10:27 -07:00
Pavel Yaskevich
4804f2131b [CSSimplify] Narrow down tuple wrapping for pack expansion matching
Follow-up for https://github.com/swiftlang/swift/pull/82326.

The optional injection is only viable is the wrapped type is
not yet resolved, otherwise it's safe to wrap the optional.
2025-06-24 15:30:25 -07:00
Doug Gregor
ab4e87fe5a Merge pull request #82443 from DougGregor/preconcurrency-unsafe-silence
Allow '@unsafe' on import declarations to silence '@preconcurrency' warning
2025-06-24 13:49:55 -07:00
Pavel Yaskevich
2e1fe444a6 [Concurrency] Global actor isolated conformances are only allowed to override nonisolated.
Follow-up for https://github.com/swiftlang/swift/pull/79893.

More than one global actor isolated conformance at any level
creates a clash and conforming type should be inferred as `nonisolated`.

Resolves: rdar://154202375
2025-06-24 12:46:41 -07:00
Pavel Yaskevich
b1470321e8 Merge pull request #82430 from xedin/issue-82397
[CSSimplify] Prevent `missing call` fix from recording fixes while ma…
2025-06-24 09:12:33 -07:00
Anthony Latsis
8e250f3edf Fix use-after-free through diagnostic argument 2025-06-24 15:42:44 +01:00
Anthony Latsis
ad8c52237c Sema: Fix the insertion location for conformances attributes 2025-06-24 14:49:03 +01:00
Meghana Gupta
86bdca5bf4 Merge pull request #82354 from meg-gupta/lifetimeenum
Add lifetime dependencies on function types representing ~Escapable enum elements with ~Escapable payloads
2025-06-23 22:07:38 -07:00
Doug Gregor
0e3da0e499 Allow '@unsafe' on import declarations to silence '@preconcurrency' warning
'@preconcurrency' imports open up memory safety holes with respect to
Sendable, which are diagnosed under strict memory safety + strict
concurrency checking. Allow one to write '@unsafe' on those imports to
silence the diagnostic about it.
2025-06-23 19:06:14 -07:00
Doug Gregor
dbf7fe6aa0 Merge pull request #82426 from DougGregor/selector-objc-async
Allow #selector to reference async method in non-async code
2025-06-24 02:33:00 +02:00
Meghana Gupta
db24b6f758 Support lifetime dependence inference on enum elements 2025-06-23 13:42:53 -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
Pavel Yaskevich
7ecb1fd1db [CSSimplify] Prevent missing call fix from recording fixes while matching types
We need to be very careful while matching types to test whether a
fix is applicable or not to avoid adding extraneous fixes and failing
the path early. This is a temporary workaround, the real fix would
be to let `matchTypes` to propagate `TMF_ApplyingFixes` down.

Resolves: rdar://154010220
Resolves: https://github.com/swiftlang/swift/issues/82397
2025-06-23 13:38:38 -07:00
Pavel Yaskevich
25585c07f3 Merge pull request #82386 from xedin/rdar-153922620
[Concurrency] References to `nonisolated(nonsending)` properties don't…
2025-06-23 13:38:09 -07:00
Doug Gregor
c34f81e110 Allow #selector to reference async method in non-async code
Fixes rdar://153118331
2025-06-23 12:41:18 -07:00
Pavel Yaskevich
c2388401a2 Merge pull request #82382 from xedin/rdar-153680826
[Concurrency] Don't infer `nonisolated(nonsending)` on synchronous wi…
2025-06-23 09:05:14 -07:00
Slava Pestov
a9819a60ce Merge pull request #82383 from slavapestov/implied-isolated-conformance
Sema: Expand isolated conformance inference to consider conformances to inherited protocols
2025-06-23 04:00:26 -04:00
Slava Pestov
b0b23a070b Sema: Expand isolated conformance inference to consider conformances to inherited protocols
Otherwise, if PDerived inherits from P and P's requirements are
witnessed by @MainActor-isolated members, we fail to infer
@MainActor isolation on the conformance to PDerived.

- Fixes https://github.com/swiftlang/swift/issues/82222.
- Fixes rdar://153219831.
2025-06-22 23:21:25 -04:00
Michael Gottesman
aee16d7b7a Merge pull request #82375 from gottesmm/pr-4e28ed16e5bf409f1bdd07e56b1074a13efabb7d
[sema] Work around a double curry thunk actor isolation inference bug that is a knock on effect of ced96aa5cd.
2025-06-20 15:46:09 -07:00
Pavel Yaskevich
35a41ab9cf [Concurrency] References to nonisolated(nonsending) properties don't leave caller's isolation
Make sure that referencing `nonisolated(nonsending)` properties,
especially through a witness is as not treated as leaving the
isolation domain of the caller.

Resolves: rdar://153922620
2025-06-20 15:26:42 -07:00
Anthony Latsis
1ceeb7089b Merge pull request #82338 from AnthonyLatsis/jepa
ASTBridging: Bridge more enums directly
2025-06-20 23:13:50 +01:00
Michael Gottesman
c28490b527 [sema] Work around a double curry thunk actor isolation inference bug that is a knock on effect of ced96aa5cd.
Specifically, there is currently a bug in TypeCheckConcurrency.cpp where we do
not visit autoclosures. This causes us to never set the autoclosure's
ActorIsolation field like all other closures. For a long time we were able to
get away with this just by relying on the isolation of the decl context of the
autoclosure... but with the introduction of nonisolated(nonsending), we found
cases where the generated single curry autoclosure would necessarily be
different than its decl context (e.x.: a synchronous outer curry thunk that is
nonisolated that returns an inner curry thunk that is
nonisolated(nonsending)). This problem caused us to hit asserts later in the
compiler since the inner closure was actually nonisolated(nonsending), but we
were thinking that it should have been concurrent.

To work around this problem, I changed the type checker in
ced96aa5cd to explicitly set the isolation of
single curry thunk autoclosures when it generates them. The reason why we did
this is that it made it so that we did not have to have a potential large source
break in 6.2 by changing TypeCheckConcurrency.cpp to visit all autoclosures it
has not been visiting.

This caused a follow on issue where since we were now inferring the inner
autoclosure to have the correct isolation, in cases where we were creating a
double curry thunk for an access to a global actor isolated field of a
non-Sendable non-global actor isolated nominal type, we would have the outer
curry thunk have unspecified isolation instead of main actor isolation. An
example of this is the following:

```swift
class A {
  var block:  @MainActor () -> Void = {}
}

class B {
  let a = A()

  func d() {
    a.block = c // Error! Passing task isolated 'self' to @MainActor closure.
  }

  @MainActor
  func c() {}
}
```

This was unintentional. To work around this, this commit changes the type
checker to explicitly set the double curry thunk isolation to the correct value
when the type checker generates the double curry thunk in the same manner as it
does for single curry thunks and validates that if we do set the value to
something explicitly that it has the same value as the single curry thunk.

rdar://152522631
2025-06-20 10:59:54 -07:00
Pavel Yaskevich
a964282275 [Concurrency] Don't infer nonisolated(nonsending) on synchronous witnesses
If the requirement is `nonisolated(nonsending)` but witness is
synchronous, prevent actor isolation inference from requirements
because this isolation only applies to asynchronous declarations
at the moment.

Resolves: rdar://153680826
2025-06-20 10:14:05 -07:00
Pavel Yaskevich
286f975c29 Merge pull request #82320 from xedin/hide-solver-hacks-behind-a-flag
[ConstraintSystem] Guard all the performance hacks with a flag
2025-06-20 00:12:16 -07:00
Michael Gottesman
857ed26104 Merge pull request #82311 from gottesmm/pr-29a7ec5f7fd1b97205b69527c465cac0e3b4128a
Revert "[flow-isolation] Allow for initialization of fields of a Global Actor isolated class in its nonisolated inits"
2025-06-19 17:35:44 -07:00
Pavel Yaskevich
91ae0e0391 Merge pull request #82326 from xedin/rdar-152940244
[CSSimplify] VariadicGenerics: Don't attempt to wrap optional into on…
2025-06-19 08:27:18 -07:00
Hamish Knight
5276f2e1ef Merge pull request #82334 from hamishknight/record-opened 2025-06-19 08:18:49 +01:00
Hamish Knight
9b21efdf7d Merge pull request #82316 from hamishknight/keyed 2025-06-19 08:18:29 +01:00
Anthony Latsis
3e9923f0c0 ASTBridging: Bridge swift::AccessorKind directly 2025-06-19 04:26:52 +01:00
Hamish Knight
c6ec3156f7 [CS] Distinguish locators for generic args in addSpecializationConstraint
Make sure we give each argument a different locator to ensure we
can correctly record any opened types.

rdar://153674889
2025-06-18 12:19:12 +01:00
Hamish Knight
3d9e49038b Merge pull request #82295 from hamishknight/wrapping-paper 2025-06-18 08:50:57 +01:00