Commit Graph

186 Commits

Author SHA1 Message Date
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
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
6bb5ad6230 Swift SIL: complete APIs for CheckedCastAddrBranchInst 2024-03-19 09:02:06 +01: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
28c1fdb96f SwiftCompilerSources: Add Instruction.endInstruction
To make the ScopedInstruction abstraction useful and formalize to use-points of scoped operations.

This is specifically for scoped operations that use their operands up to the end of their scope.

This is not for the many instructions that introduce scoped lifetimes. Allocations are not considered scoped
operations. Every owned value has a scoped lifetime just like an allocation, but the scope-ending instructions are not
considered use points.
2024-03-05 17:08:13 -08:00
Andrew Trick
0752ea5824 Add OwnershipTransitionInstruction.
These instructions carry lifetime dependence from a single operand to a single result. They are not forwarding
instructions because we use them to indicate the boundaries of a forwarded lifetime.
2024-02-26 00:12:07 -08:00
Andrew Trick
d7205edd70 Code formatting cleanup related to CopyingInstruction 2024-02-26 00:12:07 -08:00
Andrew Trick
0b81392dff Code formatting cleanup related to ForwardingInstruction. 2024-02-25 10:29:15 -08:00
Andrew Trick
a3cbc28078 SwiftCompilerSources: Add enum BeginAccess.AccessKind
So we can switch over it.
2024-02-25 10:22:06 -08:00
Erik Eckstein
c805f6cbd8 SwiftCompilerSources: refactor and fix forwarding instructions
* add ForwardingInstruction conformances to missing forwarding instruction classes
* move all the forwarding instruction conformance definitions into ForwardingInstructions.swift
* remove the default implementations of the requirements, so that every instruction needs to specify them
2024-02-22 07:12:11 +01:00
Erik Eckstein
68cc6c8780 SwiftCompilerSources: add all missing instruction classes
And require that all new instructions must be added and registered in SwiftCompilerSources as well.
2024-02-22 07:12:10 +01:00
Erik Eckstein
aadb0598c9 SIL: remove the var operands requirement from UnaryInstruction
It's not needed because UnaryInstruction is "derived" from Instruction which has this property.
2024-02-22 07:12:10 +01:00
Andrew Trick
d0ac09493a Bridge MarkDependence.resolveToNonEscaping 2024-02-12 09:57:14 -08:00
Andrew Trick
79fe8bad30 SwiftCompilerSources: improve MarkDependenceInst. 2024-02-12 09:57:14 -08:00
Andrew Trick
da3f583492 Add mark_dependence [unresolved]
In preparation for inserting mark_dependence instructions for lifetime
dependencies early, immediately after SILGen. That will simplify the
implementation of borrowed arguments.

