Commit Graph

11224 Commits

Author SHA1 Message Date
Erik Eckstein
e18bedaa87 CastOptimizer: pass the SIL function to the cast-classify APIs, instead of the module decl
NFC
2025-04-05 09:00:30 +02:00
Slava Pestov
ec0dfc8716 AST: Add new form of SubstitutionMap::getProtocolSubstitutions() 2025-04-03 17:35:33 -04:00
eeckstein
ff14828c7f Merge pull request #80463 from eeckstein/fix-sil-combine
SILCombine: fix an ownership violation when replacing open existential apply arguments
2025-04-03 23:00:00 +02:00
Joe Groff
367ad789c5 Merge pull request #80470 from jckarter/trivial-borrow-transitive-uses
MoveOnlyChecker: Don't follow trivial transitive uses of borrows.
2025-04-03 13:13:24 -07:00
Joe Groff
b5d242ad2c MoveOnlyChecker: Don't follow trivial transitive uses of borrows.
Trivial values don't have ownership tracked, so their uses can't affect the
lifetime of the original borrow. Fixes rdar://148457155.
2025-04-02 13:25:46 -07:00
Erik Eckstein
dff855034c SILCombine: fix a wrong assert in the SingleBlockOwnedForwardingInstFolder 2025-04-02 17:33:30 +02:00
Erik Eckstein
f7f5f9ad96 SILCombine: fix an ownership violation when replacing open existential apply arguments
The value of the opened existential must outlive the apply. Otherwise the optimization creates invalid SIL.

rdar://148259849
2025-04-02 17:33:30 +02:00
Michael Gottesman
8f458cd029 [rbi] Add the ability to test in SIL RegionAnalysisValueMap::getTrackableValue().
I also added some basic tests of its functionality. I am doing this in
preparation for making some more invasive changes to getTrackableValue and I
want to be able to test it out very specifically in SIL.
2025-04-01 12:33:46 -07:00
Erik Eckstein
4d1df28de0 ConstantFolding: add constant folding for some floating point intrinsics
* `sitofp` signed integer to floating point
* `rint` round floating point to integral
* `bitcast` between integer and floating point

Constant folding `bitcast`s also made it necessary to rewrite constant folding for Nan and inf values, because the old code explicitly checked for `bitcast` intrinsics.
Relying on constant folded `bitcast`s makes the new version much simpler.

It is important to constant fold these intrinsics already in SIL because it enables other optimizations.
2025-04-01 18:13:01 +02:00
Erik Eckstein
6e17385325 add a semantic attribute "optimize.sil.inline.constant.arguments"
This forces inlining the annotated function if its arguments are constant.
2025-04-01 18:12:45 +02:00
Erik Eckstein
e1f4057ffc ConstantFolding: only print a warning for infinity floating point literals if it has an AST node
This avoids false alarms for floating point literals which are imported from the `var infinity` getter of floating point types.
2025-04-01 18:12:45 +02:00
Michael Gottesman
5499734ed4 [rbi] Fix an iterator invalidation issue.
Due to compile time issues, I added a cache into
getUnderlyingTrackedValue(). This caused an iterator invalidation issue when we
recursed in the case when we had an underlying object since we would recurse
into getUnderlyingTrackedValue() instead of getUnderlyingTrackedValueHelper()
potentially causing us to cache another value and thus causing the underlying
DenseMap to expand. Now we instead just call getUnderlyingTrackedValueHelper()
so that we avoid the invalidation issue. This may cause us to use slightly more
compile time but we are still only ever going to compute the underlying value
once for any specific value.
2025-04-01 09:01:30 -07:00
Michael Gottesman
98984a2678 [rbi] Remove a dead field, rename a class, and add some comments.
Specifically,

1. UseDefChainVisitor::actorIsolation is dead. I removed it to prevent any
confusion/thoughts that it actually found isolation. I also removed it from
UnderlyingTrackedValue since that was the only place where we were using it. I
left UnderlyingTrackedValue there in case I need to add additional state there
in the future.

2. Now that UseDefChainVisitor is only used to find the base of a value (while
not looking through Sendable addresses), I renamed it to
AddressBaseComputingVisitor.

3. I renamed UseDefChainVisitor::isMerge to isProjectedFromAggregate. That is
actually what we use it for. I also added a comment explaining what it is used
for.
2025-04-01 08:48:08 -07: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
Michael Gottesman
69ee33a25a Fix require operand to also include trackableDest. 2025-03-31 18:04:50 -07:00
Pavel Yaskevich
0897962d27 Merge pull request #80373 from xedin/rdar-146101172-narrow
[SILOptimizer] Prevent devirtualization of call to distributed witnes…
2025-03-31 09:29:37 -07:00
Allan Shortlidge
8f2d5a759e Merge pull request #80321 from tshortli/warnings 2025-03-30 16:14:21 -07:00
Pavel Yaskevich
585b687103 [SILOptimizer] Prevent devirtualization of call to distributed witness requirements
This is a narrow fix, we are going to work on fixing this properly
and allowing both devirtualization and specialization for distributed
requirement witnesses.

Anything that uses an ad-hoc serialization requirement scheme cannot
be devirtualized because that would result in loss of ad-hoc conformance
in new substitution map.

