Commit Graph

9293 Commits

Author SHA1 Message Date
Gábor Horváth
c3a7203221 [6.2][cxx-interop] Fix runtime crash passing FRTs as const FRT*
Explanation: There was an inconsistency between non-const and const FRT
pointers. The former used Direct_Unowned the latter used Indirect
calling convention. We want to use Direct_Unowned for both cases. The
crash was the result of a calling convention mismatch between the
SILFunctionType of a Swift closure and the SILFunctionType of the C++
function's formal parameter that is taking a function pointer. The
compiler tried to insert a conversion between the two function types
that does not exist and caused an assertion in debug compilers and
miscompilation in production compilers.
Issue: rdar://149398905
Risk: Low, the fix is targeted and we change to a well-tested behavior
with non-const FRT pointers.
Testing: Regression test added.
Original PR: #81070
Reviewer: @j-hui
2025-04-25 10:59:45 +01:00
nate-chandler
6e270c64a1 Merge pull request #81076 from nate-chandler/cherrypick/release/6.2/rdar149850921
6.2: [FSPL] Look through unchecked addr casts.
2025-04-25 00:06:26 -07:00
nate-chandler
e539d0f996 Revert "[6.2] MoveOnlyChecker: Treat trivial stores as reinitializations rather than initializations." 2025-04-24 12:11:32 -07:00
Nate Chandler
3de77f6142 [FSPL] Look through unchecked addr casts.
rdar://149850921
2025-04-24 10:30:48 -07:00
Pavel Yaskevich
d007d7adfb [Frontend] Rename AsyncCallerExecution upcoming feature to NonisolatedNonsendingBeDefault
(cherry picked from commit c110941c27)
2025-04-22 00:33:45 -07:00
Pavel Yaskevich
4093171303 Merge pull request #80957 from xedin/rdar-145672343-6.2
[6.2][Sema/SILGen] Import ObjC async functions as nonisolated(nonsending) by default
2025-04-21 22:21:12 -07:00
Konrad `ktoso` Malawski
3728d7977f Merge pull request #80942 from ktoso/pick-wip-regression-test-for-b-da-bad-access
[6.2][Distributed] Distributed actor usage through protocol with lib-evolution
2025-04-22 10:15:49 +09:00
Pavel Yaskevich
d40c37e20d [Sema/SILGen] Import ObjC async functions as nonisolated(nonsending) by default
These functions already have special code generation that keeps them
in the caller's isolation context, so there is no behavior change here.

Resolves: rdar://145672343
(cherry picked from commit 07bad98f6d)
2025-04-21 11:22:18 -07:00
Joe Groff
4fd61eeed6 Merge pull request #80854 from jckarter/moveonly-trivial-field-as-reinitialize-6.2
[6.2] MoveOnlyChecker: Treat trivial stores as reinitializations rather than initializations.
2025-04-21 09:48:50 -07:00
Konrad 'ktoso' Malawski
694af3317a [Distributed] Distributed actor usage through protocol with lib-evo must work
This corrects how we were dealing with dispatch thunks -- mostly be
removing a lot of special casing we did but doesn't seem necessary and
instead we correct and emit all the necessary information int TBD.

This builds on  https://github.com/swiftlang/swift/pull/74935 by further refining how we fixed that issue, and adds more regression tests. It also removes a load of special casing of distributed thunks in library evolution mode, which is great.

Resolves and adds regression test for for rdar://145292018

This is also a more proper fix to the previously resolved but in a not-great-way which caused other issues:
- resolves rdar://128284016
- resolves rdar://128310903

Review followup, cleanup test
2025-04-21 20:33:22 +09:00
Pavel Yaskevich
06f880e65c [AST/ASTGen/Sema/Serialization] Remove @execution attribute
Complete the transition from `@execution` to `@concurrent` and `nonisolated(nonsending)`
2025-04-16 13:18:52 -07:00
Pavel Yaskevich
d8c64c1ff0 [AST/Sema] Intoduce nonisolated(nonsending) as a replacement for @execution(caller) 2025-04-16 10:06:08 -07:00
Pavel Yaskevich
4a973f7b4b [AST/Sema] Replace @execution(concurrent) with @concurrent 2025-04-16 10:06:08 -07:00
Joe Groff
66764a3fc3 MoveOnlyChecker: Treat trivial stores as reinitializations rather than initializations.
A trivial store is allowed to occur on an existing live value, and should not
trigger an attempt to destroy the original value completely. Fixes rdar://147791932.
2025-04-16 07:44:53 -07:00
nate-chandler
bddc926d37 Merge pull request #80781 from nate-chandler/cherrypick/release/6.2/rdar149007151
6.2: [DCE] Don't delete instructions which consume escaping values.
2025-04-15 11:04:09 -07:00
Andrew Trick
097dba34ff Merge pull request #80709 from atrick/62-irgen-addressable
[6.2] Fix IRGen for @_addressable params which may be "captured".
2025-04-11 18:03:01 -07:00
Nate Chandler
ce510590d9 NFC: [OSSACompleteLifetime] Allow forced verifying 2025-04-11 17:24:50 -07:00
Nate Chandler
77055a5eb1 [CoroutineAccessors] Control ABI via flag. 2025-04-10 14:47:05 -07:00
Andrew Trick
e048dd1cf1 Fix IRGen for @_addressable params which may be "captured".
Simply omit the 'nocapture' attribute on the parameter.

