Commit Graph

28404 Commits

Author SHA1 Message Date
Slava Pestov
0d6470345b Sema: Fix crash on invalid code in isOverrideBasedOnType() 2025-06-17 09:52:04 -04:00
Slava Pestov
ef5e2861a2 Sema: Fix crash on invalid code in diagnoseDictionaryLiteralDuplicateKeyEntries() 2025-06-17 09:52:03 -04:00
Slava Pestov
8b12f8cb8e Sema: Fix null pointer dereference in LazyStoragePropertyRequest::evaluate() 2025-06-17 09:52:03 -04:00
Slava Pestov
eec924b505 Sema: Fix crash in diagnoseIfSynthesisUnsupportedForDecl() with tuple extension 2025-06-17 09:52:03 -04:00
Slava Pestov
9a01e872da Sema: Address FIXME resulting in a crash in filterProtocolRequirements() 2025-06-17 09:52:03 -04:00
Slava Pestov
908c9368ed Parse: Only accept certain literals as enum case raw values
Just checking for LiteralExpr is too broad, because Sema doesn't
know what to do with RegexLiteralExpr for example.
2025-06-17 09:19:00 -04:00
Slava Pestov
de3fb02bf5 Merge pull request #82238 from slavapestov/coding-keys-parameter-pack
Sema: Relax enum parameter pack restriction for CodingKeys
2025-06-17 07:48:35 -04:00
Pavel Yaskevich
06be7bda39 [Concurrency] SE-0449: Implied conformances to nonisolated protocols make witnesses nonisolated
Even if the requirement is stated on an isolated protocol if the
conformance is implied by a nonisolated one all of the requirements
and witnesses should be nonisolated.
2025-06-17 00:05:16 -07:00
Pavel Yaskevich
e50acbf3d5 [Concurrency] SE-0449: nonisolated on a type should prevent isolation inference from protocol requirements
If a `nonisolated` type conforms to a global-isolated protocol
the witnesses to the protocol requirements should infer the
isolation from the protocol but instead be `nonisolated`.

Resolves: rdar://145519840
2025-06-16 21:28:41 -07:00
Sima Nerush
7e42a19187 [Concurrency] Make sure to still infer global actor if the conformance kind is explicit. 2025-06-16 13:59:15 -07:00
Sima Nerush
4fca62a771 [Concurrency] Look for explicit 'nonisolated' when getting isolation from protocol conformances. 2025-06-16 13:59:15 -07:00
Pavel Yaskevich
64404f5b7d Merge pull request #82229 from xedin/rdar-152689053
[Concurrency] NonisolatedNonsendingByDefault: Except `@Test` test-cases and `$` prefixed declarations from migration
2025-06-16 13:42:17 -07:00
Hamish Knight
060c9f4c5f Merge pull request #82237 from hamishknight/cod-cycle
[Sema] Scale back CodingKeys hack in `TypeChecker::lookupUnqualifiedType`
2025-06-16 20:37:35 +01:00
Pavel Yaskevich
17976c7775 [Concurrency] NonisolatedNonsendingByDefault: Don't attempt to migrate $ prefixed declarations
These are special declarations that are synthesized by the compiler
or a macro and warnings about them are non-actionable.
2025-06-13 14:36:41 -07:00
Pavel Yaskevich
f2f5d234dc [Concurrency] NonisolatedNonsendingByDefault: Don't attempt to migrate swift-testing test cases
The execution of these functions is controlled by the testing
framework and it's okay if their behavior changes when the feature
flag is enabled.

Resolves: rdar://152687527
2025-06-13 14:36:35 -07:00
Slava Pestov
9a101ca8f6 Sema: Relax enum parameter pack restriction for CodingKeys 2025-06-13 14:54:44 -04:00
Slava Pestov
84997b47ef Sema: Protocols don't have implicit members 2025-06-13 14:54:43 -04:00
Hamish Knight
6fd128ff67 [Sema] Scale back CodingKeys hack in TypeChecker::lookupUnqualifiedType
I previously added this hack to match the logic in
`TypeChecker::lookupUnqualified`, but it turns out that can introduce
request cycles for cases where `CodingKeys` is used in a generic
requirement for one of `Codable`'s potential value witnesses. Scale
back the hack such that it's only done when we get an initial empty
lookup result, ensuring we maintain source compatibility. Both these
lookup hacks should go away once we properly handle CodingKeys 
synthesis.

