Commit Graph

11224 Commits

Author SHA1 Message Date
Erik Eckstein
9052652651 add the prepareInitialization builtin.
It is like `zeroInitializer`, but does not actually initialize the memory.
It only indicates to mandatory passes that the memory is going to be initialized.
2025-05-20 20:46:33 +02:00
Erik Eckstein
3cbe94d7d1 inliner: tune the heuristic for constructors to be inlined into global initializer functions.
Inlining constructors into global initializers increase the changes that the global can be initialized statically.
2025-05-20 20:46:33 +02:00
Stephen Canon
3aa7b592b6 Implement Builtin.select binding llvm select instruction (#81598)
Not used (yet), but needed to implement SIMD.replacing(with:where:) idiomatically, and probably useful otherwise.
2025-05-20 13:30:59 -04:00
Hamish Knight
3ec3421987 Merge pull request #81604 from hamishknight/pretty-crash
Adopt `ABORT` throughout the compiler
2025-05-20 10:05:03 +01:00
Hamish Knight
edca7c85ad Adopt ABORT throughout the compiler
Convert a bunch of places where we're dumping to stderr and calling
`abort` over to using `ABORT` such that the message gets printed to
the pretty stack trace. This ensures it gets picked up by
CrashReporter.
2025-05-19 20:55:01 +01:00
nate-chandler
8959f60ab1 Merge pull request #81566 from nate-chandler/rdar151325025
[MoveOnlyChecker] Don't complete phis.
2025-05-19 07:21:21 -07:00
eeckstein
d985bf6435 Merge pull request #81567 from eeckstein/fix-builtin-emplace
SILGen: insert an `end_lifetime` in the throw-branch of a `Builtin.emplace`
2025-05-17 23:40:25 +02:00
Michael Gottesman
010443c854 [rbi] Treat a partial_apply as nonisolated(unsafe) if all of its captures are nonisolated(unsafe).
rdar://144111950
2025-05-17 12:21:21 -07:00
Meghana Gupta
f7529eae86 Merge pull request #81520 from meg-gupta/disableverifysemantics
Add a new semantics attribute to disable SIL verification on a function
2025-05-16 15:38:32 -07:00
Erik Eckstein
ddbc3a2fad SILGen: insert an end_lifetime in the throw-branch of a Builtin.emplace
When the called closure throws an error, it needs to clean up the buffer.
This means that the buffer is uninitialized at this point.

We need an `end_lifetime` so that the move-only checker doesn't insert a wrong `destroy_addr` because it thinks that the buffer is initialized.

Fixes a mis-compile.

rdar://151461109
2025-05-16 21:54:39 +02:00
Nate Chandler
9b3db3646a [MoveOnlyChecker] Don't complete phis.
Apply the MoveOnlyAddressChecker change from
https://github.com/swiftlang/swift/pull/73358 to the
MoveOnly[Value]Checker.

After 7713eef817, before running value
checking, all lifetimes in the function are completed.  That doesn't
quite work because lifetime completion expects not to encounter
reborrows or their adjacent phis.

rdar://151325025
2025-05-16 11:58:44 -07:00
Nate Chandler
d18a0178bb [Gardening] Whitespace cleanup. 2025-05-16 11:36:22 -07:00
nate-chandler
f4a2e46e39 Merge pull request #81541 from nate-chandler/rdar139666145
[MoveOnly] Fix consume of addr with mutated field.
2025-05-16 06:55:31 -07:00
Nate Chandler
1765f0b1e0 [MoveOnly] Fix consume of addr with mutated field.
Don't fail out of use visitation when encountering an apply which uses a
field of the value as an inout parameter.

rdar://139666145
2025-05-15 15:19:26 -07:00
Nate Chandler
dcde328fe9 [Gardening] MoveOnly: Move and add comment. 2025-05-15 15:18:50 -07:00
Meghana Gupta
aa01b2ad06 Add a new semantics attribute to disable SIL verification on a function
This provides a way to disable verification per function instead of the entire module.
2025-05-15 14:30:28 -07:00
Meghana Gupta
8c5fae087d Merge pull request #81499 from meg-gupta/fixdropdeinit
Fix InstructionDeleter for drop_deinit instruction
2025-05-14 15:22:05 -07:00
Meghana Gupta
16d1eadd5d Fix InstructionDeleter for drop_deinit instruction
Currently we delete dead drop_deinit instructions in InstructionDeleter.
For address results, we may end up with ownership errors after being promoted to value forms.
For value results, fixLifetimes mode of InstructionDeleter will insert an illegal destroy_value

rdar://151104993
2025-05-14 10:43:59 -07:00
eeckstein
7ff1066409 Merge pull request #81480 from eeckstein/fix-fso
FunctionSignatureOptimization: don't convert indirect `@in` to `@in_guaranteed` if the argument is mutated
2025-05-14 06:25:16 +02:00
Erik Eckstein
8cab792753 FunctionSignatureOptimization: don't convert indirect @in to @in_guaranteed if the argument is mutated
This fixes a verifier error because an `@in_guaranteed` argument must not be mutated.

https://github.com/swiftlang/swift/issues/81444
rdar://151147971
2025-05-13 18:53:31 +02:00
Erik Eckstein
85a49dcbbc Optimizer: make salvageDebugInfo optional when deleting instructions
Add a boolean parameter `salvageDebugInfo` to `Context.erase(instruction:)`.
Sometimes it needs to be turned off because the caller might require that after erasing the original instruction the operands no users anymore.
2025-05-13 07:37:45 +02:00
Erik Eckstein
bc4310b0eb Optimizer: simplify unchecked_addr_cast for vectors
Reimplement the simplification in swift and add a new transformation:
```
  %1 = unchecked_addr_cast %0 : $*Builtin.FixedArray<N, Element> to $*Element
```
->
```
  %1 = vector_base_addr %0 : $*Builtin.FixedArray<N, Element>
```
2025-05-12 19:25:12 +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
2c27963ea1 SILCombine: handle mark_dependence in dead-closure elimination
rdar://150686370
2025-05-06 19:42:01 +02:00
Erik Eckstein
8dd76769bb SILCombine: handle mark_dependence in apply-of-partial_apply optimization
rdar://150686370
2025-05-06 19:42:01 +02:00
Erik Eckstein
c6b1e3e854 TempRValueElimination: re-implement the pass in swift
Beside cleaning up the source code, the motivation for the translation into Swift is to make it easier to improve the pass for some InlineArray specific optimizations (though I'm not sure, yet if we really need those).
Also, the new implementation doesn't contain the optimize-store-into-temp optimization anymore, because this is covered by redundant load elimination.
2025-05-06 13:08:09 +02:00
Pavel Yaskevich
778be225e1 Merge pull request #81277 from ludwwwig/remove-unused-header
[gardening] Delete an empty header
2025-05-06 00:23:06 -07:00
Ludwig Hollmann
39aa950660 Update file header comments for headers in lib. 2025-05-04 22:26:26 +02:00
Ludwig Hollmann
9482a1be6d [gardening] Delete an empty header.
This header was supposed to be deleted by #63783.
2025-05-03 22:43:48 +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
Meghana Gupta
35d62a4a36 Introduce end_cow_mutation_addr instruction 2025-04-30 13:39:45 -07:00
Slava Pestov
6ffa8fd489 AST: Change signature of LookupConformanceFn
Instead of passing in the substituted type, we pass in the
InFlightSubstitution. This allows the substituted type to be
recovered if needed, but we can now skip computing it for
the common case of LookUpConformanceInSubstitutionMap.
2025-04-30 13:42:20 -04:00
Kuba (Brecka) Mracek
3f61189657 Merge pull request #80914 from kubamracek/inliner-knobs
[SILOptimizer] Expose SIL inliner heuristics/constants as -Xllvm configurable knobs
2025-04-30 09:37:39 -07:00
eeckstein
e2ee00700f Merge pull request #81159 from eeckstein/deinit-barrier-optimizations
Some small deinit-barrier related optimizations
2025-04-30 15:33:46 +02:00
Slava Pestov
6b4710ed22 Merge pull request #81142 from slavapestov/more-type-subst-cleanup
Clean up duplicated opened existential archetype handling in SIL and more
2025-04-30 02:42:57 -04:00
Slava Pestov
7b5b5e9602 Merge pull request #81171 from slavapestov/fix-issue-81036
AST: Use weighted reduction order for opaque return types
2025-04-30 01:53:29 -04:00
Slava Pestov
3c26321aa3 Merge pull request #81173 from slavapestov/unused-vars
Squash warnings
2025-04-30 01:48:33 -04:00
Erik Eckstein
2fc32fbd4b Inliner: don't set the lexical flag on an argument alloc_stack if the inlined function is not a deinit barrier.
There is no need to do so. And this can enable other optimizations for non-lexical alloc-stacks.
2025-04-29 20:30:21 +02:00
Slava Pestov
3229ede386 SIL: Fix unused variable warning 2025-04-29 13:57:18 -04:00
Slava Pestov
115ba5c54f AST: Factor out GenericTypeParamType::withDepth() 2025-04-29 13:55:29 -04:00
Erik Eckstein
783f90b76c LICM: handle memory dependency for store sinking correctly
Prevent sinking of stores if there are instructions other than `load` which may read from memory.
This kind of memory dependencies were ignored.
Fixes SIL verifier crashes or - in worst case - miscompiles.

rdar://150205299
2025-04-29 17:46:56 +02:00
Slava Pestov
3b83ac30a1 SILOptimizer: Clean up existential archetype remapping in CSE 2025-04-28 13:47:53 -04:00
Slava Pestov
cd7a12ec2d SILOptimizer: Use ReplaceExistentialArchetypesWithConcreteTypes in SILCombiner 2025-04-28 11:49:50 -04:00
Erik Eckstein
6ccd1aceed Optimize keypaths in language 6 mode
In language 6 mode keypath instructions are created as existentials and the optimizer needs to look through the `open_existential_ref` instructions to recognize a keypath.

rdar://150173106
2025-04-28 15:52:18 +02:00
Anthony Latsis
925b72eaec Merge pull request #76337 from DePasqualeOrg/grammar-compound-modifiers
Grammatical corrections for compound modifiers
2025-04-25 13:50:52 +01:00
nate-chandler
e4d3207b40 Revert "MoveOnlyChecker: Treat trivial stores as reinitializations rather than initializations." 2025-04-24 12:10:07 -07:00
nate-chandler
c2ed51ec63 Merge pull request #81059 from nate-chandler/rdar149896608
Revert "[DCE] Verify liveness of completed lifetimes."
2025-04-24 11:31:33 -07:00
Anthony
c9b17383c8 Grammatical corrections for compound modifiers 2025-04-24 09:21:32 +02:00
Nate Chandler
fdd896e021 Revert "[DCE] Verify liveness of completed lifetimes."
This reverts commit 3ec9b269f5.

rdar://149896608
2025-04-23 16:59:26 -07:00
Evan Wilde
82bccb54fa Merge pull request #80920 from etcwilde/ewilde/cxxonly-disable-broken-passes
SILOptimizer: Disable invalid passes in C++-only compiler
2025-04-23 13:42:38 -07:00