Commit Graph

28382 Commits

Author SHA1 Message Date
Pavel Yaskevich
873f562a4a [AST/Sema] Support for @concurrent attribute in type context 2025-04-16 10:06:08 -07:00
Pavel Yaskevich
8598ec670d [AST/ASTGen] Introduce @concurrent attribute to replace @execution(concurrent) spelling 2025-04-16 10:06:08 -07:00
Pavel Yaskevich
cd9741507b [Diagnostics] Adjust @execution(...) diagnostic to take DeclAttribute or StringRef
It has been decided to split the attribute into `@concurrent` and
`nonisolated(nonsending`. Adjusting diagnostics to accept the attribute
makes the transition easier.
2025-04-16 10:06:08 -07:00
Doug Gregor
271eebbb87 [Constraint solver] Delay Sendable on static method references involving possibly-nonsendable metatypes
Thank you, Pavel!

(cherry picked from commit 88d630446c)
2025-04-14 16:38:42 -07:00
Doug Gregor
b02a1a6ac5 Downgrade more sendability errors involving metatypes to warnings
(cherry picked from commit c7c152b14c)
2025-04-14 16:38:39 -07:00
Doug Gregor
b9ace6fb3c Downgrade sendability errors to warnings when they involve non-Sendable metatypes
The introduction of non-Sendable metatypes in Swift 6.2 (via SE-0470)
will break some existing Swift 6 code. Downgrade concurrency errors
involving non-Sendable metatypes to warnings until some future
language mode to ease the transition.

(cherry picked from commit 95b18d3482)
2025-04-14 16:38:37 -07:00
Doug Gregor
649cf9d656 [SE-0470] Teach @Sendable inference on static methods about non-sendable metatypes
The code that determines whether a reference to a static method (that
is not a call) assumed that metatypes were always Sendable. This is no
longer the case, so update this code to go through the normal Sendable
checking on the metatype.

(cherry picked from commit 3ed1d6c390)
2025-04-14 16:38:34 -07:00
Doug Gregor
678ea3df35 Fix deserialization assertion involving isolated conformances
(cherry picked from commit f09cdc2893)
2025-04-14 16:38:31 -07:00
Doug Gregor
65a7b189ba Fix crash involving captured-type checking for sendable metatypes
(cherry picked from commit e4f1b62c57)
2025-04-14 16:38:28 -07:00
Doug Gregor
5e29333d6b [SE-0470] Enable isolated conformances by default
The IsolatedConformances feature moves to a normal, supported feature.
Remove all of the experimental-feature flags on test cases and such.

The InferIsolatedConformances feature moves to an upcoming feature for
Swift 7. This should become an adoptable feature, adding "nonisolated"
where needed.

(cherry picked from commit 3380331e7e)
2025-04-14 16:38:22 -07:00
Doug Gregor
69758f6213 [SE-0470] Downgrade some isolated conformance-related errors to warnings in Swift 5
(cherry picked from commit e8b3065293)
2025-04-14 16:36:57 -07:00
Doug Gregor
49ebfcbab2 Move generic signature check for isolated conformances into GenericSignatureImpl
This is going to need a proper implementation in the requirement
machine. For the moment, provide a slightly-less-broken implementation
but leave a test case where we incorrectly accept racey code.

(cherry picked from commit 92774e0a3c)
2025-04-14 16:36:54 -07:00
Hamish Knight
9fccfa6255 [Sema] Try limit kicking interface type in filterForEnumElement
Kicking the interface type request of the base decl here is wrong
if the decl is e.g a `self` capture in a closure, since we'll be in
the middle of type-checking the closure. I'm planning on properly
fixing this by folding the lookup into the constraint system, but for
now let's at least avoid kicking the request if we don't have an enum
case or enum var. That at least prevents it from affecting cases where
e.g you're pattern matching against a property in a class.

We could potentially tighten up the checking here even further, but
that could potentially impact source compatibility for ambiguous
cases. I'd like to keep this patch low risk, and then deal with any
fallout as part of the pattern type-checking work.

rdar://146952007
2025-04-10 18:46:40 +01:00
Slava Pestov
3a4215d1a5 Merge pull request #80536 from slavapestov/fix-issue-79367-6.2
[6.2] Sema: Fix regression with 'Failure' type witness inference hack
2025-04-08 11:26:48 -04:00
Allan Shortlidge
cb444b6229 Merge pull request #80567 from tshortli/module-import-visibility-fixes-6.2
[6.2] `MemberImportVisibility` bug fixes
2025-04-08 07:13:19 -07:00
Allan Shortlidge
92346384e4 Merge pull request #80614 from tshortli/require-explicit-availability-conformances-6.2
[6.2] Sema: Fix another `-require-explicit-availability` regression
2025-04-08 04:51:55 -07:00
Hamish Knight
ead547d989 Merge pull request #80605 from hamishknight/macro-arg-apply-6.2
[6.2] [CS] Make sure macro arguments go through `coerceCallArguments`
2025-04-08 11:51:42 +01:00
Anthony Latsis
2784fe6cb0 Merge pull request #80602 from AnthonyLatsis/ammanita-pantherina-6.2
[6.2][NFC] Sema: Factor out derived conformance sources into subdirectory
2025-04-08 06:49:18 +01:00
Allan Shortlidge
3f825591de Sema: Fix another -require-explicit-availability regression.
Extensions that extend non-public types should never be required to have
explicit availability, even if they declare conformances to public protocols.