rdar://153096639
2025-06-13 19:42:48 +01:00
Hamish Knight
9a0a831b01 Merge pull request #82147 from hamishknight/fix-nested-arenas
[CS] Avoid solver-allocated inputs with `typesSatisfyConstraint`
2025-06-13 16:53:51 +01:00
Pavel Yaskevich
f0502c2257 [Concurrency] NonisolatedNonsendingByDefault/NFC: Move 'same module' check higher
This is a follow-up to https://github.com/swiftlang/swift/pull/82173
which moves the check higher to make it an early exist.
2025-06-12 10:40:31 -07:00
Pavel Yaskevich
5e17762b22 Merge pull request #82173 from xedin/rdar-152687353
[Concurrency] NonisolatedNonsendingByDefault: Migration applies only to the current module declarations
2025-06-12 10:18:59 -07:00
Pavel Yaskevich
bbe1185d85 Merge pull request #82157 from xedin/rdar-143581268
[TypeChecker] Remove `@_inheritActorContext` effect from synchronous …
2025-06-12 08:34:58 -07:00
Hamish Knight
6d0da8d5cc [CS] Avoid solver-allocated inputs with typesSatisfyConstraint
Escaping solver-allocated types into a nested allocation arena is
problematic since we can e.g lazily compute the `ContextSubMap` for a
`NominalOrBoundGenericNominalType`, which is then destroyed when we
exit the nested arena. Ensure we don't pass any types with type
variables or placeholders to `typesSatisfyConstraint`.

rdar://152763265
2025-06-12 12:11:19 +01:00
Hamish Knight
080b3fa55f [CS] Remove UnresolvedType ranking logic
We should never end up here, we should have placeholder bindings
instead for holes.
2025-06-12 12:11:19 +01:00
Hamish Knight
71d20b7635 [CS] NFC: Remove FreeTypeVariableBinding::UnresolvedType
This is now unused.
2025-06-12 12:11:19 +01:00
Slava Pestov
63a5731da1 Sema: Try to bind extensions without expanding macros
Macro expansion can call typeCheckExpr(), which performs qualified
lookups. So if we expand macros while binding extensions, these
qualified lookups can fail because they cannot find members of
extensions that have not been bound yet.

To fix this, try binding extensions without performing macro
expansion first. If any extensions remain at the end, we fall back
to the old behavior, and try to bind them again, this time
performing macro expansion.

Fixes rdar://149798059.
2025-06-11 20:07:43 -04:00
Slava Pestov
71186eb07f AST: Call setExtendedNominal() instead of cacheOutput(ExtendedNominalRequest...) 2025-06-11 20:07:42 -04:00
Pavel Yaskevich
bcd6caaea4 [Concurrency] NonisolatedNonsendingByDefault: Migration applies only to the current module declarations
Prevent migration from handling declarations that come from a
module different from the current one, this is primarily a
problem for swiftinterfaces that can get rebuilt when the module
is imported by a model that has migration mode enabled.

Resolves: rdar://152687353
2025-06-11 00:06:38 -07:00
Slava Pestov
7bbb29938e AST: Remove no longer necessary checks of getSuperclassForDecl() result 2025-06-10 16:49:57 -04:00
Pavel Yaskevich
dbe19b6d5f [TypeChecker] Remove @_inheritActorContext effect from synchronous types
The compiler would previously accept use of `@_inheritActorContext`
on a parameter with a synchronous function type which wasn't marked
as `@isolated(any)`. That is incorrect because in such cases the
attribute has no effect and furthermore would prevent Sendable
and isolation checking.

Uses like that are currently diagnosed by the type-checker but we
need to go one step further and remove the effect in such case to
prevent invalid uses.

Resolves: rdar://143581268
2025-06-10 10:15:37 -07:00
Meghana Gupta
7d454533a0 Merge pull request #82067 from meg-gupta/lifetimeunderscored
Update spelling for representing lifetime dependencies to @_lifetime
2025-06-09 19:01:31 -07:00
Pavel Yaskevich
a5d92bc346 Merge pull request #82053 from xedin/rdar-150689994
[Diagnostics] Correctly diagnose situations when immutable value is passed to `inout` parameter
2025-06-09 00:12:13 -07:00
Meghana Gupta
dcf072f9d0 Introduce a new suppressible experimental feature to guard @_lifetime 2025-06-07 12:49:07 -07:00
Meghana Gupta
0dfa1fc312 Update spelling for representing lifetime dependencies to @_lifetime 2025-06-07 12:49:07 -07:00
Anthony Latsis
d10dfb3ae9 Merge pull request #82020 from AnthonyLatsis/camellia-sinensis
Sema: Never record argument label mismatches for unlabeled trailing closures
2025-06-07 01:29:54 +01:00
Pavel Yaskevich
6bbc101a98 [Diagnostics] Correctly diagnose situations when immutable value is passed to inout parameter
Currently the note is going to point to the "callee" but that is
incorrect when the failure is related to an argument of a call.

