Commit Graph

28850 Commits

Author SHA1 Message Date
Hamish Knight
e0791bb38d [CS] Fix check in applyResultBuilderBodyTransform
If `matchResultBuilder` returns `nullopt` we should be bailing,
rather than continuing, which would attempt to solve with an empty
constraint system.
2025-08-11 11:19:14 +01:00
Hamish Knight
931289988e [CS] NFC: Remove an unused return value
`isBuildableIfChainRecursive` never returned anything other than `true`,
change it to just be a void call.
2025-08-11 11:19:14 +01:00
Hamish Knight
1e012fea05 [CS] Avoid bailing on result builder return for completion
Make sure we continue to solve the body normally rather than bailing
early.
2025-08-11 11:19:14 +01:00
Hamish Knight
acf6375d46 Introduce BindExtensionsForIDEInspectionRequest
This allows us to lazily bind extensions after mutating the AST,
ensuring we don't prematurely kick the building of lookup tables.
2025-08-10 23:49:03 +01:00
Allan Shortlidge
5e246174a9 Merge pull request #83607 from tshortli/allow-obsolete-in-unavailable-contexts
Sema: Rationalize availability checking in unavailable contexts
2025-08-08 13:00:10 -07:00
Pavel Yaskevich
4e445d1483 Merge pull request #83556 from xedin/rename-nonisolated-caller-to-nonsending
[AST] NFC: Rename function type isolation `NonisolatedCaller` to `Non…
2025-08-08 09:37:17 -07:00
Allan Shortlidge
4d41db3b5d Sema: Rationalize availability checking in unavailable contexts.
Correct several behaviors of availability checking in unavailable contexts that
were inconsistent with the checking model:

- Avoid diagnosing unintroduced and obsolted declarations in contexts that are
  unavailable in the same domain.
- Diagnose unavailability normally in type signature contexts.
2025-08-08 07:57:44 -07:00
Hamish Knight
5755fb293f Merge pull request #83585 from hamishknight/ext-info
Avoid dropping ExtInfo in `replaceParamErrorTypeByPlaceholder`
2025-08-08 09:53:12 +01:00
Gábor Horváth
35b5c817b2 Merge pull request #83520 from Xazax-hun/check-safety-function-types 2025-08-08 06:39:39 +01:00
Hamish Knight
0bd1ff0572 Avoid dropping ExtInfo in replaceParamErrorTypeByPlaceholder
Make sure we preserve the info to avoid hitting an assert.
2025-08-07 12:17:03 +01:00
Allan Shortlidge
b4fb7c81c0 AST: Refactor AvailabilityQuery constructors.
Get rid of the boolean arguments for unavailability in AvailabilityQuery's
constructors and introduce a `asUnavailable()` modifier that can be used
instead in the contexts where unavailability is relevant.
2025-08-06 18:01:44 -07:00
Allan Shortlidge
78f50ba741 AST: Refactor ConditionallyAvailableSubstitutions to use AvailabilityQuery.
Conditionally available opaque return types should support availability
conditions that are evaluated in any availability domain. Update
`ConditionallyAvailableSubstitutions` to model its conditions with
`AvailabilityQuery` instead of assuming that conditions are always a single
version query for the current platform.
2025-08-06 18:01:10 -07:00
Allan Shortlidge
14e5ba69d2 Merge pull request #83545 from tshortli/isolated-deinit-inlining-availability
Sema: Fix isolated deinit availability checking
2025-08-05 22:59:26 -07:00
Pavel Yaskevich
53ef38e31b [AST] NFC: Rename function type isolation NonisolatedCaller to NonisolatedNonsending
This reduces the number of ways we refer to caller isolated async
functions and matches the name to the attribute spelling.
2025-08-05 17:22:10 -07:00
Pavel Yaskevich
eff13b7efe Merge pull request #83531 from xedin/rdar-152553143
[CSSimplify] Skip member access on existential checks if base is exis…
2025-08-05 14:36:56 -07:00
Allan Shortlidge
a0cfe64388 Sema: Fix isolated deinit availability checking.
The availability of isolated deinits were being misdiagnosed for nominal types
that were available prior to the module's deployment target when
`-target-min-inlining-version` was specified. Only the body of an isolated
deinit uses runtime functionality that requires a minimum runtime version, so
availability must be checked in the context of the body of the deinit, not the
interface of the deinit.

Resolves rdar://157563752.
2025-08-05 13:29:07 -07:00
Gabor Horvath
402ad33463 [StrictMemorySafety] Check the safety of return types of calls
Previously, we skipped checking the return type of a function for safety
as we expected to warn at the use of the returned value:

  let x = returnsUnsafe()
  usesUnsafe(x) // warn here

Unfortunately, this resulted in missing some unsafe constructs that can
introduce memory safety issues when the use of the return value had a
different shape resulting in false negatives for cases like:

  return returnsUnsafe()

or

  usesUnsafe(returnsUnsafe())

This PR changes the analysis to always take return types of function
calls into account.

rdar://157237301
2025-08-05 12:16:44 +01:00
Pavel Yaskevich
387b4ff2d3 [CSSimplify] Skip member access on existential checks if base is existential only due to marker protocols
If the base type is composed with marker protocol(s) i.e.
`<<Type>> & Sendable`, let's skip this check because such
compositions are always opened and simplified down to a
superclass bound post-Sema.

Resolves: rdar://148782046
2025-08-04 17:00:48 -07:00
Pavel Yaskevich
7d75f712b6 Merge pull request #83511 from xedin/rdar-152553143
[CSSyntacticElement] Remove an assert that is too strict
2025-08-04 14:09:09 -07:00
Konrad `ktoso` Malawski
e963206e96 Merge pull request #83475 from jamieQ/fix-global-actor-discardable-result 2025-08-04 19:10:00 +09:00
Pavel Yaskevich
3879a47b52 [CSSyntacticElement] Remove an assert that is too strict
`return` statement withot an expression automatically gets an
implicit `()` which is allowed to be converted to types like
`()?` and `Any` or `Any?`. Let's remove a too strict assertion
that expected a contextual type to always be `()?` even
through in reality any type that `()` is convertible to is valid.

Resolves: rdar://152553143
2025-08-04 00:17:26 -07:00
Mykola Pokhylets
4e233706b9 Updated code comment to avoid giving false promises about adoption strategy of the feature 2025-08-02 20:24:46 +02:00
Mykola Pokhylets
86100fe685 Created separated warning group for warnings about unnecessary mutable weak variables 2025-08-02 20:24:46 +02:00
Mykola Pokhylets
89f8f8b9bf Wrap only changes related to the closure frontend logic 2025-08-02 20:24:46 +02:00
Mykola Pokhylets
ae48446716 Wrap SE-0481 into an upcoming feature until source incompatibilities are resolved 2025-08-02 20:24:21 +02:00
Jamie
cd3e96a320 [Sema]: fix @discardableResult interaction with implicit @Sendable conversions
Updates existing diagnostic handling to look through function
conversions when suppressing diagnostics for unused functions that are
return values from callees marked with @discardableResult.
2025-08-02 06:13:34 -05:00
Hamish Knight
4f6e318940 Merge pull request #83477 from hamishknight/rec-room 2025-08-02 09:43:34 +01:00
Pavel Yaskevich
b7a68b074d Merge pull request #83489 from xedin/rdar-157234317
[CSOptimizer] Fix a conditional that ignores function type parameters…
2025-08-02 00:04:50 -07:00
Allan Shortlidge
1439408890 Merge pull request #83493 from tshortli/downgrade-new-dynamic-member-lookup-diagnostics-in-swiftinterfaces
Sema: Adjust dynamic member subscript diagnostic in swiftinterfaces
2025-08-01 19:09:55 -07:00
Allan Shortlidge
5e12e26166 Sema: Adjust dynamic member subscript diagnostic in swiftinterfaces.
Only warn in `.swiftinterface` files since there may be existing resilient
libraries that were built with this mistake previously.

Resolves rdar://157318951.
2025-08-01 14:09:24 -07:00
Hamish Knight
fb7f2d0ff2 [CS] Limit the number of chained @dynamicMemberLookup lookups
Set an upper bound on the number of chained lookups we attempt to
avoid spinning while trying to recursively apply the same dynamic
member lookup to itself.

rdar://157288911
2025-08-01 19:08:04 +01:00
Pavel Yaskevich
9588d519c6 [CSOptimizer] Fix a conditional that ignores function type parameters to look through optionals
Since parameters that have function types don't participate in
ranking, function types that are wrapped in optionals should be
excluded as well, because it's possible to overload on that and
such overloads with optional types would gain an undue advantage.

For example:

```
func test(_: (() -> Void)?) {}
func test(_: () -> Void) {}

