Commit Graph

26323 Commits

Author SHA1 Message Date
Anthony Latsis
50de5a532a [NFC] ExistentialTypeSyntaxChecker: Document, rename and make existentialNeedsParens static 2024-06-04 02:12:40 +03:00
Kavon Farvardin
1f830177ac NFC: refactor checkConsumeExpr
I want to expose the syntactic checking to other parts of Sema, so that
we can determine whether an expression is a candidate for having a
`consume` added to it.
2024-06-03 10:47:15 -07:00
Slava Pestov
3196164341 Sema: Fix request cycle with isolation inference
Fixes rdar://129024926.
2024-06-03 13:41:42 -04:00
Michael Gottesman
88729b9e34 [sending] Make {Transferring,Sending}ArgsAndResults a LANGUAGE_FEATURE instead of an UPCOMING_FEATURE.
TLDR: This makes it so that we always can parse sending/transferring but changes
the semantic language effects to be keyed on RegionBasedIsolation instead.

----

The key thing that makes this all work is that I changed all of the "special"
semantic changes originally triggered on *ArgsAndResults to now be triggered
based on RegionBasedIsolation being enabled. This makes a lot of sense since we
want these semantic changes specifically to be combined with the checkers that
RegionBasedIsolation turns on. As a result, even though this causes these two
features to always be enabled, we just parse it but we do not use it for
anything semantically.

rdar://128961672
2024-06-01 23:25:16 -07:00
Pavel Yaskevich
979cd16876 Merge pull request #74045 from apple/revert-73158-any-to-any-sendable-override
Revert "[Sema] Warn about 'Any' to 'any Sendable' override"
2024-06-01 00:28:49 -07:00
Alex Hoppen
ba773d5c4e Merge pull request #73659 from ahoppen/ahoppen/fix-capture-crash
[CodeCompletion] Don’t compute isolated parameter captures during code completion
2024-05-31 21:26:36 -07:00
Alex Hoppen
22f0daf7d5 [CodeCompletion] Don’t compute isolated parameter captures during code completion
Computing capture information requires a type checked AST, which we don’t have during code completion. To fix an assertion failure, don’t look for a captured `isolated` parameter while computing a closure’s actor isolation during code completion.

rdar://126923558
2024-05-31 17:44:00 -07:00
Allan Shortlidge
623e6f310d Sema: Refactor TypeChecker::typeCheckStmtConditionElement().
Use a switch statement to cover all the possible kinds of condition elements
and implement diagnostics in separate functions for each kind of condition
element.

NFC.
2024-05-31 08:49:04 -07:00
Pavel Yaskevich
789a31f8c7 Revert "[Sema] Warn about 'Any' to 'any Sendable' override" 2024-05-30 23:29:02 -07:00
Slava Pestov
0d4ff45eba Merge pull request #74020 from slavapestov/pack-expansion-closures-part-7
Pack expansion closures part 7
2024-05-30 21:27:29 -04:00
Angela Laar
2a75075aa0 Merge pull request #73158 from angela-laar/any-to-any-sendable-override
[Sema] Warn about 'Any' to 'any Sendable' override
2024-05-30 17:15:28 -07:00
Slava Pestov
52e908363f Sema: Collect PackElementExpr captures in CaptureInfoRequest 2024-05-30 16:39:49 -04:00
Holly Borla
135e3f2ee9 Merge pull request #73889 from hborla/deprecate-anyactor
[Concurrency] Deprecate `AnyActor`.
2024-05-30 09:36:35 -07:00
Holly Borla
c20b0e0956 [Concurrency] Obsolete AnyActor in Swift 6 using a typealias. 2024-05-29 22:59:19 -07:00
Hamish Knight
21c0247eb2 [Sema] Preserve compatibility for weak self with @_implicitSelfCapture
In 5.10 we warned on this:

```swift
func bar(@_implicitSelfCapture _ fn: @escaping () -> Void) {}

class C {
  func foo() {
    bar { [weak self] in
      foo()
    }
  }
}
```

But with the implicit self rework, this accidentally
became an error. Fix it to ensure we continue to
warn until Swift 6 mode.

rdar://128941797
2024-05-29 16:11:38 +01:00
Pavel Yaskevich
243cc1641d [CSSimplify] Don't pile up fixes for incorrect optional chaining
If the contextual type propagated into the optional chain mismatches with
the inner type formed from its member references and that inner type
is a result of some fix, let's consider that un-salvageable and avoid
producing additional "ignore contextual type" fixes which only lead
to subpar solutions.
2024-05-28 15:52:53 -07:00
Pavel Yaskevich
d7a06284d3 [CSBindings] Optional object type variable should be connected to the optional
If both sides of an `OptionalObject` constraint are un-inferred, their
binding sets need to correctly reflect adjacency - a type variable
that represents optional would get "object" as an adjacency through
its potential binding (the binding is - "object" wrapped in a single
level of optional) and "object" type variable needs to get its parent
optional type variable added to its adjacency list explicitly.
Without this it would be possible to prematurely pick "object" before
its parent optional type variable.

