Commit Graph

11193 Commits

Author SHA1 Message Date
Ben Barham
4c5284fd40 Merge pull request #74851 from bnbarham/rebranch-build-after-branch
[rebranch] Various changes to get rebranch compiling after taking new clang branch
2024-07-02 22:01:17 -07:00
Michael Gottesman
8770e90e43 Fix a thinko.
I was working on c20abe570d and
03bfadea60 at the same time and I forgot to update
to use the new API in 03bfadea60 before I commited
c20abe570d. Sorry!
2024-07-02 21:00:59 -07:00
Michael Gottesman
c20abe570d Merge pull request #74919 from gottesmm/pr-d8b24a45ff257893c8172491f11a617fc00d5589
[region-isolation] Implement support for 'inout sending' diagnostics.
2024-07-02 20:16:25 -07:00
Meghana Gupta
c2fd130fa2 Merge pull request #74795 from meg-gupta/copyelimexpand
Enable ClosureLifetimeFixup's capture copy elimination for copyable types as well.
2024-07-02 20:06:08 -07:00
Meghana Gupta
a470b04bbf [NFC] clang-format some parts of ClousreLifetimeFixup 2024-07-02 16:26:51 -07:00
Meghana Gupta
c895a9ba10 Add a flag to disable copy elimination of captures in ClosureLifetimeFixup 2024-07-02 16:25:38 -07:00
Meghana Gupta
98074a86c4 Enable copy elimination of captures for all types in ClosureLifetimeFixup
rdar://130026658
2024-07-02 16:25:34 -07:00
Michael Gottesman
6fe749626f [region-isolation] Add 'inout sending' diagnostics.
Specifically:

1. We error now if one transfers an 'inout sending' parameter and does not
reinitialize it before the end of the function.

2. We error now if one merges an 'inout sending' parameter into an actor
isolated region and do not reinitialize it with a non-actor isolated value
before the end of the function.

rdar://126303739
2024-07-02 16:21:44 -07:00
Michael Gottesman
5d4b93fa5d [region-isolation] Add a wrapper ADT for RequireInst SILInstructions so we can attach a Kind and propagate it.
The reason why I am doing this is that I am adding support for failing to
reinitialize an inout sending parameter that was transferred. To make it really
easy to do I am just going to explicitly represent this on the RequireInst and
let the decision on what diagnostic to be done to be represented in the
pseudo-IR instead of trying to just infer it straight from the type of require
inst. This keeps all of the logic in the same place and attempts to keep the
diagnostic emitter not use logic and instead just emit.

This is NFC so I can make sure that things work before adding the additional code.
2024-07-02 16:21:44 -07:00
Ben Barham
aa7a3a8268 Cleanup std includes
Remove `deque` from files it isn't actually used in. Add it and `stack`
to files that it is - presumably they were previously transitively found
through other includes.
2024-07-02 16:13:49 -07:00
Michael Gottesman
e9e5c4eb4c [region-isolation] Ensure that some NDEBUG code is properly guarded. 2024-07-02 13:55:33 -07:00
Michael Gottesman
130835a087 Merge pull request #74871 from gottesmm/pr-32c2095d621aa2c4be4bac901c79bfa5d9bd147e
[siloptimizer] Teach VariableNameInference how to look through convert_escape_to_no_escape.
2024-07-01 18:00:47 -07:00
Michael Gottesman
a13c1dc2dc Merge pull request #74869 from gottesmm/rdar130915737
[region-isolation] Improve async let errors to always use a new style error.
2024-07-01 16:24:32 -07:00
Michael Gottesman
b5aa2fec31 [siloptimizer] Teach VariableNameInference how to look through convert_escape_to_no_escape.
This was causing us to emit old style diagnostics in certain cases.

Just doing a walk through of the diagnostics and fixing issues while I
am here sprucing up sending diagnostics.

rdar://130915737
2024-07-01 14:37:11 -07:00
Michael Gottesman
02e003f0de [region-isolation] Change capturing a value into an async let that is not further sent into an actor isolated function to use a new style error.
Just going through and fixing sending errors.

