Commit Graph

28404 Commits

Author SHA1 Message Date
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
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
Pavel Yaskevich
6cfbafd968 [CSSimplify] VariadicGenerics: Don't attempt to wrap optional into one-element tuple
If we have a tuple with unresolved pack expansion on one side
and an optional type on the other, prevent `matchTypes` from
wrapping optional into a one-element tuple because the matching
should be handled as part of the optional injection.

Resolves: rdar://152940244
2025-06-17 18:25:22 -07:00
Pavel Yaskevich
84cb3c89ff Merge pull request #79893 from simanerush/fix-explicit-nonisolated-proto-inference
[Concurrency] Look for explicit 'nonisolated' when getting isolation from protocol conformances.
2025-06-17 15:23:26 -07:00
Hamish Knight
b37e34ea8d [Sema] Tighten up function call check in resolveKeyPathExpr
Check for `CallExpr` instead of `ApplyExpr`, we don't support
arbitrary postfix operators in key paths.
2025-06-17 23:07:46 +01:00
Pavel Yaskevich
fc573b6612 [ConstraintSystem] Guard all the performance hacks with a flag
Package the flag into `performanceHacksEnabled()` method on
`ConstraintSystem` and start using it to wrap all of the hacks
in constraint generator and the solver.
2025-06-17 13:53:05 -07:00
Pavel Yaskevich
833b6b19e9 [Frontend] Remove -disable-solver-shrink option
It's folded into a more general "disable performance hacks" one.
2025-06-17 13:52:28 -07:00
Michael Gottesman
bf78c6206b Revert "[flow-isolation] Allow for initialization of fields of a Global Actor isolated class in its nonisolated inits"
This reverts commit 501bad55a8.
2025-06-17 13:01:28 -07:00
Slava Pestov
a4bfa3f72b Merge pull request #82275 from slavapestov/more-fuzzer-fixes-2
More fuzzer fixes
2025-06-17 14:57:38 -04:00
Pavel Yaskevich
2f920ceb5a Merge pull request #82289 from xedin/rdar-145519840
[Concurrency] SE-0449: `nonisolated` on a type should prevent isolati…
2025-06-17 09:02:52 -07:00
Hamish Knight
89a7014db9 [Sema] Add null check in createMemberwiseInitParameter
The property wrapper initializer info may be null if e.g we had a
request cycle, just use the property's interface type in that case.

rdar://82899428
2025-06-17 15:16:44 +01:00
Slava Pestov
b79f2817f9 Sema: Fix MissingCallFailure::diagnoseAsError() crash with special base names 2025-06-17 09:52:04 -04:00