Commit Graph

26323 Commits

Author SHA1 Message Date
Tim Kientzle
598e5104ef Merge pull request #74184 from tbkka/tbkka-assertions2
Add `#include "swift/Basic/Assertions.h"` to a lot of source files
2024-06-20 12:13:28 -07:00
Holly Borla
991e7fd7b8 Merge pull request #74454 from hborla/throws-never-diagnostics
[TypeCheckEffects] Diagnose type mismatches for thrown errors in contexts that throw `Never`.
2024-06-19 20:18:05 -07:00
Michael Gottesman
9b0e0f5010 Follow up fixes with feedback from #74129
Didn't need to modify any tests since this shouldn't have any functional
change. Just a slight cleanup.
2024-06-19 20:04:05 -07:00
Holly Borla
ca266d38ff Merge pull request #74560 from hborla/isolated-parameter-checking
[Concurrency] Calls that pass an isolated parameter matching the isolation of the context do not exit to nonisolated.
2024-06-19 18:50:56 -07:00
Slava Pestov
e41a173752 Merge pull request #74538 from slavapestov/fix-rdar129540617
Sema: Re-introduce the hack for re-using generic signature of extended protocol
2024-06-19 19:20:22 -04:00
Holly Borla
4ff4cfd0a3 [NFC] Remove an unused local variable in isolated parameter checking. 2024-06-19 14:51:13 -07:00
Holly Borla
2804daff5b [Concurrency] Calls that pass an isolated parameter matching the isolation of
the context do not exit to nonisolated.

Setting the `mayExitToNonisolated` during isolated parameter checking was
done after a check that bails out early when the isolated argument matches
the isolated paramter of the caller, so the actor isolation checker was
accidentally considering the call as exiting to a nonisolated context. This
lead to bogus diagnostics during the region isolation pass.
2024-06-19 14:51:01 -07:00
Pavel Yaskevich
adaaf5a522 Merge pull request #74542 from gregomni/issue-74463
[Sema] Tuple mismatch with argument locator should be handled by ArgumentMismatch
2024-06-19 14:39:14 -07: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
Slava Pestov
f747121080 Sema: Re-introduce the hack for re-using generic signature of extended protocol
In Swift 5.10 if you wrote `extension Foo {}` for some protocol Foo,
the extension would always re-use the generic signature of Foo, which
is <Self where Self: Foo>. In Swift 6 this no longer works because Foo
might be ~Copyable, in which case `extension Foo {}` adds default
requirements, so we changed GenericSignatureRequest to just always
build a new signature if we're given an extension.

However, to avoid a request cycle with a code example that really should
have never worked at all, I'm re-introducing the hack for re-using the
signature.

Fixes rdar://problem/129540617.
2024-06-19 13:25:09 -04:00
Konrad `ktoso` Malawski
8c5d9e2085 Merge pull request #74475 from ktoso/wip-async-get-if-let
[Concurrency] if let value on async value should be banned (not crash)
2024-06-19 23:21:15 +09:00
Konrad `ktoso` Malawski
0d3a4b44b8 [Concurrency] if let value on async value should be banned (not crash)
The issue is that the shorthand if let syntax injects an implicit
expression: https://github.com/apple/swift/pull/40694/ in ParseStmt and
that the 'diagnoseUnhandledAsyncSite' explicitly avoids reporting errors
in implicit expressions.

This change is that we don't mark the implicit declref code emitted by
the `if let prop` as implicit anymore, and this way the reporting works
out as expected.

Added some tests covering this as well as properly erroring out for the
nonexistent syntax of shortand + awaiting which doesn't exist, and we
properly error on it.

