Commit Graph

2864 Commits

Author SHA1 Message Date
Michael Gottesman
b2c85a8294 [region-isolation] Rather than tracking task isolated values via a separate non-transferrable array... just track it by using ValueIsolationRegionInfo on a value.
In a subsequent commit, this is going to let me begin handling parameters with
actor regions in a nice way (and standardize all of the errors).

This is meant to be a refactoring commit that uses the current tests in tree to
make sure I did it correctly, so no tests need to be updated.
2024-03-10 22:08:40 -07:00
Michael Gottesman
93844934f9 [region-isolation] Begin tracking region information instead of just whether a value is actor derived.
To keep this as an NFC commit, I only modeled initially actor isolated using
this. I am going to make it so that we properly treat global actor isolated
values as actor isolated/etc in a subsequent commit.
2024-03-10 22:08:40 -07:00
Nate Chandler
a54a8ddaa3 [SIL] Key consume addr checking off var_decl attr.
Previously, the lexical attribute on allock_stack instructions was used.
This doesn't work for values without lexical lifetimes which are
consumed, e.g. stdlib CoW types.  Here, the new var_decl attribute on
alloc_stack is keyed off of instead.  This flag encodes exactly that a
value corresponds to a source-level VarDecl, which is the condition
under which checking needs to run.
2024-03-09 05:29:01 -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
Michael Gottesman
f63ac2e16c [region-isolation] Simplify TransferNonTransferrable diagnostic to be like UseAfterTransfer by using an emitter struct.
This makes it easier to debug/maintain/understand the code since the place that
emits the diagnostics is no longer split from the place that decides if a
diagnostic should be emitted. It also lets me eliminate the utility data
structure used to transfer data over.
2024-03-08 12:42:15 -08:00
Meghana Gupta
44c2c07997 Merge pull request #72152 from meg-gupta/silcrash
Fix computation of argument index in the presence of indirect error results
2024-03-07 16:14:06 -08:00
Alexis Laferrière
1a840948a0 Merge pull request #72156 from apple/revert-72124-fix-embedded-dead-code-elim
Revert "embedded: allow dead function elimination for de-serialized functions"
2024-03-07 13:14:18 -08:00
nate-chandler
8ddbc8bf0e Merge pull request #72144 from nate-chandler/partial-consumption/20240306/1
[NoncopyablePartialConsumption] Allow consume.
2024-03-07 10:51:55 -08:00
Michael Buch
8957f8186a Revert "embedded: allow dead function elimination for de-serialized functions" 2024-03-07 16:48:04 +00:00
Meghana Gupta
f3b225a395 Fix computation of argument index in the presence of indirect error results
Fixes rdar://124108894
2024-03-07 02:02:33 -08:00
eeckstein
d70ce6bb34 Merge pull request #72124 from eeckstein/fix-embedded-dead-code-elim
embedded: allow dead function elimination for de-serialized functions
2024-03-07 07:39:17 +01:00
Nate Chandler
e40581a61b [MoveChecker] Visit and delete markers in PO.
Visit in post-order in order to resolve markers from the inside out,
required for per-field consume.
2024-03-06 20:54:17 -08:00
Michael Gottesman
c31d1e020d Merge pull request #72140 from gottesmm/pr-3d00d8785342736dc2f0b13a52ebfbe0b7fe3420
[region-isolation] Simplify the code for use after transfer errors.
2024-03-06 20:36:35 -08:00
Michael Gottesman
9bfddfe464 [region-isolation] Simplify the code for use after transfer errors.
Specifically, we previously would generate a list of errors to emit and then
have one centralized piece of code that went through the list and emitted them.
Instead, we now have a low level emitter struct that is just used to emit the
diagnostic at the immediate point where we would create previously an error
record. This places the diagnostic emission next to the piece of code that
triggered it being emitted making it easier to debug why an error was emitted
using -Xllvm -swift-diagnostics-assert-on-*.

I am going to do the same for transfer non transferrable in a little bit once
the async let patch has landed. It has some transfer non transferable error
additions that I want to get in so I am going to wait on that.

NFCI.
2024-03-06 16:47:39 -08:00
Joe Groff
828abb3f75 SILGen: Forward move-only ownership through optional chains.
Allow noncopyable values to be consumed, borrowed, or mutated transitively
through optional chains.
2024-03-06 13:44:02 -08:00
Erik Eckstein
cc9e53bb08 embedded: allow dead function elimination for de-serialized functions
In embedded swift all de-serialized get public linkage because all the code is generated in the top-level module.
This change moves the point where we make de-serialized functions public to the end of the pipeline.
This allows dead function elimination to remove unused de-serialized functions.
For some stdlib functions (actually one: the Double initializer for a builtin integer) is essential, because codegen for embedded produces an unresolved symbol.