Resolves: https://github.com/apple/swift/issues/73207
Resolves: rdar://126960579
2024-05-28 15:45:03 -07:00
Konrad `ktoso` Malawski
168bc7b454 [Concurrency] Fix how we obtain DA-as-A conformance for cross module
Resolves rdar://127206143
2024-05-28 13:37:21 +09:00
Allan Shortlidge
7c6815ce3c Merge pull request #73898 from tshortli/nonescapable-in-swiftinterface
Sema: Relax feature check for non-escapable types in swiftinterfaces
2024-05-26 10:24:01 -07:00
Allan Shortlidge
344a894ab5 Merge pull request #73841 from jamieQ/diagnose-noasync-in-defer
[Sema]: improve noasync diagnostics in defer statement bodies
2024-05-25 17:20:01 -07:00
Doug Gregor
6559ed6b6b Merge pull request #73912 from DougGregor/async-for-each-next-isolation-availability
Fix source location info to address availability error with `next(isolation:)`.
2024-05-25 10:13:08 -07:00
Jamie
e68c36bca2 [Sema]: improve noasync diagnostics in defer statement bodies
updates noasync diagnostics in TypeCheckAvailability.cpp to diagnose
defer bodies as if they had the same `isAsyncContext()` value as their
nearest non-defer parent scope.

resolves: https://github.com/apple/swift/issues/73614
2024-05-25 09:53:20 -05:00
Doug Gregor
3564d14a84 Fix source location info to address availability error with next(isolation:)
Due to a missing source location in the implicitly-generated `await` in the
async for loop, we misdiagnosed availability within an `if #available`.

Fixes rdar://128560745.
2024-05-24 22:29:42 -07:00
Holly Borla
0773c832f2 Merge pull request #73877 from hborla/non-sendable-isolated-any
[Concurrency] `@isolated(any)` does not imply `@Sendable`.
2024-05-24 16:01:47 -07:00
Allan Shortlidge
4bc1abb4be Sema: Relax feature check for non-escapable types in swiftinterfaces.
Checking for the presence of a feature flag in order to allow syntax tends to
result in condfails when applied to `.swiftinterfaces`, since older compilers
that have this restriction may be used to compile newer interfaces where the
restriction has been lifted. Remove this restriction for non-escapable types
when typechecking an interface.

Resolves rdar://128577611
2024-05-24 13:53:50 -07:00
Holly Borla
8d6f16ef4b [Concurrency] @isolated(any) does not imply @Sendable. 2024-05-24 12:22:01 -07:00
Holly Borla
1ffc6b7dbe Merge pull request #73878 from hborla/invalid-accessor-macro
[Macros] Don't allow macros to add accessors to `let` variables.
2024-05-24 08:08:48 -07:00
Pavel Yaskevich
fd4274571b Merge pull request #73849 from xedin/collect-closures-to-pack-expansion-they-appear-in
[ConstraintSystem] Fix type-checking of closures in pack expansion contexts
2024-05-24 00:24:49 -07:00
Holly Borla
3c6918a2c4 [Macros] Don't allow macros to add accessors to let variables. 2024-05-23 22:22:07 -07:00
Anthony Latsis
3ae93a95c3 Merge pull request #72726 from Jamezzzb/issue-65913 2024-05-23 23:53:26 +03:00
Holly Borla
f3d4969e07 Merge pull request #73832 from hborla/task-local-macro-hack
[Macros] Ignore the `@TaskLocal` macro attached to vars with projected value vars.
2024-05-23 11:39:33 -07:00
James Brown
5f8fec536d [Sema] Correct 'await' insertion fixIt
When using shorthand syntax for optional binding,
if the variable we are binding is accessed asynchronously,
provide an insertion fixIt of the form: ' = await (identifier)'.
Previously, we would suggest only adding the 'await'
which resulted in an error since the identifier is required.
2024-05-23 13:05:03 -04:00
Holly Borla
7ded57b162 [Macros] Ignore the @TaskLocal macro attached to vars with projected values.
VarDecls with `@_projectedValueProperty` have already had the property
wrapper transform applied. This only impacts swiftinterfaces, and if
a swiftinterface was produced against a Concurrency library that does
not declare `TaskLocal` as a macro, we need to ignore the macro to avoid
producing duplicate declarations. This is only needed temporarily until
all swiftinterfaces have been built against the Concurrency library
containing the new macro declaration.
2024-05-22 18:05:49 -07:00
Pavel Yaskevich
bc3b2748bc [CSSyntacticElement] Bring type variables from outer pack expansion into scope
If closure appears inside of a pack expansion, the elements
that reference pack elements have to bring expansion's shape
type in scope to make sure that the shapes match.
2024-05-22 14:43:10 -07:00
Pavel Yaskevich
888ab81c1e [ConstraintSystem] Connect closure to outer pack expansions it appears in
Type variable reference collector needs to be augmented to collect
type variables associated with pack expansions that a closure references
elements of, otherwise it would get disconnected from the context.
2024-05-22 14:42:39 -07:00
Doug Gregor
c18d2b149f Merge pull request #73741 from DougGregor/suggest-preconcurrency-conformances
Suggest `@preconcurrency` on conformances it could help
2024-05-21 22:18:09 -07:00
Doug Gregor
2c0914ce1a Revert "conformance location" back to what it was
We moved some diagnostics around, which ended up breaking some downstream
tests that we don't want to break. Restore the location.
2024-05-21 18:22:17 -07:00
nate-chandler
7e93317263 Merge pull request #73756 from nate-chandler/rdar128358780
[TypeCheckAttr] @frozen is valid even when building without enable-library-evolution
2024-05-21 13:20:30 -07:00
Becca Royal-Gordon
d9912009b0 Merge pull request #73309 from beccadax/objcimpl-category-on-objc 2024-05-21 10:19:14 -07:00
Doug Gregor
5a0e70a2bc Update diagnostic text to address code review feedback 2024-05-20 22:06:40 -07:00
Doug Gregor
640042f396 Suggest @preconcurrency on conformances it could help
When diagnosing a case where an actor-isolated witness cannot satisfy
a non-isolated requirement, also suggest that the conformance could be
annotated with `@preconcurrency`.
2024-05-20 22:06:40 -07:00
Nate Chandler
2eea24cd35 [TypeCheckAttr] Frozen is valid without resilience
Even when building not for library evolution, @frozen is a valid
attribute on enums.

