Commit Graph

6754 Commits

Author SHA1 Message Date
Adrian Prantl
a03fcb5ff0 Merge pull request #74621 from adrian-prantl/126688061
Fix a regression that caused the compiler to drop the path names of g…
2024-06-22 07:14:27 -07:00
Adrian Prantl
c9f5af5617 Fix a regression that caused the compiler to drop the path names of generated
macro expansion source code when emitting DWARF 4 or earlier.

rdar://126688061
2024-06-21 18:58:11 -07:00
Michael Gottesman
74944a69bd Merge pull request #74239 from gottesmm/taskinit-sending
[sending] Mark Task.init, Task.detached and friends as taking a sending closure instead of a __owned @Sendable
2024-06-21 10:36:29 -07:00
Michael Gottesman
43e1c5499f [sending] Make the operation of Builtin.createAsyncTask/friends a sending non-Sendable function instead of an @Sendable function.
This matches the interface of the public stdlib APIs that wrap these builtin calls.
2024-06-21 02:24:03 -07:00
Michael Gottesman
f781ad366d [sending] Compensate in SILGen for a typechecker bug where we do not properly mark actor isolated async closures passed to an inheritActorContext argument as being Sendable.
The reason why I am fixing this is that otherwise, we get a warning when one
creates an actor isolated closure and pass it into a task, e.x.:

```swift
@MainActor func test() {
  // We would get a warning on the closure below saying that we are sending
  // a closure that is MainActor isolated.
  Task {
    ...
  }
}
```
2024-06-21 02:24:03 -07:00
Allan Shortlidge
15d9f4c8ce SILGen: Ignore invalid associated conformances.
With lazy type checking, invalid conformances can make it all the way to
SILGen. As a result, `SILGenModule::useConformance()` needs to handle invalid
conformances more gracefully by ignoring them instead of asserting.

