Commit Graph

559 Commits

Author SHA1 Message Date
Erik Eckstein
d10602ea28 SIL: improve and fix mark-dependence instruction APIs
* Move the mutating APIs into Context.swift, because SIL can only be mutated through a MutatingContext
* move the `baseOperand` and `base` properties from the instruction classes to the `MarkDependenceInstruction` protocol
* add `valueOrAddressOperand` and `valueOrAddress` in the `MarkDependenceInstruction` protocol
2025-05-23 18:53:57 +02:00
Erik Eckstein
b760ab0679 DeadStoreElimination: don't assume that the operand of an dealloc_stack is an alloc_stack.
It can also be a `partial_apply`.
Fixes a compiler crash
https://github.com/swiftlang/swift/issues/81698
rdar://151822502
2025-05-22 19:08:30 +02:00
Erik Eckstein
e3b770853a SIL: add GlobalVariable.type 2025-05-20 20:46:33 +02:00
Erik Eckstein
140b883b9a SIL: let TypeValueInst.value return an optional Int
and don't require the client to check if it's an integer type.
Also, implement `var value` natively and without bridging.
2025-05-15 21:29:02 +02:00
Erik Eckstein
5dc71aa0a5 AST/SIL: support source location in diagnostics for de-serialized debug info
Diagnostics only work with `SourceLoc` which is basically a pointer into a buffer of the loaded source file.
But when debug info is de-serialized, the SIL `Location` consists of a filename+line+column.
To "convert" this to a `SourceLoc`, the file must be loaded.
This change adds `DiagnosticEngine.getLocationFromExternalSource` for this purpose.
Also, the new protocol `ProvidingSourceLocation` - to which `SourceLoc` and `Location` conform - help to generalize the helper struct `Diagnostic` and make this "conversion" happen automatically.
2025-05-14 11:43:47 +02:00
Erik Eckstein
f6ce61cf43 SIL: support vector_base_addr in AccessUtils and WalkUtils
This enables alias analysis and optimizations, like, redundant load elimination, to benefit from it.
2025-05-12 19:24:32 +02:00
Erik Eckstein
0e790fcc5d SIL: support vector_base_addr in SmallProjectionPath
Add a `vectorBase` field kind which corresponds to `vector_base_addr`.
Also, improve `mayOverlap`: it didn't catch the case that the first element of a vector cannot overlap with another element.
2025-05-12 19:24:32 +02:00
Erik Eckstein
a38db6439a SIL: add the vector_base_addr instruction
It derives the address of the first element of a vector, i.e. a `Builtin.FixedArray`, from the address of the vector itself.
Addresses of other vector elements can then be derived with `index_addr`.
2025-05-12 19:24:31 +02:00
Erik Eckstein
17fbcb5314 Swift SIL: fix SIL.Type.builtinVectorElementType
The element type must be lowered. Otherwise it would crash for e.g. function types as element types.
2025-05-12 19:24:31 +02:00
Erik Eckstein
ff2341e83a Swift AST/SIL: add Type APIs for Builtin.FixedArray
* `Type.isBuiltinFixedArray`
* `Type.builtinFixedArrayElementType`
2025-05-12 19:24:31 +02:00
Erik Eckstein
e6b9374b49 SIL: add AccessBase.storageIsLexical 2025-05-06 13:08:09 +02:00
Erik Eckstein
d2f8c0cf49 Swift SIL: add some Instruction APIs
* `OpenExistentialAddrInst.isImmutable`
* `YieldInst.convention`
* `CopyAddrInst.set(isTakeOfSource:)` and `CopyAddrInst.set(isInitializationOfDestination:)`
2025-05-06 12:35:21 +02:00
Erik Eckstein
8f39c3cad8 Swift SIL: rename isTakeOfSrc -> isTakeOfSource and isInitializationOfDest -> isInitializationOfDestination
Trying to avoid abbreviations in ABI names
2025-05-06 12:35:21 +02:00
Andrew Trick
170c563b00 [NFC] cleanup Instruction/Value.findVarDecl() APIs.
These APIs are quite convoluted. The checks for var_decl need to be performed in
just the right order. The is a consequence of complexity in the SIL
representation itself, not a problem with the APIs.

It is common for code to accidentally call a less-complete form of the API. It
is essential that they be defined in a central location, and the we get the same
answer whether we start with an Instruction, Argument, or Value. The primary
public interface should always check for debug_value users. The varDecl property
is actually an implementation detail.

