Commit Graph

26323 Commits

Author SHA1 Message Date
Slava Pestov
3b2a6d8c1a SourceKit: Use getNextDepth()/getMaxDepth() 2024-05-01 12:09:01 -04:00
Slava Pestov
33071e2525 Sema: Use getNextDepth()/getMaxDepth() 2024-05-01 12:09:01 -04:00
Pavel Yaskevich
0bbe26d7c2 Merge pull request #73352 from apple/revert-73083-reland-delay-inference-from-OptionalObject
Revert "[CSBindings] Delay inference through OptionalObject if "object" is l-value capable"
2024-05-01 09:00:06 -07:00
Slava Pestov
7757c34c47 Merge pull request #73348 from slavapestov/pack-expansion-closures-part-1
Preliminary steps towards support for closures that capture pack element environments
2024-05-01 08:35:31 -04:00
Becca Royal-Gordon
981233ad37 Merge pull request #73128 from beccadax/objcimpl-resilient
Handle resilient stored properties in objcImpl
2024-04-30 20:50:33 -07:00
Holly Borla
43681259e9 Merge pull request #73310 from hborla/async-stream-sendable-error
[Concurrency] Stage in new `Async{Throwing}Stream.init(unfolding:)` errors as warnings.
2024-04-30 19:23:19 -07:00
Slava Pestov
da31c59bcb Sema: Track active pack expansions across closure boundaries 2024-04-30 21:38:45 -04:00
Slava Pestov
97d95218f8 AST: Record captured generic environments in CaptureInfo 2024-04-30 21:38:15 -04:00
Pavel Yaskevich
7594e43b2c Revert "[CSBindings] Delay inference through OptionalObject if "object" is l-value capable" 2024-04-30 13:43:37 -07:00
Slava Pestov
f0f9c56409 Sema: Better -debug-constraints output when we failed because of free type variables 2024-04-30 16:10:36 -04:00
Slava Pestov
c11beb5d2f Sema: Make wonky logic explicit in diagnoseImplicitSelfUseInClosure()
We walk up the DeclContext hierarchy looking for closures, but they might
not have had their types set yet because they're currently being type
checked.
2024-04-30 16:10:36 -04:00
Slava Pestov
78d70ab842 Sema: Update comments on ContextualizeClosuresAndMacros
The discriminator assignment has since been split off into a separate
thing, so all this does now is re-parent children of autoclosures.
2024-04-30 16:10:18 -04:00
Becca Royal-Gordon
4578be2810 Set a minimum deployment target for objcImpl
We’re not committing to @objc @implementation back-deploying to pre-stable Apple platforms.
2024-04-30 12:03:46 -07:00
Holly Borla
5019d23c62 Merge pull request #73308 from hborla/flow-isolation-nonisolated-unsafe
[Concurrency] Don't diagnose `nonisolated(unsafe)` properties during flow isolation.
2024-04-26 20:46:38 -07:00
Holly Borla
38cc9511ee [Concurrency] Stage in new Async{Throwing}Stream.init(unfolding:) errors
as warnings.

Marking the closure parameter to these inits as `@Sendable` changed the
inferred isolation of closure arguments in actor-isolated contexts, which
caused new effects checker errors when accessing isolated properties and
methods without `await`. Mark these `init`s as `@preconcurrency`, and fix
the effects checker to downgrade those errors to warnings when the context
of the call is `@preconcurrency`.
2024-04-26 18:09:37 -07:00
Holly Borla
425b8052c7 [Concurrency] Don't diagnose 'nonisolated(unsafe)' properties during flow isolation. 2024-04-26 17:31:25 -07:00
Holly Borla
9773e89bb7 Merge pull request #73279 from hborla/actor-nonisolated-let
[Concurrency] Check `varIsSafeAcrossActors` in `getActorIsolationForReference`.
2024-04-26 08:52:27 -07:00
Holly Borla
39c7962661 [Concurrency] Only treat 'nonisolated let' properties in actors as isolated
if access is from outside the module or the property type is not 'Sendable'.
2024-04-25 22:28:16 -07:00
Rintaro Ishizaki
724e7c0a29 Merge pull request #73237 from rintaro/macros-checkdefinition-nosourcefile
[Macros] Don't use 'ExportedSourceFile' for macro definition checking
2024-04-25 11:53:49 -07:00
Cal Stephens
e4e80787ac Simplify autoclosure check in shouldOnlyWarn 2024-04-25 07:36:32 -07:00
Cal Stephens
985e8d9941 Update DeclContext::getInnermostClosureForSelfCapture to return a ClosureExpr 2024-04-25 06:44:54 -07:00
Cal Stephens
74a33eb420 Improve 'shouldOnlyWarn' logic 2024-04-25 06:26:50 -07:00
Rintaro Ishizaki
f5aca556dd [Macros] Don't use 'ExportedSourceFile' for macro definition checking
`macro` declarations often appear in files that does not contain any
expansions (e.g. `.swiftinterface`). So invoking `SwiftParser` for the
entire file is a waste.
2024-04-24 22:05:15 -07:00
Nate Chandler
016489e103 [BitwiseCopyable] Don't infer for @sensitive. 2024-04-24 15:52:20 -07:00
Nate Chandler
ed5c7ef7ae [BitwiseCopyable] Promote to feature.
SE-0426 was accepted.
2024-04-24 15:52:20 -07:00
Slava Pestov
f0aba4dcdd Merge pull request #73215 from slavapestov/capture-fix-and-cleanup
Fix regression from CaptureInfoRequest
2024-04-24 15:54:17 -04:00
Michael Gottesman
326f0f4291 Merge pull request #73212 from gottesmm/move-error
[region-isolation] Suppress non-Sendable region isolation errors appropriately when the type is imported by using @preconcurrency import.
2024-04-24 01:39:46 -05:00
Michael Gottesman
9ce43d5a98 [region-isolation] Suppress non-Sendable region isolation errors appropriately when the type is imported by using @preconcurrency import.
This translates the rules for @preconcurrency import from SE-0337 into the
region isolation world. Specifically if a module is compiled without strict
concurrency checking and imported with @preconcurrency:

1. All types from that module that are implicitly non-Sendable have diagnostics
suppressed in swift 5 and swift 6.

2. All types from that module that are explicitly non-Sendable emit warnings in
both swift 5 and swift 6.

rdar://126804052
2024-04-23 22:26:07 -05:00
Slava Pestov
83bb9d0fe2 Sema: Fix regression with -experimental-skip-non-inlinable-function-bodies-without-types
My recent capture analysis refactoring broke a subtle corner case that wasn't
exercised by the test suite.

If a local inside g() was skipped, but the outer function was not skipped, we would
return the empty list of captures for g(). But if the interface type of g() actually
involves an outer generic parameter type, then the empty capture list did not record
the fact that a generic signature was needed, so we attempted to form a call to the
local function without a generic signature.
2024-04-23 22:28:03 -04:00
Slava Pestov
0dd20fd1fe Merge pull request #73204 from slavapestov/member-operator-check
Sema: Ban uncallable protocol member operators
2024-04-23 18:50:44 -04:00
Michael Gottesman
e85dfbd043 Merge pull request #73202 from gottesmm/move-error
[region-isolation] When RegionIsolation is enabled, delay the preconcurrency import not used diagnostic to the SIL pipeline.
2024-04-23 16:11:48 -05:00
Slava Pestov
feea84dc6c Sema: Ban uncallable protocol member operators
Member operators of concrete nominal types must declare at least
one parameter with that type, like

```
struct S {
  static func +(lhs: S, rhs: Int) -> S {}
}
```

For protocol member operators, we would look for a parameter of type
`Self`, or an existential type `any P`. While the latter was
consistent with the concrete nominal type case, it was actually
wrong because then the resulting interface type does not give the
type checker any way to bind the `Self` type parameter.

There were two existing test cases that now produce errors, which I
believe is now correct. While this is technically a source break,
because these bogus operators seemingly cannot be witnessed or called,
such a protocol probably had no conforming types.

Fixes https://github.com/apple/swift/issues/73201.
2024-04-23 15:28:16 -04:00
Alexis Laferrière
8785cf5a3d Merge pull request #73183 from xymus/access-level-import-more-notes
Sema: Local duplicate of the note about which import limits access-level
2024-04-23 10:54:32 -07:00
Michael Gottesman
c4f7076baf [region-isolation] When RegionIsolation is enabled, delay the preconcurrency import not used diagnostic to the SIL pipeline.
The reason why I am doing this is that I am going to be adding support for
preconcurrency imports to TransferNonSendable. That implies that we can have
preconcurrency import suppression in the SIL pipeline and thus that emitting the
diagnostic in Sema is too early.

To do this, I introduced a new module pass called
DiagnoseUnnecessaryPreconcurrencyImports that runs after the SILFunction pass
TransferNonSendable. The reason why I use a module pass is to ensure that
TransferNonSendable has run on all functions before we attempt to emit these
diagnostics. Then in that pass, we iterate over all of the modules functions and
construct a uniqued array of SourceFiles for these functions. Then we iterate
over the uniqued SourceFiles and use the already constructed Sema machinery to
emit the diagnostic using the source files.

