Commit Graph

11224 Commits

Author SHA1 Message Date
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
Doug Gregor
c6eb33b6f1 Merge pull request #79408 from DougGregor/region-isolation-metatype-extraction
Correct the region isolation rule for metatype extraction instructions
2025-02-14 21:49:13 -08:00
Alex Martini
633f101e0a Fix double 'the the' in various places 2025-02-14 17:27:51 -08:00
Doug Gregor
a32470f14a Correct the region isolation rule for metatype extraction instructions
Now that metatypes might not be Sendable, we need the Assign rule for
operations that produce the metatype of a value or existential.
2025-02-14 15:33:57 -08:00
eeckstein
484a4da4b6 Merge pull request #79388 from eeckstein/fix-analysis-invalidation
PassManager: invalidate analysis if a pass forgot to do so.
2025-02-14 13:05:51 +01:00
Doug Gregor
2989770cd6 Merge pull request #79352 from DougGregor/strict-sendable-metatypes
Add StrictSendableMetatypes to require Sendable requirements on metatypes
2025-02-14 03:40:36 -08:00
Erik Eckstein
9b143d876b PassManager: invalidate analysis if a pass forgot to do so.
If a pass forgot to call invalidateAnalysis but deleted some instructions, the pass-manager can fix this.

Currently following passes do not invalidate analysis when they change the SIL:
* LowerTupleAddrConstructor
* DestroyAddrHoisting
* MoveOnlyChecker
* PredictableDeadAllocationElimination

Ideally we should fix those passes. But with this addition in the pass-manager it's not strictly necessary.

Fixes a compiler crash.
2025-02-14 08:08:43 +01:00
Meghana Gupta
cf22bced31 Merge pull request #79315 from meg-gupta/typevaluecse
Add CSE support for type_value instruction and add a few bounds check tests for InlineArray
2025-02-13 20:54:26 -08:00
Meghana Gupta
a31a603e49 Handle type_value instruction in CSE 2025-02-13 10:30:25 -08:00
Erik Eckstein
af5ac6d283 Re-instate the allocVector builtin
Although it's not used anymore we still have to support it to be able to read old Swift.interface files which still contain the builtin.

rdar://144781646
2025-02-13 17:55:27 +01:00
Erik Eckstein
6af5876f72 PerformanceInliner: add the @_semantics("optimize.sil.inline.aggressive") attribute to enable inlining into large functions.
This attribute overrides the limit of maximum number of basic blocks in the caller.
2025-02-13 07:40:24 +01:00
Erik Eckstein
3136218a64 PerformanceInliner: allow inlining of small functions even if the caller block limit is exceeded
This can fix performance problems in large functions.

rdar://141320229
2025-02-13 07:30:44 +01:00
Doug Gregor
37d71f362e Add StrictSendableMetatypes to require Sendable requirements on metatypes
Introduce a new experimental feature StrictSendableMetatypes that stops
treating all metatypes as `Sendable`. Instead, metatypes of generic
parameters and existentials are only considered Sendable if their
corresponding instance types are guaranteed to be Sendable.

Start with enforcing this property within region isolation. Track
metatype creation instructions and put them in the task's isolation
domain, so that transferring them into another isolation domain
produces a diagnostic. As an example:

    func f<T: P>(_: T.Type) {
      let x: P.Type = T.self
      Task.detached {
        x.someStaticMethod() // oops, T.Type is not Sendable
      }
    }
2025-02-12 20:21:57 -08:00
Erik Eckstein
e0b4f71af6 SIL: remove the alloc_vector instruction
It's not needed anymore, because the "FixedArray" experimental feature is replaced by inline-arrays.
2025-02-12 10:51:14 +01:00
Erik Eckstein
6407f9a0bd remove the allocVector builtin
It's not needed anymore, because the "FixedArray" experimental feature is replaced by inline-arrays.
2025-02-12 10:51:14 +01:00
Erik Eckstein
83aaccc188 remove the "array.copy_into_vector" array-semantic
It's not needed anymore, because the "FixedArray" experimental feature is replaced by inline-arrays.
2025-02-12 10:51:14 +01:00
Erik Eckstein
5b93eb31bf Optimizer: remove the AllocVectorLowering pass
It's not needed anymore, because the "FixedArray" experimental feature is replaced by inline-arrays.
2025-02-12 10:51:14 +01:00
eeckstein
aa0833b0b3 Merge pull request #79110 from eeckstein/verify_mark_dependence
SIL: Fix memory behavior of mark_dependence
2025-02-11 06:39:43 +01:00
Arnold Schwaighofer
ed32270d72 Merge pull request #79191 from aschwaighofer/access_enforcement_fixes
AccessEnforcement: Fix analysis to include mayReleases as potentially executing unknown code
2025-02-10 16:57:31 -08:00
Erik Eckstein
d918b316c9 TempRValueOptimization: don't optimize copies to mark_dependence base values.
We want to keep the original lifetime of the base. If we would eliminate the base alloc_stack, we risk to insert a destroy_addr too early.
2025-02-10 17:57:47 +01:00