Commit Graph

103252 Commits

Author SHA1 Message Date
Hamish Knight
736ed5bd82 Merge pull request #82911 from hamishknight/unbounded-6.2
[6.2] [Completion] Avoid using unbound contextual type in argument completion
2025-07-09 21:27:57 +01:00
Michael Gottesman
f920aba2f9 [rbi] Use interned StringRefs for diagnostics instead of SmallString<64>.
This makes the code easier to write and also prevents any lifetime issues from a
diagnostic outliving the SmallString due to diagnostic transactions.

(cherry picked from commit 010fa39f31)
2025-07-09 12:25:06 -07:00
Michael Gottesman
85fafa5b1e [rbi] Begin tracking if a function argument is from a nonisolated(nonsending) parameter and adjust printing as appropriate.
Specifically in terms of printing, if NonisolatedNonsendingByDefault is enabled,
we print out things as nonisolated/task-isolated and @concurrent/@concurrent
task-isolated. If said feature is disabled, we print out things as
nonisolated(nonsending)/nonisolated(nonsending) task-isolated and
nonisolated/task-isolated. This ensures in the default case, diagnostics do not
change and we always print out things to match the expected meaning of
nonisolated depending on the mode.

I also updated the tests as appropriate/added some more tests/added to the
SendNonSendable education notes information about this.

(cherry picked from commit 14634b6847)
2025-07-09 12:25:03 -07:00
Michael Gottesman
ca8cdc1fd7 [rbi] Thread through a SILFunction into print routines so we can access LangOpts.Features so we can change how we print based off of NonisolatedNonsendingByDefault.
We do not actually use this information yet though... This is just to ease
review.

(cherry picked from commit 4433ab8d81)
2025-07-09 12:24:17 -07:00
Michael Gottesman
0ec2527bdc [rbi] Wrap use ActorIsolation::printForDiagnostics with our own SILIsolationInfo::printActorIsolationForDiagnostics.
I am doing this so that I can change how we emit the diagnostics just for
SendNonSendable depending on if NonisolatedNonsendingByDefault is enabled
without touching the rest of the compiler.

This does not actually change any of the actual output though.

