Commit Graph

4105 Commits

Author SHA1 Message Date
Mykola Pokhylets
4d0b624866 Make deinit non-isolated by default
Failing: Distributed/Runtime/distributed_actor_deinit.swift
2024-07-11 13:09:08 +02:00
Andrew Trick
12acde2215 Merge pull request #75096 from meg-gupta/lifetimedeparg
Add support for lifetime dependence in parameter position
2024-07-10 22:56:23 -07:00
Kavon Farvardin
bbc02a5544 Merge pull request #75141 from kavon/invertible-conformance-same-sourcefile
NCGenerics: enforce same-source conformance rule
2024-07-10 17:50:13 -07:00
Meghana Gupta
154989463b Add support for lifetime dependence in parameter position 2024-07-10 14:20:03 -07:00
Meghana Gupta
4993f4bf22 Merge pull request #74956 from meg-gupta/lifetimedepfunctiontype
Add some diagnostics related to lifetime dependence and function types
2024-07-10 14:19:05 -07:00
Kavon Farvardin
233742a565 NCGenerics: enforce same-source conformance rule
SE-427 says the conformance to Copyable must appear in the same source
file as the nominal type.

resolves rdar://131486561
2024-07-10 14:02:10 -07:00
Meghana Gupta
bbd54ae8a8 Ban annotating function type with lifetime dependence 2024-07-09 09:13:14 -07:00
Doug Gregor
45d4d975cd Deprecate @_unsafeInheritExecutor and remove it from Swift 6 2024-07-08 23:35:34 -07:00
Doug Gregor
5f049b63ef Diagnose attempts to use #isolation within an @_unsafeInheritExecutor function
An `@_unsafeInheritExecutor` function is unsafe because it doesn't
really "inherit" the executor, it just avoids immediately hopping off
the executor. That means that using `#isolation` within such a
function is fundamentally broken. Ban the use of `#isolation` within
such a function, providing a Fix-It that removes the
`@_unsafeInheritExecutor` attribute and adds a defaulted parameter

    isolation: (any Actor)? = #isolation

instead. That's the real, safe pattern that want going forward.

We did say it was unsafe, after all. Part of rdar://131151376.
2024-07-08 23:34:28 -07:00
Kavon Farvardin
04454054b7 NCGenerics: add availability checking
Not all runtimes can correctly operate with types that use noncopyable
generics. When the generic argument of a type is noncopyable, old
runtimes can't recognize that to correctly check conformances that may
be conditional on those arguments being Copyable, etc.

resolves rdar://126239335
2024-07-07 15:38:00 -07:00
Doug Gregor
e50beb0a46 Merge pull request #74962 from DougGregor/typed-throws-backdeploy-fixes
Typed throws backdeploy fixes
2024-07-04 00:12:52 -07:00
Doug Gregor
21e5066249 Diagnose deployment constraints on type metadata involving typed throws
Fixes the rest of rdar://121530587.
2024-07-03 21:08:54 -07:00
Alejandro Alonso
427077b148 Merge pull request #74901 from Azoy/static-exclusive-requirements
[Sema] Let protocols define getter requirements for @_staticExclusiveOnly types
2024-07-03 14:33:19 -07:00
Michael Gottesman
34195ff213 Merge pull request #74610 from gottesmm/pr-324fd70c13e87a329334341aae4667f2d1be152c
[sending] Remove transferring.
2024-07-02 14:02:18 -07:00
Alejandro Alonso
66de676348 Update include/swift/AST/DiagnosticsSema.def
Co-authored-by: Hamish Knight <hamish_knight@apple.com>
2024-07-02 13:00:52 -07:00
Alejandro Alonso
2f0750a450 Let protocols define getter requirements for @_staticExclusiveOnly types 2024-07-02 10:35:11 -07:00
Michael Gottesman
a4eb43ec88 Merge pull request #74850 from gottesmm/pr-34859085fc34b650049006f026ab33726f79b600
[concurrency] Standardize sending of non-isolated -> nonisolated to match the keyword 'nonisolated'.
2024-06-29 22:19:28 -07:00
Michael Gottesman
474aa47732 [concurrency] Standardize sending of non-isolated -> nonisolated to match the keyword 'nonisolated'.
rdar://130827967
2024-06-29 18:09:38 -07:00
Xi Ge
fb43cf6ffb Merge pull request #74801 from beccadax/objcimpl-enablement
Enable @objc @implementation (SE-0436) as an ordinary language feature
2024-06-28 09:12:52 -07:00
Becca Royal-Gordon
6deec96034 Update objcImpl diagnostics to final syntax
Update diagnostics that mention `@_objcImplementation` to mention `@objc @implementation` instead.