Resolves rdar://126169564
2024-06-19 17:20:18 +09: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
Greg Titus
6266564700 Tuple mismatch with argument locator should be handled by ArgumentMismatch 2024-06-18 21:58:39 -07:00
Slava Pestov
74f851d210 Sema: Remove a bit of dead code 2024-06-18 21:27:41 -04:00
Slava Pestov
ba34ee1be0 Sema: Pass TypeResolution around by const reference since it's large 2024-06-18 21:27:41 -04:00
Tim Kientzle
1098054291 Merge branch 'main' into tbkka-assertions2 2024-06-18 17:52:00 -07:00
Steven Wu
fef4ee4935 Merge pull request #74199 from cachemeifyoucan/eng/PR-128876895
[ScanDependencies] Make sure `canImport` resolution agrees with `import`
2024-06-18 09:14:19 -07:00
Holly Borla
cdfe3364be Merge pull request #74509 from hborla/fix-infer-sendable-from-global-actor
[Concurrency] Fix `@Sendable` inference for global-actor-isolated function types.
2024-06-18 07:08:10 -07:00
Holly Borla
1406b28de0 [Concurrency] Consider the upcoming feature flags in the originating module when
applying `@Sendable` inference for global-actor-isolated function types.

Otherwise, for libraries that do not enable `GlobalActorIsolatedTypesUsability`,
clients that do will encounter mangling mismatches for any library APIs that
have global-actor-isolated function types that are not explicitly `@Sendable`.
2024-06-17 18:01:45 -07:00
Hamish Knight
61421e86e5 Merge pull request #74423 from hamishknight/fully-typed
[CS] Fill in ErrorTypes for expressions that fail to type-check
2024-06-17 23:59:46 +01: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
Rintaro Ishizaki
2f7aa428db [Macros] In-process plugin server
Separate swift-syntax libs for the compiler and for the library plugins.
Compiler communicates with library plugins using serialized messages
just like executable plugins.

* `lib/swift/host/compiler/lib_Compiler*.dylib`(`lib/CompilerSwiftSyntax`):
  swift-syntax libraries for compiler. Library evolution is disabled.
* Compiler (`ASTGen` and `swiftIDEUtilsBridging`) only depends on
  `lib/swift/host/compiler` libraries.
* `SwiftInProcPluginServer`: In-process plugin server shared library.
  This has one `swift_inproc_plugins_handle_message` entry point that
  receives a message and return the response.
* In the compiler
  * Add `-in-process-plugin-server-path` front-end option, which specifies
    the `SwiftInProcPluginServer` shared library path.
  * Remove `LoadedLibraryPlugin`, because all library plugins are managed
    by `SwiftInProcPluginServer`
  * Introduce abstract `CompilerPlugin` class that has 2 subclasses:
    * `LoadedExecutablePlugin` existing class that represents an
      executable plugin
    * `InProcessPlugins` wraps `dlopen`ed `SwiftInProcPluginServer`
  * Unified the code path in `TypeCheckMacros.cpp` and `ASTGen`, the
    difference between executable plugins and library plugins are now
    abstracted by `CompilerPlugin`
2024-06-17 11:36:52 -07:00
Hamish Knight
5ec4d1cc98 [CS] Fill in ErrorTypes for expressions that fail to type-check
Ensure we always produce typed AST, even if we
fail to apply a solution. This fixes a cursor info
issue where we'd to type-check a closure twice
due to it not having a type set.

rdar://129417672
2024-06-17 17:58:52 +01:00
Greg Titus
3e7f323276 Merge pull request #74464 from gregomni/issue-46902
[Sema] Fix hole where missing_nullary_call wasn't diagnosed in ternary condition.
2024-06-17 08:49:44 -07:00
Greg Titus
10138d8390 Fix hole where missing_nullary_call wasn't diagnosed in ternary condition. 2024-06-16 22:19:48 -07:00
Holly Borla
775191cd94 [TypeCheckEffects] Diagnose type mismatches for thrown errors in contexts that
throw `Never`.

