Commit Graph

1084 Commits

Author SHA1 Message Date
Andrew Trick
581010d00c SIL: Make drop_deinit a ForwardingInstruction.
drop_deinit forwards ownership while effectively stripping the deinitializer. It is similar to a type cast.

Fixes rdar://125590074 ([NonescapableTypes] Nonescapable types
cannot have deinits)
2024-04-03 18:53:18 -07:00
Andrew Trick
bac1dc9699 Cleanup LifetimeDependenceUtils comments. 2024-04-03 10:46:09 -07:00
Andrew Trick
fbae21ff21 LifetimeDependence: handle dependent values in throwing calls.
Fixes rdar://125564278 (~Escapable: crash in LifetimeDependenceInsertion)
2024-04-03 10:46:09 -07:00
Andrew Trick
89063c93e4 Add Value.definingInstructionOrTerminator 2024-04-03 10:46:09 -07:00
Andrew Trick
1b6be740e8 Fix LifetimeDependenceDefUseWalker for address yields.
Do not treat address yields as escapes.

Fixes rdar://125752476 (`UnsafeRawPointer` property in non-escapable type doesn't compile)
2024-04-01 22:16:45 -07:00
Andrew Trick
6fcec2ff96 SwiftCompilerSources: organize parameter pack instructions 2024-04-01 21:46:18 -07:00
Andrew Trick
66dcf6a35c SwiftCompilerSources: fix PackElementSetInst
It is not a SingleValueInstruction.
2024-04-01 21:46:10 -07:00
Andrew Trick
a1bb9f401a Fix SILVerifier and AddressUtils handling of addr casts.
These core utils did not handle UnconditionalCheckedCastAddrInst or
UncheckedRefCastAddrInst correctly.
2024-04-01 21:46:10 -07:00
Andrew Trick
f19d94ce3f Always-enable lifetime-depenence diagnostics.
-enable-experimental-feature NonescapableTypes now only controls syntax and some type inferrence features.
2024-03-27 13:57:11 -07:00
Andrew Trick
36b9ed4f9b Fix LifetimeDependenceDiagnostics to ignore closure captures
ClosureLifetimeFixup now emits mark_dependence [nonescaping]. Those should be
ignored by diagnostics. In the capture case, the dependence has already been
resolved, and may not match the SIL patterns that we expect for source-level
lifetime dependencies.

Fixes rdar://125375685 ([nonescapable] Fix lifetime-dependence diagnostics in the stdlib)
2024-03-27 13:54:27 -07:00
Mayank Kumar Gupta
3093925aa0 [Minor][SIL] Refactor matches function in Effects 2024-03-26 00:22:07 +05:30
Kuba (Brecka) Mracek
89cd62604b Merge pull request #72472 from kubamracek/embedded-keypaths
[embedded] Compile-time (literal) KeyPaths for Embedded Swift
2024-03-25 10:58:51 -07:00
Andrew Trick
d7b9149ee5 Fix visitNonEscapingLifetimeEnds to handle mark_dependence uses
Now it visits unknown uses separately rather than asserting.
2024-03-22 14:29:57 -07:00
Andrew Trick
a0b2ae9c2c Add AccessBase.storeBorrow.
Don't treat StoreBorrow addresses as unknown bases. While they are never the base of a formal access, they are returned
as the AccessBase when querying the enclosing scope of an address.
2024-03-22 11:51:58 -07:00
Andrew Trick
f037b635fb LifetimeDependenceUtils: cleanup Scope initialization.
And fix a couple latent bugs.
2024-03-22 11:51:58 -07:00
Andrew Trick
08be9aebf2 LifetimeDependence cleanup logging 2024-03-22 11:51:58 -07:00
Kuba Mracek
796554f55d [embedded] Respect ownership in SimplifyKeyPath, emit destroy_value instructions for keypath operands 2024-03-21 17:54:05 -07:00
Erik Eckstein
367dc1a299 SwiftCompilerSources: add OperandSet and OperandWorklist
Implemented by bridging the C++ OperandSet, similar to BasicBlockSet and NodeSet
2024-03-21 15:52:39 +01:00
Kuba Mracek
b642d771be [embedded] Compile-time (literal) KeyPaths for Embedded Swift
Enable KeyPath/AnyKeyPath/PartialKeyPath/WritableKeyPath in Embedded Swift, but
for compile-time use only:

- Add keypath optimizations into the mandatory optimizations pipeline
- Allow keypath optimizations to look through begin_borrow, to make them work
  even in OSSA.
- If a use of a KeyPath doesn't optimize away, diagnose in PerformanceDiagnostics
- Make UnsafePointer.pointer(to:) transparent to allow the keypath optimization
  to happen in the callers of UnsafePointer.pointer(to:).
2024-03-20 15:35:46 -07:00
Andrew Trick
7da493498a Merge pull request #72407 from atrick/pointer-escape-bailout
Fix lifetime dependence in the presence of pointer escapes.
2024-03-19 11:40:38 -07:00
Erik Eckstein
1d4054ca32 Optimizer: add simplification for checked_cast_addr_br instructions 2024-03-19 11:58:15 +01:00
Erik Eckstein
d34dec835c SimplifyBuiltin: use dynamic cast utilities in folding metatype comparisons 2024-03-19 11:58:15 +01:00
Erik Eckstein
308b5f9ff7 Swift Optimizer: add bridging for dynamic cast utilities
* `func canDynamicallyCast`
* `var CheckedCastAddrBranchInst.dynamicCastResult`
2024-03-19 10:54:38 +01:00
Erik Eckstein
6bb5ad6230 Swift SIL: complete APIs for CheckedCastAddrBranchInst 2024-03-19 09:02:06 +01:00
Andrew Trick
3e7d9dba71 AddressUseVisitor: follow mark_dependence [nonescaping].
Treat mark_dependence [nonescaping] as a dependent value even if the dependence base does not have a recognizable
scope (e.g. a multiply-defined alloc_stack). This happens because ClosureLifetimeFixup creates redundant mark_dependence
instructions for partial_apply captures. We constantly need to work around this broken representation of nonescaping closures.
2024-03-18 17:45:33 -07:00
Andrew Trick
e77fff3d23 LocalVariableUtils logging 2024-03-18 17:45:33 -07:00
Andrew Trick
f1fbbcd438 Handle escaping addresses in LocalVariableAccessWalker
Fixes rdar://124564951 (Compiler crash when evaluating pointer escape
in autoclosure; LifetimeDepenenceScopeFixup; Fatal error: check
findPointerEscape() before computing interior liveness.)
2024-03-18 17:45:33 -07:00
Andrew Trick
73e28df4be ForwardingUtils logging 2024-03-18 17:45:33 -07:00
Andrew Trick
00fbf4f1af LocalVariableUtils logging 2024-03-18 17:45:33 -07:00
Andrew Trick
352724ea0d LifetimeDependenceScopeFixup logging 2024-03-18 17:45:33 -07:00
Andrew Trick
b7eaee9448 Disable verbose LifetimeDependenceUtils 2024-03-18 17:45:28 -07:00
Andrew Trick
009bc58045 Disable verbose AddressUtils 2024-03-18 17:45:28 -07:00
Andrew Trick
ff14633532 Handle ConvertEscapeToNoEscapeInst in NonEscapingClosureDefUseWalker 2024-03-18 17:38:12 -07:00
Andrew Trick
5e9e282b62 LifetimeDependenceUtils comment clarification and cleanup. 2024-03-18 17:38:12 -07:00
Andrew Trick
95a100a9c0 Add a comment in LifetimeDependenceUseDefWalker. 2024-03-18 17:38:12 -07:00
Andrew Trick
bdabc2145a Add computeKnownLiveness utility
To fix LifetimeDependenceScopeFixup in the presense of pointer escapes.
2024-03-18 17:38:12 -07:00
Andrew Trick
aa208bbf91 Add SILType::containsNoEscapeFunction()
Add PartialApplyInst.hasNoescapeCapture
Add PartialApplyInst.mayEscape

