Commit Graph

11193 Commits

Author SHA1 Message Date
Meghana Gupta
4c46faad26 Fix mem2reg for load_borrows with reborrows
StackAllocationPromoter::pruneAllocStackUsage substitutes loads/stores of alloc_stack
with values. For some reason isLoadFromStack was bailing out for load_borrows with
reborrows leaving them to be fixed up by fixBranchesAndUses which uses live in value
from predecessors for substitution which is obviosly incorrect the block containing
the load_borrow has a store before it.

Fixes rdar://145834542
2025-03-04 10:18:08 -08:00
Susana Monteiro
593f320460 Merge pull request #79325 from swiftlang/susmonteiro/copy-constructor-default-args
[cxx-interop] Prevent usage in Swift of C++ copy constructor with default args
2025-03-04 15:40:22 +00:00
Gábor Horváth
c91e295234 Merge pull request #79576 from swiftlang/gaborh/fix-consume-calling-conv
[cxx-interop] Fix calling convention for rvalue reference params
2025-03-04 02:31:49 -08:00
Meghana Gupta
cf6c4c9422 Merge pull request #79699 from meg-gupta/prboundscheck
Add support for bounds check optimization of Span and InlineArray
2025-03-03 14:32:27 -08:00
susmonteiro
bc6573ec32 [cxx-interop] Prevent usage in Swift of C++ copy constructor with default args 2025-03-03 13:22:11 +00:00
Gabor Horvath
00fa738209 [cxx-interop] Fix calling convention for rvalue reference params
In C++, we always expected to invoke the dtor for moved-from objects.
This is not the case for swift. Fortunately, @inCxx calling convention
is already expressing that the caller supposed to destroy the object.
This fixes the missing dtor calls when calling C++ functions taking
rvalue references. Fixes #77894.

rdar://140786022
2025-03-03 11:47:12 +00:00
Andrew Trick
19c8bd625f Add FIXMEs for calls to liveness that fail to check pointer escapes. 2025-03-02 23:51:34 -08:00
Andrew Trick
727aed3a86 Fix ClosureLifetimeFixup to handle pointer escapes.
Fix insertDeallocOfCapturedArguments to conservatively sink deallocs over
pointer escapes.
2025-03-02 23:51:34 -08:00
Andrew Trick
7760dbc983 Fix ClosureLifetimeFixup handling of incomplete liveness.
Correctly handle pointer escapes and dependent uses to avoid miscompiles.
2025-03-02 23:51:34 -08:00
Meghana Gupta
2b072a56c1 Allow duplicating mark_dependence [nonescaping] on addresses 2025-02-28 17:11:59 -08:00
Meghana Gupta
26277c8363 Add support for bounds check optimization of Span and InlineArray 2025-02-28 17:11:52 -08:00
Pavel Yaskevich
4e51155f64 Merge pull request #78995 from jamieQ/DI-add-stats
[NFC]: add a FrontendStatsTracer for definite init
2025-02-28 16:05:35 -08:00
Meghana Gupta
6908e9b776 Annotate some Span and InlineArray's methods with semantics 2025-02-28 09:52:00 -08:00
Meghana Gupta
3fe1029ef8 [NFC] Reorganize and rename ArrayBoundsCheckOpts.cpp 2025-02-28 09:50:58 -08:00
Slava Pestov
d8a1649722 Merge pull request #79666 from slavapestov/fix-rdar144644342
Sema: Fix Sendable generic parameter fixit
2025-02-27 18:37:50 -05:00
nate-chandler
39acb9ac8a Merge pull request #79521 from nate-chandler/rdar145154549
[OSSACanonicalizeOwned] Dead-end extend base lifetime.
2025-02-27 14:36:43 -08:00
Slava Pestov
74222a62b8 Merge pull request #79659 from slavapestov/pointless-predicate
AST: Remove TypeBase::isOpenedExistential()
2025-02-27 14:46:18 -05:00
Meghana Gupta
b7952284eb Merge pull request #79644 from meg-gupta/arraypropoptfix
Fix hoisting array semantics call with non-dominant self in ossa
2025-02-27 10:40:23 -08:00
Slava Pestov
e37a2d065d Sema: Fix Sendable generic parameter fixit
Fixes rdar://problem/144644342.
2025-02-27 13:15:13 -05:00
Nate Chandler
8e7dae560d [OSSACanOwned] Bail on escaping inner pointers.
If there is a pointer escape, we cannot safely rewrite its lifetime.
2025-02-27 07:20:27 -08:00
Nate Chandler
f1bc3b5205 [OSSACanOwned] Dead-end extend base lifetime.
Regardless of consumes of copies, if the original lexical value is not
consumed on a dead-end path, it must remain live to that dead-end.