Detect this situation in `RValueTreatedAsLValueFailure::diagnoseAsNote`
and produce a correct note.

Resolves: rdar://150689994
2025-06-06 14:36:19 -07:00
Pavel Yaskevich
aa92bcf9b0 Merge pull request #82004 from xedin/rdar-151911135
[Concurrency] Fix `SendableMetatype` conformance failures to behave l…
2025-06-06 14:07:55 -07:00
John McCall
237e617fab Merge pull request #82008 from rjmccall/dont-copy-print-options
Prevent PrintOptions from being implicitly copied
2025-06-06 17:06:02 -04:00
Pavel Yaskevich
aaf153d7a1 [Concurrency] Fix SendableMetatype conformance failures to behave like Sendable ones
No warnings with minimal checking, warnings with `strict-concurrency=complete` and
if declaration is `@preconcurrency` until next major swift version.

Resolves: rdar://151911135
Resolves: https://github.com/swiftlang/swift/issues/81739
2025-06-06 08:48:29 -07:00
Pavel Yaskevich
622475bf15 [ConstraintSystem] Look through ArgumentAttribute element when computing a callee
This element is used purely for diagnostic purposes and locator
should behavior as if it's completely transparent.
2025-06-05 22:30:46 -07:00
Pavel Yaskevich
3495c61840 [Diagnostics] Use contains instead of has when non-Sendable type appears inside of a member type 2025-06-05 11:14:55 -07:00
Pavel Yaskevich
6d45229367 [Concurrency] Downgrade errors to warnings when Sendable requirement is inferred from a preconcurrency protocol
If a type gets `Sendable` conformace requirement through another
`@preconcurrency` protocol the error should be downgraded even
with strict concurrency checking to allow clients time to address
the new requirement.

Resolves: rdar://146027395
2025-06-05 11:13:38 -07:00
Pavel Yaskevich
7cca7225a1 [Concurrency] NFC: Rename ImpliedByStandardProtocol to ImpliedByPreconcurrencyProtocol
The new name better reflects the intention for this Sendable check kind.
2025-06-05 11:13:37 -07:00
Pavel Yaskevich
e24196e365 [Concurrency] Clean-up duplicate code in checkSendableInstanceStorage 2025-06-05 11:13:37 -07:00
Anthony Latsis
f2e1420a90 Sema: Never record argument label mismatches for unlabeled trailing closures
Fixes a crash on invalid. The previous logic was causing a label
mismatch constraint fix to be recorded for an unlabeled trailing closure
argument matching a variadic paramater after a late recovery argument
claim in `matchCallArgumentsImpl`, because the recovery claiming skips
arguments matching defaulted parameters, but not variadic ones. We may
want to reconsider that last part, but currently it regresses the
quality of some diagnostics, and this is a targeted fix.

The previous behavior is fine because the diagnosis routine associate
with the constraint fix (`diagnoseArgumentLabelError`) skips unlabeled
trailing closures when tallying labeling issues — *unless* there are no
other issues and the tally is zero, which we assert it is not.

Fixes rdar://152313388.
2025-06-05 18:01:20 +01:00
Anthony Latsis
7c431c9a9a [NFC] Make a function static 2025-06-05 17:59:34 +01:00
John McCall
b3493bfa23 Prevent PrintOptions from being implicitly copied.
NFC *except* that I noticed a bug by inspection where we suppress
`@escaping` when print enum element types. Since this affects
recursive positions, we end up suppressing `@escaping` in places
we shouldn't. This is unlikely to affect much real code, but should
still obviously be fixed.

The new design is a little sketchy in that we're using `const` to
prevent direct use (and allow initialization of `const &` parameters)
but still relying on modification of the actual object.  Essentially,
we are treating the `const`-ness of the reference as a promise to leave
the original value in the object after computation rather than a
guarantee of not modifying the object. This is okay --- a temporary
bound to a `const` reference is still a non-`const` object formally
and can be modified without invoking UB --- but makes me a little
uncomfortable.
2025-06-05 12:52:01 -04:00
Mykola (Nickolas) Pokhylets
87e536ebec Merge pull request #80440 from nickolas-pohilets/mpokhylets/weak-let 2025-06-05 09:59:33 +02:00
Doug Gregor
c1f7771e84 Merge pull request #81998 from DougGregor/raw-conformance-isolation-cleanup
Make (Raw)ConformanceIsolation requests work on the normal protocol conformance
2025-06-04 20:40:24 -07:00
Doug Gregor
352f39207b Merge pull request #81983 from DougGregor/non-sendable-metatype-suppress
Only emit the non-sendable metatype capture diagnostic under region-based isolation
2025-06-04 17:46:07 -07:00