Resolves rdar://148697770.
2025-04-07 14:57:13 -07:00
Hamish Knight
ce260ae75a [CS] Make sure macro arguments go through coerceCallArguments
Previously we would avoid rewriting the arguments in CSApply, but
that can result in incorrect behavior in MiscDiagnostics passes, e.g
incorrectly treating all closure arguments as escaping. Make sure
we rewrite the arguments as we would in regular type-checking.

rdar://148665502
2025-04-07 19:00:27 +01:00
Anthony Latsis
b1c4ead097 [NFC] Sema: Factor out derived conformance sources into subdirectory 2025-04-07 18:38:32 +01:00
Hamish Knight
6d287beb93 [Sema] Remove redundant check
The initializer for a lazy property is always subsumed, so we should
have already bailed.
2025-04-07 17:29:36 +01:00
Hamish Knight
999169e7ae [Sema] Requestify PatternBindingDecl capture computation
Introduce `PatternBindingCaptureInfoRequest`, and kick it after
contextualizing a property initializer. This ensures it gets run
for stored properties added by macro expansions.

rdar://143429551
2025-04-07 17:29:36 +01:00
Allan Shortlidge
746cddc330 Sema: Improve MemberImportVisibility diags for for-in loops.
Ensure that source locations are attached to the implicit calls to
`makeIterator()` and `next()` for diagnostics.

Partially resolves rdar://144535697.
2025-04-06 09:53:18 -07:00
Slava Pestov
69ebffbace Sema: Fix regression with 'Failure' type witness inference hack
We have a special hack to infer the 'Failure' type witness in
'AsyncIteratorProtocol' by considering the type of 'next()'
witness.

In eaf06eae0e I added a check to
fix some assertions that could happen if 'next()' was witnessed
by a declaration in a protocol extension or superclass, which
has a different generic signature.

However my check was too narrow, because it also prohibited
this form of inference when 'next()' was in a different
extension of the same nominal type.

Allow this again.

Fixes https://github.com/swiftlang/swift/issues/79367.
Fixes rdar://problem/145341658.
2025-04-04 10:28:17 -04:00
Hamish Knight
918d4b54cf Merge pull request #80461 from hamishknight/in-sequence
[ASTScope] Allow `try` in unfolded sequence to cover following elements
2025-04-03 20:23:51 +01:00
Allan Shortlidge
5cd5f31c9c Sema: Fix a regression in -require-explicit-availability diagnostics.
The changes in https://github.com/swiftlang/swift/pull/80040 caused the
compiler to start diagnosing extensions containing only members that are
either `@_spi`, `@_alwaysEmitIntoClient`, or unavailable when the
`-require-explicit-availability` flag is passed. Extensions should not be
diagnosed when they only contain members that would not be diagnosed
themselves.

Resolves rdar://148275432.
2025-04-02 17:12:38 -07:00
Joe Groff
562d7dc832 Merge pull request #80438 from jckarter/substitute-away-escapable-lifetime-deps
Type substitution eliminates dependencies with Escapable targets.
2025-04-02 16:56:54 -07:00
Pavel Yaskevich
f61a3c941b Merge pull request #80443 from xedin/rdar-148256978
[CSBindings] Avoid delaying leading-dot inference only if chain is di…
2025-04-02 11:08:44 -07:00
Allan Shortlidge
192da54004 Merge pull request #80450 from tshortli/fix-parentheses-warning 2025-04-02 10:40:17 -07:00
Pavel Yaskevich
75f4ca78ce Merge pull request #80397 from jameesbrown/pack-exp-overload
[CS] Dont wrap packexp in extra layer of expansion
2025-04-02 09:45:01 -07:00
Joe Groff
6b605f41cb Type substitution eliminates dependencies with Escapable targets.
When a generic function has potentially Escapable outputs, those outputs
declare lifetime dependencies, which have no effect when substitution
leads to those types becoming `Escapable` in a concrete context.
This means that type substitution should canonically eliminate lifetime
dependencies targeting Escapable parameters or returns, and that
type checking should allow a function value with potentially-Escapable
lifetime dependencies to bind to a function type without those dependencies
when the target of the dependencies is Escapable.

