Commit Graph

2864 Commits

Author SHA1 Message Date
eeckstein
999669c860 Merge pull request #78441 from stzn/improve-use-before-initialized-diagnostic
[Diagnostics] A self argument implicitly passed as an inout parameter is diagnosed as used before initialized
2025-01-12 16:44:48 +01:00
Meghana Gupta
8397fc364c Merge pull request #78460 from meg-gupta/removeossa
Fix build option for Synchronization and Distributed
2025-01-08 15:20:07 -08:00
Meghana Gupta
d55cb2ad6c Bailout of PredictableMemOpt utilities when in non-ossa
These utilities are called from MandatorPerformanceOptimizations which can run
on serialized non-ossa functions. Add a bailout to handle this case.
2025-01-07 01:19:09 -08:00
stzn
d429a90ebc [Diagnostics] A self argument implicitly passed as an inout parameter is diagnosed as used before initialized 2025-01-06 05:05:26 +09:00
Michael Gottesman
5d4239af57 [concurrency] Add new isolation kind CallerIsolationInheriting.
Right now it is basically a version of nonisolated beyond a few simple cases
like constructors/destructors where we are pretty sure we want to not support
this.

This is part of my bringup strategy for changing nonisolated/unspecified to be
caller isolation inheriting.
2025-01-02 13:18:30 -08:00
Ben Barham
8111fe9343 Merge pull request #78262 from bnbarham/skip-non-wmo-diag
[Embedded] Do not produce `cannot_specialize_class` for live issues
2024-12-20 10:40:07 -08:00
Ben Barham
a2fda1d9f3 [Embedded] Do not produce cannot_specialize_class for live issues
SourceKit explicitly disables WMO, silence the diagnostic in this case
(but leave it enabled for explicit non-WMO builds otherwise).
2024-12-19 15:31:41 -08:00
Nate Chandler
c327c59460 [SGC] Complete deadend-reachable lifetimes.
For a function to have complete lifetimes, the lifetime of every def in
the function which is backwards-reachable from a dead-end block must be
completed.

Previously, every def in every block which appears in the post-order of
the function's blocks is completed.  This was not enough: defs in
"unreachable blocks" (i.e. those which aren't forwards-reachable from
the function entry) must be completed too, and such blocks do not appear
in the function's post-order.

Here, defs in unreachable blocks are be completed too.  Such defs must
also be completed in relative post-order.  To do this, roots for the
non-entry post-orders must be found.