It is questionable whether a function like findVarDecl() that returns a basic
property of SIL and does not require arguments should be a property instead. It
is a function to hint that it may scan the use-list, which is not something
we normally want SIL properties to do. Use-lists can grow linearly in function
size. But, again, this is a natural result of the SIL representation and needs
to be considered an implementation detail.
2025-05-05 22:51:01 -07:00
Meghana Gupta
ba845de874 Fix newly introduced warnings in LifetimeDependenceScopeFixup 2025-05-05 11:22:16 -07:00
Erik Eckstein
93c41c649c Swift SIL: add Builder.createUncheckedOwnershipConversion 2025-05-02 18:07:57 +02:00
Meghana Gupta
3cad5c5924 Merge pull request #81043 from meg-gupta/fixcow
Insert end_cow_mutation_addr for lifetime dependent values dependent on mutable addresses
2025-05-01 07:26:28 -07:00
Andrew Trick
b670a6d9cc Merge pull request #81191 from atrick/var-walker-recursion
LifetimeDependenceDiagnostics: bug fixes and output clarity
2025-04-30 15:36:32 -07:00
Meghana Gupta
35d62a4a36 Introduce end_cow_mutation_addr instruction 2025-04-30 13:39:45 -07:00
Andrew Trick
83b0ce1098 LifetimeDependenceDiagnostics: note for unsupported closure capture
Add a note explaining that dependence on closure captures is not
supported. Otherwise, the diagnostics are very confusing:
"it depends on a closure capture; this is not yet supported"
2025-04-29 23:55:55 -07:00
Andrew Trick
25e9cbf3f1 [NFC] SwiftCompilerSource: bridge Function.accessorKindName 2025-04-29 22:09:42 -07:00
Andrew Trick
49755bd0ed Refactor debugVarDecl so arguments also support debug_value users. 2025-04-29 22:09:42 -07:00
Erik Eckstein
ffc17322f9 SIL: bridge Function.isDeinitBarrier back from Swift to C++ SIL
This API already existed in Swift, but not in the C++ SIL.
2025-04-29 20:30:21 +02:00
Erik Eckstein
65178170b1 ComputeSideEffects: handle program termination functions which are defined in the same module
This case was neglected. The fix can result in better side effect analysis, e.g. in the stdlib core module.
2025-04-29 20:30:21 +02:00
Erik Eckstein
d80f7a3560 SIL: make BeginBorrowInstruction.endOperands and BeginBorrowValue.scopeEndingOperands consistent.
* rename `ScopedInstruction.endOperands` -> `scopeEndingOperands`
* let them behave the same way. For `load_borrow` there was a difference because `endOperands` didn't consider branches to re-borrow phis.
2025-04-28 10:24:56 +02:00
Erik Eckstein
cbf5c196b2 SIL: rename protocol BorrowIntroducingInstruction -> BeginBorrowInstruction
to match with `BeginBorrowValue`
2025-04-28 10:07:45 +02:00
Erik Eckstein
0dee86590d SIL: make protocol ScopeInstruction an Instruction protocol
This allows to remove the `var instruction` property.

NFC
2025-04-28 09:40:06 +02:00
Andrew Trick
33fbe11bf8 Fix LifetimeDependenceScopeFixup: read access can depend on 'inout'
Allow a dependency on a local [read] access scope to be transfered to the
caller's [modify] access.

Fixes rdar://149560133 (Invalid lifetime dependence error when
trying to return Span from an inout argument)
2025-04-22 11:54:53 -07:00
Andrew Trick
a1aaed9159 LifetimeDependenceScopeFixup: handle returning dependent Optional
Add support for returnValue phis (e.g. to return an Optional .some or .none).

