Commit Graph

28619 Commits

Author SHA1 Message Date
Anton Korobeynikov
6a0e0d223e Initial support for differentiation of throwing functions 2025-07-23 14:00:56 -07:00
Hamish Knight
cb0a21da2a Merge pull request #83170 from hamishknight/fix-assert
[IDE] Fix assertion failure in `PostfixCompletionCallback::Result::tryMerge`
2025-07-21 18:48:03 +01:00
Slava Pestov
bb4f61e97b Merge pull request #83141 from slavapestov/fix-rdar82992151
Sema: Improve the infinite opaque return type check
2025-07-19 09:30:17 -04:00
Slava Pestov
b70f8a82b1 Sema: Improve the infinite opaque return type check
Now look through other opaque return types that appear in the
underlying type. This catches various forms of recursion that
otherwise would cause a SILGen or SILOptimizer crash.

- Fixes rdar://82992151.
2025-07-18 20:03:03 -04:00
Slava Pestov
97ce526153 Sema: Replace a usage of SubstFlags::SubstituteOpaqueArchetypes with transformRec()
The semantics of SubstFlags::SubstituteOpaqueArchetypes are changing
so this is no longer useful here.
2025-07-18 19:12:33 -04:00
Allan Shortlidge
5601e66a69 Sema: Generalize more-available-than-enclosing-decl diagnostics.
NFC.
2025-07-18 13:27:08 -07:00
Allan Shortlidge
034c62cf01 AST: Generalize availability fix-its to support custom availability domains.
Resolves rdar://156118254.
2025-07-18 13:27:08 -07:00
Allan Shortlidge
aeb5a46d9e AST: Emit warnings for redundant availability checks in custom domains. 2025-07-18 13:27:08 -07:00
Allan Shortlidge
a3fbe3d530 AST: Introduce queries on Decl for active @available attrs.
Use these queries to replace some duplicated code. Also, move the
`attr_inlinable_available.swift` test to the `Availability` sub-directory since
the test has more to do with availability checking than it has to do
specifically with the `@inlinable` attr.
2025-07-18 13:27:08 -07:00
Allan Shortlidge
6b29700554 Merge pull request #83162 from tshortli/misc-availability-cleanups
Miscellaneous availability cleanups
2025-07-18 12:03:46 -07:00
Pavel Yaskevich
7a7aefd6ab Merge pull request #83164 from xedin/nonisolated-nonseding-with-special-decls
[Concurrency] NonisolatedNonsendingByDefault: Infer `nonisolated(nonsending)` on declaration with special special semantics
2025-07-18 09:39:55 -07:00
Hamish Knight
33b58d25d8 [CS] NFC: Factor out Solution::hasAppliedSelf 2025-07-18 10:54:17 +01:00
Allan Shortlidge
634f28176e AST: Move parentDeclForInferredAvailability() to Decl.
NFC.
2025-07-17 18:59:14 -07:00
Pavel Yaskevich
358869ff54 [Concurrency] NonisolatedNonsendingByDefault: Extend nonisolated(nonsending) to _openExistential
`_openExistential` is type-checked in a special way which
means that we need to explicitly inject `nonisolated(nonsending)`
isolation when forming a reference to this builtin.
2025-07-17 17:35:12 -07:00
Pavel Yaskevich
48f4d7b688 [Concurrency] NonisolatedNonsendingByDefault: Extend nonisolated(nonsending) to withoutActuallyEscaping
`withoutActuallyEscaping` is type-checked in a special way which
means that we need to explicitly inject `nonisolated(nonsending)`
isolation when forming a reference to this builtin.
2025-07-17 17:35:08 -07:00
Holly Borla
9214b0c6f1 Merge pull request #83136 from hborla/invalid-isolated-conformance-downgrade
[Concurrency] Downgrade isolated conformances to `SendableMetatype` protocols to a warning for implicitly `@preconcurrency` protocols.
2025-07-17 16:38:51 -07:00
Holly Borla
4b50238ebf [Concurrency] Downgrade isolated conformances to SendableMetatype
protocols to a warning for implicitly `@preconcurrency` protocols.
2025-07-17 10:12:41 -07:00
Doug Gregor
dbbdfce238 Merge pull request #83109 from DougGregor/unsafe-covers-unsafe 2025-07-16 22:02:12 -07:00
Allan Shortlidge
59b136ccc4 Merge pull request #83054 from tshortli/unavailable-setters-require-read-only-key-paths
ConstraintSystem: Make key paths for properties with unavailable setters read-only
2025-07-16 21:31:41 -07:00
Hamish Knight
213ad8aa8c Merge pull request #83096 from hamishknight/ret
[Sema] Set ReturnStmt result even if type-checking fails
2025-07-17 02:58:26 +01:00
Anthony Latsis
d7ec3a34bb Merge pull request #83094 from swiftlang/jepa-main
Sema: Make `@concurrent` not imply `async` on closures
2025-07-17 01:54:04 +01:00
Anthony Latsis
58d5059617 Sema: Make @concurrent not imply async on closures
The present approach is not prudent because `@concurrent` synchronous
functions, a natural extension, are a likely-to-happen future direction,
whereas the current inference rule is entirely grounded on `@concurrent`
being exclusive to async functions.

