Commit Graph

462 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
Andrew Trick
b0f2ca03a7 AccessUtils: allow mark_deps to be tracked by the EnclosingScope.
This encourages AccessPathWalker clients to handle enclosing mark_deps. In
some cases, it is necessary. The accessBaseWithScopes API now provides both
nested begin_access and mark_dependence.
2025-01-11 15:40:22 -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
2d10da001a SIL: add some Builder-create functions 2024-12-21 08:28:20 +01:00
Erik Eckstein
f8e013a21c Fix a compiler warning in SIL/Function.swift 2024-12-20 09:10:17 +01:00
Erik Eckstein
4fdf16de1b SIL: add CanonicalType.canBeClass
And move the implementation of `SIL.Type.canBeClass` to the AST Type. The SIL Type just calls the AST Type implementation.
Also rename `SIL.Type.canonicalASTType` -> `SIL.Type.astType`.
2024-12-19 20:53:46 +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
Erik Eckstein
1545e01ab5 SIL: Let SubstitutionMap.replacementTypes return AST types rather than optional SIL types.
This is what the C++ SubstitutionMap does. One has to use `Type.loweredType` to get from the AST type to the SIL type.
2024-12-19 20:53:45 +01:00
Erik Eckstein
1f4332ad39 SIL: add AST.Type.loweredType and CanonicalType.loweredType 2024-12-19 20:53:45 +01:00
Erik Eckstein
50bf66e217 SIL: replace CanonicalType.objectType and CanonicalType.addressType with silType
`SIL.Type` itself has `objectType` and `addressType` to convert between both variants.
2024-12-19 20:53:45 +01:00
Hamish Knight
95ae8d1b16 Merge pull request #78288 from hamishknight/use-typename
[SwiftCompilerSources] Use interpolation instead of `String(describing:)`
2024-12-19 19:26:50 +00:00
Hamish Knight
f728466273 [SwiftCompilerSources] Use interpolation instead of String(describing:)
`String(describing:)` does a bunch of dynamic casts
that can be pretty slow. Use interpolation instead,
which bypasses them.

For `swift-frontend`, this brings the time taken
for type-checking an empty file down from ~100ms
to ~70ms.