Fixes rdar://148039510 ([nonescapable] IRGen: lower addressable
params to LLVM: captures(ret: address, provenance))

(cherry picked from commit 2d9df8ff78)
2025-04-10 09:43:13 -07:00
Andrew Trick
78c9fe4c56 Add SILFunctionType::isAddressable & ApplySite::isAddressable.
(cherry picked from commit 501abb0975)
2025-04-08 14:02:19 -07:00
Gábor Horváth
60dced5579 Merge pull request #80584 from swiftlang/gaborh/rvalue-ref-calling-conv-6.2
[6.2][cxx-interop] Fix calling rvalue ref of a trivial type
2025-04-08 16:44:39 +01:00
eeckstein
8975d1e7de Merge pull request #80578 from eeckstein/isolated-conformance-opt-6.2
[6.2] CastOptimizer: handle isolated conformances
2025-04-07 20:25:20 +02:00
Gábor Horváth
56e0ea6b6d [6.2][cxx-interop] Fix calling rvalue ref of a trivial type
Explanation: Fixes a runtime crash in the generated binary due to
mismatched calling convention when calling a function taking an rvalue
reference.
Scope: Affects C++ APIs taking rvalue references to directly passed
types (e.g., trivially destructible types).
Issue: rdar://148585343
Risk: Low, targeted to rvalue references which is a newly supported
feature.
Testing: Added tests to test suite
Reviewer: John Hui
2025-04-07 11:42:02 +01:00
Erik Eckstein
eb6ff30be7 SILLinker: de-serialize Executor witness tables for the xExecutorRef builtins
Fixes unresolved symbol linker errors in embedded mode.
rdar://148538336
2025-04-07 11:07:56 +02:00
Erik Eckstein
8978e07b4a SILLinker: make sure to de-serialize base protocol witness tables in embedded mode
Fixes unresolved symbol linker errors or compiler crashes
rdar://148538336
2025-04-07 11:07:56 +02:00
Erik Eckstein
575388e188 CastOptimizer: handle isolated conformances
Check the isolation of conformances to avoid wrong folding of dynamic casts
rdar://147417762
2025-04-07 10:58:02 +02:00
Erik Eckstein
8f2c17a149 CastOptimizer: pass the SIL function to the cast-classify APIs, instead of the module decl
NFC
2025-04-07 10:58:02 +02:00
Erik Eckstein
6987748517 SIL: add matchesActorIsolation
Returns true if the conformance is not isolated or if its isolation matches the isolation `inFunction`.
2025-04-07 10:58:02 +02:00
eeckstein
70bc9cdb1f Merge pull request #80486 from eeckstein/fix-struct-extract
SIL: fix the ownership computation of `struct_extract` and `tuple_extract`
2025-04-03 18:32:07 +02:00
Erik Eckstein
0b9f5eb86c SIL: add some asserts to catch broken enum ASTs 2025-04-03 08:14:42 +02:00
Erik Eckstein
f1fc864dc6 SIL: fix the ownership computation of struct_extract and tuple_extract
A struct or tuple value can have "none" ownership even if its type is not trivial.
This happens when the struct/tuple contains a non-trivial enum, but it's initialized with a trivial enum case (e.g. with `Optional.none`).

```
  %1 = enum $Optional<String>, #Optional.none!enumelt
  %2 = struct $S (%32)               // has ownership "none"
  %3 = struct_extract %2, #S.x       // should also have ownership "none" and not "guaranteed"
```

So far it got "guaranteed" ownership which is clearly wrong.

Fixes an assertion crash in redundant load elimination.

https://github.com/swiftlang/swift/issues/80430
rdar://148311534
2025-04-03 06:40:26 +02:00
Joe Groff
562d7dc832 Merge pull request #80438 from jckarter/substitute-away-escapable-lifetime-deps
Type substitution eliminates dependencies with Escapable targets.
2025-04-02 16:56:54 -07:00
Joe Groff
6b605f41cb Type substitution eliminates dependencies with Escapable targets.
When a generic function has potentially Escapable outputs, those outputs
declare lifetime dependencies, which have no effect when substitution
leads to those types becoming `Escapable` in a concrete context.
This means that type substitution should canonically eliminate lifetime
dependencies targeting Escapable parameters or returns, and that
type checking should allow a function value with potentially-Escapable
lifetime dependencies to bind to a function type without those dependencies
when the target of the dependencies is Escapable.