If we were to ship this rule, we would have to keep the promise for
backwards compatibility when implementing the aforementioned future
direction, replacing one inconsistency with another, and possibly
introducing new bug-prone expression checking code.

```swift
func foo(_: () -> Void) {}
func foo(_: () async -> Void) {}

// In a future without this change and  `@concurrent` synchronous
// functions accepted, the first call resolves to the first overload,
// and the second call resolves to the second, despite `@concurrent` no
// longer implying `async`.
foo { }
foo { @concurrent in }
```

This change also drops the fix-it for removing `@concurrent` when used
on a synchronous closure. With the inference rule gone, and the
diagnosis delayed until after solution application, this error raises a
fairly balanced choice between removing the attribute and being
explicit about the effect, where a unilateral suggestion is quite
possibly more harmful than useful.
2025-07-16 20:46:29 +01:00
Doug Gregor
f64516b01d [Strict memory safety] "unsafe" expression never propagates unsafe outward
In the effects checker, we were propagating the "has an unsafe use
site" outside of an `unsafe` expression. The result of this is that we
would not produce a warning for silly expressions like `unsafe unsafe
ptr.pointee`, where the first (outer) `unsafe` is unnecessary. Stop
propagating that bit so we properly diagnose the spurious "unsafe".

Fixes issue #82315 / rdar://153672668.
2025-07-16 12:44:08 -07:00
Hamish Knight
72db18073c [Sema] Set ReturnStmt result even if type-checking fails
Make sure we set the updated expression since e.g pre-checking may
have folded a top-level SequenceExpr that we need to remove from the
AST.
2025-07-16 14:40:57 +01:00
Doug Gregor
1a406a2901 Merge pull request #83072 from DougGregor/se-0466-nested-no-inference 2025-07-15 23:48:44 -07:00
Slava Pestov
de068cb130 Merge pull request #83070 from slavapestov/remove-redundant-functor
AST: Remove MakeAbstractConformanceForGenericType
2025-07-15 23:44:59 -04:00
Allan Shortlidge
fa267fefff Merge pull request #83051 from tshortli/diagnose-more-invalid-os-versions
Sema: Diagnose invalid platform versions in more places
2025-07-15 17:06:39 -07:00
Allan Shortlidge
99380bf00f Sema: Sometimes allow universally unavailable declarations to be referenced.
In implicit contexts that are universally unavailable, allow writable key paths
to be formed to properties with setters that are also marked as universally
unavailable. This fixes a regression from the previous commit where the code
synthesized for `@Observable` properties in universally unavailable classes was
rejected by the availability checker.
2025-07-15 14:08:57 -07:00
Slava Pestov
ee440f3c91 AST: Remove MakeAbstractConformanceForGenericType
While the intent behind this functor was noble, it has grown in complexity
considerably over the years, and it seems to be nothing but a source of
crashes in practice. I don't want to deal with it anymore, so I've decided
to just subsume all usages with LookUpConformanceInModule instead.
2025-07-15 16:34:11 -04:00
Doug Gregor
9c793a890e [SE-0466] Nested types of nonisolated types don't infer main-actor isolation
Under discussion as part of an amendment to SE-0466, limit default main
actor inference so it doesn't apply to a nested type within a
nonisolated type.
2025-07-15 13:00:45 -07:00
Allan Shortlidge
4076fa6b2e ConstraintSystem: Make key paths for properties with unavailable setters read-only.
Previously, only conditional unavailability was considered, but setters that
are always unavailable must also make a keypath read-only.