rdar://145226757
2025-02-27 07:20:27 -08:00
Nate Chandler
5ffe092fa5 [OSSACanOwned] Extend all lifetimes to dead-ends.
Uses of borrows may occur between the borrow and a dead-end regardless
of lexicality, so always extend lifetimes to dead-ends.
2025-02-27 07:20:25 -08:00
Slava Pestov
541757a491 AST: Remove TypeBase::isOpenedExistential()
At one point, OpenedArchetypeType did not exist as a separate subclass
of ArchetypeType, so this method did something. Now, it's just
equivalent to calling is<> or isa<>.

I also removed a couple of asserts that were obvious no-ops as a result.
2025-02-27 09:55:36 -05:00
Meghana Gupta
199482a623 Fix hoisting array semantics call with non-dominant self
If we have a self value that does not dominate loop preheader,
and the array semantics call does not consume the self value,
that means there will be instructions that consume the self value
with the loop.

In ossa, we cannot hoist such semantic calls because there is no
support for creating destroys for them in the preheader.
Add a bailout to avoid the ownership error.

rdar://145673368
2025-02-26 12:11:59 -08:00
Andrew Trick
b3a445fb55 Fix BorrowingOperand::getBorrowIntroducingUserResult()
To handle borrowing operands that produce a dependence value but do not create a
nested borrow scope. This includes non-reborrow borrowed-from and guaranteed
mark_dependence [nonescaping].
2025-02-25 23:08:54 -08:00
Andrew Trick
f1792d80b3 Fix BorrowingOperand.visitScopeEndingUses
Only return false if the visitor returns false. Clients were ignoring the
result.

If the BorrowingOperand does not create a borrow scope, call visitUnknownUse
instead.

Until we have complete lifetimes, to avoid breaking code that cannot handle dead
defs, consider a dead borrow scope to be an unknown use.
2025-02-25 23:08:54 -08:00
Michael Gottesman
f01d27514d [rbi] Convert an assert to an if check.
This also fixes a case where we would have inferred the wrong isolation (which
the assert caught). I think we missed this since it only comes up with final
classes.

rdar://142568522
2025-02-25 13:39:09 -08:00
Michael Gottesman
929891807c Merge pull request #79611 from gottesmm/pr-1af1f4e53db03b01babcd0470c532fe00f6a7a11
[rbi] Respect nonisolated(unsafe) when assigning or merging into a sending out parameter.
2025-02-25 13:35:23 -08:00
eeckstein
d9489d7757 Merge pull request #79604 from eeckstein/fix-licm
LICM: fix handling of stores of Optional.none in OSSA
2025-02-25 22:13:43 +01:00
Michael Gottesman
dab324080b [rbi] Make convert_escape_to_no_escape and convert_function lookthrough if their result/operand is non-Sendable.
In these cases, we want to lookthrough so we propagate through
nonisolated(unsafe) and make it easier to discover that we are processing
keypaths (the reason I am making this change).
2025-02-25 08:39:39 -08:00
Dario Rexin
f5dd557307 Merge pull request #79506 from drexin/wip-145095088
[SILOptimizer] Don't apply CMO to key paths that reference inaccessib…
2025-02-25 07:08:52 -08:00
Erik Eckstein
bfdeb57863 LICM: fix handling of stores of Optional.none in OSSA
Currently we don't support hoisting ownership instructions.
But the check was missing a store of Optional.none because such a value has no ownership even if the optional is not trivial.

Fixes a SIL verifier crash.
https://github.com/swiftlang/swift/issues/79491
2025-02-25 09:34:59 +01:00
Dario Rexin
bde7daa2f2 [SILOptimizer] Don't apply CMO to key paths that reference inaccessible properties
rdar://145095088
2025-02-24 23:07:18 -08:00
Anton Korobeynikov
4310507d35 Ensure we're commuting instructions only when internal one has a single
use. Fix couple of similar single use predicates while there.

