Commit Graph

2489 Commits

Author SHA1 Message Date
Slava Pestov
27c52eb4a9 Sema: Clean up buildOtherConstructorRef() 2025-09-09 18:58:09 -04:00
Slava Pestov
9e2d4c520f Sema: More DynamicSelfType cleanup 2025-09-09 18:58:09 -04:00
Slava Pestov
af3b5e8e3b Sema: Clean up getMemberReferenceTypeFromOpenedType() 2025-09-08 10:31:49 -04:00
Slava Pestov
ab4e754ef9 Sema: Don't stick CovariantReturnConversionExpr around property access with DynamicSelfType base
It could be that refTy->hasDynamicSelfType() is true whereas
varDecl->getValueInterfaceType()->hasDynamicSelfType() is false.
This happens if the base of the access is dynamic Self, so the
refTy is (Self) -> @lvalue Int or whatever.

Note that replaceDynamicSelfType() behaves correctly in this case;
it leaves that Self in place, because it's in contravariant
position.

However, the other place where we check the condition would then
form a nonsensical CovariantReturnConversionExpr around the result
of the access, even though no conversion was necessary here; the
type of the returned value does not involve Self.

Simplify this logic further with the correct condition.

Fixes rdar://159531634.
2025-09-08 10:31:27 -04:00
Hamish Knight
cac98f3a18 Merge pull request #84142 from hamishknight/for-none
[CS] NFC: Remove `CTP_ForEachStmt`
2025-09-06 22:43:28 +01:00
Hamish Knight
71d825dcb8 [CS] NFC: Remove CTP_ForEachStmt 2025-09-05 22:20:28 +01:00
Slava Pestov
aa3a0756f4 Merge pull request #84115 from slavapestov/remove-covariant-result-type
Remove TypeBase::replaceCovariantResultType()
2025-09-05 07:40:34 -04:00
Slava Pestov
55082c4eea Sema: Split off buildVarMemberRef() from buildMemberRef() 2025-09-04 18:07:46 -04:00
Slava Pestov
1ddcdc74d4 Sema: Convert conditional into an assert 2025-09-04 17:54:00 -04:00
Slava Pestov
250e3fd08b Sema: Split off buildStaticCurryThunk() from buildMemberRef() 2025-09-04 17:53:14 -04:00
Slava Pestov
d81fbd6c63 Sema: Split off buildDynamicMemberRef() from buildMemberRef() 2025-09-04 17:46:40 -04:00
Slava Pestov
853f50c90d Sema: Remove usage of replaceCovariantResultType() 2025-09-04 17:24:07 -04:00
Hamish Knight
7fb532e4e6 Merge pull request #83776 from hamishknight/the-diags-never-stop-no
[Diags] Allow multiple in-flight diagnostics
2025-09-03 19:59:44 +01:00
Hamish Knight
a9e339b973 [CS] Strengthen check for completion in CSApply
Turns out we don't always set a completion callback for some unqualified
completion positions. Upgrade the check for a completion callback to
a check for a completion buffer to account for this. This avoids
unnecessary type-checker work as well as fixing a couple of
double-type-checking crashers.
2025-08-29 16:20:06 +01:00
Kavon Farvardin
bb8b1e1b42 Merge pull request #83984 from kavon/avoid-not-noncopyable
nfc: avoid !isNoncopyable()
2025-08-28 17:46:39 -07:00
Hamish Knight
2f5cfad7bc Merge pull request #83974 from hamishknight/reprap
[Sema] Avoid marking TypeRepr invalid with `SilenceErrors`
2025-08-29 01:09:55 +01:00
Kavon Farvardin
3bb8fa848a nfc: !isNoncopyable() -> isCopyable() 2025-08-28 12:13:21 -07:00
Hamish Knight
5b8dfc70ab [CS] Emit fallback diagnostic if needed for IgnoreInvalidASTNode
If no other error has been emitted, make sure we emit a fallback
diagnostic rather than crashing in the ASTVerifier or SILGen.
2025-08-28 15:31:48 +01:00
Slava Pestov
a7d12e7919 Sema: Small CSApply cleanup 2025-08-27 15:34:26 -04:00
Slava Pestov
d8bf4a96e3 Sema: Remove a usage of replaceCovariantResultType() 2025-08-27 15:34:26 -04:00
Slava Pestov
aa35045008 Sema: Remove a usage of replaceCovariantResultType() 2025-08-27 15:34:26 -04:00
Slava Pestov
b871a08065 Sema: Remove a usage of replaceCovariantResultType() 2025-08-27 15:34:25 -04:00
Hamish Knight
89feb8fabb [Diags] Remove some now unnecessary calls to flush 2025-08-17 11:48:21 +01:00
Slava Pestov
d93b120e24 Sema: Remove usage of replaceCovariantResultType() in CSApply 2025-08-15 18:37:15 -04:00
Slava Pestov
1fbdc20be1 Sema: Remove usage of replaceCovariantResultType() in CSApply 2025-08-15 18:37:15 -04:00
Pavel Yaskevich
53ef38e31b [AST] NFC: Rename function type isolation NonisolatedCaller to NonisolatedNonsending
This reduces the number of ways we refer to caller isolated async
functions and matches the name to the attribute spelling.
2025-08-05 17:22:10 -07:00
Pavel Yaskevich
db13a63588 [CSApply] Key path dynamic member lookup argument is Sendable only if its captures are
Previously dynamic member subscript wasn't allowed to use `& Sendable`,
since this restriction was lifted the argument cannot simply assume
the parameter type any longer, the key path captures have to be checked
to determine whether it could be marked as Sendable or not.