rdar://126928265
2024-04-23 12:42:43 -05:00
Alexis Laferrière
fd59933ff5 Merge pull request #73179 from xymus/deprecated-impl-only
Sema: Warn that resilient uses of `@_implementationOnly` are deprecated
2024-04-23 09:22:12 -07:00
Angela Laar
f6404cde71 [Sema] Warn about 'Any' to 'any Sendable' override
Until Swift 6, warn about overriding Any property in parent class to any Sendable
2024-04-23 03:06:42 -07:00
Kavon Farvardin
f0a69a3ef1 prevent uses of Escapable in general
This protocol appears in the stdlib as scaffolding for the
`NonescapableTypes` feature, which is still experimental and not gone
through evolution as an approved addition to the stdlib.

Rather than delete it from the stdlib, because it needs to still remain
to support that feature work, gate references to it behind a feature
flag.

Additionally, prevent documentation from seeing this declaration.

rdar://126705184
2024-04-22 20:40:11 -07:00
Rintaro Ishizaki
3d32f5fc8a Merge pull request #73123 from rintaro/ide-complete-docatch-boundvar-rdar126699879
[CodeCompletion] Fix completion for 'catch' pattern bound values
2024-04-22 15:48:42 -07:00
Alexis Laferrière
e4ac42b458 Merge pull request #73176 from xymus/silence-ambiguity-warning
Sema: Offer solution to silence inconsistent import access-level warnings
2024-04-22 15:28:05 -07:00
Alexis Laferrière
3d611e2a85 Sema: Simplify warning about @_implementationOnly being deprecated 2024-04-22 14:44:44 -07:00
Kavon Farvardin
04e100dc0d Merge pull request #73131 from kavon/rdar126730410
NCGenerics: omit flag in interfaces
2024-04-22 14:18:50 -07:00
Alexis Laferrière
909c9c17f7 Merge pull request #73125 from xymus/superfluous-package-imports
Sema: Don't warn on package imports providing a type extended by a package extension
2024-04-22 13:16:34 -07:00
Alexis Laferrière
56095cf745 Sema: duplicate the note about which import limits access-level
Access-level on imports limit where decls from the target module can
be referenced. This is reported by the typical error about and a note
on the import. However, when using an IDE and editing a large file,
the note on the import is easy to miss. Address this by duplicating
the information on the error line as well so it's never out of the
current viewport.

rdar://119438201
2024-04-22 12:07:31 -07:00
Rintaro Ishizaki
0e122544ca [CodeCompletion] Fix completion for 'catch' pattern bound values
Previously code completion for 'catch' pattern bound values didn't work
correctly because code completion type checker fails to type check the
value decl in the pattern.
That was because the body of the 'do' statement is not type checked, so
the thrown error is not determined, then falled backed to the default
'Never', which doesn't matches any patterns.
To resolve this, always type check the body when typechecking 'catch'
patterns. Also, pretends 'do {}' throws 'any Error' even without
any throwing expressions in the body.

rdar://126699879
2024-04-22 11:09:12 -07:00
Alexis Laferrière
bd9c385ce5 Sema: Offer solution to silence inconsistent import access-level warnings
Adoption InternalImportsByDefault provides a safe access-level by default
to imports, as such ambiguities are not a risk and showing this warning is
superflous. When this warning is shown, make sure we note this alternative.
2024-04-22 10:52:21 -07:00
Alexis Laferrière
ff797cfd66 Sema: Warn on resilient uses of @_implementationOnly as deprecated
Report uses of `@_implementationOnly` in resilient modules as deprecated.
With a fixit to replace it with `internal` or delete it when imports
are internal by default.

Uses of `@_implementationOnly` in non-resilient modules is already reported
as being unsafe.
2024-04-22 10:32:58 -07:00
nate-chandler
1faeb50fff Merge pull request #73121 from nate-chandler/rdar126715654
[NoncopyablePartialConsumption] Promote to feature.
2024-04-22 07:01:10 -07:00
Holly Borla
a08c24044e Merge pull request #73168 from hborla/isolated-backing-property-wrapper
[Concurrency] Don't error on isolated property wrapper initializers inside `MainActor`-isolated structs.
2024-04-21 19:44:31 -07:00
Holly Borla
a6d9c15fb3 [Concurrency] Don't error on isolated property wrapper initializers inside
MainActor-isolated structs.
2024-04-21 10:01:31 -07:00
Slava Pestov
e342a38b87 Sema: Convert TypeChecker::computeCaptures() into two requests
We now compute captures of functions and default arguments
lazily, instead of as a side effect of primary file checking.

Captures of closures are computed as part of the enclosing
context, not lazily, because the type checking of a single
closure body is not lazy.

This fixes a specific issue with the `-experimental-skip-*` flags,
where functions declared after a top-level `guard` statement are
considered to have local captures, but nothing was forcing these
captures to be computed.

Fixes rdar://problem/125981663.
2024-04-20 22:16:25 -04:00