rdar://141197164
2024-12-18 11:25:43 -08:00
Nate Chandler
7c4036e908 [NFC] SGC: Extract range completion.
In preparation for completing lifetimes in multiple ranges (namely
post-orders of subgraphs of the function), extract a complete-in-range
method.
2024-12-18 11:25:42 -08:00
Nate Chandler
f9b32a5c4d [NFC] CLF: Compute reachable blocks only.
Don't form a set of unreachable blocks, we only need to check whether
any given block is unreachable, which can be done via
`ReachableBlocks::isVisited`.
2024-12-18 11:25:42 -08:00
Nate Chandler
e926d22b2d [NFC] SILGenCleanup: Added logging. 2024-12-18 11:25:42 -08:00
Nate Chandler
c53b1a5711 [Gardening] Detypo'd comment. 2024-12-18 11:25:41 -08:00
Usama Hameed
203f906364 Serialize/Deserialize source locations for instructions (#77281)
This commit adds support for serializing and deserializing source locations for instructions.
2024-12-12 16:15:44 +05:00
nate-chandler
5637eaf3ca Merge pull request #77968 from nate-chandler/rdar139842132
[OSSACanonicalizeOwned] Record traversed defs and don't traverse copies of guaranteed values.
2024-12-06 07:00:20 -08:00
Nate Chandler
498294efa2 [NFC] OSSACanOwned: Record defs in SmallVector.
In preparation for only recording the defs once, replace the
GraphNodeWorklist of defs with a SetVector.  Preserve the current
visitation order by creating a worklist of indices to be visited.
2024-12-05 08:24:46 -08:00
Erik Eckstein
e328eee05c DefiniteInitialization: correctly handle upcasts in delegating initializers
Fixes a crash due to a wrong class type when creating a value_metatype instruction

rdar://140926647
2024-12-05 13:12:51 +01:00
Michael Gottesman
87495c6b83 Merge pull request #77900 from gottesmm/rdar127477211
[region-isolation] Perform checking of non-Sendable results using rbi rather than Sema.
2024-12-03 22:08:49 -08:00
Gábor Horváth
b744793716 Merge pull request #77878 from swiftlang/gaborh/import-rval-ref
[cxx-interop] Import rvalue references as consuming parameters
2024-12-03 16:14:02 +00:00
Kuba (Brecka) Mracek
8792efedf0 Merge pull request #77115 from kubamracek/embedded-mangling-prefix
[Mangling] [NFC] Prepare for a new mangling prefix for Embedded Swift: $e
2024-12-03 08:10:49 -08:00
Kuba Mracek
6f4ae28520 [ASTMangler] Pass ASTContext to all instantiations of ASTMangler 2024-12-02 15:01:04 -08:00
Michael Gottesman
cff835e061 [region-isolation] Perform checking of non-Sendable results using rbi rather than Sema.
In terms of the test suite the only difference is that we allow for non-Sendable
types to be returned from nonisolated functions. This is safe due to the rules
of rbi. We do still error when we return non-Sendable functions across isolation
boundaries though.

The reason that I am doing this now is that I am implementing a prototype that
allows for nonisolated functions to inherit isolation from their caller. This
would have required me to implement support both in Sema for results and
arguments in SIL. Rather than implement results in Sema, I just finished the
work of transitioning the result checking out of Sema and into SIL. The actual
prototype will land in a subsequent change.

rdar://127477211
2024-12-02 16:54:12 -05:00
Allan Shortlidge
3e50a90c45 AST: Introduce Decl::getUnavailableAttr().
It replaces `DeclAttr::getUnavailable()` and `AvailableAttr::isUnavailable()`
as the designated way to query for the attribute that makes a decl unavailable.
2024-12-02 07:35:58 -08:00
Gabor Horvath
1601564342 [cxx-interop] Import rvalue references as consuming parameters
Unfortunately, importing them as is results in ambiguous call sites.
E.g., std::vector::push_back has overloads for lvalue reference and
rvalue reference and we have no way to distinguish them at the call site
in Swift. To overcome this issue, functions with rvalue reference
parameters are imported with 'consuming:' argument labels.

Note that, in general, move only types and consuming is not properly
supported in Swift yet. We do not invoke the dtor for the moved-from
objects. This is a preexisting problem that can be observed with move
only types before this PR, so the fix will be done in a separate PR.
Fortunately, for most types, the moved-from objects do not require
additional cleanups.

rdar://125816354
2024-12-02 13:09:21 +00:00
Doug Gregor
a93e8fd006 Merge pull request #77752 from DougGregor/perf-diag-check-throws
[Performance diagnostics] Enable checking of throw instructions
2024-12-01 22:54:07 -08:00
Doug Gregor
1d3332d471 Remove the now-unused NonErrorHandlingBlocks 2024-11-21 16:06:45 -08:00
Doug Gregor
c09bbf4c10 [Performance diagnostics] Enable checking of throw instructions
When performance diagnostics were introduced, typed throws didn't exist
so it was not generally possible to have throws anywhere without
triggering performance diagnostics. As a short term hack, we disabled
checking of `throw` instructions and the basic blocks that terminate
in a `throw`.

Now that typed throws is available and can be used to eliminate
allocations with error handling, remove all of the hacks. We'll now
diagnose attempts to throw or catch existential values (e.g., the `any
Error` used for untyped throws), but typed throws are fine.
2024-11-21 16:06:44 -08:00
Michael Gottesman
e6b4e0f9f1 Merge pull request #77709 from gottesmm/pr-6feaf0c91a7d95d75b36d32cc91a32150d992162
[region-isolation] Some initial NFCI refactoring commits before adding experimental support for inheriting isolation to nonisolated functions
2024-11-19 22:22:50 -08:00
Michael Gottesman
d94e4c4434 [region-isolation] Using the print method from the previous commit, ensure that we dump out SentNeverSendable, InOutSendingNotDisconnectedAtExit, AssignNeverSendableIntoSendingResult earlier when we initially detect them.
This just improves the ability to quickly triage bugs in SendNonSendable. It
used to be this way, but in the process of doing some refactoring, I moved the
logging too late by mistake.
2024-11-19 12:48:30 -08:00
Michael Gottesman
d33f819038 [region-isolation] Move freeform logging on the specific error we are emitting into a method on the error itself.
I am doing this since I discovered that we are not printing certain errors as
early as we used to (due to the refactoring I did here), which makes it harder
to see the errors that we are emitting while processing individual instructions
and before we run the actual dataflow.

A nice side-effect of this is that it will make it easy to dump the error in the
debugger rather than having to wait until the point in the code where the normal
logging takes place.
2024-11-19 12:48:30 -08:00
Andrew Trick
4612728581 [NFC] Add BeginApplyInst::getEndApplyUses() API.
A begin_apply token may be used by operands that do not end the coroutine:
mark_dependence.

We need an API that gives us only the coroutine-ending uses. This blocks
~Escapable accessors.

end_borrow is considered coroutine-ending even though it does not actually
terminate the coroutine.

We cannot simply ask isLifetimeEnding, because end_apply and abort_apply do not
end any lifetime.
2024-11-18 01:37:00 -08:00
Andrew Trick
eb8d9f4960 Merge pull request #77575 from atrick/preserve_extend_lifetime
Preserve extend_lifetime during dead instruction code elimination.
2024-11-13 05:22:30 -08:00
Andrew Trick
b30fd77906 Remove all trivial extend_lifetime instructions
during the MoveOnlyWrappedTypeEliminator pass.

Such instructions are only valid in RAW SIL. This pass generally removes marker
instructions that are only used for ownership diagnostics.

Fixes rdar://139450982 ([GH:#77451] Assert failure on
`extend_lifetime` verify with `onone-simplification` pass disabled)
2024-11-12 23:53:56 -08:00
Erik Eckstein
51e3e5ed80 Optimizer: rename BorrowArgumentsUpdater -> GuaranteedPhiUpdater
NFC
2024-11-12 09:26:59 +01:00
Erik Eckstein
6b8c6a3c3b SIL: rename updateBorrowedFrom to updateBorrowArguments
NFC
2024-11-12 09:26:58 +01:00
Arnold Schwaighofer
34c417d9ff Merge pull request #77379 from aschwaighofer/enable_aggressive_reg2mem
Enable heuristic that tries to keep large values in memory
2024-11-06 11:36:33 -08:00
nate-chandler
12a137a7b4 Merge pull request #77401 from nate-chandler/rdar139235335
[CapturePromotion] dealloc_box doesn't mutate.
2024-11-05 18:14:52 -08:00
Nate Chandler
027070a170 [NFC] CapturePromotion: Use macro.
Keep to a single spelling for an "always OK" instruction.
2024-11-05 11:43:21 -08:00
Nate Chandler
986d155db7 [CapturePromotion] dealloc_box doesn't mutate.
The instruction only deallocates the box, it doesn't destroy its
contents.  It's even less mutating than a `destroy_value`, which is
already regarded as non-mutating.
2024-11-05 11:42:21 -08:00
Arnold Schwaighofer
dc3c19164a PMO: Don't block pmo for large types - rather only block expansion of tuples 2024-11-04 17:06:24 -08:00
Michael Gottesman
32b4de60a9 Rename transfer -> send.
Accomplished using clangd's rename functionality.
2024-11-04 15:17:51 -08:00
Michael Gottesman
0a56827073 [region-isolation] Rename TransferNonSendable.cpp -> SendNonSendable.cpp.
Just beginning the elimination of the word transferred from the code base.
2024-11-02 16:58:17 -07:00
Michael Gottesman
1966980c6b Merge pull request #77354 from gottesmm/rdar136593706
[region-isolation] Fix an off by one error when mapping AST capture indices to SIL level parameter indices.
2024-11-01 20:03:42 -07:00
Michael Gottesman
3c38c79f7a [region-isolation] Implement MergeIsolationRegionInst.
I am adding this instruction to express artificially that two non-Sendable
values should be part of the same region. It is meant to be used in cases where
due to unsafe code using Sendable, we stop propagating a non-Sendable dependency
that needs to be made in the same region of a use of said Sendable value. I
included an example in ./docs/SIL.rst of where this comes up with @out results
of continuations.
2024-11-01 11:25:53 -07:00
Arnold Schwaighofer
501f2be057 Merge pull request #77331 from aschwaighofer/large_types_reg2mem_aggressive
LargeTypesReg2Mem: Add a new heuristic that trys harder to keep large     values on the stack
2024-11-01 06:15:18 -07:00
Arnold Schwaighofer
787c996394 LargeTypesReg2Mem: Add a new heuristic that trys harder to keep large
values on the stack