Marking them unresolved is needed to make OSSA verification
conservative until lifetime dependence diagnostics runs.
2024-02-08 22:53:16 -08:00
Erik Eckstein
fa0be3c10f SwiftCompilerSources: bridge some SIL APIs
* `TryApplyInst.specializationInfo`
* `BasicBlock.addFunctionArgument`
* `Function.appendNewBlock`
2024-01-31 17:16:12 +01:00
Erik Eckstein
7a62f15dae pass Context: verify that only the currently transformed function is modified 2024-01-31 17:16:12 +01:00
Andrew Trick
4796e55256 SwiftCompilerSources CopyingInstruction
And UnmanagedRetain/Release.
2024-01-30 08:38:57 -08:00
Andrew Trick
9950784adb SwiftCompilerSources API for SourceDestAddrInstructions. 2024-01-30 08:38:57 -08:00
Arnold Schwaighofer
edd7eaa0d7 OSLog: os_log strings should be in the __oslogstring section on machO
rdar://121384422
2024-01-26 08:30:56 -08:00
Andrew Trick
d9a8a0eb60 Added SourceDestAddrInstruction 2024-01-22 23:42:54 -08:00
Andrew Trick
e7a3ceb0d5 SwiftCompilerSources: add VarDecl.sourceLoc 2024-01-22 08:29:07 -08:00
Andrew Trick
a80686b485 [SIL] bridge MoveValue and BeginBorrow .isFromVarDecl 2024-01-22 08:29:07 -08:00
Andrew Trick
d8b901052a Add Swift SIL instructions needed by AddressUseVisitor 2024-01-17 08:37:14 -08:00
Erik Eckstein
bc99986cf9 SIL: add a dependency token operand to global_addr
Optionally, the dependency to the initialization of the global can be specified with a dependency token `depends_on <token>`.
This is usually a `builtin "once"` which calls the initializer for the global variable.
2024-01-10 09:33:58 +01:00
nate-chandler
7365f9f36b Merge pull request #70774 from nate-chandler/nfc/20240108/1/deinit-barrier-component-predicates
[NFC] SIL: Clarified deinit barrier APIs.
2024-01-08 23:11:38 -08:00
Nate Chandler
77fd37be99 [NFC] SIL: Renamed maySynchronize.
Dropped the NotConsideringSideEffects suffix.
2024-01-08 13:35:20 -08:00
Andrew Trick
264cbaea42 Add mark_dependence [nonescaping] flag.
The dependent 'value' may be marked 'nonescaping', which guarantees that the
lifetime dependence is statically enforceable. In this case, the compiler
must be able to follow all values forwarded from the dependent 'value', and
recognize all final (non-forwarded, non-escaping) use points. This implies
that `findPointerEscape` is false. A diagnostic pass checks that the
incoming SIL to verify that these use points are all initially within the
'base' lifetime. Regular 'mark_dependence' semantics ensure that
optimizations cannot violate the lifetime dependence after diagnostics.
2024-01-04 14:47:35 -08:00
Andrew Trick
2128c21106 Migrate SwiftCompilerSources to FunctionConvention.
Layers:
- FunctionConvention: AST FunctionType: results, parameters
- ArgumentConventions: SIL function arguments
- ApplyOperandConventions: applied operands

The meaning of an integer index is determined by the collection
type. All the mapping between the various indices (results,
parameters, SIL argument, applied arguments) is restricted to the
collection type that owns that mapping. Remove the concept of a
"caller argument index".
2024-01-03 12:24:50 -08:00
Andrew Trick
7dc3d72483 Merge pull request #70485 from atrick/bridge-util
[NFC] Bridging and utilities for SwiftCompilerSources required by lifetime dependence utilities.
2023-12-19 13:07:45 -08:00
Andrew Trick
2a9aef9eb8 [SIL] add BeginApplyInst.token 2023-12-19 02:05:16 -08:00
Andrew Trick
b637f06acd [SIL] Bridge findPointerEscape() and fix OnoneSimplifyable
Do not bridge the hasPointerEscape flag until it is implemented.
2023-12-18 09:16:55 -08:00
Erik Eckstein
84e06322b9 SwiftCompilerSources: bridge_object_to_word is not a ForwardingInstruction
Fix this mismatch between C++ SIL and swift SIL.
Fixes a crash in begin_borrow simplification
Also add an assert to catch such cases.

rdar://119763595
2023-12-18 11:08:22 +01:00
Erik Eckstein
e652f2c92e SIL: add the alloc_vector and vector instructions
* `alloc_vector`: allocates an uninitialized vector of elements on the stack or in a statically initialized global
* `vector`: creates an initialized vector in a statically initialized global
2023-12-09 18:49:55 +01:00
Erik Eckstein
6aaf2005d3 SwiftCompilerSources: remove the BeginBorrowInst.endBorrows API
Using this API almost certainly indicates a bug, because it neglects re-borrows.
2023-11-27 16:20:47 +01:00
Erik Eckstein
e4d227a5fb SwiftCompilerSources: add StoreBorrowInst and BorrowIntroducingInstruction
`BorrowIntroducingInstruction` is a protocol to which all instructions conform which start a borrow-scope which must be ended by `EndBorrowInst` instructions: `begin_borrow`, `load_borrow` and `store_borrow`
2023-11-27 16:20:47 +01:00
Erik Eckstein
37c715c58c SwiftCompilerSources: add EndLifetimeInst 2023-11-27 09:21:33 +01:00
Erik Eckstein
3bfabf6e8a SimplifyBeginBorrow: don't remove begin_borrow instructions which have the [point_escape] flag set. 2023-11-14 12:26:23 +01:00
Erik Eckstein
95c83e9899 Swift SIL: add BeginBorrowInst.isLexical 2023-11-13 20:18:07 +01:00
Slava Pestov
05ccd9734c SIL: Introduce ThrowAddrInst 2023-10-31 16:58:54 -04:00
Hamish Knight
2ac0860716 [AST] Remove BridgedVarDecl + BridgedNominalTypeDecl duplicates
These are now stamped out by the ASTBridgingWrappers.
2023-10-30 23:49:56 +00:00
Hamish Knight
cae5d33368 [AST] Move BridgedNominalTypeDecl + BridgedVarDecl to ASTBridging
And renaming OptionalBridgedVarDecl to
BridgedNullableVarDecl for consistency with the
existing nullable AST node wrappers.
2023-10-30 23:49:55 +00:00
Erik Eckstein
b6938475b9 Optimizer: add simplification for the convert_escape_to_noescape instruction
Including the required bridging stuff.

  %2 = thin_to_thick_function %1 to $() -> ()
  %3 = convert_escape_to_noescape %2 : $() -> () to $@noescape () -> ()