Resolves: https://github.com/swiftlang/swift/issues/79318
Resolves: rdar://146101172
2025-03-29 19:27:46 -07:00
Arnold Schwaighofer
0222f90cf0 Merge pull request #80256 from aschwaighofer/disable_cond_fail_by_function
Disable cond_fail instructions by filtering the instruction's parent function
2025-03-28 13:18:19 -07:00
Allan Shortlidge
43fcb2cecd SIL/SILOptimizer: Fix unused variable warnings. 2025-03-28 12:33:39 -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
ac60612242 [Compile Time Values] Emit diagnostic note with parameter location on a non-@const argument to a @const parameter 2025-03-27 14:33:38 -07:00
Artem Chikin
608e068a7a [Compile Time Values] Restrict the check for local variables to not apply to parameter value declarations
And remove some debug prints
2025-03-27 14:33:38 -07:00
Artem Chikin
114af54875 [Compile Time Values] Rebase on top of newly-added experimental feature for the '@const' attribute 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
Arnold Schwaighofer
cc76edea15 Add a -print-cond-fail-messages-include-function-name option
Additionally, also consider the function name as the key to base cond_fail
removal on under `-cond-fail-config-file`.
2025-03-26 08:12:35 -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
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
nate-chandler
17952d4d6f Merge pull request #80221 from nate-chandler/general-coro/20250320/1
[CoroutineAccessors] Default overrides of new symbols.
2025-03-25 12:22:40 -07:00
Pavel Yaskevich
5af7e0d09b Merge pull request #80236 from xedin/is-self-recursive-cache
[SILOptimizer] Turn "is self-recursive" check into analysis
2025-03-25 10:37:07 -07:00
Nate Chandler
4951e9d091 [DFE] Default overrides are alive.
They are used externally and can't be eliminated as dead when there are
no uses from SIL (of which in fact there never are any).
2025-03-25 07:22:43 -07:00
Pavel Yaskevich
41c88f864a [SILOptimizer] Turn "is self-recursive" check into analysis
The body of a function has to be re-analyzed for every call
site of the function, which is very expensive and if the
body is not changed would produce the same result.

This takes about ~10% from swift-syntax overall build time
in release configuration.
2025-03-24 00:25:13 -07:00
Doug Gregor
731f58443c Address review feedback on AbstractConformance in ProtocolConformanceRef 2025-03-23 20:54:39 -07:00
Kuba (Brecka) Mracek
033f6679e8 Merge pull request #80185 from kubamracek/embedded/used
[embedded] Link in @_used declarations from other modules in SILLinker
2025-03-22 12:01:56 -07:00
Arnold Schwaighofer
7da2333017 Merge pull request #80167 from aschwaighofer/print_cond_fail_message_strings
SIL: Add an option to print all the cond_fail message strings encountered during IRGenPrepare
2025-03-21 15:45:46 -07:00
eeckstein
962be95c75 Merge pull request #79511 from swiftlang/78848-fix
Ensure we're commuting instructions only when internal one has a single use.
2025-03-21 09:16:34 +01:00
Kuba Mracek
9a293ed29a [embedded] Link in @_used declarations from other modules in SILLinker 2025-03-20 15:52:15 -07:00
Arnold Schwaighofer
e11e02675c SIL: Add an option to print all the cond_fail message strings encountered during IRGenPrepare
Run the swift-frontend in a mode that will generate LLVM IR adding the
option `-print-cond-fail-messages` will dump all cond_fail message strings
encountered in the SIL.

```
% swift-frontend -Xllvm -print-cond-fail-messages -emit-ir/-c ...
cond_fail message encountered: Can't take a prefix of negative length from a collection
cond_fail message encountered: Range out of bounds
cond_fail message encountered: Array index is out of range
```
2025-03-20 09:46:16 -07:00
Arnold Schwaighofer
69e9dd34c2 Merge pull request #80127 from aschwaighofer/disable_cond_fail_by_message_comment
Add comment for cond-fail-config-file option
2025-03-20 08:06:55 -07:00
eeckstein
29876fd491 Merge pull request #80137 from eeckstein/fix-cast-optimizer
CastOptimizer: fix optimization of casts from non-existentials to existentials
2025-03-20 07:26:18 +01:00
Amritpan Kaur
3c30d68d2e Merge pull request #78823 from amritpan/method-keypaths
[Sema/SILGen/IRGen] Implement method & initializer keypaths.
2025-03-19 18:59:17 -07:00
Erik Eckstein
21264019cd CastOptimizer: fix optimization of casts from non-existentials to existentials
We need to consider that archetypes (generic types) can be existentials if they conform to self-conforming protocols.

Fixes a miscompile
rdar://147269904
2025-03-19 20:30:48 +01:00
Amritpan Kaur
39b48bb218 [SIL] Handle KeyPathComponentKind::Method in helpers. 2025-03-19 10:54:09 -07:00
Amritpan Kaur
e7e354d989 [NFC] Generalize subscript code for methods. 2025-03-19 10:54:09 -07:00
Arnold Schwaighofer
1e15a85378 Add comment for cond-fail-config-file option 2025-03-19 10:28:57 -07:00
Arnold Schwaighofer
2f30161563 Merge pull request #80097 from aschwaighofer/remove_cond_fails_by_message
SIL: Allow to selectively disabled cond_fails by cond_fail message
2025-03-19 10:26:21 -07:00