rdar://123772098
2024-03-06 20:51:09 +01:00
cui fliter
127077b3aa chore: fix some comments
Signed-off-by: cui fliter <imcusg@gmail.com>
2024-03-05 17:23:22 +08:00
Michael Gottesman
f06244f397 [region-isolation] Take into account that Swift's RPO order doesn't include blocks that are dead.
When we run RegionAnalysis, since it uses RPO order, we do not visit dead
blocks. This can create a problem when we emit diagnostics since we may merge in
a value into the region that was never actually defined. In this patch, if we
actually visit the block while performing dataflow, I mark a bit in its state
saying that it was live. Then when we emit diagnostics, I do not visit blocks
that were not marked live.

rdar://124042351
2024-03-04 17:09:51 -08:00
Michael Gottesman
2ad0c1aa4a Merge pull request #71998 from gottesmm/pr-ca981c22b983cdfc472ae9c1d737c76dae955aed
[region-isolation] Refactor out the stubify dead function if no longer used functionality from move only checker into its own pass and put it before region based isolation.
2024-03-01 17:21:45 -08:00
Michael Gottesman
3236bc26fa [region-isolation] Refactor out the stubify dead function if no longer used functionality from move only checker into its own pass and put it before region based isolation.
I am doing this since region based isolation hit the same issue that the move
checker did. So it makes sense to refactor the functionality into its own pass
and move it into a helper pass that runs before both.

It is very conservative and only stubifies functions that the specialization
passes explicitly mark as this being ok to be done to.
2024-03-01 13:11:07 -08:00
Michael Gottesman
6eb31b42b1 [region-isolation] Assigning into a transferring parameter should be a store, not a transfer.
rdar://123865943
2024-02-29 16:20:00 -08:00
Nate Chandler
6100a1b495 Allow partial consumption of self in deinit.
Basic support for partial consumption in deinit without full support for
all future uses of drop_deinit.
2024-02-28 15:57:09 -08:00
Joe Groff
a82f8a9f1f Merge pull request #71942 from jckarter/reenable-borrow-to-destructure-transform
Reenable BorrowToDestructureTransform during the MoveOnlyAddressChecker.
2024-02-28 07:31:15 -08:00
Joe Groff
62b05c8e42 Reenable BorrowToDestructureTransform during the MoveOnlyAddressChecker.
The comment stated that this was used to turn switches into consumes (which
is no longer relevant), but it looks like it is also necessary for the
move-only address checker to be able to properly understand partial consumes
of fields in some code patterns. Now that we surround borrowing switches
in plenty of opaque accesses to protect them from being pried apart by the
move checker, it should be safe to reenable this.
2024-02-27 20:11:58 -08:00
Michael Gottesman
b85f75f6b5 Delete some unused variables 2024-02-27 13:14:47 -08:00
Michael Gottesman
11f0ff6e32 [sil] Ensure that all SILValues have a parent function by making it so that SILUndef is uniqued at the function instead of module level.
For years, optimizer engineers have been hitting a common bug caused by passes
assuming all SILValues have a parent function only to be surprised by SILUndef.
Generally we see SILUndef not that often so we see this come up later in
testing. This patch eliminates that problem by making SILUndef uniqued at the
function level instead of the module level. This ensures that it makes sense for
SILUndef to have a parent function, eliminating this possibility since we can
define an API to get its parent function.

rdar://123484595
2024-02-27 13:14:47 -08:00
Meghana Gupta
bd46860dfb Merge pull request #71913 from meg-gupta/savecodesize
Create mark_dependence for array allocation in OSLogOptimization
2024-02-27 09:49:27 -08:00
Holly Borla
420859cdb4 Merge pull request #71906 from hborla/extract-function-isolation
[Concurrency] Add an API in the Concurrency library for extracting isolation from a dynamically isolated function value.
2024-02-27 09:19:44 -08:00
Meghana Gupta
0fc2e1343e Create mark_dependence for array allocation in OSLogOptimization
With #70242 mark_dependence was added while emitting uninitialized array allocation
between the unsafe pointer and the array value returned.
Without it, we can end up with use after free of the unsafe pointer if the array's lifetime
is shortened. Along with this change, pattern matching of all array optimizations was updated to include
mark_dependence.