->
  %3 = thin_to_thick_function %1 to $@noescape () -> ()
2023-10-27 10:47:07 +02:00
Andrew Trick
972a69f17e SwiftCompilerSources bridging review feedback 2023-10-12 14:33:37 -07:00
Andrew Trick
d7c1c50d9b SwiftCompilerSources: VarDecl bridging for SIL. 2023-10-12 14:33:37 -07:00
Andrew Trick
ae5ad5557d Add Swift BeginApplyInst::yieldedValues 2023-10-12 14:33:37 -07:00
Erik Eckstein
2dbd6cc56b SwiftCompilerSources: rework bridging
Introduce two modes of bridging:
* inline mode: this is basically how it worked so far. Using full C++ interop which allows bridging functions to be inlined.
* pure mode: bridging functions are not inlined but compiled in a cpp file. This allows to reduce the C++ interop requirements to a minimum. No std/llvm/swift headers are imported.

This change requires a major refactoring of bridging sources. The implementation of bridging functions go to two separate files: SILBridgingImpl.h and OptimizerBridgingImpl.h.
Depending on the mode, those files are either included in the corresponding header files (inline mode), or included in the c++ file (pure mode).

The mode can be selected with the BRIDGING_MODE cmake variable. By default it is set to the inline mode (= existing behavior). The pure mode is only selected in certain configurations to work around C++ interop issues:
* In debug builds, to workaround a problem with LLDB's `po` command (rdar://115770255).
* On windows to workaround a build problem.
2023-10-09 09:52:52 +02:00
Andrew Trick
bce9817162 SwiftCompilerSources: add ForwardingInstruction 2023-10-03 23:54:57 -07:00
Kavon Farvardin
b688a1f4a1 [SILOpt] experimental async demotion pass
For chains of async functions where suspensions can be statically
proven to never be required, this pass removes all suspensions and
turns the functions into synchronous functions.

For example, this function does not actually require any suspensions,
once the correct executor is acquired upon initial entry:

```
func fib(_ n: Int) async -> Int {
  if n <= 1 { return n }
  return await fib(n-1) + fib(n-2)
}
```

So we can turn the above into this for better performance:

```
func fib() async -> Int {
  return fib_sync()
}

func fib_sync(_ n: Int) -> Int {
  if n <= 1 { return n }
  return fib(n-1) + fib(n-2)
}
```

while rewriting callers of `fib` to use the `sync` entry-point
when we can prove that it will be invoked on a compatible executor.

This pass is currently experimental and under development. Thus, it
is disabled by default and you must use
`-enable-experimental-async-demotion` to try it.
2023-09-21 12:21:02 -07:00
Erik Eckstein
ad594f2713 Swift SIL: add some APIs
* `AssignInst`
* `Function.isDestructor`
* `MarkUninitializedInst.kind`
* `Type.isMoveOnly`
* `RefElementAddrInst.isImmutable` and `RefElementAddrInst.set(isImmutable:)`
* `BeginBorrowInst.endBorrows`
* `Context.hadError` and `Context.silStage`
2023-09-19 15:10:30 +02:00