Commit Graph

28619 Commits

Author SHA1 Message Date
Allan Shortlidge
a4f59f9481 AST: Return @backDeployed attribute along with version from Decl query.
Also, introduce a convenience on `BackDeployedAttr` for getting its associated
`AvailabilityDomain`.

NFC.
2025-07-06 19:44:53 -07:00
Slava Pestov
27e65732b1 Merge pull request #82785 from slavapestov/fix-rdar154684522
RequirementMachine: Increase default type differences limit to 13000
2025-07-06 16:37:43 -04:00
Doug Gregor
2e27ff8734 Merge pull request #82814 from DougGregor/region-inference-dynamic-isolated-conformances
[SE-0470] Extend region analysis to account for isolated conformances
2025-07-06 09:24:17 -07:00
Slava Pestov
c5d8ae5b00 Sema: Remove unused variable 2025-07-06 11:22:55 -04:00
Slava Pestov
ed329944fa Merge pull request #82757 from slavapestov/fix-issue-60552
Sema: Fix leading dot with protocol composition or parameterized protocol contextual type
2025-07-05 14:57:59 -04:00
Pavel Yaskevich
0444d297b6 [AST/Sema] SE-0487: Remove @preEnumExtensibility attribute 2025-07-04 11:06:44 -07:00
Pavel Yaskevich
43eec8fede [AST/Sema] SE-0487: Expand @nonexhaustive attribute to support warn argument
The spelling `@nonexhaustive(warn)` replaces `@preEnumExtensibility`
attriubte.
2025-07-04 10:20:25 -07:00
Hamish Knight
20bbd8d8c2 Merge pull request #82770 from hamishknight/simple-fix
[CS] Ensure type variables are eliminated by `Solution::simplifyType`
2025-07-04 14:08:27 +01:00
Nate Cook
85208293c9 Allow inout parameters in expression macros (#82370)
Sema seems to be flagging inout expressions (e.g. &foo) in expression
macros as invalid, setting up a catch 22 where Sema emits an error when
a parameter has the '&' sigil and type checking fails when it doesn't.

This resolves the issue by allowing inout expressions inside macro
expansion expressions.

Resolves https://github.com/swiftlang/swift/issues/82369.
2025-07-03 23:52:16 -07:00
Doug Gregor
deec3e1cd5 [SE-0470] Warn about isolated conformance to SendableMetatype-inheriting protocol
An isolated conformance to a SendableMetatype-inheriting protocol
cannot actually be used in generic code, because the SendableMetatype
requirement itself prevents it. Warn about this case so folks aren't
surprised at runtime.

This is a part of issue #82550 / rdar://154437489.
2025-07-03 22:27:23 -07:00
Doug Gregor
507c4056aa [SE-0470] Check uses of isolated conformances in collection literals
Fixes rdar://151646584.
2025-07-03 22:27:23 -07:00
Konrad 'ktoso' Malawski
b0d2ca9be6 [Concurrency] Fix nonisolated(nonsending) interaction with #isolation 2025-07-04 10:20:08 +09:00
Pavel Yaskevich
fe1ae75711 [AST/Sema] SE-0487: Rename @extensible into @nonexhaustive
This is an accepted spelling for the attribute. This commit
also renames the feature flag from `ExtensibleAttribute` to
`NonexhaustiveAttribute` to match the spelling of the attribute.
2025-07-03 17:50:05 -07:00
Konrad `ktoso` Malawski
ec8caf3cdd Remove the experimental @Task macro (#82437) 2025-07-03 10:15:21 -07:00
Pavel Yaskevich
79af04ccc4 Merge pull request #82731 from xedin/rdar-154808850
[Concurrency] SE-0461: Extend `nonisolated(nonsending)` inference to function types
2025-07-03 09:17:10 -07:00
Hamish Knight
d6037049b1 [CS] Ensure type variables are eliminated by Solution::simplifyType
`TypeSimplifier` may not eliminate type variables from e.g the
pattern types of pattern expansion types since they can remain
unresolved due to e.g having a placeholder count type. Make sure we
eliminate any remaining type variables along with the placeholders.
There's probably a more principled fix here, but this is a quick and
low risk fix we can hopefully take for 6.2.

rdar://154954995
2025-07-03 16:24:31 +01:00
Michael Gottesman
677b897ff6 Merge pull request #82555 from gottesmm/pr-b4de2f5d58d852cd3e9e606101e1b0ff42ce6092
[nonisolated-nonsending] Make the AST not consider nonisolated(nonsending) to be an actor isolation crossing point.
2025-07-03 05:22:57 -07:00
Hamish Knight
31408fe5cb Merge pull request #82724 from hamishknight/diag-it 2025-07-03 09:23:44 +01:00
Hamish Knight
e2a8ace0ca Merge pull request #82721 from hamishknight/err-val 2025-07-03 09:23:24 +01:00
Slava Pestov
561ecd8826 Sema: Fix leading dot with protocol composition or parameterized protocol contextual type
- Fixes https://github.com/swiftlang/swift/issues/60552.
- Fixes rdar://problem/99699879.
2025-07-03 00:19:48 -04:00
Allan Shortlidge
ede7bdb5d7 Merge pull request #82671 from tshortli/zippered-miscompile-if-unavailable
SILGen: Fix `if #unavailable` mis-compile for zippered libraries
2025-07-02 16:05:51 -07:00
Michael Gottesman
c12c99fb73 [nonisolated-nonsending] Make the AST not consider nonisolated(nonsending) to be an actor isolation crossing point.
We were effectively working around this previously at the SIL level. This caused
us not to obey the semantics of the actual evolution proposal. As an example of
this, in the following, x should not be considered main actor isolated:

```swift
nonisolated(nonsending) func useValue<T>(_ t: T) async {}
@MainActor func test() async {
  let x = NS()
  await useValue(x)
  print(x)
}
```

we should just consider this to be a merge and since useValue does not have any
MainActor isolated parameters, x should not be main actor isolated and we should
not emit an error here.

I also fixed a separate issue where we were allowing for parameters of
nonisolated(nonsending) functions to be passed to @concurrent functions. We
cannot allow for this to happen since the nonisolated(nonsending) parameters
/could/ be actor isolated. Of course, we have lost that static information at
this point so we cannot allow for it. Given that we have the actual dynamic
actor isolation information, we could dynamically allow for the parameters to be
passed... but that is something that is speculative and is definitely outside of
the scope of this patch.

rdar://154139237
2025-07-02 12:13:29 -07:00
Pavel Yaskevich
bb0cd6f0a6 [Concurrency] SE-0461: Extend nonisolated(nonsending) inference to function types
Currently only declarations would get `nonisolated(nonsending)`
inferred if the upcoming flag is enabled, this changes extend
this to apply to asynchronous nonisolated function types as well.

Resolves: rdar://154808850
2025-07-02 12:12:06 -07:00
Allan Shortlidge
59d74fa1c7 Sema: Diagnose opaque types that depend on availability of a custom domain.
Serialization and IRGen don't yet support opaque return types that would depend
on querying availability of a custom domain so we need to reject this code to
avoid mis-compiling it.
2025-07-02 11:23:42 -07:00
Allan Shortlidge
4a76c04cf5 SILGen: Fix if #unavailable mis-compile for zippered libraries.
Inverted availability queries were mis-compiled for zippered libraries because
the code that emits calls to `isOSVersionAtLeastOrVariantVersionAtLeast()` was
not updated when the `if #unavailable` syntax was introduced (at that time
support for zippered libraries had not yet been upstreamed). The result of
these calls is now inverted when appropriate.

To make it easier to manage the growing complexity of supporting availability
queries, Sema now models the relevant information about an availability query
with the new `AvailabilityQuery` type. It encapsulates the domain for the
query, the result if it is known at compile time, and the version tuple
arguments to pass to a runtime invocation if applicable.

Resolves rdar://147929876.
2025-07-02 11:23:42 -07:00
Allan Shortlidge
b493b56e7e Sema: Remove OpaqueUnderlyingTypeChecker::AvailabilityContext.
`AvailabilityContext` is now a fundamental type used throughout the compiler,
so it's confusing for `OpaqueUnderlyingTypeChecker` to repurpose this name to
represent an `IfStmt`.

NFC.
2025-07-02 11:23:42 -07:00
Slava Pestov
cc17c04fae Merge pull request #82692 from slavapestov/fix-issue-82614
Concurrency: Move PackExpansionType check to swift::diagnoseNonSendableTypes()
2025-07-02 12:50:10 -04:00
Hamish Knight
e4e82ec8fc [Sema] Avoid applying diagnostic hack to caller-side expression macros
We can't assume that type-checking the expression macro in the
parameter will also fail if it fails at the call site since e.g
name lookup may differ. Make sure we only apply this logic to simple
literals.

rdar://154771596
2025-07-02 17:46:10 +01:00
Pavel Yaskevich
c677554d3a Merge pull request #82689 from xedin/rdar-154754939
[Concurency] Allow declarations with `@isolated(any)` parameters be m…
2025-07-02 09:33:05 -07:00
Hamish Knight
5df9933fad [AST] Enforce non-null type for value GenericTypeParamType
Make sure we have a value type for a value generic parameter.
2025-07-02 14:46:55 +01:00
Hamish Knight
3daae5955e [AST] Use ErrorType for invalid value generic parameter
If we fail to resolve the value type for a value generic parameter,
previously we would have returned a null Type, causing crashes
downstream. Instead, return an ErrorType, leaving a null Type for
cases where the generic parameter isn't a value generic at all.

rdar://154856417
2025-07-02 14:46:55 +01:00
Hamish Knight
1bd32a1a6b NFC: Constify GenericTypeParamDeclGetValueTypeRequest's parameter 2025-07-02 14:46:55 +01:00
Doug Gregor
98b1494b0c Merge pull request #82669 from DougGregor/isolated-deinit-main-actor-mode 2025-07-02 00:52:40 -07:00
Doug Gregor
46572f80a2 Merge pull request #82661 from DougGregor/back-deploy-main-actor-isolated-deinit
[SE-0371] Back-deploy support for main-actor-isolated deinit
2025-07-01 20:50:19 -07:00
Slava Pestov
66cda77b4a Concurrency: Move PackExpansionType check to swift::diagnoseNonSendableTypes()
This was added in #80220 to fix a related issue with captures of packs,
but it's even better to sink this down into diagnoseNonSendableTypes(),
so that we can handle packs in parameter position as well.

- Fixes https://github.com/swiftlang/swift/issues/82614.
- Fixes rdar://problem/154649522.
2025-07-01 20:31:09 -04:00
Pavel Yaskevich
a522448e90 [Concurency] Allow declarations with @isolated(any) parameters be marked as @concurrent/nonisolated(nonsending)
It's shouldn't be possible to use these attributes directly on
the function type that is `@isolated(any)` as per SE-0461 proposal
but it shouldn't preclude declarations that have parameters with
`@isolated(any)` from using them.

Resolves: rdar://154754939
2025-07-01 15:07:23 -07:00
Egor Zhdan
01719983dc Merge pull request #82627 from swiftlang/egorzhdan/void-begin-crash
[cxx-interop] Do not crash for `void begin()`
2025-07-01 17:35:16 +01:00
Hamish Knight
dc880588ff Merge pull request #82619 from hamishknight/fuzzy
[test] Add some more known crashers
2025-07-01 13:24:42 +01:00
Pavel Yaskevich
529a9f80a4 Merge pull request #82645 from xedin/rdar-153646123
[Concurrency] Forego Sendable checking if conversion doesn't change t…
2025-07-01 00:20:38 -07:00
Doug Gregor
78464f8592 [SE-0466] Infer isolated deinit in main-actor-by-default mode
Now that main-actor-isolated deinit can be back-deployed, enable
inference of isolated deinit within main-actor-by-default mode.

Implements rdar://154729369.
2025-06-30 22:03:07 -07:00
Doug Gregor
7789a0ce64 [SE-0371] Back-deploy support for main-actor-isolated deinit
When targeting a platform that predates the introduction of isolated
deinit, make a narrow exception that allows main-actor-isolated deinit
to work through a special, inlineable entrypoint that is
back-deployed. This implementation

  1. Calls into the real implementation when available, otherwise
  2. Checks if we're on the main thread, destroying immediately when
we are, otherwise
  3. Creates a new task on the main actor to handle destruction.

This implementation is less efficient than the implementation in the
runtime, but allows us to back-deploy this functionality as far back
as concurrency goes.

Fixes rdar://151029118.
2025-06-30 17:38:08 -07:00
Pavel Yaskevich
bec4ebd126 Merge pull request #82574 from xedin/solver-perf-behind-a-flag
[ConstraintSystem] Implement disjunction favoring algorithm behind a flag
2025-06-30 16:27:01 -07:00
Pavel Yaskevich
d3f86b4efd Merge pull request #82593 from xedin/rdar-148076903
[Concurrency] Fix a crash caused by misuse of `isolated` modifier
2025-06-30 13:06:17 -07:00
Hamish Knight
40c0242274 [CS] Use value() instead of * for ArgumentMismatchFailure
Make sure we reliably crash rather than producing garbage.
2025-06-30 20:52:06 +01:00
Pavel Yaskevich
053199eb12 [Concurrency] Forego Sendable checking if conversion doesn't change the global actor
`FunctionConversionExpr` is allowed to modify different attributes
of a type, sometimes it could strip `@Sendable` but keep the same
global actor attribute in place, that needs to be handled explicitly
before performing Sendable checking because in this case there is
going to be no isolation context change for arguments or results.

Resolves: rdar://153646123
2025-06-30 12:07:41 -07:00
Alexis Laferrière
529cc3ccb6 Merge pull request #82039 from xymus/cdecl-enum
PrintAsClang: Introduce `@cdecl` enums
2025-06-30 09:56:28 -07:00
Egor Zhdan
883ff18adb [cxx-interop] Do not crash for void begin()
When importing C++ methods, Swift always assumes that methods named `begin()` and `end()` are unsafe, since these methods commonly return iterator types that are inherently unsafe in Swift.

Some additional logic in Sema tries to diagnose usages of `.begin()` and `.end()` from Swift and suggest safe alternatives. That logic had a null pointer dereference bug.

rdar://153814676 / resolves https://github.com/swiftlang/swift/issues/82361
2025-06-30 16:26:56 +01:00
John McCall
c8889b3c6e Merge pull request #82592 from rjmccall/local-function-isolation-fixes
Local function isolation fixes
2025-06-30 01:47:45 -04:00
John McCall
3439e0caab Fix a bunch of bugs with the isolation of local funcs. Since we
use local funcs to implement `defer`, this also fixes several
bugs with that feature, such as it breaking in nonisolated
functions when a default isolation is in effect in the source file.

Change how we compute isolation of local funcs. The rule here is
supposed to be that non-`@Sendable` local funcs are isolated the
same as their enclosing context. Unlike closure expressions, this
is unconditional: in instance-isolated functions, the isolation
does not depend on whether `self` is captured. But the computation
was wrong: it didn't translate global actor isolation between
contexts, it didn't turn parameter isolation into capture isolation,
and it fell through for several other kinds of parent isolation,
causing the compiler to try to apply default isolation instead.
I've extracted the logic from the closure expression path into a
common function and used it for both paths.

The capture computation logic was forcing a capture of the
enclosing isolation in local funcs, but only for async functions.
Presumably this was conditional because async functions need the
isolation for actor hops, but sync functions don't really need it.
However, this was causing crashes with `-enable-actor-data-race-checks`.
(I didn't investigate whether it also failed with the similar
assertion we do with preconcurrency.) For now, I've switched this
to capture the isolated instance unconditionally. If we need to
be more conservative by either only capturing when data-race checks
are enabled or disabling the checks when the isolation isn't captured,
we can look into that.

Fix a bug in capture isolation checking. We were ignoring captures
of nonisolated declarations in order to implement the rule that
permits `nonisolated(unsafe)` variables to be captured in
non-sendable closures. This check needs to only apply to variables!
The isolation of a local func has nothing to do with its sendability
as a capture.

That fix exposed a problem where we were being unnecessarily
restrictive with generic local func declarations because we didn't
consider them to have sendable type. This was true even if the
genericity was purely from being declared in a generic context,
but it doesn't matter, they ought to be sendable regardless.

Finally, fix a handful of bugs where global actor types were not
remapped properly in SILGen.
2025-06-29 01:23:04 -04:00
Hamish Knight
54a8a861bc Merge pull request #82596 from hamishknight/solve-escape
[CS] Fix a couple of use-after-frees
2025-06-29 02:32:29 +01:00