func compute(handler: () -> Void) {
  test(handler)
}
```

Without this change the second overload would be ignored and
the first one would be an exact match.

Resolves: rdar://157234317
2025-08-01 10:59:52 -07:00
Pavel Yaskevich
e2ad4a9a59 Merge pull request #83471 from xedin/rdar-150068895
[CSDiagnostics] Diagnose requirement failures in closure parameter po…
2025-08-01 09:41:19 -07:00
Hamish Knight
1f4cca6f4d [CS] Fix nested subscript dynamic member lookups
Previously we would incorrectly attempt to treat a nested dynamic member
lookup for a subscript as a member reference. Fix `isSubscriptMemberRef`
such that we treat it as a subscript reference.
2025-08-01 12:29:22 +01:00
Pavel Yaskevich
6c8da764e2 Merge pull request #83439 from xedin/allow-debugging-of-decl-specialization-comparison
[CSRanking] Pass down a flag to enable debug output in `CompareDeclSp…
2025-08-01 00:08:01 -07:00
Pavel Yaskevich
3524025cd3 Merge pull request #83414 from xedin/cs-optimizer-unconstrained-generic-type-matching
[CSOptimizer] Decrease an operator argument score only if requires op…
2025-08-01 00:07:44 -07:00
Pavel Yaskevich
e5080a48db [CSDiagnostics] Diagnose requirement failures in closure parameter positions
Fix "affected" declaration computation to handle situations when
a generic type happens to be in a closure parameter position.