(cherry picked from commit 4ce4fc4f95)
2025-07-09 12:24:17 -07:00
Anthony Latsis
f5d547cd44 AST: Cut down on DescriptiveDeclKind usage in DiagnosticsSIL.def
(cherry picked from commit 5c190b9613)
2025-07-09 12:24:17 -07:00
Michael Gottesman
f24ff98f9a [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
(cherry picked from commit c12c99fb73)
2025-07-09 12:24:17 -07:00
nate-chandler
0cd265d0f8 Merge pull request #82903 from nate-chandler/cherrypick/release/6.2/rdar155059418
6.2: [ODL] Visit objc_method insts.
2025-07-09 11:16:10 -07:00
Michael Gottesman
5361765212 Merge pull request #82428 from gottesmm/release/6.2-144111950
[6.2][rbi] Treat a partial_apply as nonisolated(unsafe) if all of its captures are nonisolated(unsafe).
2025-07-09 11:06:52 -07:00
Doug Gregor
457d44c624 [SE-0466] Enable SendableProhibitsMainActorInference by default
This implements the SE-0466 amendment under discussion for all code
with default main-actor isolation.

Finalizes rdar://151029300.
2025-07-09 10:49:03 -07:00
Doug Gregor
1cc5a865a5 Merge pull request #82904 from DougGregor/region-isolation-isolated-conformances-6.2
[6.2] Extend region analysis to account for isolated conformances
2025-07-09 10:25:21 -07:00
Gábor Horváth
b51b58db30 [6.2][cxx-interop] Fix unqualified name lookup failure
Explanation: C++ interop synthesizes certain forwarding functions in an
_ObjC module. This confuses MemberImportVisibility. This patch adds
logic to work this around by keeping a mapping between the synthesized
and the original function and looks up where the synthesized functions
belong to based on the original functions' parent module.
Scope: C++ forward interop when MemberImportVisibility is enabled.
Issues: rdar://154887575
Original PRs: #82840
Risk: Low, a narrow change makes getModuleContextForNameLookupForCxxDecl more
precise, and it is only used with MemberImportVisibility.
Testing: Added a compiler test.
Reviewers: @egorzhdan, @tshortli, @hnrklssn
2025-07-09 17:59:11 +01:00
Joe Groff
6f4748c5ef SILGen: Bitcast indirect returns that differ only in concurrency annotations.
A call to a `@preconcurrency` function goes through a function conversion
that removes `Sendable` from existentials among other things. Implement
support for this by bitcasting indirect return slots whose type differs
from the formal indirect return type in concurrency markings only.

Fixes rdar://154240007
2025-07-09 07:56:23 -07:00
Joe Groff
7c12be865e Merge pull request #82881 from jckarter/dont-try-to-address-project-static-properties-6.2
[6.2] SILGen: Don't try to project static stored properties as addressable from their base.
2025-07-09 07:51:09 -07:00
Alastair Houghton
bd289dc548 [Concurrency] Remove custom global executors from 6.2.
The custom global executors work is not landing in 6.2, so make
sure it isn't public there.

rdar://151147606
2025-07-09 15:45:15 +01:00
Hamish Knight
c562306c8d [Completion] Downgrade a couple of ASSERTs for 6.2 2025-07-09 13:07:56 +01:00
Hamish Knight
91222b9ebe [Completion] Avoid using unbound contextual type in argument completion
Match the logic in `getTypeForCompletion` and avoid using an unbound
generic type as the expected type for a completion.

rdar://155420395
2025-07-09 13:02:32 +01:00
Doug Gregor
1d86ed5f15 [Region analysis] Simplify logic for dynamic casts by making them less special
Extend and use SILIsolationInfo::getConformanceIsolation() for the dynamic
cast instructions.
2025-07-08 17:33:33 -07:00
Doug Gregor
066fa0b828 [Region isolation] Re-simplify handling of init_existential* instructions
Centralize the logic for figuring out the conformances for the various
init_existential* instructions in a SILIsolationInfo static method, and
always go through that when handling "assign" semantics. This way, we
can use CONSTANT_TRANSLATION again for these instructions, or a simpler
decision process between Assign and LookThrough.

The actually undoes a small change made earlier when we stopped looking
through `init_existential_value` instructions. Now we do when there are
no isolated conformances.
2025-07-08 17:33:33 -07:00
Doug Gregor
22ca6b98e5 [Region isolation] Factor SILIsolationInfo creation into static methods
Better match the style of SILIsolationInfo by moving the code for determining
SILIsolationInfo from conformances or dynamic casts to existentials into
static `getXYZ` methods on SILIsolationInfo.

Other than adding an assertion regarding disconnected regions, no
intended functionality change.
2025-07-08 17:33:33 -07:00
Doug Gregor
6637960bdc [SE-0470] Track the potential introduction of isolated conformances in regions
When we introduce isolation due to a (potential) isolated conformance,
keep track of the protocol to which the conformance could be
introduced. Use this information for two reasons:

1. Downgrade the error to a warning in Swift < 7, because we are newly
diagnosing these
2. Add a note indicating where the isolated conformance could be introduced.

(cherry picked from commit 02c34bb830)
2025-07-08 17:32:06 -07:00
Doug Gregor
900a4cc90f Extend region analysis to account for isolated conformances
When a conformance becomes part of a value, and that conformance could
potentially be isolated, the value cannot leave that particular
isolation domain. For example, if we perform a runtime lookup for a
conformance to P as part of a dynamic cast `as? any P`, the
conformance to P used in the cast could be isolated. Therefore, it is
not safe to transfer the resulting value to another concurrency domain.

Model this in region analysis by considering whether instructions that
add conformances could end up introducing isolated conformances. In
such cases, merge the regions with either the isolation of the
conformance itself (if known) or with the region of the task (making
them task-isolated). This prevents such values from being sent.

Note that `@concurrent` functions, which never dynamically execute on
an actor, cannot pick up isolated conformances.

Fixes issue #82550 / rdar://154437489

(cherry picked from commit 62770ff2d7)
2025-07-08 17:29:52 -07:00
Nate Chandler
ba0b2e7c51 [ODL] Visit objc_method insts.
No update is needed for the values they produce.  This pass should
really be refactored not to crash on instructions that aren't explicitly
listed or at least not to compile if not every instruction is listed.

rdar://155059418
2025-07-08 17:24:41 -07:00
Michael Gottesman
6ce93c8a37 [rbi] Treat a partial_apply as nonisolated(unsafe) if all of its captures are nonisolated(unsafe).
rdar://144111950
(cherry picked from commit 010443c854)
2025-07-08 13:35:52 -07:00
Nate Cook
4f87475f73 [6.2] Allow inout parameters in expression macros (#82824)
Cherry pick of #82370 to 6.2 branch.

---

* **Explanation**: Resolves an issue where sema is flagging inout
expressions 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.
* **Risk**: Low. It allows inout expressions in one additional context.
* **Testing**: Tested by lit tests, including new tests for the newly
allowed expression.
* **Issue**: rdar://153840234
* **Reviewer**:  @slavapestov
* **Main branch PR**:  https://github.com/swiftlang/swift/pull/82370
2025-07-08 15:00:53 -05:00
Doug Gregor
719fb9ca26 Merge pull request #82848 from DougGregor/isolated-conformance-to-sendablemetatype-proto-error-6.2
[6.2] Diagnose isolated conformance to SendableMetatype-inheriting protocol
2025-07-08 09:09:07 -07:00
John McCall
c0db6b64f6 Merge pull request #82868 from rjmccall/dont-capture-defer-isolation-6.2
[6.2] Don't force a capture of an isolated parameter in defer bodies
2025-07-08 11:58:33 -04:00
Joe Groff
e2ac7a0ac2 SILGen: Don't try to project static stored properties as addressable from their base.
An oversight from https://github.com/swiftlang/swift/pull/82288. Fixes #82368 / rdar://153837014.
2025-07-08 08:52:22 -07:00
Konrad `ktoso` Malawski
0bf7b29acf Merge pull request #82826 from ktoso/pick-wip-correct-isolated-handling-with-caller-isolation 2025-07-08 20:16:41 +09:00
John McCall
fb9e730fc9 Don't force a capture of an isolated parameter in defer bodies.
SILGen already has an exception for this from -enable-actor-data-race-checks,
so there's no need for it, and it causes problems in actor inits.

Fixes rdar://155239032
2025-07-07 23:30:22 -04:00
Joe Groff
8bf8b54fe6 Merge pull request #82843 from jckarter/afd-clang-imports-6.2
[6.2] Lower imported C structs and unions as addressable-for-dependencies.
2025-07-07 19:20:28 -07:00
Doug Gregor
6b4271c3a8 Fixup for 6.2 branch 2025-07-07 14:17:59 -07:00
Doug Gregor
3755a6b7e1 [SE-0470] Promote isolated-conformance-to-sendable-metatype protocol to error
Forming an isolated conformance to a SendableMetatype-inherting
protocol opens up a soundness hole any time the conformance is used.
Reword the recently-introduced diagnostic for this case and promote it
to an error (except when it's preconcurrency).

Fixes rdar://154808002.
2025-07-07 13:17:12 -07:00
Doug Gregor
7b369d02dc [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-07 13:17:04 -07:00
Hamish Knight
35cbdd8dab Merge pull request #82803 from hamishknight/context-fail-6.2
[6.2] [Completion] Map failable initializer result type into context
2025-07-07 19:38:08 +01:00
Artem Chikin
8cec61e50d Merge pull request #82779 from artemcm/62_DepScanImportAccessControl
[6.2 🍒][Dependency Scanning] Keep track of each imported module's access control
2025-07-07 10:53:00 -07:00
Artem Chikin
dc91d088c2 Merge pull request #82772 from artemcm/62_FixDepScanCxxStdlibLookup
[6.2 🍒][Dependency Scanning][C++ Interop] Do not skip lookup of 'CxxStdlib' overlay for the source module
2025-07-07 10:52:38 -07:00
Andrew Trick
61a4ee9d28 Merge pull request #82810 from atrick/62-lifetimediag
[6.2] Fix a lifetime dependence diagnostic
2025-07-07 09:29:49 -07:00
Joe Groff
79b59f1977 Lower imported C structs and unions as addressable-for-dependencies.
C code is highly likely to want to use pointers as references between dependent
structs, and we would like to be able to readily map these to lifetime-dependent
Swift values. Making C types addressable-for-dependencies ensures that any function
producing a dependency on such a value receives a stable in-memory address for that
value, allowing borrows and inout accesses to always be representable as pointers.

rdar://153648393
2025-07-07 08:46:43 -07:00
Meghana Gupta
2e7556c144 Fix a lifetime dependence diagnostic
`LifetimeDescriptor::getName()` can crash if the descriptor had a `self`.
Replace with `LifetimeDescriptor::getString()`

(cherry picked from commit 6d0a6d2760)
2025-07-04 11:44:35 -07:00
Erik Eckstein
33c91065b7 Optimizer: add var insertedPhis in SSAUpdater 2025-07-04 20:37:45 +02:00
Hamish Knight
9671ed9d85 [Completion] Map failable initializer result type into context
Make sure we don't pass an interface type to `setTypeContext`.

rdar://155038769
2025-07-04 13:59:07 +01:00
Hamish Knight
ee5f4df5ee Merge pull request #82775 from hamishknight/simple-fix-6.2
[6.2] [CS] Ensure type variables are eliminated by `Solution::simplifyType`
2025-07-04 10:56:34 +01:00
nate-chandler
dd6813f1b8 Merge pull request #82788 from nate-chandler/cherrypick/release/6.2/rdar153693915
6.2: [Mem2Reg] Don't promote proj(unchecked_addr_cast).
2025-07-04 00:20:11 -07:00
eeckstein
bf3dd8c577 Merge pull request #82764 from eeckstein/fix-mandatory-perf-opt-6.2
[6.2] MandatoryPerformanceOptimizations: don't de-virtualize a generic class method call to specialized method
2025-07-04 07:54:01 +02:00
eeckstein
0de2e8a834 Merge pull request #82763 from eeckstein/fix-mowte-6.2
[6.2] MoveOnlyWrappedTypeEliminator: handle EndCOWMutationAddr
2025-07-04 07:53:29 +02:00
Adrian Prantl
a825c451f5 Merge pull request #82767 from charles-zablit/charles-zablit/demangling/use-printFunctionName-to-6.2
[NFC][demangling] switch to using NodePrinter::printFunctionName
2025-07-03 16:36:59 -07:00
Nate Chandler
211299d4d2 [Mem2Reg] Don't promote proj(unchecked_addr_cast).
In OSSA, the result of an `unchecked_bitwise_cast` must immediately be
copied or `unchecked_bitwise_cast`'d again.  In particular, it is not
permitted to borrow it.  For example, the result can't be borrowed for
the purpose of performinig additional projections (`struct_extract`,
`tuple_extract`) on the borrowed value.  Consequently, we cannot promote
an address if such a promotion would result in such a pattern.  That
means we can't promote an address `%addr` which is used like
`struct_element_addr(unchecked_addr_cast(%addr))` or
`tuple_element_addr(unchecked_addr_cast(%addr))`.  We can still promote
`unchecked_addr_cast(unchecked_addr_cast(%addr))`.

In ownership-lowered SIL, this doesn't apply and we can still promote
address with such projections.

rdar://153693915
2025-07-03 15:32:41 -07:00
Alexis Laferrière
c0d0cf5f3d Parser: Reject @cdecl attributes with the string format 2025-07-03 15:08:00 -07:00
Alexis Laferrière
1ac555012b AST: Fix crash on references to @cdecl enums at code generation
Add related end-to-end test.
2025-07-03 14:11:27 -07:00