Fixes rdar://149397018 (Wrapping non escapable in an Optional
(or any copy lifetime wrapper) is an escape)
2025-04-21 22:33:38 -07:00
Erik Eckstein
7a8a50a2b3 Swift SIL: add Type.hasValidSignatureForEmbedded 2025-04-18 06:58:40 +02:00
Erik Eckstein
f7d81f7ac7 Swift SIL: deal with a generic self type in SubstitutionMap.getMethodSubstitutions
If the method is a default witness methods (`selfType` != nil) it has generic self type.
In this case the generic self parameter is at depth 0 and the actual generic parameters of the substitution map are at depth + 1, e.g:
```
    @convention(witness_method: P) <τ_0_0><τ_1_0 where τ_0_0 : GenClass<τ_1_0>.T>
                                      ^      ^
                                   self      params of substitution map at depth + 1
```
2025-04-18 06:58:39 +02:00
Erik Eckstein
cab62320eb Swift SIL: improvements for Location
* make `var sourceLoc` return nil if the location doesn't have a valid line number
* add `var decl`
2025-04-18 06:58:39 +02:00
Erik Eckstein
5a67af507e Swift SIL: add Function.isSpecialization 2025-04-18 06:58:39 +02:00
Erik Eckstein
dbf1bf0e43 Swift SIL: add a comment for VTable.specializedClassType 2025-04-18 06:58:39 +02:00
Erik Eckstein
e154e12913 Swift SIL: add APIs for box types 2025-04-18 06:58:39 +02:00
Erik Eckstein
f0f1c3c84b SIL: make SILFunctionConvention constructible without needing a SIL function
Add an initializer which takes the `hasLoweredAddresses` directly and add `Context.moduleHasLoweredAddresses`
2025-04-18 06:58:38 +02:00
Erik Eckstein
1c9a7cd562 SwiftCompilerSources: refactor DiagnosticEngine
* move it from the SIL to the AST module (where it belongs)
* change the signature of `diagnose` from `diagnose(location, .some_error)` to `diagnose(.some_error, at: location)`
* add an overload to allow passing a `SIL.Location` directly to `diagnose`
* add a `Diagnostic : Error` utility struct which allows throwing a `Diagnostic`
2025-04-18 06:58:38 +02:00
Erik Eckstein
8e874cd2b2 SIL: add better support for specialized witness tables.
Store specialize witness tables in a separate lookup table in the module. This allows that for a normal conformance there can exist the original _and_ a specialized witness table.
Also, add a boolean property `isSpecialized` to `WitnessTable` which indicates whether the witness table is specialized or not.
2025-04-18 06:58:34 +02:00
Andrew Trick
6f8605263d Fix unidentified LifetimeDependence.Scope initialization.
Fixes rdar://149226564 (Compiler crash with non-escapable storing another
non-escapable and having a deinit)
2025-04-16 16:46:38 -07:00
Andrew Trick
43debc529f [NFC] minor cleanup 2025-04-16 16:43:23 -07:00
Andrew Trick
2bdaa68e98 SwiftCompilerSources: add IgnoredUseInst as incidental
Fixes rdar://148540048 (Assigning span value to `_` results in an incorrect escape diagnostic)
2025-04-16 16:42:36 -07:00
Erik Eckstein
18ea816e79 SIL: make CopyBlockInst conform to UnaryInstruction 2025-04-15 11:02:39 +02:00
Andrew Trick
6e51dd8534 Merge pull request #80628 from atrick/address-escape-effect
Fix escape analysis: addressable parameters.
2025-04-08 13:40:02 -07:00
Andrew Trick
05a9acbb40 Fix escape analysis: addressable parameters.
An address-type parameter may escape via an indirect argument if the function's
result depends on the argument's address.
2025-04-08 00:07:30 -07:00
Slava Pestov
ec82f6bf4d SIL: Remove SILWitnessTable::AssociatedConformanceWitness::SubstType 2025-04-07 21:36:06 -04:00
nate-chandler
1d3e669d63 Merge pull request #80555 from nate-chandler/bug/20250404/1
[SIL] Fix bridged begin_apply results.
2025-04-07 07:25:16 -07:00
Erik Eckstein
9df1039379 SIL: add matchesActorIsolation
Returns true if the conformance is not isolated or if its isolation matches the isolation `inFunction`.
2025-04-05 09:00:30 +02:00
Nate Chandler
df2fb88e9b [SIL] Fix bridged begin_apply results.
The `yield_once_2` adds an extra result at the end, the deallocation.
Fix the indexing for the token and yielded results.
2025-04-04 18:12:26 -07:00
Erik Eckstein
f4955978d8 SIL: fix AllocStackInst.isLexical
If wrongly returned false.
2025-04-03 23:04:49 +02:00
Artem Chikin
281f84da0f [Compile Time Values] Rewrite the 'Diagnose Unknown Compile Time Values' diagnostic pass in Swift 2025-03-28 10:30:07 -07:00