Resolves: https://github.com/swiftlang/swift/issues/77105
Resolves: rdar://138227393
2025-07-28 09:59:17 -07:00
Pavel Yaskevich
56976c55d1 [CSApply] Register argument matches for dynamic member lookup subscripts
We missed this before because the argument/parameter types are equal.
2025-07-25 13:22:17 -07:00
Slava Pestov
97ce526153 Sema: Replace a usage of SubstFlags::SubstituteOpaqueArchetypes with transformRec()
The semantics of SubstFlags::SubstituteOpaqueArchetypes are changing
so this is no longer useful here.
2025-07-18 19:12:33 -04:00
Michael Gottesman
648bb8fe30 [concurrency] Perform some fixes so that transfernonsendable_closureliterals_isolationinference.swift now passes.
The reason why this failed is that concurrently to @xedin landing
79af04ccc4, I enabled
NonisolatedNonsendingByDefault on a bunch of other tests. That change broke the
test and so we needed to fix it.

This commit fixes a few issues that were exposed:

1. We do not propagate nonisolated(nonsending) into a closure if its inferred
context isolation is global actor isolated or if the closure captures an
isolated parameter. We previously just always inferred
nonisolated(nonsending). Unfortunately since we do not yet have capture
information in CSApply, this required us to put the isolation change into
TypeCheckConcurrency.cpp and basically have function conversions of the form:

```
(function_conversion_expr type="nonisolated(nonsending) () async -> Void"
   (closure_expr type="() async -> ()" isolated_to_caller_isolation))
```

Notice how we have a function conversion to nonisolated(nonsending) from a
closure expr that has an isolation that is isolated_to_caller.

2. With this in hand, we found that this pattern caused us to first thunk a
nonisolated(nonsending) function to an @concurrent function and then thunk that
back to nonisolated(nonsending), causing the final function to always be
concurrent. I put into SILGen a peephole that recognizes this pattern and emits
the correct code.

3. With that in hand, we found that we were emitting nonisolated(nonsending)
parameters for inheritActorContext functions. This was then fixed by @xedin in

With all this in hand, closure literal isolation and all of the other RBI tests
with nonisolated(nonsending) enabled pass.

rdar://154969621
2025-07-07 17:21:41 -07: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
Hamish Knight
2b05212ff5 [CS] Avoid escaping solver-allocated types in computeSubstitutions
Make sure we call `simplifyType` for the opened type bindings to
ensure holes get converted to UnresolvedType.

