Commit Graph

1365 Commits

Author SHA1 Message Date
Erik Eckstein
f5ca12d42b Simplification: check for isolated conformances when simplifying metatype casts
rdar://147417762
2025-04-05 09:00:30 +02: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
Erik Eckstein
f4955978d8 SIL: fix AllocStackInst.isLexical
If wrongly returned false.
2025-04-03 23:04:49 +02:00
Erik Eckstein
f8d6efd485 SimplifyAllocStack: bail if the address of the allocated existential escapes
This is not a problem if the alloc_stack already contains the opened existential.
Fixes a miscompile
rdar://148253142
2025-04-03 23:04:49 +02:00
Erik Eckstein
1100bf9bfb SimplifyAllocStack: rename a variable and update a comment
NFC
2025-04-03 06:58:00 +02:00
Erik Eckstein
ee18f8c168 Simplification: fix a crash in alloc_stack simplification
Handle the case that a type dependent operand is a dynamic-self argument and not an open-existential instruction.

rdar://148258964
2025-04-01 10:58:45 +02:00
Artem Chikin
66334f8f1b Merge pull request #79290 from artemcm/ConstProtoSIL
[Compile Time Values] Implement a mandatory SIL pass to verify '@const' values
2025-04-01 00:12:27 -07:00
Andrew Trick
81ca8fd3ec Enable NonEscapableType support on Windows.
SwiftCompilerSources for Windows is now fully enabled, so there is no
longer any reason to gate these passes under an OS check.

commit d482ab73bc
Author: Hiroshi Yamauchi <hjyamauchi@gmail.com>
Date:   Fri Dec 13 09:24:44 2024 -0800

Update the pinned toolchain for Windows and enable SwiftCompilerSources for Win/ARM64
2025-03-31 11:21:06 -07: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
Artem Chikin
72a420919a [Compile Time Values] Add mandatory optimization pipeline driver for '@const' globals 2025-03-27 14:33:38 -07:00
Artem Chikin
d484ec7c1f [Compile Time Values] Implement a mandatory SIL pass to verify '@const' values 2025-03-27 14:33:35 -07:00
Doug Gregor
e0b52cd20e [SIL] Extend checked-cast instructions with "prohibit isolated conformances" flag
When performing a dynamic cast to an existential type that satisfies
(Metatype)Sendable, it is unsafe to allow isolated conformances of any
kind to satisfy protocol requirements for the existential. Identify
these cases and mark the corresponding cast instructions with a new flag,
`[prohibit_isolated_conformances]` that will be used to indicate to the
runtime that isolated conformances need to be rejected.
2025-03-26 22:31:47 -07:00
Andrew Trick
97b249bd11 Merge pull request #80263 from atrick/markdep-addr
SIL: add mark_dependence_addr
2025-03-26 10:33:42 -07:00
Erik Eckstein
8b2d27007f DiagnoseInfiniteRecursion: re-implement the pass in swift and fix a bug
Fixes a false alarm in case of recursive calls with different type parameters.
For example:

```
protocol P {
  associatedtype E: P
}

func noRecursionMismatchingTypeArgs1<T: P>(_ t: T.Type) {
  if T.self == Int.self {
    return
  }
  noRecursionMismatchingTypeArgs1(T.E.self)
}
```
2025-03-26 09:14:38 +01:00
Erik Eckstein
ac55dae26c AST: add the possibility to compare SubstitutionMaps 2025-03-26 08:45:38 +01:00
Erik Eckstein
85a6df30d6 SIL: add lookup(method:) in VTable and WitnessTable 2025-03-26 08:45:23 +01:00
Erik Eckstein
1844c14c44 SIL: add var ClassMethodInst.member 2025-03-26 08:45:07 +01:00
Erik Eckstein
67556cfbf4 SIL: add some Function APIs
* `var wasDeserializedCanonical`
* `var genericSignature`
* `func mapTypeIntoContext`
* `var forwardingSubstitutionMap`
2025-03-26 08:45:07 +01:00
Erik Eckstein
59ad8b6623 Optimizer: add var Context.currentModuleContext 2025-03-26 08:43:55 +01:00
Erik Eckstein
1ce545ba3d SIL: add some DeclRef APIs
* `var decl`
* `func ==`
* `func calleesAreStaticallyKnowable`
2025-03-26 08:43:55 +01:00
Erik Eckstein
b39a6cdd22 AST: add var GenericSignature.genericParameters 2025-03-26 07:30:11 +01:00
Erik Eckstein
42bba8f484 AST: add some Declaration APIs
* `var Declaration.parentModule`
* `var AbstractFunctionDecl.isOverridden`
2025-03-26 07:30:11 +01:00
Erik Eckstein
e1af31bc19 AST: add var Conformance.rootConformance 2025-03-26 07:30:10 +01:00
Erik Eckstein
d523e303c3 SIL/AST: move some SIL.Type APIs to the TypeProperties protocol which makes them also available for AST.Type and AST.CanonicalType 2025-03-26 07:30:10 +01:00
Erik Eckstein
380ea889bc SIL: fix self-argument APIs in Function
`var selfArgument` should return an optional, i.e. nil if the function doesn't have a self argument.
2025-03-26 07:30:10 +01:00
Andrew Trick
69b6b1d309 LifetimeDependenceDefUseWalker: handle addressable dependencies 2025-03-25 23:02:45 -07:00
Andrew Trick
d9dd93560d Support mark_dependence_addr in SIL passes. 2025-03-25 23:02:45 -07:00
Andrew Trick
e7000e4668 SIL: Add mark_dependence_addr 2025-03-25 23:02:42 -07:00
Kuba (Brecka) Mracek
41ae31647a Merge pull request #76045 from kubamracek/mergeable-traps
Add -Xfrontend -mergeable-traps as a way to emit mergeable traps
2025-03-25 07:13:18 -07:00
eeckstein
02fc68badf Merge pull request #80237 from eeckstein/fix-alias-of-end-apply
AliasAnalysis: fix effect of `end_apply` / `abort_apply` for read-only coroutines
2025-03-24 21:08:40 +01:00
Kuba Mracek
ed5e89a501 Also respect -mergeable-traps when merging cond_fails in SILOptimizer 2025-03-24 09:04:44 -07:00
Erik Eckstein
be73bd552e AliasAnalysis: fix effect of end/abort_apply for read-only coroutines
The lifetime of yielded values always end at the end_apply.
This is required because a yielded address is non-aliasing inside the begin/end_apply scope, but might be aliasing after the end_apply.
For example, if the callee yields an `ref_element_addr` (which is encapsulated in a begin/end_access).
Therefore, even if the callee does not write anything, the effects must be "read" and "write".

Fixes a SIL verifier error
rdar://147601749
2025-03-24 10:51:53 +01:00
Andrew Trick
001b162dc9 Surface addressableForDeps in SILType and FunctionConventions
With this approach, you cannot tell whether a parameter is addressable only
from the function type. Instead you need the SILValue that will be passed to the
call site.
2025-03-23 19:00:42 -07:00
Andrew Trick
7cecf57e50 Add SILType::isAddressableForDeps 2025-03-23 19:00:42 -07:00
Andrew Trick
a431a7bc5f LifetimeDependence: conditionallyAddressableParamIndices
Preserve conditionallyAddressableParamIndices independent of any
addressableParamIndices. The conditional dependencies are subject to change
based on type substitution.
2025-03-23 16:59:11 -07:00
Andrew Trick
ea8cb3c1b4 LifetimeDependenceDiagnostics: recognize store_borrow ranges
Avoid an unnecessary diagnostic when the dependent value's uses are covered by a
StoreBorrow.
2025-03-20 12:17:24 -07:00
Andrew Trick
bd7d3ec915 LifetimeDependentInsertion: assert on non-inout parameter dependency
The will be supported in a future commit that adds mark_dependence_addr.
2025-03-19 11:57:53 -07:00
Slava Pestov
8bcd09aaa4 SIL: Preliminary refactoring of SILWitnessTable::AssociatedConformanceWitness
The Protocol field isn't really necessary, because the conformance
stores the protocol. But we do need the substituted subject type
of the requirement, just temporarily, until an abstract conformance
stores its own subject type too.
2025-03-18 19:38:42 -04:00
Andrew Trick
ce18a4bce8 Merge pull request #79985 from atrick/fix-destroyhoist
Fix DestroyHoisting: InteriorLiveness for noescape closures
2025-03-18 05:07:27 -07:00
Erik Eckstein
04ede105d6 Simplification: remove redundant array casts
Remove casts between arrays of the same type.