Resolves: rdar://150068895
2025-07-31 17:23:54 -07:00
Pavel Yaskevich
b0c116056e Merge pull request #83420 from xedin/rdar-157061896
[Concurrency] Downgrade errors when isolated member is referenced from a preconcurrency context
2025-07-31 09:06:14 -07:00
Anthony Latsis
103521394b Merge pull request #82989 from CrazyFanFan/feature/fix-it-add-static-main
[Diagnostics] Add fix-it to `@main` struct without main static function.
2025-07-31 01:25:37 +01:00
Pavel Yaskevich
5899eb25bb [CSRanking] Pass down a flag to enable debug output in CompareDeclSpecializationRequest
There is no debug output from the `CompareDeclSpecializationRequest`
because the flag that enables it is not passed down from the primary
constraint system.
2025-07-30 13:32:21 -07:00
Pavel Yaskevich
b046efccc1 [Concurrency] Downgrade errors when isolated member is referenced from a preconcurrency context
Such references used to be downgraded until Swift 6 but since the
context is `@preconcurrency` it should be possible for API authors
to introduce concurrency annotations such as `@Sendable` without
breaking clients even when they are compiled in Swift 6 mode.

Resolves: rdar://157061896
2025-07-30 11:02:40 -07:00
Anthony Latsis
bbd84429a0 Merge pull request #83400 from swiftlang/jepa-main
Address `llvm::PointerUnion::{is,get}` deprecations
2025-07-30 17:19:58 +01:00
John McCall
7542f2f965 Merge pull request #83385 from rjmccall/rewrite-nonisolated-nonsending-closure-types
Rewrite the type of `nonisolated(nonsending)` closures.
2025-07-30 00:25:03 -04:00
Pavel Yaskevich
9445a9fca9 [CSOptimizer] Decrease an operator argument score only if requires optional injection
This makes sure that optional and non-optional types are ranked
uniformly when matched against a generic parameter type that
could accept either of them.

This is a more general fix for https://github.com/swiftlang/swift/pull/83365
2025-07-29 16:49:47 -07:00
Anthony Latsis
fec049e5e4 Address llvm::PointerUnion::{is,get} deprecations
These were deprecated in
https://github.com/llvm/llvm-project/pull/122623.
2025-07-29 18:37:48 +01:00
Allan Shortlidge
9302cbe568 Sema: Diagnose @dynamicMemberLookup subscripts that are not accessible enough.
Since this is a source breaking change, downgrade the diagnostic to a warning
until the next language version unless library evolution is enabled, in which
case this would have resulted in a broken `.swiftinterface` and it therefore
makes sense to diagnose eagerly.

Resolves rdar://156919010.
2025-07-28 22:36:39 -07:00
John McCall
92b9857e6a Rewrite the type of nonisolated(nonsending) closures.
The constraint solver does not reliably give closures a function type
that includes `nonisolated(noncaller)`, even when the immediate context
requires a conversion to such a type. We were trying to work around this
in SILGen, but the peephole only kicked in if the types matched exactly,
so a contextual conversion that e.g. added `throws` was still emitting
the closure as `@concurrent`, which is of course the wrong semantics.
It's relatively easy to avoid all this by just rewriting the closure's
type to include `nonisolated(nonsending)` at a point where we can reliably
decide that, and then SILGen doesn't have to peephole anything for
correctness.

Fixes rdar://155313349
2025-07-28 22:20:38 -04:00
Pavel Yaskevich
436a279273 Merge pull request #83348 from xedin/rdar-138227393
[CSApply] Key path dynamic member lookup argument is Sendable only if its captures are
2025-07-28 16:23:21 -07:00
Pavel Yaskevich
72299f6abc Merge pull request #83365 from xedin/rdar-156853018
[CSOptimizer] A narrow fix for nil coalescing operator optimization
2025-07-28 16:23:03 -07:00
Pavel Yaskevich
db13a63588 [CSApply] Key path dynamic member lookup argument is Sendable only if its captures are
Previously dynamic member subscript wasn't allowed to use `& Sendable`,
since this restriction was lifted the argument cannot simply assume
the parameter type any longer, the key path captures have to be checked
to determine whether it could be marked as Sendable or not.

Resolves: https://github.com/swiftlang/swift/issues/77105
Resolves: rdar://138227393
2025-07-28 09:59:17 -07:00