rdar://128358780
2024-05-20 17:22:47 -07:00
Doug Gregor
8d7e69459a Merge pull request #73742 from DougGregor/fixit-unused-preconcurrency-conformance
Add a Fix-It to the warning about unnecessary `@preconcurrency` conformance
2024-05-19 20:32:36 -07:00
Doug Gregor
e1a4a1e8e6 Don't diagnose accesses to global/static variables within the same module
When SE-0412 (strict concurrency for global variables) is enabled, each
global or static mutable variable will be diagnosed if it isn't
explicitly on a global actor or `nonisolated(unsafe)`.

Suppress diagnostics for references to such global variables when they
are in the same module as the declaration of the global variable
itself. While these diagnostics are technically correct, they are not
strictly necessary since we've already diagnosed the global variable
itself (with more actionable advice), and they tend to pile on the
developer in a manner that is not helpful.
2024-05-19 18:35:19 -07:00
Doug Gregor
6eb42dff9f Merge pull request #73739 from DougGregor/global-var-concurrency-fixits
Provide more Fix-It guidance for concurrency-unsafe global variables (SE-0412)
2024-05-19 18:33:01 -07:00
Doug Gregor
6f969be881 Merge pull request #73738 from DougGregor/more-preconcurrency-fixes
More preconcurrency fixes
2024-05-19 18:30:05 -07:00
Doug Gregor
e9220b48d8 Add a Fix-It to the warning about unnecessary @preconcurrency conformance
When we diagnose an unnecessary `@preconcurrency` on a conformance,
also provide a Fix-It to remove the `@preconcurrency`.
2024-05-19 17:03:08 -07:00
Doug Gregor
d4ce618e2f Provide more Fix-It guidance for concurrency-unsafe global variables (SE-0412)
When diagnosing a concurrency-unsafe global or static variable, provide
Fix-Its with specific guidance and advice. This is intended to aid the
workflow for folks enabling strict concurrency checking or Swift 6.
There are up to three Fix-Its attached to a diagnostic about
concurrency-unsafe global/static variables:

* convert 'global' to a 'let' constant to make the shared state
immutable, which replaces `var` with `let`
* restrict 'global' to the main actor if it will only be accessed from the
main thread, which adds `@MainActor`
* unsafely mark %0 as concurrency-safe if all accesses are protected
by an external synchronization mechanism, which adds `nonisolated(unsafe)`

I fretted over two things before deciding on this path:

1. For the second note, the reality is that any global actor will
suffice, but `@MainActor` is orders of magnitude more common than any
other global actor, so "common case convenience" wins over "precise
but less useful.
2. For the third note, `nonisolated(unsafe)` should only be used
sparingly, and surfacing it via Fix-It could cause overuse. However,
developers need to know about it, and this is how we do that. It comes
last in the list of notes (after the better options) and says "unsafe"
in not one but two places.
2024-05-19 15:05:39 -07:00
Doug Gregor
cc75d5e0cd Allow @preconcurrency to suppress an implied Sendable conformance
When a retroactive conformance to a protocol that inherits from `Sendable`
introduces an implicit `Sendable` conformance, allow `@preconcurrency`
to suppress the diagnostic about the `Sendable` conformance being
introduced outside of the original source file.

Fixes rdar://125080066.
2024-05-19 13:57:35 -07:00
Doug Gregor
e4dac750dc Unify two implementations of "concurrency diagnostic behavior limit"
The "send non-Sendable" pass had a copy of the code for determining
what limit to put on the diagnostic behavior for a given reference to
a nominal type declaration. Rather than update that copy for the
recent changes to the canonical version of this in the type checker,
share the computation.
2024-05-19 13:22:31 -07:00