Refactor DiagnoseInvalidEscapingCaptures. This may change functionality because tuples containing a noescape closure are now correctly recognized. Although I'm not sure such tupes can ever be captured directly.
2024-03-18 17:38:12 -07:00
Andrew Trick
6b3d62cb5e SwiftCompilerSources: Add append methods to SingleInlineArray. 2024-03-18 17:38:12 -07:00
Kuba Mracek
f5797941b7 [embedded] Specialize superclasses in VTableSpecializer as part of MandatoryPerformanceOptimizations 2024-03-15 21:30:08 -07:00
Nate Chandler
8ed11e1788 [SIL] Expose alloc_stack flag to Swift sources.
Code in SwiftCompilerSources should be able to create an `alloc_stack`
with the `var_decl` flag.
2024-03-11 21:15:58 -07:00
Erik Eckstein
c5c2688633 InitializeStaticGlobals: don't merge stores for structs with unreferencable storage
like C bitfields.

Fixes a compiler crash
rdar://122360051
2024-03-08 11:14:48 +01:00
Andrew Trick
3364648f2b Merge pull request #72148 from atrick/enable-lifetime-diagnostics
Enable lifetime dependence diagnostics for Nonescapable types.
2024-03-07 18:54:33 -08:00
John McCall
8499640224 Merge pull request #72143 from rjmccall/builtin-create-task
Unify and simplify the task-creation builtins
2024-03-07 21:45:06 -05:00
Andrew Trick
8419cc599f Guard LifetimeDependenceScopeFixup under experimental NonescapableTypes
Out of paranoia, don't even try to run this path unless we see
-enable-experimental-feature NonescapableTypes.
2024-03-07 15:13:50 -08:00
Andrew Trick
df7326d790 Fix SILType::isEscapable for box types.
SILBoxTypes have their own generic signature and substitution
map. This means that every time we query isEscapable or mayEscape, we
need to extract the type of the box's field and perform type
substitution so that the AST query only sees types from the function's
generic environment.

Fixes rdar://124179106 (Assertion failed in SIL:
(!type->hasTypeParameter() && "caller forgot to mapTypeIntoContext!"))
2024-03-07 13:34:46 -08:00
John McCall
0a282c044f Unify all of the task-creation builtins coming out of SILGen.
We've been building up this exponential explosion of task-creation
builtins because it's not currently possible to overload builtins.
As long as all of the operands are scalar, though, it's pretty easy
to peephole optional injections in IRGen, which means we can at
least just use a single builtin in SIL and then break it apart in
IRGen to decide which options to set.

I also eliminated the metadata argument, which can easily be recreated
from the substitutions.  I also added proper verification for the builtin,
which required (1) getting `@Sendable` right more consistently and (2)
updating a bunch of tests checking for things that are not actually
valid, like passing a function that returns an Int directly.
2024-03-06 22:21:12 -05:00
eeckstein
d1ec089c72 Merge pull request #72088 from language-core/main
chore: fix some comments
2024-03-06 10:08:50 +01:00
Andrew Trick
31b3a91912 Merge pull request #71703 from atrick/lifetime-extend
LifetimeDependenceScopeFixup: fix handling of returned dependence
2024-03-05 23:17:21 -08:00
Andrew Trick
3bee32639b LifetimeDependenceDefUseWalker: use LocalVariableReachableUses. 2024-03-05 18:08:16 -08:00
Andrew Trick
ffe9c48976 Add LocalVariableUtils
This includes a reaching-def analysis that can be used by diagnostic passes. Diagnostics should be flow-sensitive.
2024-03-05 18:08:16 -08:00