rdar://130915737
2024-07-01 13:12:36 -07:00
Michael Gottesman
78d74cf716 [region-isolation] Make sil-region-isolation-assert-on-unknown-pattern also work with TransferNonSendable versions of the error.
This asserts only option is an option to make it quicker/easier to triage
unknown pattern match errors by aborting when we emit it (allowing one to
immediately drop into the debugger at that point).

Previously, it only happened for errors in RegionAnalysis not in
TransferNonSendable itself.
2024-07-01 13:12:36 -07:00
Meghana Gupta
12484ff919 Merge pull request #74842 from meg-gupta/addopenpackedgecase
Fix isTriviallyDuplicatable to handle open_pack_element
2024-07-01 10:53:53 -07:00
Meghana Gupta
d6729280f3 [NFC] clang-format parts of tryRewriteToPartialApplyStack 2024-07-01 09:53:14 -07:00
Meghana Gupta
56d59c9db3 [NFC] Rename OrigUnusedDuringClosureLifetimeWalker -> OrigUnmodifiedDuringClosureLifetimeWalker 2024-07-01 09:53:14 -07:00
Meghana Gupta
ab3eaf2441 Merge pull request #71881 from meg-gupta/fixmem2reg
Fix mem2reg of lexical enum stack locations
2024-06-30 05:31:24 -07:00
Nate Chandler
7edf36ff6a [Mem2Reg] Cleanup and refactoring. 2024-06-29 14:49:06 -07:00
Meghana Gupta
5282194682 Fix isTriviallyDuplicatable to handle open_pack_element
SILInstruction::clone doesn't know how to clone instructions that produce
the archetype uuid. SILCloner is equipped to handle such instructions.

Optimizations like LoopRotate use  SILInstruction::clone and will be
incorrect for such instructions.

rdar://130047619
2024-06-29 13:42:05 -07:00
Nate Chandler
451a814363 [MoveOnlyAddressChecker] Complete block args.
Now that the underlying issue (PrunedLiveness' merging of summaries for
branch instructions) has been fixed, reinstate lifetime completion and
add a test to verify that it behaves correctly.

This reverts commit c552b90b61
("Temporarily turn off completing lifetimes of block arguments").

rdar://130427564
2024-06-28 15:07:31 -07:00
Ben Barham
d8f381e660 Merge pull request #74804 from bnbarham/rename-equals
Update `StringRef::equals` references to `operator==`
2024-06-28 11:22:20 -07:00
Meghana Gupta
b1fc313f22 Merge pull request #74802 from meg-gupta/temprvalueedgecase
Allow TempRValueOpt of lexical alloc_stacks when base of copy source is @in_guaranteed
2024-06-27 22:00:05 -07:00
Ben Barham
d72f5b12c4 Update StringRef::equals references to operator==
`equals` has been deprecated upstream, use `operator==` instead.
2024-06-27 19:14:06 -07:00
Meghana Gupta
e4566c84b0 Merge pull request #74768 from meg-gupta/clffix
Fixes to ClosureLifetimeFixup's copy elimination for noncopyable values
2024-06-27 18:52:08 -07:00
Meghana Gupta
42c1f9cb33 Fix mem2reg of lexical enum stack locations
When we have a non trivial enum lexical stack location, and we store a
 none value, after mem2reg we can end up with an ownership error
because of the leaking move_value [lexical].

This change avoids creating move_value [lexical] for such stores.

Do the same when we have store_borrow of none values, even though there
is no ownership error in this case, handle it like store for consistency
2024-06-27 17:34:56 -07:00
Meghana Gupta
32e72a6732 Allow TempRValueOpt of lexical alloc_stacks when base of copy source has guaranteed convention
A guaranteed function argument is live for the duration of the function.
It should be safe to allow TempRValueOpt when it is the base of the copy source of a lexical alloc_stack.
2024-06-27 16:18:15 -07:00
Meghana Gupta
e71cd4b005 Improve copy elimination of noncopyable captures in ClosureLifetimeFixup
For a mark_dependence user of the stack, look through the mark_dependence chain
to match the partial_apply.