Resolves rdar://128286622
2024-06-20 20:08:55 -07:00
Tim Kientzle
1098054291 Merge branch 'main' into tbkka-assertions2 2024-06-18 17:52:00 -07:00
Akira Hatanaka
1b0df4eefe [SILGen] Fix a crash when a closure is converted to a pointer to a function returning a non-trivial C++ type (#73561)
When emitting a native-to-foreign thunk, pass the thunk's result address parameter to the native function if both the thunk and the native function return their results indirectly and the thunk is not for an async function.

Also, remove an outdated assertion.

rdar://124501345
2024-06-18 15:03:44 -07:00
Pavel Yaskevich
ce6bac43f7 Merge pull request #74483 from xedin/fix-sendable-to-any-bridging
[SILGen] Fix `any Sendable` to `Any` bridging when result should be p…
2024-06-18 09:41:57 -07:00
Joe Groff
0246150135 Merge pull request #74505 from jckarter/noncopyable-unexpected-enum-case
SILGen: Don't use `diagnoseUnexpectedEnumCase` intrinsic for noncopyable enums.
2024-06-18 06:36:06 -10:00
Akira Hatanaka
d92f181ace Create two versions (for caller and callee) of the functions that answer questions about parameter convention (#74124)
Create two versions of the following functions:

isConsumedParameter
isGuaranteedParameter
SILParameterInfo::isConsumed
SILParameterInfo::isGuaranteed
SILArgumentConvention::isOwnedConvention
SILArgumentConvention::isGuaranteedConvention

These changes will be needed when we add a new convention for
non-trivial C++ types as the functions will return different answers
depending on whether they are called for the caller or the callee. This
commit doesn't change any functionality.
2024-06-18 09:06:09 -07:00
Holly Borla
dd71e3de36 Merge pull request #74456 from hborla/reduced-error-type
[SILGen] Compute the reduced thrown error type when emitting a function prolog and epilog.
2024-06-17 18:30:03 -07:00
Joe Groff
e3fef32a9b SILGen: Don't use diagnoseUnexpectedEnumCase intrinsic for noncopyable enums.
It should be impossible to reach an unexpected case statically while using
noncopyable enums, and the intrinsic has not been updated to remove its
`Copyable` requirement. Emit a plain trap in cases where this code emission
path might still occur, such as when a redundant but incomplete set of case
patterns follow a wildcard pattern. Fixes rdar://130037881.
2024-06-17 14:29:56 -10:00
Pavel Yaskevich
1e9e351a3f [SILGen] Fix any Sendable to Any bridging when result should be placed in a buffer
If the context indicates that the result of `id-to-Any` should be
placed in some pre-allocated buffer, let's not attempt marker existential
transformation because that would much the expected layout already.
2024-06-17 09:45:00 -07:00
Holly Borla
5041986100 [SILGen] Compute the reduced thrown error type when emitting a function
prolog and epilog.
2024-06-15 22:43:32 -07:00
Ellie Shin
32a24f9264 Merge pull request #74416 from apple/elsh/pcmo-global
[PackageCMO] Global var and accessor linkage should be kept private/hidden in SILGen.
2024-06-14 12:21:01 -07:00
Konrad `ktoso` Malawski
2ec717b115 [Concurrency] TaskExecutor ownership fixes (#74000) 2024-06-14 22:56:33 +09:00
Ellie Shin
0a734c2a62 [PackageCMO] Global var and accessor linkage should be kept private/hidden in SILGen.
This PR contains changes that ensure the following:
* Global accessor linkage is kept hidden if its decl is resilient.
  - LinkageLimit::Never is returned for Global Accessor if its decl is resilient.
  - Since it's kept hidden, the use site should not expect a call to a global accessor
    if the static var decl being accessed is resilient. The bypassing resilience logic
    in AbstractStorageDecl::isResilient(accessingModule, decl) has been removed; to be
    addressed in Package CMO optimization pass.
* sil_global linkage is kept private if its decl is resilient.

Resolves rdar://129829925
2024-06-14 01:34:34 -07:00
Anton Korobeynikov
0f4dacd47b [AutoDiff] Fix custom derivative thunk for Optional (#74378)
Enable the nil coalescing operator (aka `??`) for Optional type.

Fixes #55882

Co-authored-by: Andrew Savonichev <andrew.savonichev@gmail.com>
2024-06-13 10:53:18 -07:00
John McCall
71eb55a8d2 Properly handle @objc thunks for generic classes and actors
Fixes rdar://129187133
2024-06-13 04:44:36 -04:00
Slava Pestov
322ce5a1ab SIL: Consistently drop substitution map when forming apply instructions
Fixes rdar://129298104.
2024-06-11 10:36:15 -04:00
Max Desiatov
12f402f715 Revert "[AutoDiff] Fix custom derivative thunk for Optional (#71721)" (#74268)
This reverts commit aa5dddb952.

Fixes `preset=buildbot,tools=RA,stdlib=DA` CI job, which without this revert fails on `AutoDiff/SILGen/nil_coalescing.swift` test.
2024-06-11 09:24:19 +01:00
nate-chandler
77437410be Merge pull request #74235 from nate-chandler/rdar127115078
[SILGen] Forward address-only self to borrowing accessors.
2024-06-10 14:02:21 -07:00
Erik Eckstein
2200632a95 SILGen: ignore unreachable var decls
Fixes a crash in case a lazy var is declared after a return statement

https://github.com/apple/swift/issues/73736
2024-06-10 16:19:47 +02:00
Doug Gregor
25830d6bc3 Merge pull request #74225 from DougGregor/flow-sensitive-actor-init-isolation
Teach `#isolation` to respect the flow-sensitive nature of actor initializers
2024-06-10 01:52:38 -07:00
Doug Gregor
d1ae73f436 Handle flow-sensitive #isolation in distributed actor initializers.
Distributed actors can be treated as actors by accessing the `asLocalActor`
property. When lowering `#isolation` in a distributed actor initializer,
use a separate builtin `flowSensitiveDistributedSelfIsolation` to
capture the conformance to `DistributedActor`, and have Definite
Initialization introduce the call to the `asLocalActor` getter when
needed.
2024-06-09 22:48:43 -07:00
Nate Chandler
e3fbad50fe [SILGen] Forward addr self to borrow accessors.
Utilize and expand the pre-existing peephole.

rdar://127115078
2024-06-08 10:15:08 -07:00
Doug Gregor
956243cd7e Teach #isolation to respect the flow-sensitive nature of actor initializers
Actor initializers have a flow-sensitive property where they are isolated
to the actor being initialized only after the actor instance itself is
fully-initialized. However, this behavior was not being reflected in
the expansion of `#isolation`, which was always expanding to `self`,
even before `self` is fully formed.

This led to a source compatibility issue with code that used the async
for..in loop within an actor initializer *prior* to the point where the
actor was fully initialized, because the type checker is introducing
the `#isolation` (SE-0421) but Definite Initialization properly rejects
the use of `self` before it is initialized.

Address this issue by delaying the expansion of `#isolation` until
after the actor is fully initialized. In SILGen, we introduce a new
builtin for this case (and *just* this case) called
`flowSensitiveSelfIsolation`, which takes in `self` as its argument
and produces an `(any Actor)?`. Definite initialization does not treat
this as a use of `self`. Rather, it tracks these builtins and
replaces them either with `self` (if it is fully-initialized at this
point) or `nil` (if it is not fully-initialized at this point),
mirroring the flow-sensitive isolation semantics described in SE-0327.

Fixes rdar://127080037.
2024-06-07 14:54:20 -07:00
nate-chandler
033fc2354f Merge pull request #74157 from nate-chandler/rdar128710064
[SILGen] Store_borrow into in_guaranteed.
2024-06-07 06:47:16 -07:00
Nate Chandler
c35b86a30d [SILGen] Borrow into in_guaranteed.
Don't create a copy in order to pass a value `@in_guaranteed`.  Just
`store_borrow` the value.

rdar://128710064
2024-06-06 15:45:22 -07:00
Meghana Gupta
af1d6017f9 Merge pull request #74132 from meg-gupta/deleteresultdependson
Remove resultDependsOn/resultDependsOnSelf
2024-06-06 10:23:31 -07:00
Andrew Savonichev
aa5dddb952 [AutoDiff] Fix custom derivative thunk for Optional (#71721)
Enable the nil coalescing operator (aka `??`) for Optional type.

Fixes #55882

Co-authored-by: Anton Korobeynikov <anton@korobeynikov.info>
2024-06-05 23:41:48 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Nate Chandler
16e080ddb6 [Gardening] Detypo'd. 2024-06-05 11:43:11 -07:00
Meghana Gupta
470fa2f365 Remove resultDependsOn/resultDependsOnSelf 2024-06-05 11:36:16 -07:00
Ellie Shin
6216ec648f Merge pull request #73902 from apple/elsh/pkg-cmo-inline
[SIL][PackageCMO] Allow optimizing [serialized_for_pkg] functions
2024-06-04 11:39:19 -07:00
Joe Groff
f4b4db6c7e Merge pull request #74041 from jckarter/diagnose-unimplemented-shared-noncopyable-case-patterns
SILGen: Diagnose unsupported shared case blocks for noncopyable switch subjects.
2024-06-03 16:06:04 -07:00
Joe Groff
44483be120 SILGen: Diagnose unsupported shared case blocks for noncopyable switch subjects.
This isn't fully implemented yet so it would crash eventually, so instead of
letting the compiler crash put up a proper diagnostic indicating this isn't
yet implemented. rdar://129034189
2024-05-31 09:50:26 -07:00
Joe Groff
16803828e7 Merge pull request #73744 from jamieQ/diagnose-unreachable-opened-existentials
[SILGen]: diagnose unreachable opened existentials
2024-05-31 07:11:41 -07:00
Slava Pestov
0d4ff45eba Merge pull request #74020 from slavapestov/pack-expansion-closures-part-7
Pack expansion closures part 7
2024-05-30 21:27:29 -04:00
Slava Pestov
23be369c0e SILGen: Update for PackElementExpr captures
Fixes https://github.com/apple/swift/issues/68941.
Fixes https://github.com/apple/swift/issues/69282.
Fixes https://github.com/apple/swift/issues/72153.
Fixes rdar://110711746.
Fixes rdar://119212867.
Fixes rdar://124202697.
2024-05-30 16:39:49 -04:00
Emil Pedersen
11a535952e Merge pull request #73995 from Snowy1803/rdar126556557
[DebugInfo] [SILGen] Remove all invalid debug info from intermediates
2024-05-30 11:26:24 -07:00
Emil Pedersen
a5305346d5 [DebugInfo] [SILGen] Remove all invalid debug info from intermediates
The debug info on intermediates were not removed if the function used
parameter packs

Fixes #73030
rdar://126556557
2024-05-29 18:13:17 -07:00
Ellie Shin
4ecfc96578 [SIL][PackageCMO] Allow optimizing [serialized_for_pkg] functions during SIL
inlining, generic/closure specialization, and devirtualization optimization passes.

SILFunction::canBeInlinedIntoCaller now exlicitly requires a caller's SerializedKind_t arg.
isAnySerialized() is added as a convenience function that checks if [serialized] or [serialized_for_pkg].

Resolves rdar://128704752
2024-05-27 23:05:56 -07:00
Konrad `ktoso` Malawski
168bc7b454 [Concurrency] Fix how we obtain DA-as-A conformance for cross module
Resolves rdar://127206143
2024-05-28 13:37:21 +09:00
Emil Pedersen
a7a80130c2 Merge pull request #73866 from Snowy1803/silgen-description
[DebugInfo] [SILGen] Always use emitDebugDescription (NFCI)
2024-05-24 15:34:17 -07:00
Ellie Shin
9392a69810 Merge pull request #73754 from apple/elsh/serialized_kind
Support inlinability with [serialized_for_package]
2024-05-24 10:13:36 -07:00
Akira Hatanaka
b5cc5615bd [SILGen] Fix a crash when a closure is converted to a block returning a value indirectly (#73520) 2024-05-23 21:22:32 -07:00
Ellie Shin
5ccc4cd394 SIL function can be serialized with different kinds: [serialized] or
[serialized_for_package] if Package CMO is enabled. The latter kind
allows a function to be serialized even if it contains loadable types,
if Package CMO is enabled. Renamed IsSerialized_t as SerializedKind_t.

The tri-state serialization kind requires validating inlinability
depending on the serialization kinds of callee vs caller; e.g. if the
callee is [serialized_for_package], the caller must be _not_ [serialized].
Renamed `hasValidLinkageForFragileInline` as `canBeInlinedIntoCaller`
that takes in its caller's SerializedKind as an argument. Another argument
`assumeFragileCaller` is also added to ensure that the calle sites of
this function know the caller is serialized unless it's called for SIL
inlining optimization passes.

The [serialized_for_package] attribute is allowed for SIL function, global var,
v-table, and witness-table.

Resolves rdar://128406520
2024-05-23 15:53:02 -07:00
Emil Pedersen
0bc6ece9db [DebugInfo] [SILGen] Always use emitDebugDescription (NFCI) 2024-05-23 14:05:13 -07:00