Commit Graph

28850 Commits

Author SHA1 Message Date
Pavel Yaskevich
b264e27a75 [CSOptimizer] A narrow fix for nil coalescing operator optimization
`??` is overloaded on optionality of the second parameter,
prevent ranking the argument candidates for this parameter
if there are candidates that come from failable initializer
overloads because non-optional candidates are always going
to be better and that can skew the selection.

Resolves: rdar://156853018
2025-07-28 00:35:02 -07:00
Allan Shortlidge
da7a215f61 Sema: Diagnose overrides that are unavailable in Embedded Swift. 2025-07-26 18:46:06 -07:00
Allan Shortlidge
67cc4c6ec3 Sema: Diagnose override availability for custom domains.
Resolves rdar://156159486.
2025-07-26 18:46:05 -07:00
Allan Shortlidge
60554b3de1 Sema: Fix rendering of accessor names in an availability diagnostic. 2025-07-26 15:36:46 -07:00
Allan Shortlidge
0fabfa3f99 Sema: Check custom domain availability during conformance checking.
Protocol requirement witnesses cannot only be available in a custom
availability domain if the requirement does not have the same availability
constraint.

Resolves rdar://156462516.
2025-07-25 21:30:53 -07:00
Allan Shortlidge
47b0e91f76 Merge pull request #83328 from tshortli/refactor-availability-constraint
AST: Simplify and clarify `AvailabilityConstraint`
2025-07-25 20:26:21 -07:00
Allan Shortlidge
0fa2ca38dc AST: Simplify and clarify AvailabilityConstraint.
Remove some unnecessary complexity from `AvailabilityConstraint`, rename some
of its members, and add more complete documentation.

NFC.
2025-07-25 15:15:03 -07:00
Pavel Yaskevich
56976c55d1 [CSApply] Register argument matches for dynamic member lookup subscripts
We missed this before because the argument/parameter types are equal.
2025-07-25 13:22:17 -07:00
Doug Gregor
9f7dff0417 [SE-0466] Treat explicit "nonisolated" like implicit "nonisolated" on protocols
Make explicit "nonisolated" also not special on protocols, so a
nonisolated protocol does not suppress default isolation.
SendableMetatype is the proper way to suppress default isolation for a
protocol.

Unfortunately, these rules made it appear like issue #82168
was fixed, when in fact it was not. Keep the test case, but as a
failing test, and we'll investigate separately.
2025-07-25 09:47:24 -07:00
Doug Gregor
436e965b66 [SE-0466] Under main actor default isolation, explicit nonisolated is not special
Given an explicitly-nonisolated type such as

    nonisolated struct S { }

all extensions of S were also being treated as nonisolated. This meant
that being implicitly nonisolated (i.e., when you're using nonisolated
default isolation) was different from explicitly-writing nonisolated,
which is unfortunate and confusing. Align the rules, such that an
extension of S will get default isolation:

    extension S {
      func f() { } // @MainActor if we're in main actor default isolation
    }
2025-07-25 09:46:34 -07:00
Doug Gregor
e65eecbadc [SE-0466] Extensions and members thereof can apply default isolation
Extensions of nonisolated types can get default isolation from context
(e.g., @MainActor) independently. This was previously true for members,
but not conformances, and recently regressed for members. Fix the logic
to consistently allow such extensions to be default main-actor
isolated, which affects both their members and conformances.