This change adds mark_dependence for uninitialized array allocation in OSLogOptimization which was left out previously.
With this, potential use-after-free of the unsafe pointer is prevented and all updated array optimizations apply
to the array created by OSLogOptimization.

Fixes rdar://122922902
2024-02-27 00:39:09 -08:00
Holly Borla
2c6344f461 [SILOptimizer] Handle FunctionExtractIsolationInst in the mandatory passes. 2024-02-26 17:59:27 -08:00
Joe Groff
d671f2a6c0 MoveOnlyAddressChecker: Treat opaque accesses consistently in CopiedLoadBorrowEliminationVisitor.
Don't prepare loads from inside an opaque access that the checker isn't going to visit.
Fixes rdar://123601728.
2024-02-26 15:50:03 -08:00
Michael Gottesman
e7f7900063 Merge pull request #71829 from gottesmm/pr-071a183496e8c0d173d958388af193d807f57f56
[region-isolation] Change two diagnostics to use the user facing sugared type instead of the SIL type
2024-02-25 22:43:17 -08:00
Ben Barham
f292ec9784 Use the new template deduction guides rather than makeArrayRef
LLVM has removed `make*ArrayRef`, migrate all references to their
constructor equivalent.
2024-02-23 20:04:51 -08:00
Michael Gottesman
c698f7c5e9 [region-isolation] Use the user facing type rather than the SIL type when emitting a function argument captured by actor isolated closure error. 2024-02-22 19:45:46 -08:00
Michael Gottesman
37bae7af83 [region-isolation] Use the sugared AST type when emitting a TransferNonTransferrable error for passing an argument as a transferrig parameter. 2024-02-22 19:45:46 -08:00
Michael Gottesman
a703f225d7 Merge pull request #71823 from gottesmm/strong_transferring
[region-isolation] Improve errors around strong transferring and wordsmith main error
2024-02-22 17:03:39 -08: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
Michael Gottesman
02be75a603 [region-isolation] Emit a better error when a function parameter is assigned into a different transferring parameter.
Just eliminating another "call site passes `self`" error.
2024-02-22 13:50:07 -08:00
Michael Gottesman
8fd70eca94 [region-isolation] Create helpers for inferring name from value and infer name/root from value.
This just cleans up the code by not exposing the details from the
VariableNameInferrer outside of the utilities. It also makes it easier to write
conditional code that uses these helpers by returning an optional, so instead of
having a long setup + an if statement, we just have an if statement optional
check.
2024-02-22 13:50:07 -08:00
Michael Gottesman
7f43c3aa86 [region-isolation] Eliminate "call site passes self" error from all SIL tests. 2024-02-22 13:50:07 -08:00
Michael Gottesman
1c193caedb [region-isolation] Eliminate more "call site passes self" warnings
I just did a full pass through. There were some cases around nonisolated
closures defined in methods and global actor isolated things where we are now
emitting the wrong message. I am going to fix that in subsequent commits.
2024-02-22 13:50:06 -08:00
Michael Gottesman
e4bd7f7dcd [region-isolation] Track the full isolation crossing when emitting transfer non transferrable error.
Preparing for beginning to emit named errors where I need this information. This
just lets me do it before that other commit to make it cleaner.

NFC.
2024-02-22 13:50:06 -08:00
Michael Gottesman
eeba7910b8 [region-isolation] Inline an initForApply call that wasn't really necessary.
Just simplifying code. I also deleted dead code as well.
2024-02-22 13:50:06 -08:00
Michael Gottesman
31baceb6f2 [region-isolation] Reformat transfer non sendable so that utility code is next to the routines that use the utility.
NFC.

Before this commit, the diagnostic emission was split into utilities that were
used by one large emitter class. This could get confusing since there was some
duplication of names in between the utilities. Now instead, each part of the
main diagnostic emitter is in the MARK: section of the utilities that it uses.

Just making the pass easier for me to reason about.
2024-02-22 13:50:06 -08:00
Erik Eckstein
71fcae7fe8 SwiftCompilerSources: add the ability to implement SIL verification in swift 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
5637284e48 Merge pull request #71368 from bnbarham/std-optional-all-the-things
Migrate llvm::Optional to std::optional
2024-02-21 16:54:00 -08:00
nate-chandler
b719a6aac1 Merge pull request #71783 from nate-chandler/nfc/20240221/1
[NFC] Removed non-verifier uses of MemoryLocations.
2024-02-21 12:44:10 -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
a4e92e7eb5 Merge pull request #71735 from rjmccall/isolated-any-silgen
Basic SILGen for @isolated(any); still missing closures.
2024-02-21 13:10:44 -05:00