```
  %1 = function_ref @_arrayConditionalCast : (@guaranteed Array<Int>) -> @owned Optional<Array<Int>>
  %2 = apply %1(%0) : (@guaranteed Array<Int>) -> @owned Optional<Array<Int>>
```
->
```
  %1 = copy_value %0
  %2 = enum $Optional<Array<Int>>, #Optional.some!enumelt, %1
```

This can be a result of specialization, e.g.

```
func foo<T>(from: [T]) -> [Int]? {
  return from as? [Int]
}

func bar(a: [Int]) -> [Int]? {
  return foo(from: a)
}
```

rdar://139632757
2025-03-15 08:32:58 +01:00
Erik Eckstein
d31d82c6fe SIL: remove a workaround for a Windows 5.10 host compiler crash
https://github.com/apple/swift/issues/73253 should be fixed in 6.0, which is now used as host compiler.
2025-03-14 09:49:53 +01:00
Erik Eckstein
37455b6ab6 Optimizer: use formal types instead of SIL types for classifying dynamic casts.
Casts always work with formal rather than lowered types.
This fixes a potential bug when lowered types are different than formal types, like function types.
2025-03-14 09:45:27 +01:00
Erik Eckstein
d52f7d1619 AST/SIL: Refactor and simplify AST.Type, AST.CanonicalType and SIL.Type
* let `SIL.Type` conform to `TypeProperties` to share the implementation of common type properties between the AST types and `SIL.Type`
* call references to an `AST.Type` `rawType` (instead of just `type`)
* remove unneeded stuff
* add comments
2025-03-14 09:40:22 +01:00
Andrew Trick
995c74966d Fix DestroyHoisting: InteriorLiveness for noescape closures
InteriorLiveness has a new "visitInnerUses" mode used by DestroyHoisting. That
mode may visit dependent values, which was not valid for noescape
closures. ClosureLifetimeFixup inserts destroys of noescape closures after the
destroys of the captures. So following such dependent value could result in an
apparent use-after-destroy. This causes DestroyHoisting to insert redundant
destroys.

Fix: InteriorUses will conservatively only follow dependent values if they are
escapable. Non-escapable values, like noescape closures are now considered
escapes of the original value that the non-escapable value depends on. This can
be improved in the future, but we may want to rewrite ClosureLifetimeFixup first.

Fixes the root cause of: rdar://146142041
2025-03-13 09:17:31 -07:00
eeckstein
ca76efabb4 Merge pull request #79908 from eeckstein/fix-witness-table-specialization
embedded: fix specialization of associated conformance entries in witness tables
2025-03-11 18:16:23 +01:00
Erik Eckstein
23b4c6fc34 embedded: fix specialization of associated conformance entries in witness tables
When creating a specialized witness table, we need to get the right specialized conformance.
In IRGen don't emit associated conformance witness table entries if the protocol is not a class protocol.
In this case the associated type can never be used to create an existential. Therefore such a witness table entry is never used at runtime in embedded swift.

Fixes a compiler crash

rdar://146448091
2025-03-11 11:33:10 +01:00
Erik Eckstein
5212d92b57 Swift AST: add Conformance.getAssociatedConformance 2025-03-11 11:17:00 +01:00
WeZZard
4c479824ef [SILOptimizer] Eliminate non-case handling for implicit Optional non-Optional casting of unchecked_ref_cast in ValueDefUseWalker. 2025-03-11 09:39:50 +08:00
WeZZard
2237faca04 [SILOptimizer] Refines the implementation of of the bridged SILType for Swift. 2025-03-11 09:29:11 +08:00
WeZZard
35f82ba402 [SILOptimizer] Fixes the ValueDefUseWalker to handle potential unchecked_ref_cast between optional and non-optional class types.
The `unchecked_ref_cast` is designed to be able to cast between
`Optional<ClassType>` and `ClassType`. We need to handle these cases by
checking if the type is optional and adjust the path accordingly.
2025-03-10 19:17:31 +08:00