For `swift build`, this brings the time taken for
a null build down from ~600ms to ~450ms (the
larger delta is presumably due to the fact that
there's much more Swift code in `swift-package`).
2024-12-19 15:33:39 +00:00
Andrew Trick
7a11d5a3f1 SwiftCompilerSources: bridge Function.sourceFileKind. 2024-12-18 16:56:45 -08:00
Andrew Trick
3897929e4a LifetimeDependence: handle dependence on trivial values. 2024-12-16 16:09:37 -08:00
Andrew Trick
98da813f02 [NFC] SwiftCompilerSources: add isConvertPointerToPointerArgument 2024-12-14 22:46:54 -08: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
bd08d6afa1 SIL: make Operand Equatable
To be able to use `!=` for operands.
2024-12-12 08:36:58 +01:00
Erik Eckstein
62b26dc8c4 SIL: make isEmpty and singleElement available for all Sequences
and not just for `CollectionLikeSequence`.
To support stdlib's lazy map and filter sequences.
2024-12-10 16:28:11 +01:00
Erik Eckstein
bcdbc05260 SIL: make Builde.insertionPoint public 2024-12-10 16:28:11 +01: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
Erik Eckstein
aa274a213b WalkUtils: handle mark_dependence instruction in the ValueUseDefWalker
It was already handled in the ValueDefUseWalker
2024-11-28 09:40:13 +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
e5069281d4 SwiftCompilerSources: Add Operand.isScopeEndingUse. 2024-11-18 22:02:44 -08:00
Andrew Trick
442739a176 [NFC] Add a Builder.insertionBlock API.
Some utilities, like Builder.insert(after:) pass a Builder object that
represents an insertion point. That insertion point is sometimes needed to
determine which instructions to create (endApply vs. abortApply). But there is
no way to recover the insertion point. We don't want to simply return an
instruction, because that could be interpreted in different ways. Instead we
provide insertion block, but only in those situations where it makes sense and can't
be used incorrectly.
2024-11-18 01:37:00 -08:00
Andrew Trick
5fc103b8ac [NFC] AccessUtils: add accessBaseWithScopes
And simplify enclosingAccessScope.

These two APIs now directly compute what is being asked for. Previously, each
invocation of enclosingAccessScope would recompute the base and all nested
scopes, but throw away that information. Sometimes we do not want to compute
that information, and other times we need all of it. Instead, provide separate
APIs that do exactly what is needed.

These are common APIs used by other utilities. This avoids quadratic traversals in those
cases. It is also easier to understand and debug.

These utilities will be used in LifetimeDependenceScopeFixup.
2024-11-18 01:37:00 -08:00
Andrew Trick
0fb3cb96de [NFC] Add AccessBase.address
LifetimeDependence uses the address of the AccessBase to compute liveness. It is
more convenient to switch over all AccessBase kinds here rather than force all
clients to do it.
2024-11-18 01:37:00 -08:00
Andrew Trick
ec0026f7e5 [NFC] AccessBase: correct initialization from pointer_to_address
AccessBase already identifies a base address as either a .global (addressor) or
a .pointer. When initializing an AccessBase from a pointer_to_address, precisely
identify one of these kinds of accesses, rather than simply marking it
.unidentified.

This used to be a special case in the AccessPathWalker. But that's not the right
place to handle it.
2024-11-18 01:37:00 -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
Andrew Trick
3e26cf81d0 SwiftCompilerSources: bridge createEndApply and createAbortApply. 2024-11-18 01:37:00 -08:00
Erik Eckstein
f7d49a9680 SIL: add the Argument.set(reborrow:) and Argument.hasBorrowEndingUse APIs 2024-11-12 09:26:58 +01:00
Erik Eckstein
f0633d5638 AccessUtils: support computing "constant" access paths
Add `Value.constantAccessPath`. It is like `accessPath`, but ensures that the projectionPath only contains "constant" elements.
This means: if the access contains an `index_addr` projection with a non-constant index, the `projectionPath` does _not_ contain the `index_addr`.
Instead, the `base` is an `AccessBase.index` which refers to the `index_addr`.
2024-11-04 19:26:44 +01: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
709dfc2d21 MandatoryPerformanceOptimization: don't let not-inlinable functions to be inlined
Also refactor canInline.

Fixes a compiler crash.
rdar://137544788
2024-10-15 12:19:50 +02:00
Erik Eckstein
e0533e6125 SIL: add an API to replace all entries of a VTable
* add `ModulePassContext.replaceVTableEntries()`
* add `ModulePassContext.notifyFunctionTablesChanged()`
2024-10-14 14:43:11 +02:00
Erik Eckstein
62317d86a6 SwiftCompilerSources: add the LoadBorrowInst.isUnchecked API 2024-10-11 09:41:36 +02:00
Erik Eckstein
6bf7cc8f2f Swift SIL: add flag parameters to Builder.createBeginBorrow 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
eeckstein
4a069c9926 Merge pull request #76790 from eeckstein/add-ast-module
SwiftCompilerSources: introduce the AST module
2024-10-02 10:50:18 +02:00
Erik Eckstein
6fdb713e94 SwiftCompilerSources: implement WitnessTable.Entry as enum 2024-10-02 07:10:30 +02: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
fadff007a1 SwiftCompilerSources: move protocol BridgedRandomAccessCollection from the SIL to the Basic module 2024-10-02 07:10:29 +02:00
Allan Shortlidge
6f91b4156c ASTGen/SIL: Suppress retroactive conformance warnings.
When building ASTGen and SIL using the Swift 6.0 compiler the compiler emits
diagnostics about various retroactive conformances. Since Swift code in the
compiler needs to remain compatible with the Swift 5.10 compiler for now, use
module qualification syntax to suppress the warning. I've also included the
`@retroactive` attribute in a comment to document the retroactive conformance
acknowledgement more explicitly.

NFC.
2024-10-01 17:07:03 -07:00
Erik Eckstein
46d3909471 SIL: improve VTable and WitnessTable
* add missing APIs
* bridge the entries as values and not as pointers
* add lookup functions in `Context`
* make WitnessTable.Entry.Kind enum cases lower case
2024-09-25 19:32:07 +02:00
Erik Eckstein
c6f384c3b1 SIL: add some APIs to SubstitutionMap 2024-09-25 19:31:40 +02:00