Fixes rdar://147533059.
2025-04-02 08:54:45 -07:00
Allan Shortlidge
918c6c32cb SIL: Fix a -Wimplicit-fallthrough warning. 2025-04-01 13:11:36 -07:00
Artem Chikin
66334f8f1b Merge pull request #79290 from artemcm/ConstProtoSIL
[Compile Time Values] Implement a mandatory SIL pass to verify '@const' values
2025-04-01 00:12:27 -07:00
Shubham Sandeep Rastogi
65a515b2d4 Merge pull request #80079 from rastogishubham/EnhanceDump
Add dump overloads to print debug info for SIL.
2025-03-31 11:41:55 -07:00
Artem Chikin
281f84da0f [Compile Time Values] Rewrite the 'Diagnose Unknown Compile Time Values' diagnostic pass in Swift 2025-03-28 10:30:07 -07:00
Anthony Latsis
fffa8c2f51 Diag: Abstract away some calls to DeclAttribute::getAttrName 2025-03-28 02:01:27 +00:00
Artem Chikin
72a420919a [Compile Time Values] Add mandatory optimization pipeline driver for '@const' globals 2025-03-27 14:33:38 -07:00
Artem Chikin
d484ec7c1f [Compile Time Values] Implement a mandatory SIL pass to verify '@const' values 2025-03-27 14:33:35 -07:00
Doug Gregor
e0b52cd20e [SIL] Extend checked-cast instructions with "prohibit isolated conformances" flag
When performing a dynamic cast to an existential type that satisfies
(Metatype)Sendable, it is unsafe to allow isolated conformances of any
kind to satisfy protocol requirements for the existential. Identify
these cases and mark the corresponding cast instructions with a new flag,
`[prohibit_isolated_conformances]` that will be used to indicate to the
runtime that isolated conformances need to be rejected.
2025-03-26 22:31:47 -07:00
Michael Gottesman
de7a62e13e Merge pull request #80312 from gottesmm/pr-126bc735b2d01c0f2f35f27268ff26d404b2fb16
[sil] Make SILFunctionTypeInfo a struct enum.
2025-03-26 18:05:57 -07:00
Shubham Sandeep Rastogi
b016c742c6 Add dump overloads to print debug info for SIL.
This patch adds dump overload methods to SILInstruction, SILBasicBlock,
SILFunction, and SILModule that prints the debug information as well.
2025-03-26 10:47:45 -07:00
Becca Royal-Gordon
5bb6245a5a [NFC] Check that SILGen doesn’t use ABI-only decls
Adds assertions in various places where properties that can vary between ABI-only decls and their counterparts—particularly function and parameter attributes—are handled in SILGen, ensuring that we don’t accidentally end up processing ABI-only decls there.
2025-03-26 10:47:13 -07:00
Andrew Trick
97b249bd11 Merge pull request #80263 from atrick/markdep-addr
SIL: add mark_dependence_addr
2025-03-26 10:33:42 -07:00
Michael Gottesman
8cfb029b5c [sil] Make SILFunctionTypeInfo a struct enum.
I am doing this in preparation for adding the ability to represent in the SIL
type system that a function is global actor isolated. Since we have isolated
parameters in SIL, we do not need to represent parameter, nonisolated, or
nonisolated caller in the type system. So this should be sufficient for our
purposes.

I am adding this since I need to ensure that we mangle into thunks that convert
execution(caller) functions to `global actor` functions what the global actor
is. Otherwise, we cannot tell the difference in between such a thunk and a thunk
that converts execution(caller) to execution(concurrent).
2025-03-26 10:23:44 -07:00
John McCall
4da795fd61 Merge pull request #80297 from rjmccall/zero-objc-async-result-on-error-path
Pass a zero normal result to ObjC async completion handlers on the error path
2025-03-26 12:42:38 -04:00
Andrew Trick
d9dd93560d Support mark_dependence_addr in SIL passes. 2025-03-25 23:02:45 -07:00
Andrew Trick
e7000e4668 SIL: Add mark_dependence_addr 2025-03-25 23:02:42 -07:00
John McCall
3fe70968cc Remove the substitution map from zeroInitializer builtin in SIL.
This is a value operation that can work just fine on lowered types,
so there's no need to carry along a formal type. Make the value/address
duality clearer, and enforce it in the verifier.
2025-03-26 00:34:15 -04:00