This heuristic can be enabled by passing -Xfrontend
-enable-aggressive-reg2mem.

rdar://123916109
2024-10-31 13:22:06 -07:00
Arnold Schwaighofer
3ab4484145 SILOptimizer: Add destructure peepholes
```
 (%7, ...) = destructure_tuple %6 : $(A, ...)
 tuple_addr_constructor [assign] %9 : $*(A, ...) with (%7 : $A, ...)
   =>
 store [assign] %6 to %9
```

and

```
 (tuple (destructure_tuple %t))
  => %t
```
2024-10-31 09:47:27 -07:00
Michael Gottesman
c3d445831b [region-isolation] Fix an off by one error when mapping AST capture indices to SIL level parameter indices.
This problem comes up with the following example:

```swift
class A {
    var description = ""
}

class B {
    let a = A()

    func b() {
        let asdf = ""
        Task { @MainActor in
            a.description = asdf // Sending 'asdf' risks causing data races
        }
    }
}
```

The specific issue is that the closure we generate actually includes an
implicit(any) parameter at the SIL level which occurs after the callee operand
but before the captures. This caused the captured variable index from the AST
and the one we compute from the partial_apply to differ by 1. So we need to
subtract 1 in such a case. That is why we used to print 'asdf' instead of 'a'
above.

DISCUSSION: This shows an interesting difference between SIL applied arg indices
and AST indices. SIL applied arg indices would include the implicit(any)
parameter since it is a parameter in the SIL function type. In contrast, this
doesn't show up in the formal AST parameters or captures. To make it easier to
reason about this, I added a new API to ApplySite called
ApplySite::getASTAppliedArgIndex and added large comments to
getASTAppliedArgIndex and getAppliedArgIndex that explains the issue.

rdar://136593706
https://github.com/swiftlang/swift/issues/76648
2024-10-30 18:32:45 -07:00
John McCall
db157c94ef Strengthen verification of the operand of hop_to_executor and extract_executor. 2024-10-30 14:41:50 -07:00
Michael Gottesman
2b6b98d767 Merge pull request #77238 from gottesmm/region_isolation_refactoring
[region-isolation] Refactor code so that I can more easily add additional error kinds
2024-10-25 22:13:43 -07:00
Michael Gottesman
df24fc41ce [region-isolation] Convert AssignIsolatedIntoSendingResult to be emitted as a verbatim error. 2024-10-24 16:27:21 -07:00