Fixes #78848
2025-02-24 13:59:31 -08:00
Michael Gottesman
b286373631 [rbi] Make a confusing comment clearer.
From talking with @dgregor, it became clear that this comment was easily
interpreted as saying that AssignFresh always introduced a disconnected value...
which is not the case. Instead, AssignFresh just introduces a new value that
could have any form of isolation. The actual isolation of the value is assigned
via tryToTrackValue and eventually SILIsolationInfo::get().
2025-02-24 10:09:32 -08:00
Meghana Gupta
653925bff0 Merge pull request #79476 from meg-gupta/lrfix
Fix loop rotate when header has instructions producing ownership results
2025-02-20 11:03:31 -08:00
Daniil Kovalev
83a028d105 [AutoDiff] Allow closure differentiation when used as default arg val (#78373)
If the default argument generator (and, consequently, the function taking this default argument) has public visibility, it's OK to have a closure (which always has private visibility) as the default value of the argument.
2025-02-19 22:34:56 -08:00
eeckstein
06042c1cba Merge pull request #79483 from eeckstein/fix-temp-lvalue-opt
TempLValueOpt: avoid creating invalid apply argument aliasing.
2025-02-20 06:55:33 +01:00
eeckstein
ee360e0854 Merge pull request #79484 from eeckstein/fix-simplify-cfg
SimplifyCFG: remove all borrowed-from uses from arguments when merging blocks
2025-02-20 06:55:09 +01:00
eeckstein
3aae44dbef Merge pull request #79482 from eeckstein/fix-const-expr
ConstExpr: fix handling of store_borrow
2025-02-20 06:53:50 +01:00
Michael Gottesman
dcba66f646 Merge pull request #79502 from gottesmm/pr-0157e2d0f6c260a7cd233938fd987b1ada6a30da
[rbi] Fix a thinko where while finding closure uses, I was not checking if functions had a body when looking for arguments.
2025-02-19 21:13:21 -08:00
Konrad `ktoso` Malawski
e8668684a1 Merge pull request #79411 from amartini51/typo_144059094
Remove double word ("a a" and "the the")
2025-02-20 13:05:06 +09:00
Michael Gottesman
8f952d2f3d [rbi] Fix a thinko where while finding closure uses, I was not checking if functions had a body when looking for arguments.
rdar://145089562
2025-02-19 14:45:09 -08:00
Meghana Gupta
4561658799 Avoid creating unoptimizable copies in CSE
CSE uses OSSA rauw which creates copies and copies that are created to optimize
across borrow scopes are unoptimizable. This PR avoids this situation for now.
2025-02-19 11:20:43 -08:00
Erik Eckstein
328e6aad07 ConstExpr: fix handling of store_borrow
The `store_borrow` instruction has a result and that must be set.
Fixes a false error of the OSLogOptimization.
rdar://144896232
2025-02-19 13:30:07 +01:00
Erik Eckstein
5ef3b96da2 SimplifyCFG: remove all borrowed-from uses from arguments when merging blocks
So far we only considered the forwarding use. But there may be other uses.

Fixes a compiler crash.
rdar://145091197
2025-02-19 13:25:48 +01:00
Erik Eckstein
f0b7bdb382 TempLValueOpt: avoid creating invalid apply argument aliasing.
An indirect argument (except `@inout_aliasable`) must not alias with another indirect argument.
Now, if we would replace tempAddr with destAddr in
```
  apply %f(%tempAddr, %destAddr) : (@in T) -> @out T
```
we would invalidate this rule.
This is even true if the called function does not read from destAddr.

Fixes a SIL verification error.
rdar://145090659
2025-02-19 10:33:18 +01:00
Meghana Gupta
03038d201e Fix loop rotate when header has instructions producing ownership results
rdar://145086395
2025-02-18 14:42:28 -08:00
Daniil Kovalev
1a42a0ce5f [AutoDiff] Support curry thunks differentiation in fragile funcs (#77615)
Inside fragile functions, we expect function derivatives to be public, which could be achieved by either explicitly marking the functions as differentiable or having a public explicit derivative defined for them. This is obviously not
possible for single and double curry thunks which are a special case of `AutoClosureExpr`.

Instead of looking at the thunk itself, we unwrap it and look at the function being wrapped. While the thunk itself and its differentiability witness will not have public visibility, it's not an issue for the case where the function being wrapped (and its witness) have public visibility.

Fixes #54819
Fixes #75776
2025-02-17 14:43:50 -08:00
Jamie
10b37530e5 [NFC]: add a FrontendStatsTracer for definite init 2025-02-15 10:41:04 -06:00