Previously, this mistake slipped through the effects checker because it used
a fallback type of `any Error` if a catch node had a null thrown error type.
This change also fixes an issue where thrown error type mismatches were not
diagnosed at all in autoclosures.
2024-06-15 20:38:20 -07:00
Greg Titus
fb2d667e45 Merge pull request #74243 from gregomni/rvalue-ambiguous
[Sema] Score non-settable overload choices higher in RValueToLValue fix
2024-06-15 15:35:39 -07:00
Greg Titus
843ce585a3 Set fix impact for non-settable overload choices higher, so we get diagnoses from better choices. 2024-06-15 11:43:21 -07:00
Doug Gregor
aa90b432e9 Drop a very, very dated comment that we don't need. The FIXME suffices 2024-06-14 22:21:41 -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
c8d9e1813e [sending] Make the protocol errors only occur in swift 6.
For now, just turn off the error in swift 5 mode. I wanted to make this an error
but right now I do not have all of the time to do it so this is good in the
short term so that people can adopt sending on protocols without breaking people
using their framework in executables still compiling in swift 5.
2024-06-14 09:47:21 -07:00
Hamish Knight
a9d3df06b3 Merge pull request #74352 from hamishknight/complete-disjunction
[Completion] Skip `tryOptimizeGenericDisjunction` if there's a completion child
2024-06-14 09:25:19 +01: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
Doug Gregor
3a7b993646 Merge pull request #74362 from DougGregor/enum-case-sendable-fn
Treat references to enum cases with associated values as `@Sendable` functions
2024-06-13 15:07:08 -07:00
Doug Gregor
95e12ca584 Don't apply @Sendable to enum cases in pattern matching 2024-06-13 11:56:18 -07:00
Hamish Knight
26e8245e22 [Sema] Requestify pattern resolution
Add a cached request to perform pattern resolution.
This is needed to prevent the constraint system
from resolving the same pattern multiple times
along different solver paths, which could result
in creating different pattern nodes for each path.
Once pattern resolution is moved to pre-checking
we ought to be able to make this uncached.

rdar://128661960
2024-06-13 15:27:47 +01:00
Kavon Farvardin
9eba052ab2 Merge pull request #74322 from kavon/se427-noimplicit-for-invertible
SE-427: Make conditional conformances to Copyable more explicit.
2024-06-12 22:03:49 -07:00
Michael Gottesman
81100ad660 [sending] Fix type inference for sending results of closures.
The previous commit fixed things like:

```swift
let x: () -> sending String = { "" }
```

This commit fixes this test case:

```swift
let x = { () -> sending String in "" }
```
2024-06-12 16:59:24 -07:00
Michael Gottesman
2ac874e8e3 [sending] Fix a few bugs around closure inference of sending parameters and results.
I found this while writing tests for the earlier part of this work. Since this
is also type checking work, I am just folding this work into that work.
2024-06-12 16:13:05 -07:00
Michael Gottesman
83bcf23dca [sending] Check for a nullptr in AssociatedTypeInference when calling computeFailureTypeWitness.
The problem happens when a type conforms to AsyncIterator.next when next in the
protocol returns its value as sending, but the witness does not have sending.
This results in the function subtyping rules rejecting the witness... but we
still leave in the witness as a nullptr... so we need to handle it here.

rdar://129300953
2024-06-12 16:13:05 -07:00
Michael Gottesman
3c166b5d96 [sending] Implement non-protocol function subtyping rules.
rdar://127675288
2024-06-12 16:13:05 -07:00
Michael Gottesman
1c9b1780f6 [sending] Do not let protocol function reqs with a sending result be witnessed by a function without a sending result.
This is important since the witness is not promising to return a disconnected
value and the caller of the requirement is going to accept that.

rdar://127675288
2024-06-12 16:13:05 -07:00
Doug Gregor
c65264738b Treat references to enum cases with associated values as @Sendable functions
When `InferSendableFromCaptures`, make sure to treat references to enum
cases that have associated values as `@Sendable` functions.
2024-06-12 14:58:56 -07:00
Alexis Laferrière
9c868f8454 Merge pull request #74351 from xymus/cross-import-hidden-imports
Sema: Support access-level on imports with cross-import overlays
2024-06-12 14:56:49 -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
Kavon Farvardin
ec4a125f3e NCGenerics: ext's might not infer invertible req's
If the extension adds conformance to an invertible protocol, it's
confusing for people to also infer conditional requirements on the
generic parameters for those invertible protocols. This came up in the
review of SE-427.
2024-06-12 14:44:22 -07:00