rdar://154553285
2025-06-28 11:19:13 +01:00
Michael Gottesman
c28490b527 [sema] Work around a double curry thunk actor isolation inference bug that is a knock on effect of ced96aa5cd.
Specifically, there is currently a bug in TypeCheckConcurrency.cpp where we do
not visit autoclosures. This causes us to never set the autoclosure's
ActorIsolation field like all other closures. For a long time we were able to
get away with this just by relying on the isolation of the decl context of the
autoclosure... but with the introduction of nonisolated(nonsending), we found
cases where the generated single curry autoclosure would necessarily be
different than its decl context (e.x.: a synchronous outer curry thunk that is
nonisolated that returns an inner curry thunk that is
nonisolated(nonsending)). This problem caused us to hit asserts later in the
compiler since the inner closure was actually nonisolated(nonsending), but we
were thinking that it should have been concurrent.

To work around this problem, I changed the type checker in
ced96aa5cd to explicitly set the isolation of
single curry thunk autoclosures when it generates them. The reason why we did
this is that it made it so that we did not have to have a potential large source
break in 6.2 by changing TypeCheckConcurrency.cpp to visit all autoclosures it
has not been visiting.

This caused a follow on issue where since we were now inferring the inner
autoclosure to have the correct isolation, in cases where we were creating a
double curry thunk for an access to a global actor isolated field of a
non-Sendable non-global actor isolated nominal type, we would have the outer
curry thunk have unspecified isolation instead of main actor isolation. An
example of this is the following:

```swift
class A {
  var block:  @MainActor () -> Void = {}
}

class B {
  let a = A()

  func d() {
    a.block = c // Error! Passing task isolated 'self' to @MainActor closure.
  }

  @MainActor
  func c() {}
}
```

This was unintentional. To work around this, this commit changes the type
checker to explicitly set the double curry thunk isolation to the correct value
when the type checker generates the double curry thunk in the same manner as it
does for single curry thunks and validates that if we do set the value to
something explicitly that it has the same value as the single curry thunk.

rdar://152522631
2025-06-20 10:59:54 -07:00
Pavel Yaskevich
efc6efc4ed [CSApply] Don't inject global actor into closure type if it's marked as @concurrent
When the attribute is specified explicitly passing a `@concurrent`
closure to a global actor-isolated parameter or contextual type
should result in a conversion and closure itself should be nonisolated.

Resolves: rdar://151797372
2025-05-21 15:22:03 -07:00
Hamish Knight
edca7c85ad Adopt ABORT throughout the compiler
Convert a bunch of places where we're dumping to stderr and calling
`abort` over to using `ABORT` such that the message gets printed to
the pretty stack trace. This ensures it gets picked up by
CrashReporter.
2025-05-19 20:55:01 +01:00
Pavel Yaskevich
a4f6d710cf [Sema] Start propagating @_inheritActorContext(always) attribute to closures 2025-05-14 20:08:00 -07:00
Pavel Yaskevich
3b3d13c6da Merge pull request #81422 from xedin/fix-csapply-to-avoid-marking-autoclosure-closures-as-nonimplicit
[CSApply] Don't attempt to mark autoclosures as non-implicit
2025-05-12 09:47:45 -07:00
Pavel Yaskevich
37e2f374aa [CSApply] Don't attempt to mark autoclosures as non-implicit
While building an initializer call the declaration reference
should have the same implicitness as the call when it doesn't
require thunking, otherwise don't attempt to mark autoclosures
as non-implicit because it could break assumptions elsewhere.
2025-05-09 14:43:48 -07:00
Alejandro Alonso
02d9779ba3 Merge pull request #81184 from Azoy/no-more-is-array-type
[AST] Rename isArrayType and split the InlineArray portion
2025-05-08 20:52:51 -07:00
Michael Gottesman
ced96aa5cd [concurrency] Ensure that we treat closures that are nonisolated(nonsending) via their ActorIsolation as nonisolated(nonsending).
Some notes:

1. In most cases, I think we were getting lucky with this by just inferring the
closure's isolation from its decl context. In the specific case that we were
looking at here, this was not true since we are returning from an @concurrent
async function a nonisolated(nonsending) method that closes over self. This
occurs since even when NonisolatedNonsendingByDefault we want to start importing
objc async functions as nonisolated(nonsending).

2. I also discovered that in the ActorIsolationChecker we were not visiting the
inner autoclosure meaning that we never set the ActorIsolation field on the
closure. After some discussion with @xedin about potentially visiting the
function in the ActorIsolationChecker, we came to the conclusion that this was
likely to result in source stability changes. So we put in a targeted fix just
for autoclosures in this specific case by setting their actor isolation in the
type checker.

3. Beyond adding tests to objc_async_from_swift to make sure that when
NonisolatedNonsendingByDefault is disabled we do the right thing, I noticed that
we did not have any tests that actually tested the behavior around
objc_async_from_swift when NonisolatedNonsendingByDefault is enabled. So I added
the relevant test lines so we can be sure that we get correct behavior in such a
case.

rdar://150209093
2025-05-06 14:15:23 -07:00
Slava Pestov
6ffa8fd489 AST: Change signature of LookupConformanceFn
Instead of passing in the substituted type, we pass in the
InFlightSubstitution. This allows the substituted type to be
recovered if needed, but we can now skip computing it for
the common case of LookUpConformanceInSubstitutionMap.
2025-04-30 13:42:20 -04:00
Alejandro Alonso
e68b398d41 Rename isArrayType and split the InlineArray portion 2025-04-29 15:57:10 -07:00
Doug Gregor
1b94c3b3d6 Always emit "unsafe does not cover any unsafe constructs" warning
Check for unsafe constructs in all modes, so that we can emit the
"unsafe does not cover any unsafe constructs" warning consistently.
One does not need to write "unsafe" outside of strict memory safety
mode, but if you do... it needs to cover unsafe behavior.
2025-04-25 23:22:09 -07:00
Hamish Knight
3c302349ee Merge pull request #80853 from hamishknight/macro-async-warning 2025-04-18 16:22:28 +01:00
Pavel Yaskevich
3de72c5452 [TypeChecker] Allow closures to assume nonisolated(nonsending)
Always infer `nonisolated(nonsending)` from context directly on
a closure unless the closure is marked as `@concurrent`, otherwise
the closure is not going to get correct isolation and going to hop
to the wrong executor in its preamble.

Resolves: rdar://149107104
2025-04-16 17:19:21 -07:00
Hamish Knight
b36eb57dbd [Sema] Downgrade noasync diagnostic to warning for closure macro args
Downgrade to a warning until the next language mode. This is
necessary since we previously missed coercing macro arguments to
parameter types, resulting in cases where closure arguments weren't
being treated as `async` when they should have been.

rdar://149328745
2025-04-16 19:22:52 +01:00
Hamish Knight
b6a09d1b33 Reapply: [CS] Make sure macro arguments go through coerceCallArguments
Previously we would avoid rewriting the arguments in CSApply, but
that can result in incorrect behavior in MiscDiagnostics passes, e.g
incorrectly treating all closure arguments as escaping. Make sure
we rewrite the arguments as we would in regular type-checking.

rdar://148665502
2025-04-16 19:22:52 +01:00
Hamish Knight
aa2bb0c9ea Merge pull request #80830 from swiftlang/revert-80583-macro-arg-apply
Revert "[CS] Make sure macro arguments go through `coerceCallArguments`"
2025-04-16 19:19:38 +01:00
Hamish Knight
475e02a381 Revert "[CS] Make sure macro arguments go through coerceCallArguments" 2025-04-15 18:44:14 +01:00
Alejandro Alonso
79a51dfcc1 Move resolving param type to CSApply 2025-04-14 15:33:08 -07:00