Fixes rdar://130707698
2024-06-27 15:38:41 -07:00
Kavon Farvardin
05f5e511fc Diags: say "actors" cannot be ~Copyable
rdar://130450351
2024-06-25 12:06:22 -07:00
Michael Gottesman
112071e57d [sending] Remove transferring.
Out of an abundance of caution, we:

1. Left in parsing support for transferring but internally made it rely on the
internals of sending.

2. Added a warning to tell people that transferring was going to
be removed very soon.

Now that we have given people some time, remove support for parsing
transferring.

rdar://130253724
2024-06-21 16:03:21 -07:00
Slava Pestov
3a91280f08 Sema: Diagnose 'lazy' variable initializer with effect
This used to crash in SILGen.

Fixes https://github.com/apple/swift/issues/60128
Fixes https://github.com/apple/swift/issues/60129
2024-06-20 21:34:54 -04:00
Holly Borla
4bec599931 Merge pull request #74543 from hborla/promote-isolated-any
[Features] Promote `IsolatedAny` and its alias to a language feature.
2024-06-19 10:32:30 -07:00
Holly Borla
966269d31a [Features] Promote IsolatedAny and its alias to a language feature.
The proposal is accepted and implemented for Swift 6.0.
2024-06-18 22:09:16 -07:00
Steven Wu
7d85aa423d [ScanDependencies] Make sure canImport resolution agrees with import
Fix the problem that when the only module can be found is an
invalid/out-of-date swift binary module, canImport and import statement
can have different view for if the module can be imported or not.

Now canImport will evaluate to false if the only module can be found for
name is an invalid swiftmodule, with a warning with the path to the
module so users will not be surprised by such behavior.

rdar://128876895
2024-06-17 14:14:48 -07:00
Michael Gottesman
f9954181ae Merge pull request #74129 from gottesmm/pr-d17a3faab1ceab8b831d7649c1005be9c49d771c
[region-isolation] Implement function sub typing rules
2024-06-14 12:53:22 -07:00
Michael Gottesman
16d0194d77 [sending] Improve the sending mismatch errors and make them warnings when not in swift 6.
This will ensure that we do not break anyone who has adopted APIs like
CheckedContinuation.resume that now have sending parameters.

An example of where this can come up is shown by the ProcessType in SwiftToolsCore:

```swift
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
@discardableResult
public func waitUntilExit() async throws -> ProcessResult {
    try await withCheckedThrowingContinuation { continuation in
        DispatchQueue.processConcurrent.async {
            self.waitUntilExit(continuation.resume(with:))
        }
    }
}
```

This fails to compile since self.waitUntilExit doesn't expect a function that
takes a sending parameter. We want to give people time to fix such issues.
2024-06-13 22:23:08 -07:00
Alexis Laferrière
4dc060303e Merge pull request #74142 from xymus/access-level-conformances
Sema: Report public conformances to non-publicly imported protocols
2024-06-13 19:34:37 -07:00
Alexis Laferrière
67694c2ab0 Sema: Report public conformances to non-publicly imported protocols
Exportability checking for non-public imports relies on classic
access-level checks for some of the work. However while conforming
to a local internal protocol from a public type is allow we should
disallow it for imported types, even when imported as internal.

Track exportability issues on conformances to protocols separately
from the general category. Use that information to improve the
diagnostics and report these issues for access-level on imports.