Fixes rdar://156644976.
2025-07-25 09:46:26 -07:00
Slava Pestov
ca50986f3a Merge pull request #83308 from slavapestov/fix-rdar156095800
Embedded Swift: Fix === and !== with existential
2025-07-25 08:41:38 -04:00
Pavel Yaskevich
94b0b55837 Merge pull request #83286 from xedin/treat-std-string-as-default-literal-type
[ConstraintSystem] C++ Interop: Binding a string literal to `std.stri…
2025-07-25 00:05:14 -07:00
Pavel Yaskevich
cd9c37cac6 [ConstraintSystem] C++ Interop: Binding a string literal to std.string shouldn't increase the score
Since this is a C++ stdlib type we need make sure that any overloads
that use it are preferred over custom types that also conform to
`ExpressibleByStringLiteral` when argument is a string literal.

This is important for operators like `==` which could be heterogenous
and have a custom C++ type that conforms to `ExpressibleByStringLiteral`
on either side together with `std.string` i.e.
`==(std.string, const CustomString &)`, such overloads should only
be selected if argument passed to `CustomString` is non-literal because
literals are convered by a stdlib `==(std.string, std.string)` overload.
2025-07-24 14:08:15 -07:00
Slava Pestov
6b2fbb79b9 Sema: Fix crash in MissingConformanceFailure::diagnoseAsError()
It's difficult to trigger this because the code path is only
reached for the standard operators. The issue in question was
in embedded Swift due to an unsupported usage of the ===
operator, but we expect an upcoming standard library change to
actually make us accept that code.

However, the fix should be pretty safe, even without a test case.

Fixes the crash in rdar://156095800.
2025-07-24 15:10:21 -04:00
Slava Pestov
ca618bbea4 Sema: Change DerivedConformance::derivesProtocolConformance() to take the conformance 2025-07-24 12:55:47 -04:00
Slava Pestov
c699553fa0 Sema: Fix upcoming request cycle in ConformanceChecker::resolveSingleWitness() 2025-07-24 12:55:47 -04:00
Slava Pestov
5866d8a36a Sema: Fix crash with invalid reference to macro 2025-07-24 12:55:47 -04:00
Slava Pestov
c472c22e71 Merge pull request #83268 from slavapestov/fix-rdar156454697
Sema: Handle ArchetypeType and DynamicSelfType in determineBestChoicesInContext()
2025-07-24 08:17:47 -04:00
Doug Gregor
5023b90f93 Merge pull request #82921 from DougGregor/sendable-prohibits-mainactor-by-default
[SE-0466] Enable SendableProhibitsMainActorInference by default
2025-07-23 16:21:37 -07:00
Slava Pestov
30c7f4afa7 Sema: Handle ArchetypeType and DynamicSelfType in determineBestChoicesInContext()
This fixes a regression introduced in https://github.com/swiftlang/swift/pull/82574.

The test case demonstrates the issue: we would incorrectly choose the base class
overload of == if one of the parameters was an archetype or dynamic Self.

Fixes rdar://156454697.
2025-07-23 17:22:42 -04:00
Holly Borla
335d7e84b4 Merge pull request #83175 from hborla/local-decl-isolation-alt
[Concurrency] Only apply default main actor to local and nested decls that are in a main actor isolated context.
2025-07-23 11:12:16 -07:00
Pavel Yaskevich
24210cf2d4 Merge pull request #83210 from xedin/rdar-143586718
[Concurrency] InferSendableFromCaptures: Rework check to delay lookup
2025-07-23 00:23:18 -07:00
Crazy凡
061ce725d7 [Diagnostics] Add fix-it to @main struct without main static function. 2025-07-23 15:04:26 +08:00
Anthony Latsis
c7b51edf0a Merge pull request #83204 from swiftlang/jepa-main
Address rebranch deprecations
2025-07-23 06:00:57 +01:00
Holly Borla
7b0ba7b5ed [Concurrency] Local storage is always default nonisolated. 2025-07-22 21:35:40 -07:00
Allan Shortlidge
e6186690a5 Sema: Consolidate requirement check failures and refactor RequirementCheck.
Consolidate some of the closely related protocol requirement check failures and
then turn `RequirementCheck` into a proper wrapper around a union of associated
values for `CheckKind`.

NFC.
2025-07-22 15:27:25 -07:00
Allan Shortlidge
1cb47e8561 Sema: Stop using AvailabilityInference in several type checker files.
Prefer queries on `AvailabilityContext` over queries on `AvailabilityRange`.

NFC.
2025-07-21 17:01:58 -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
Pavel Yaskevich
94e28b63d7 [Concurrency] InferSendableFromCaptures: Rework check to delay lookup
The current implementation of the check accounts only for the overload
choices present in the initial lookup but for some situations, like
bridged or optional base types, `performMemberLookup` uses a secondary
lookup as well, results of which are ignored.

Let's fold the check into `addChoice` instead and set the the flag there
to make sure that all of the choices are considered.

Resolves: rdar://143586718
2025-07-21 10:33:46 -07:00
Anthony Latsis
2920ea84d1 Address llvm::(Mutable)ArrayRef ctor deprecations
See:
- https://github.com/llvm/llvm-project/pull/146113
- https://github.com/llvm/llvm-project/pull/146011
2025-07-21 12:36:53 +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
Holly Borla
858e145069 [Concurrency] Only apply default main actor to local and nested
decls that are in a main actor isolated context.

This prevents `@MainActor` from being inferred in a context where
it cannot be used, while still allowing main actor code to be used
in local contexts that are also main actor isolated.
2025-07-18 09:47:47 -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