Fixes rdar://147533059.
2025-04-02 08:54:45 -07:00
Slava Pestov
03d8fd7ceb Merge pull request #80445 from slavapestov/fix-issue-80288
Sema: Fix handling of getter typed throws in witness matching
2025-04-02 08:01:10 -04:00
Hamish Knight
d958c0e080 [AST] Introduce Expr::isAlwaysLeftFolded
Use this to query for `try`-like expressions when it comes to binary
operator folding.
2025-04-02 12:29:45 +01:00
Pavel Yaskevich
bf2d01e562 Merge pull request #80419 from xedin/revert-pr-79397
Revert "Sema: Allow optional-to-optional CGFloat <-> Double conversion"
2025-04-02 00:10:23 -07:00
Allan Shortlidge
8819d6db9e Distributed: Squash a -Wparentheses warning.
The following warning was being  emitted by newer versions of clang:

```
comparisons like 'X<=Y<=Z' don't have their mathematical meaning [-Wparentheses]
```

This code needs to be reworked to ensure that the conditions that are meant to
be asserted are true.
2025-04-01 16:47:56 -07:00
Allan Shortlidge
14147bf87d Merge pull request #80428 from tshortli/custom-availability-domain-scopes
AST: Build availability scopes for custom domain conditionals
2025-04-01 16:43:19 -07:00
Slava Pestov
b26c59962b Sema: Fix handling of getter typed throws in associated type inference
We must replace type parameters with archetypes in the thrown error type
of the witness. The requirement type remains an interface type.
2025-04-01 17:21:32 -04:00
Slava Pestov
de3cf4d982 Sema: Visit getter throws type in ReferencedAssociatedTypesRequest 2025-04-01 14:53:49 -04:00
Slava Pestov
b30006837e Sema: Fix handling of getter typed throws in witness matching
Witness matching didn't handle the case where either the
requirement or the witness is a property with a throwing
getter, and the thrown error type contains a type parameter.

We must open the thrown error types first, replacing type
parameters with type variables, for the matching to work.

Associated type inference needs a similar fix. I'll land a
combined test case for both once I fix that.

Fixes https://github.com/swiftlang/swift/issues/80288.
Fixes rdar://problem/147874955.
2025-04-01 14:53:49 -04:00
Anthony Latsis
4bddb3a705 Merge pull request #80427 from AnthonyLatsis/alcer-americanus
[SE-0461] Consistently diagnose protocol requirements in migration (adoption) mode
2025-04-01 19:53:22 +01:00
Pavel Yaskevich
d34222d461 [CSBindings] Avoid delaying leading-dot inference only if chain is directly connected to a contextual type
Additional restrictions on when protocol inference could be considered
viable. If the chain is connected directly to a contextual type there
cannot be any other inference sources for the base type.

Resolves: rdar://148256978
2025-04-01 10:33:30 -07:00
Allan Shortlidge
cce02961f9 AST/SILGen: Make availability ranges stored by PoundAvailableInfo optional.
Rather than representing a missing availability range on `PoundAvailableInfo`
with a default-constructed `AvailabilityRange` (empty), store the ranges as
optionals instead. This allows an empty range to represent an availability
condition which is known to be false at compile time, which will be necessary
when generating SIL for `if #available` queries that check custom availability
domains.
2025-04-01 07:46:46 -07:00
Allan Shortlidge
b6a425ab6a Sema: Avoid diagnosing required availability in swiftinterface files.
The `-require-explicit-availability` compiler flag is designed to help
developers find declarations that they've written with missing availability.
The flag is not printed in swiftinterface files, though, so if a module has
both `-library-level=api` and also has `-require-explicity-availability=ignore`
(as the Swift stdlib does) then the result is that superfluous diagnostics are
emitted when typechecking the emitted module interface that should have been
suppressed by the `ignore` flag. Suppress these diagnostics when typechecking
swiftinterface files since they are only designed to be seen by the owner of
the module when they are building the module from source and they don't have
much value in the context of interface verification.
2025-04-01 07:12:50 -07:00
Artem Chikin
66334f8f1b Merge pull request #79290 from artemcm/ConstProtoSIL
[Compile Time Values] Implement a mandatory SIL pass to verify '@const' values
2025-04-01 00:12:27 -07:00
Anthony Latsis
e9406e04e5 [SE-0461] Consistently diagnose protocol requirements in migration (adoption) mode 2025-04-01 04:03:55 +01:00
Pavel Yaskevich
05798e5f45 Revert "Sema: Remove dead diagnostic"
This reverts commit d56d7045a2.
2025-03-31 14:39:44 -07:00
Pavel Yaskevich
35077a01d1 Revert "Sema: Allow optional-to-optional CGFloat <-> Double conversion"
This reverts commit f0f5ffcebf.
2025-03-31 13:58:38 -07:00
Michael Gottesman
918756f854 Merge pull request #80374 from gottesmm/pr-ee297e6b432cd07483ec86444ffd6a8b5334c203
[concurrency] Fix a few issues with @execution(caller)/@execution(concurrent).
2025-03-31 09:20:01 -07:00
James Brown
913733f508 [CS] Dont wrap packexp in extra layer of expansion
Arguments that were already pack expansions were being wrapped in a
second layer--preventing some would-be unambiguous overloads from
resolving. This adds a check to avoid doing that.
2025-03-31 11:07:33 -04:00