rdar://128420980
2024-06-12 14:48:46 -07:00
Kavon Farvardin
a1e14ae0c7 Sema: ext's must add solo invertible conformances
This helps prevent confusion after not inferring requirements if the
extension adds a Copyable conformance.
2024-06-12 14:44:22 -07:00
Kavon Farvardin
2893e3dd8d Sema: reword inverse-on-extension message
We should be saying "can't suppress Copyable" instead, since you can't
"suppress" ~Copyable.
2024-06-12 14:44:22 -07:00
Xi Ge
bcdcdf19f6 Merge pull request #74302 from nkcsgexi/revert-pkg-export
Revert recent changes for exportability for package declarations
2024-06-11 17:13:21 -07:00
Meghana Gupta
f1a887515b Merge pull request #74195 from meg-gupta/immortal
Add dependsOn(immortal)
2024-06-11 15:51:34 -07:00
Xi Ge
34d9b6cb6b Revert "Sema: Report references to missing imports from package extensions"
This reverts commit 12f7abcef6.
2024-06-11 14:03:45 -07:00
Xi Ge
6f5b40543d Revert "Handle package exportability."
This reverts commit d182d01c28.
2024-06-11 11:54:00 -07:00
Meghana Gupta
c14559173d Add dependsOn(immortal) 2024-06-11 11:18:10 -07:00
Pavel Yaskevich
51d817cd0e Merge pull request #74242 from iMostfa/feature/SR-9615-escaping-and-inout-support
Remove `@escaping` from inout closures
2024-06-11 00:28:33 -07:00
iMostafa
9769418dfa Better message diagnostics for inout @escaping closure 2024-06-10 21:40:10 +02:00
Holly Borla
005b45c1cc [Sema] Diagnose deprecated default implementations in the witness checker.
If a protocol provides a deprecated default implementation for a requirement
that is not deprecated, the compiler should emit a warning so the programmer
can provide an explicit implementation of the requirement. This is helpful
for staging in new protocol requirements that should be implemented in
conforming types.
2024-06-10 07:10:38 -07:00
Meghana Gupta
af1d6017f9 Merge pull request #74132 from meg-gupta/deleteresultdependson
Remove resultDependsOn/resultDependsOnSelf
2024-06-06 10:23:31 -07:00
Kavon Farvardin
02e0770834 Merge pull request #73916 from kavon/ncgenerics-implicit-wrapping-127450418
ConstraintSystem: clarify consuming conversions
2024-06-05 13:16:49 -07:00
Meghana Gupta
470fa2f365 Remove resultDependsOn/resultDependsOnSelf 2024-06-05 11:36:16 -07:00
Kavon Farvardin
77e8fb0b74 NCGenerics: implicit casts require 'consume'
It's better if this is an error from the start.
2024-06-05 09:52:17 -07:00
Kavon Farvardin
c9cfe28e6d NCGenerics: improve diagnostics
Removing the old, ad-hoc diagnostics code improves the diagnostics we
emit, since the existing diagnostics for missing conformances is already
pretty good.

rdar://127369509
2024-06-04 15:06:32 -07:00
Kavon Farvardin
e55e247f0c ConstraintSystem: clarify consuming conversions
There are a number of implicit conversions in Swift, such as to Optional
and to an existential, which are now possible for noncopyable types.

But all type casts are consuming operations for noncopyable types. So
it's confusing when a function that takes a borrowed argument of
optional type appears to be consuming:

```
func f(_ x: borrowing NC?) { ... }

let x = NC()
f(x)
f(x) // error!
```

So, rather than for people to write `x as T?` around all implicit
conversions, require them to write `consume x` around expressions
that will consume some lvalue. Since that makes it much more clear what
the consequences will be.

Expressions like `f(g())`, where you're passing an rvalue to the callee,
are not confusing. And those are exactly the expressions you're not
allowed to write `consume` for, anyway.

fixes rdar://127450418
2024-06-04 14:04:19 -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
Holly Borla
3c6918a2c4 [Macros] Don't allow macros to add accessors to let variables. 2024-05-23 22:22:07 -07:00
Andrew Trick
b5b0c75ccd Remove diagnostic: lifetime_dependence_on_bitwise_copyable
Allow lifetime depenendence on types that are BitwiseCopyable & Escapable.

This is unsafe in the sense that the compiler will not diagnose any use of the
dependent value outside of the lexcial scope of the source value. But, in
practice, dependence on an UnsafePointer is often needed. In that case, the
programmer should have already taken responsibility for ensuring the lifetime of the
pointer over all dependent uses. Typically, an unsafe pointer is valid for the
duration of a closure. Lifetime dependence prevents the dependent value from
being returned by the closure, so common usage is safe by default.

Typical example:

func decode(_ bufferRef: Span<Int>) { /*...*/ }

extension UnsafeBufferPointer {
  // The client must ensure the lifetime of the buffer across the invocation of `body`.
  // The client must ensure that no code modifies the buffer during the invocation of `body`.
  func withUnsafeSpan<Result>(_ body: (Span<Element>) throws -> Result) rethrows -> Result {
    // Construct Span using its internal, unsafe API.
    try body(Span(unsafePointer: baseAddress!, count: count))
  }
}

func decodeArrayAsUBP(array: [Int]) {
  array.withUnsafeBufferPointer { buffer in
    buffer.withUnsafeSpan {
      decode($0)
    }
  }
}

In the future, we may add SILGen support for tracking the lexical scope of
BitwiseCopyable values. That would allow them to have the same dependence
behavior as other source values.
2024-05-22 17:10:56 -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