Commit Graph

169 Commits

Author SHA1 Message Date
Michael Gottesman
05511c955a [sil] Add conformance to UnaryInstruction for IgnoredUseInst. 2025-01-23 10:58:45 -08:00
Michael Gottesman
7ae56aab2e [sil] Add a new instruction ignored_use.
This is used for synthetic uses like _ = x that do not act as a true use but
instead only suppress unused variable warnings. This patch just adds the
instruction.

Eventually, we can use it to move the unused variable warning from Sema to SIL
slimmming the type checker down a little bit... but for now I am using it so
that other diagnostic passes can have a SIL instruction (with SIL location) so
that we can emit diagnostics on code like _ = x. Today we just do not emit
anything at all for that case so a diagnostic SIL pass would not see any
instruction that it could emit a diagnostic upon. In the next patch of this
series, I am going to add SILGen support to do that.
2025-01-22 21:12:36 -08:00
Erik Eckstein
43b6fd4edb SIL: add the IndexingInstruction protocol
It defines (and implements) the `base` and `index` properties, which are used in the conforming classes `IndexRawPointerInst`, `IndexAddrInst` and `TailAddrInst`
2024-12-21 08:28:21 +01:00
Erik Eckstein
969a788e7f SIL: add the Builtin.name getter and Builtin.arguments 2024-12-21 08:28:21 +01:00
Erik Eckstein
1856d4e94c SIL: add APIs to set and get the alignment of a pointer_to_address instruction.
Also add a getter for the `isInvariant` property.
2024-12-21 08:28:21 +01:00
Erik Eckstein
ca7facde35 SIL: add some use-list APIs
* `users`: maps from a sequence of operands to a sequence of instructions
* `users(ofType:)` : as `users`, but filters users of a certain instruction type
* `Value.users`: = `Value.uses.users`
2024-12-19 20:53:45 +01:00
Andrew Trick
f5fc17804e [NFC] SwiftCompilerSources: Add VariableScopeInstruction utility
To diagnose dependence on trivial variables.
2024-12-14 22:46:54 -08:00
Erik Eckstein
c5efad1e2d SIL: make isLexical a protocol requirement of Value
This avoids the need for checking if a value is a `move_value`, `begin_borrow` or function argument to get the is-lexical information.
2024-12-10 16:28:11 +01:00
Andrew Trick
c05044c65c Add MarkDependenceInst.settleToEscaping
This allows emitting mark_dependence [unresolved] in some cases even if the
diagnostics can't currently handle them.
2024-11-18 22:02:44 -08:00
Andrew Trick
5be742fd8c SwiftCompilerSources: fix BeginApplyInst.endOperands.
isScopeEndingUse is not the same as endsLifetime.
2024-11-18 22:02:44 -08:00
Andrew Trick
cdb646dc95 SwiftCompilerSources: add ScopedInstruction.endInstructions.
Add endInstructions requirement so it can be called on an unknown
ScopedInstruction.
2024-11-18 01:37:00 -08:00
Andrew Trick
801c192af1 SwiftCompilerSources: fix EndApplyInst to be SingleValueInstruction.
To be consistent with the C++ implementation.
2024-11-18 01:37:00 -08:00
Andrew Trick
b5bef612ed SwiftCompilerSources: fix BeginApply.endOperands()/endInstructions()
Only return the EndApplyInst and AbortApplyInst uses.
2024-11-18 01:37:00 -08: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
Erik Eckstein
62317d86a6 SwiftCompilerSources: add the LoadBorrowInst.isUnchecked API 2024-10-11 09:41:36 +02:00
Michael Gottesman
561662d6cc [sil] Add a new instruction called ThunkInst.
For now this will only be used for HopToMainActorIfNeeded thunks. I am creating
this now since in the past there has only been one option for creating
thunks... to create the thunk in SILGen using SILGenThunk. This code is hard to
test and there is a lot of it. By using an instruction here we get a few benefits:

1. We decouple SILGen from needing to generate new kinds of thunks. This means
that SILGenThunk does not need to expand to handle more thunks.

2. All thunks implemented via ThunkInst will be easy to test in a decoupled way
with SIL tests.

3. Even though this stabilizes the patient, we still have many thunks in SILGen
and various parts of the compiler. Over time, we can swap to this model,
allowing us to hopefully eventually delete SILGenThunk.
2024-10-02 14:15:49 -07:00
Erik Eckstein
10782cf42b SwiftCompilerSources: introduce the AST module
As the optimizer uses more and more AST stuff, it's now time to create an "AST" module.
Initially it defines following AST datastructures:
* declarations: `Decl` + derived classes
* `Conformance`
* `SubstitutionMap`
* `Type` and `CanonicalType`

Some of those were already defined in the SIL module and are now moved to the AST module.
This change also cleans up a few things:
* proper definition of `NominalTypeDecl`-related APIs in `SIL.Type`
* rename `ProtocolConformance` to `Conformance`
* use `AST.Type`/`AST.CanonicalType` instead of `BridgedASTType` in SIL and the Optimizer
2024-10-02 07:10:29 +02:00
Erik Eckstein
f3a9b08e7a SwiftCompilerSources: bridged ProtocolConformance
And use that in some Builder APIs
2024-09-25 19:31:40 +02:00
Erik Eckstein
897ef2c5d4 SIL: add label to SubstitutionMap.init's bridged argument 2024-09-25 19:31:39 +02:00
Kuba Mracek
df38313572 The metatype operand on AllocRefDynamicInst is not always at index 1, use getNumTailTypes() 2024-09-23 15:42:38 -07:00
Alejandro Alonso
b35ac50d3c Optimize TypeValueInst in Swift 2024-09-04 15:13:48 -07:00
Alejandro Alonso
75c2cbf593 Implement value generics
Some requirement machine work

Rename requirement to Value

Rename more things to Value

Fix integer checking for requirement

some docs and parser changes

Minor fixes
2024-09-04 15:13:25 -07:00
Erik Eckstein
345f9c1dfc AliasAnalysis: handle destroy_value [dead_end] in computeMemoryEffect
We don't have to take deinit effects into acount for a `destroy_value [dead_end]`.
Such destroys are lowered to no-ops and will not call any deinit.
2024-08-05 17:02:06 +02:00
Erik Eckstein
084d60d7b7 Swift SIL: add some APIs to instructions and other small improvments 2024-07-29 17:33:44 +02:00
Erik Eckstein
95bd329b1f Swift SIL: bridge the hasPointerEscape flags of MoveValueInst and BeginBorrowInst 2024-07-29 17:33:43 +02:00
Nate Chandler
2a5d07522d [SIL] Add extend_lifetime instruction.
It indicates that the value's lifetime continues to at least this point.
The boundary formed by all consuming uses together with these
instructions will encompass all uses of the value.
2024-06-05 16:28:26 -07:00
Emil Pedersen
d39d838c2b Skip meta instructions for Builder.init with automatic location 2024-05-24 16:01:11 -07:00
Kshitij
ab751d57ab [Autodiff] Adds logic to generate specialized functions in the closure-spec pass 2024-05-13 11:16:42 -07:00
Kshitij
003c9082cb [Autodiff] Adds SwiftCompilerSources changes in preparation for the Autodiff closure-spec optimization pass 2024-05-02 09:14:05 -07:00
Erik Eckstein
ac4bc89c9a SIL: add the borrowed-from instruction.
It declares from which enclosing values a guaranteed phi argument is borrowed from.
2024-04-10 13:38:10 +02: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
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