Since this is a superset of the `markDepChain` logic, remove that.
So that we don't have 2 ways to check for the same.
2024-06-27 10:34:29 -07:00
Akira Hatanaka
42bc49d3fe Add a new parameter convention @in_cxx for non-trivial C++ classes that are passed indirectly and destructed by the caller (#73019)
This corresponds to the parameter-passing convention of the Itanium C++
ABI, in which the argument is passed indirectly and possibly modified,
but not destroyed, by the callee.

@in_cxx is handled the same way as @in in callers and @in_guaranteed in
callees. OwnershipModelEliminator emits the call to destroy_addr that is
needed to destroy the argument in the caller.

rdar://122707697
2024-06-27 09:44:04 -07:00
Meghana Gupta
960619b0a0 Fix ClosureLifetimeFixup's copy elimination for noncopyable values
On finding unrecognized user, reset `initialization` of the stack so that we
don't inadvertently eliminate copy
2024-06-27 02:55:29 -07:00
Erik Eckstein
655494495e use the new ASSERT macro for two asserts which should also fire in a release-built compiler 2024-06-27 09:49:29 +02:00
Erik Eckstein
c576015d8a fix a crash when de-virtualizing class or actor methods with typed throws
The de-virtualizer utility didn't handle indirect error results when de-virtualizing class or actor methods.
This resulted in a missing argument for the indirect error result in the new try_apply instruction.

rdar://130545338
2024-06-27 09:47:33 +02:00
Michael Gottesman
f0fff2e5a0 [region-isolation] Treat sendable return values as Sendable when the returning function has a known actor isolation.
rdar://130544081
2024-06-26 16:31:45 -07:00
Ellie Shin
116abbb1dc Merge pull request #74641 from swiftlang/elsh/cmo-ufi 2024-06-26 09:06:39 -07:00
Joe Groff
636a19d11b Merge pull request #74707 from jckarter/consume-during-borrow-checks
MoveOnlyAddressChecker: More robust checking for consume-during-borrow.
2024-06-26 08:22:04 -07:00
eeckstein
31c07c95b0 Merge pull request #74689 from eeckstein/refactor-dynamic-self-check
SwiftCompilerSources: refactor `Function.mayBindDynamicSelf`
2024-06-26 08:47:18 +02:00
eeckstein
b68c55cd90 Merge pull request #74685 from eeckstein/assertion-improvements
Some assertion improvements
2024-06-26 08:45:50 +02:00
Michael Gottesman
2b5fa0e847 Merge pull request #74705 from gottesmm/pr-93a2750af4fb0c65ca129d545c4af30cd9e718f9
[region-isolation] Given a .none #isolation parameter, infer the isolation from the callee rather than the isolated parameter.
2024-06-25 19:38:19 -07:00
Ellie Shin
1e5266e7b6 [PackageCMO] Don't allow modifying AST.
Currently not all types are visited in canSerialize* calls, sometimes
 resulting in an internal type getting @usableFromInline, which is
 incorrect.

 For example, for `let q = P() as? Q`, where Q is an internal class
 inherting a public class P, Q is not visited in the canSerialize*
 checks, thus resulting in `@usableFromInline class Q`; this is not
 the intended behavior in the conservative mode used by PackageCMO
 as it modifies AST.

 To properly fix, instruction visitor needs to be refactored to do
 both the "canSerialize" check (that visits all types) and serialize
 or update visibility (modify AST in non-conservative modes).

 This PR provides a short-term fix that prevents modifying AST, and
 also ensures that the generated interfaces with PackageCMO flags
 are not affected by the optimization or contain modified AST.

rdar://130292190
2024-06-25 18:15:29 -07:00
Alejandro Alonso
cb2a766470 Handle existential_metatype in moveonlytype eliminator 2024-06-25 14:16:53 -07:00
Michael Gottesman
f43911b30f [region-isolation] Given a .none #isolation parameter, infer the isolation from the callee rather than the isolated parameter.
Otherwise, we will have differing isolation from other parameters since
the isolations will look different since one will have the .none value
as an instance and the other will not have one and instead will rely on
the AST isolation info. That is the correct behavior here since we do
not actually have an actor here.

I also removed some undefined behavior in the merging code. The way the
code should work is that we should check if the merge fails and in such
a case emit an unknown pattern error... instead of not checking
appropriately on the next iteration and hitting undefined behavior.

rdar://130396399
2024-06-25 14:12:15 -07:00
Joe Groff
27a8852290 MoveOnlyAddressChecker: More robust checking for consume-during-borrow.
- While an opaque borrow access occurs to part of a value, the entire scope of
  the access needs to be treated as a liveness range, so add the `EndAccess`es
  to the liveness range.
- The SIL verifier may crash the compiler on SILGen-generated code when the
  developer's source contains consume-during-borrow code patterns. Allow
  `load_borrow` instructions to be marked `[unchecked]`, which suppresses
  verifier checks until the move checker runs and gets a chance to properly
  diagnose these errors.

Fixes rdar://124360175.
2024-06-25 14:10:02 -07:00
Erik Eckstein
c61733f985 SwiftCompilerSources: refactor Function.mayBindDynamicSelf
Instead of bridging the whole function, just bridge `hasDynamicSelfMetadata` and do the other work in swift.
2024-06-25 17:59:23 +02:00
Erik Eckstein
718ea4b018 replace require with the new ASSERT macro 2024-06-25 10:45:55 +02:00
Michael Gottesman
dcd348fa5f Merge pull request #74673 from gottesmm/pr-820f4317d3273ec87c02ce9d16e1dc14a759dd40
[transfer-non-sendable] Teach SILIsolationInfo how to handle "look through instructions" when finding actor instances.
2024-06-24 21:48:27 -07:00
Michael Gottesman
c01f551ebe [transfer-non-sendable] Teach SILIsolationInfo how to handle "look through instructions" when finding actor instances.
From the perspective of the IR, we are changing SILIsolationInfo such that
inferring an actor instance means looking at equivalence classes of values where
we consider operands to look through instructions to be equivalent to their dest
value. The result is that cases where the IR maybe puts in a copy_value or the
like, we consider the copy_value to have the same isolation info as using the
actor directly. This prevents a class of crashes due to merge failings. Example:

```swift
actor MyActor {
  init() async {

  init(ns: NonSendableKlass) async {
    self.k = NonSendableKlass()
    self.helper(ns)
  }

  func helper(_ newK: NonSendableKlass) {}
}
```

Incidently, we already had a failing test case from this behavior rather than
the one that was the original genesis. Specifically:

1. If a function's SILIsolationInfo is the same as the isolation info of a
SILValue, we assume that no transfer actually occurs.

2. Since we were taking too static of a view of actor instances when comparing,
we would think that a SILIsolationInfo of a #isolation parameter to as an
argument would be different than the ambient's function isolation which is also
that same one. So we would emit a transfer non transferrable error if we pass in
any parameters of the ambient function into another isolated function. Example:

```swift
actor Test {

  @TaskLocal static var local: Int?

  func withTaskLocal(isolation: isolated (any Actor)? = #isolation,
                     _ body: (consuming NonSendableValue, isolated (any Actor)?) -> Void) async {
    Self.$local.withValue(12) {

      // We used to get these errors here since we thought that body's isolation
      // was different than the body's isolation.
      //
      //  warning: sending 'body' risks causing data races
      //  note: actor-isolated 'body' is captured by a actor-isolated closure...
      body(NonSendableValue(), isolation)
    }
  }
}
```

rdar://129400019
2024-06-24 18:16:11 -07:00
Michael Gottesman
baec06ed23 [variable-name-inference] Add support for handling EndInitLetRefInst. 2024-06-24 18:16:11 -07:00
Meghana Gupta
c552b90b61 Temporarily turn off completing lifetimes of block arguments 2024-06-24 08:14:18 -07:00