Resolves rdar://155832511.
2025-07-15 10:33:44 -07:00
Pavel Yaskevich
a28d065893 Merge pull request #83056 from xedin/rdar-155847011
[Concurrency] Replace `nonisolated` with `nonisolated(nonsending)` wh…
2025-07-15 10:08:00 -07:00
Konrad `ktoso` Malawski
9cc555c567 Merge pull request #83053 from ktoso/pick-better-class-sendable-diagnostic
[Concurrency] add fixit to add final to non-sendable class -> Sendable
2025-07-15 17:23:30 +09:00
Hamish Knight
818979fed8 Merge pull request #83034 from hamishknight/origami
[Sema] Avoid folding sequences multiple times
2025-07-15 09:14:55 +01:00
Pavel Yaskevich
b519c07428 [Concurrency] Replace nonisolated with nonisolated(nonsending) when isolation is inferred
With `NonisolatedNonsendingByDefault` an explicit `nonisolated`
attribute in declaration context is inferred to mean `nonisolated(nonsending)`
and it should be printed as such in interface files and other places.

The inference logic that did didn't remove the original attribute
which meant that it would be printed twice i.e.
`nonisolated nonisolated(nonsending) func test() async` which is
incorrect and would fail swift interface validation.

Resolves: rdar://155847011
2025-07-15 00:42:53 -07:00
Konrad 'ktoso' Malawski
f52f445358 [Concurrency] add fixit to add final to non-sendable class -> Sendable
The previous message was just suggesting unchecked Sendable, but instead
we should be suggesting to add final to the class. We also don't
outright suggest using unchecked Sendable -- following
https://github.com/swiftlang/swift/pull/81738 precedent.

Resolves rdar://155790695
2025-07-15 10:42:25 +09:00
Allan Shortlidge
d09e117dc0 AST: Canonicalize platform versions for @backDeployed attrs.
Also, diagnose invalid platform versions.

Part of rdar://155558161.
2025-07-14 16:40:16 -07:00
Allan Shortlidge
67d784fbaf Sema: Diagnose invalid platform versions in @_originallyDefinedIn.
Part of rdar://155558161.
2025-07-14 16:40:09 -07:00
Allan Shortlidge
910989c2c2 AST: Store parsed version in OriginallyDefinedInAttr instead of canonical.
Canonicalize the version on-demand instead.

NFC, part of rdar://155558161.
2025-07-14 16:04:04 -07:00
Allan Shortlidge
e03cf967c3 Sema: Diagnose invalid OS versions in if #available queries.
Part of rdar://155558161.
2025-07-14 16:03:52 -07:00
Hamish Knight
95f1b07e87 [Sema] Remove completion assert in foldSequence for now
Turns out we can also hit this case for some pattern type-checking
cases. I'll fix those in a follow-up and reinstate the assertion.
2025-07-14 18:50:42 +01:00
Hamish Knight
af96c9860c [Sema] Avoid folding sequences multiple times for completion
Completion can end up calling into pre-checking multiple times in
certain cases, make sure we don't attempt to fold a SequenceExpr
multiple times since its original AST is in a broken state
post-folding. Instead, just return the already-folded expression.

rdar://133717866
2025-07-14 17:30:02 +01:00
Doug Gregor
5412de70ac Use the "prohibits isolated conformances" check for capture metatypes
When checking whether a capture of a metatype is Sendable, we had an
incomplete and incorrect check for SendableMetatype conformance.
Replace that with the proper "prohibits isolated conformances" check
on the generic signature, which matches what we do on the caller side.

Fixes issue #82905 / rdar://155399531.
2025-07-12 08:45:13 -07:00
Slava Pestov
355786caa6 Merge pull request #83015 from slavapestov/prepared-overloads-part-3
Prepared overloads, part 3
2025-07-12 08:56:01 -04:00
Slava Pestov
deb80cd985 Merge pull request #83004 from slavapestov/fix-rdar155624135
AST: Change RequirementEnvironment::getRequirementToWitnessThunkSubs() to use contextual types
2025-07-11 21:11:49 -04:00
Slava Pestov
b39d3aee57 Sema: Special-case recording of Bind constraint in PreparedOverload 2025-07-11 19:57:29 -04:00
Slava Pestov
6e212de774 Sema: Lazily build prepared overload when simplifying BindOverload constraint 2025-07-11 19:57:29 -04:00
Slava Pestov
44750115f0 Sema: You can't simplify types while preparing an overload 2025-07-11 19:57:29 -04:00
Slava Pestov
906e9cbe4d Sema: Remove unnecessary getFixedTypeRecursive() call in getTypeOfMemberReference() 2025-07-11 19:57:29 -04:00
Slava Pestov
44bd5be56f Merge pull request #82976 from slavapestov/prepared-overloads-part-2
Prepared overloads, part 2
2025-07-11 19:10:15 -04:00