Commit Graph

1342 Commits

Author SHA1 Message Date
Meghana Gupta
72a9075b8e Return index from SwitchValueInst::getUniqueCaseForDestination 2024-04-03 10:30:52 -07:00
Anton Korobeynikov
d84847ac9d Reland Allow normal function results of @yield_once coroutines (#71645)
* Allow normal function results of @yield_once coroutines

* Address review comments

* Workaround LLVM coroutine codegen problem: it assumes that unwind path never returns.
This is not true to Swift coroutines as unwind path should end with error result.
2024-03-27 13:09:02 -07:00
Andrew Trick
d7b9149ee5 Fix visitNonEscapingLifetimeEnds to handle mark_dependence uses
Now it visits unknown uses separately rather than asserting.
2024-03-22 14:29:57 -07:00
Erik Eckstein
4e61c5620c MandatoryInlining: look through sendable function conversions
Allows inlining of sendable transparent functions

rdar://124401627
2024-03-13 09:58:30 +01:00
Nate Chandler
3dbeebaa9b [SIL] Add var_decl flag to alloc_stack. 2024-03-08 22:28:22 -08:00
Nate Chandler
37d8984bea [NFC] SIL: Typed move_value's isFromVarDecl. 2024-03-08 22:28:22 -08:00
Nate Chandler
83bc56fd5b [NFC] SIL: Typed begin_borrow's isFromVarDecl. 2024-03-08 22:28:22 -08:00
Nate Chandler
7fecf6149c [NFC] SIL: Typed begin_borrow's isFixed. 2024-03-08 22:28:20 -08:00
Nate Chandler
46b08bd386 [SIL] NFC: Typed move_value's hasPointerEscape. 2024-03-08 22:27:52 -08:00
Nate Chandler
70d90b4b43 [NFC] SIL: Typed begin_borrow's hasPointerEscape. 2024-03-08 22:27:52 -08:00
Nate Chandler
401440748f [NFC] SIL: Typed alloc_box's hasPointerEscape. 2024-03-08 22:27:52 -08:00
Nate Chandler
7db84f25b1 [NFC] SIL: Typed move_value's isLexical. 2024-03-08 22:27:52 -08:00
Nate Chandler
9f6c30919b [NFC] SIL: Typed begin_borrow's isLexical. 2024-03-08 22:27:50 -08:00
Nate Chandler
c6eb3112b5 [NFC] SIL: Typed alloc_stack's isLexical. 2024-03-08 21:24:39 -08:00
Nate Chandler
ec6b447b68 [NFC] SIL: Typed alloc_box's hasDynamicLifetime. 2024-03-08 21:24:39 -08:00
Nate Chandler
dfa5c9814b [NFC] SIL: Typed alloc_stack's hasDynamicLifetime. 2024-03-08 21:24:39 -08:00
Nate Chandler
11dd0e4aa6 [NFC] SIL: Typed debug_value's wasMoved.
Help avoid errors with boolean flags by using the new
UsesMoveableValueDebugInfo_t.
2024-03-08 21:24:39 -08:00
Nate Chandler
e10d595328 [NFC] SIL: Typed alloc_box's wasMoved.
Help avoid errors with boolean flags by using the new
UsesMoveableValueDebugInfo_t.
2024-03-08 21:24:39 -08:00
Nate Chandler
611511a71f [NFC] SIL: Typed alloc_stack's wasMoved.
Help avoid errors with boolean flags by introducing
UsesMoveableValueDebugInfo_t.
2024-03-08 21:24:39 -08:00
Nate Chandler
5ccec0e31c [NFC] SIL: Shortened member name.
Renamed "getUsesMoveableValueDebugInfo" to "usesMoveableValueDebugInfo".
Clarifies the predicate from "does the receiver have the
usesMoveableValueDebugInfo field set?" to "does the receiver use moveable
value debug info?".
2024-03-08 21:24:38 -08:00
John McCall
0a282c044f Unify all of the task-creation builtins coming out of SILGen.
We've been building up this exponential explosion of task-creation
builtins because it's not currently possible to overload builtins.
As long as all of the operands are scalar, though, it's pretty easy
to peephole optional injections in IRGen, which means we can at
least just use a single builtin in SIL and then break it apart in
IRGen to decide which options to set.

I also eliminated the metadata argument, which can easily be recreated
from the substitutions.  I also added proper verification for the builtin,
which required (1) getting `@Sendable` right more consistently and (2)
updating a bunch of tests checking for things that are not actually
valid, like passing a function that returns an Int directly.
2024-03-06 22:21:12 -05:00
Joe Groff
161183cbc4 Merge pull request #71803 from jckarter/begin-borrow-fixed-switch-subject
SIL: Enclose switch subjects in a new begin_borrow [fixed] variant.
2024-02-22 14:45:17 -08:00
Erik Eckstein
3488cd364f SIL: remove instruction leaks checking
It's not thread safe and can cause false alarms in case multiple modules exist in different threads. E.g. when building swiftmodules from interfaces.
The leaking check is not important anymore because the builder APIs enforce that instructions are not leaking.
I.e. it's not possible to create an instruction without inserting it into a basic block. Also, it's not possible to remove an instruction from a block without deleting it.

rdar://122169263
2024-02-22 14:09:11 +01:00
Erik Eckstein
c996601f97 SIL: object instruction is not a forwarding instruction
Because it can only appear in the initializer list of a global variable.
2024-02-22 07:12:10 +01:00
Joe Groff
d75a62ce64 SIL: Enclose switch subjects in a new begin_borrow [fixed] variant.
We want to preserve the borrow scope during switch dispatch so that move-only
checking doesn't try to analyze destructures or consumes out of it. SILGen
should mark anywhere that's a potential possibility with its own marker so that
it gets borrow checked independently.
2024-02-21 20:41:20 -08:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
John McCall
868fc6ad46 Basic SILGen for @isolated(any).
The main piece that's still missing here is support for closures;
they actually mostly work, but they infer the wrong isolation for
actor-isolated closures (it's not expressed in the type, so obviously
they're non-isolated), so it's not really functional.  We also have
a significant problem where reabstraction thunks collide incorrectly
because we don't mangle (or represent!) formal isolation into
SILFunctionType; that's another follow-up.  Otherwise, I think SILGen
is working.
2024-02-19 21:21:03 -05:00
John McCall
b23bc82cdb Merge pull request #71574 from rjmccall/isolation-any-sil-irgen
SIL and IRGen support for `@isolated(any)` function types
2024-02-13 11:57:16 -05:00
Joe Groff
2170b4e725 Merge pull request #71489 from jckarter/borrowing-switch-8
MoveOnlyAddressUtils: Fixes for borrowing switch over address-only types.
2024-02-13 07:51:40 -08:00
John McCall
d5142668f4 SIL and IRGen support for @isolated(any). SILGen to come. 2024-02-13 03:04:13 -05:00
Joe Groff
0365c6abba MoveOnlyAddressUtils: Fixes for borrowing switch over address-only types.
Relax some existing pattern matches and add some unhandled instructions to the
walkers so that borrowing switches over address-only enums are properly analyzed
for incorrect consumption. Add a `[strict]` flag to `mark_unresolved_move_only_value`
to indicate a borrow access that should remain a borrow access even if the subject
is later stack-promoted from a box.
2024-02-12 20:20:50 -08:00
Andrew Trick
d0ac09493a Bridge MarkDependence.resolveToNonEscaping 2024-02-12 09:57:14 -08:00
Andrew Trick
da3f583492 Add mark_dependence [unresolved]
In preparation for inserting mark_dependence instructions for lifetime
dependencies early, immediately after SILGen. That will simplify the
implementation of borrowed arguments.

Marking them unresolved is needed to make OSSA verification
conservative until lifetime dependence diagnostics runs.
2024-02-08 22:53:16 -08:00
Nate Cook
e317febc9d Revert "Allow normal function results of @yield_once coroutines (#69843)"
This reverts commit aa5b505014.
2024-02-07 14:57:31 -06:00
Anton Korobeynikov
aa5b505014 Allow normal function results of @yield_once coroutines (#69843)
This adds SIL-level support and LLVM codegen for normal results of a coroutine.

The main user of this will be autodiff as VJP of a coroutine must be a coroutine itself (in order to produce the yielded result) and return a pullback closure as a normal result.

For now only direct results are supported, but this seems to be enough for autodiff purposes.
2024-02-06 22:13:15 -08:00
Nate Chandler
b535725647 [NFC] SIL: Renamed SpecifyTestInst.
The instruction's spelling was changed to `specify_test` but the class
name wasn't updated from `TestSpecificationInst`.  Update it here.
2024-02-06 16:29:09 -08:00
Michael Gottesman
ad584a7945 [sil] Add getOperand() variants for pack instructions.
We already had getValue() variants... this just expands those to operands. The
reason why this is useful is that these instructions have specific operands with
specific meanings as assigned by an internal enum struct. Rather than having to
access those directly by using getAllOperand()[EnumCase]... better to have a
named method.
2024-01-29 21:34:41 -08:00
nate-chandler
f2d68a21dc Merge pull request #71162 from nate-chandler/partial-consumption/20240125/1/scope-end-diagnostic
[MoveChecker] Distinguished scope end diagnostics.
2024-01-29 18:27:10 -08:00
Arnold Schwaighofer
edd7eaa0d7 OSLog: os_log strings should be in the __oslogstring section on machO
rdar://121384422
2024-01-26 08:30:56 -08:00
Nate Chandler
2c14ecefc2 [Gardening] SIL: Tweaked comment. 2024-01-25 11:01:14 -08:00
Andrew Trick
246da83f0f Merge pull request #71055 from atrick/lifetime-dependence
Lifetime dependence utilities
2024-01-23 08:19:24 -08:00
Andrew Trick
37171e698a Handle mark_dependence [nonescaping] like a borrowing instruction. 2024-01-22 23:57:03 -08:00
Joe Groff
960938f87e SILGen: Always match noncopyable values by borrowing.
Even if the final pattern ends up consuming the value, the match itself
must be nondestructive, because any match condition could fail and cause
us to have to go back to the original aggregate. For copyable values,
we can always copy our way out of consuming operations, but we don't
have that luxury for noncopyable types, so the entire match operation
has to be done as a borrow.

For address-only enums, this requires codifying part of our tag layout
algorithm in SIL, namely that an address-only enum will never use
spare bits or other overlapping storage for the enum tag. This allows
us to assume that `unchecked_take_enum_data_addr` is safely non-side-
effecting and match an address-only noncopyable enum as a borrow.
I put TODOs to remove defensive copies from various parts of our
copyable enum codegen, as well as to have the instruction report
its memory behavior as `None` when the projection is nondestructive,
but this disturbs SILGen for existing code in ways SIL passes aren't
yet ready for, so I'll leave those as is for now.

This patch is enough to get simple examples of noncopyable enum switches
to SILGen correctly. Additional work is necessary to stage in the binding
step of the pattern match; for a consuming switch, we'll need to end
the borrow(s) and then reproject the matched components so we can
consume them moving them into the owned bindings. The move-only checker
also needs to be updated because it currently always tries to convert
a switch into a consuming operation.
2024-01-19 13:59:04 -08:00
Michael Gottesman
26a75fe5e6 [region-isolation] Implement checking for transferring parameters.
NOTE: This does not handle yet assignment into transferring parameters. In the
next commit, I am going to teach the checker that assigning into such a
parameter is a transfer.
2024-01-18 13:20:28 -08:00
Erik Eckstein
bc99986cf9 SIL: add a dependency token operand to global_addr
Optionally, the dependency to the initialization of the global can be specified with a dependency token `depends_on <token>`.
This is usually a `builtin "once"` which calls the initializer for the global variable.
2024-01-10 09:33:58 +01:00
Andrew Trick
119d40d99b Merge pull request #70705 from atrick/markdep-nonescaping
Add mark_dependence [nonescaping] flag.
2024-01-05 11:33:33 -08:00
Andrew Trick
264cbaea42 Add mark_dependence [nonescaping] flag.
The dependent 'value' may be marked 'nonescaping', which guarantees that the
lifetime dependence is statically enforceable. In this case, the compiler
must be able to follow all values forwarded from the dependent 'value', and
recognize all final (non-forwarded, non-escaping) use points. This implies
that `findPointerEscape` is false. A diagnostic pass checks that the
incoming SIL to verify that these use points are all initially within the
'base' lifetime. Regular 'mark_dependence' semantics ensure that
optimizations cannot violate the lifetime dependence after diagnostics.
2024-01-04 14:47:35 -08:00
Nate Chandler
73d68a3f28 [IRGen] Pack metadata may be alloc'd for layouts.
Previously, mayRequirePackMetadata only considered whether a type
involved a pack.  That failed to account for the case of outlined value
functions that require pack metadata when the type involves a pack in
its layout.  Here, mayRequirePackMetadata now considers also whether the
layout corresponding to a type involves a pack.

rdar://119829826
2024-01-04 12:21:47 -08:00
Andrew Trick
b637f06acd [SIL] Bridge findPointerEscape() and fix OnoneSimplifyable
Do not bridge the hasPointerEscape flag until it is implemented.
2023-12-18 09:16:55 -08:00
nate-chandler
680c737ddb Merge pull request #64789 from nate-chandler/more-move-values
[SILGen] Used move_value for more lexical values.
2023-12-15 07:07:54 -08:00