Commit Graph

1058 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
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
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
eeckstein
cc11a9baf3 Merge pull request #81203 from eeckstein/fix-objc-class-casting
CastOptimizer: don't assume dynamic casts from ObjectiveC classes to unrelated classes will fail
2025-05-02 07:07:56 +02:00
Meghana Gupta
35d62a4a36 Introduce end_cow_mutation_addr instruction 2025-04-30 13:39:45 -07:00
Erik Eckstein
7a5dbdc20b CastOptimizer: don't assume dynamic casts from ObjectiveC classes to unrelated classes will fail
In case of ObjectiveC classes, the runtime type can differ from its declared type.
Therefore a cast between (compile-time) unrelated classes may succeed at runtime.

rdar://149810124
2025-04-30 16:42:42 +02:00
nate-chandler
b93ed3e32b Merge pull request #81081 from swiftlang/revert-80839-moveonly-trivial-field-as-reinitialize
Revert "MoveOnlyChecker: Treat trivial stores as reinitializations rather than initializations."
2025-04-24 19:34:08 -07:00
nate-chandler
e4d3207b40 Revert "MoveOnlyChecker: Treat trivial stores as reinitializations rather than initializations." 2025-04-24 12:10:07 -07:00
Nate Chandler
02cad73cef [FSPL] Look through unchecked addr casts.
rdar://149850921
2025-04-23 21:29:22 -07: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
Joe Groff
3860023081 Merge pull request #80839 from jckarter/moveonly-trivial-field-as-reinitialize
MoveOnlyChecker: Treat trivial stores as reinitializations rather than initializations.
2025-04-16 17:38:55 -07:00
Joe Groff
a1ff2e38dc MoveOnlyChecker: Treat trivial stores as reinitializations rather than initializations.
A trivial store is allowed to occur on an existing live value, and should not
trigger an attempt to destroy the original value completely. Fixes rdar://147791932.
2025-04-15 13:40:22 -07:00
nate-chandler
9cc1947527 Merge pull request #80766 from nate-chandler/rdar149007151
[DCE] Don't delete instructions which consume escaping values.
2025-04-12 08:31:12 -07:00
Nate Chandler
9fa0888bbe NFC: [OSSACompleteLifetime] Allow forced verifying 2025-04-11 14:57:39 -07:00
Erik Eckstein
75a0cc031b CastOptimizer: handle isolated conformances
Check the isolation of conformances to avoid wrong folding of dynamic casts
rdar://147417762
2025-04-05 09:00:30 +02:00
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
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
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
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
e7000e4668 SIL: Add mark_dependence_addr 2025-03-25 23:02:42 -07:00
Doug Gregor
731f58443c Address review feedback on AbstractConformance in ProtocolConformanceRef 2025-03-23 20:54:39 -07:00
Erik Eckstein
d225c47d25 AST: rename OpenArchetypeType -> ExistentialArchetypeType
NFC
2025-03-11 20:21:46 +01:00
Erik Eckstein
a54502aee9 MemAccessUtils: handle the obsolete allocVector builtin
This builtin was removed. But to be able to parse old Swift.swiftinterface files it is required to handle the builtin in MemAccessUtils.
2025-03-11 08:03:17 +01:00
Erik Eckstein
810064b7dc Cleanup and additions to AST and SIL Type/CanonicalType
* factor out common methods of AST Type/CanonicalType into a `TypeProperties` protocol.
* add more APIs to AST Type/CanoncialType.
* move `MetatypeRepresentation` from SIL.Type to AST.Type and implement it with a swift enum.
* let `Builder.createMetatype` get a CanonicalType as instance type, because the instance type must not be a lowered type.
2025-03-07 15:59:33 +01:00
Meghana Gupta
cf6c4c9422 Merge pull request #79699 from meg-gupta/prboundscheck
Add support for bounds check optimization of Span and InlineArray
2025-03-03 14:32:27 -08:00
Andrew Trick
2fe155ac30 OSSALifetimeCompletion: check liveness failure
This transformation is invalid without complete liveness. Add a release assert
to check this. Temporarily hide the assert under -verify-lifetime-completion
until the passes that use this utility are fixed to check escapes.
2025-03-02 23:51:34 -08:00
Andrew Trick
d73a081fe7 Add pointer escape and dependent use tracking to InteriorLiveness
Rig TransitiveAddressWalker to keep track of enough information for passes to
correctly check for pointer escapes and dependence uses. Requires for precise
bail-outs and asserts.
2025-03-02 23:51:34 -08:00
Meghana Gupta
9ce8bb3682 Add a new abstraction FixedStorageSemanticsCall 2025-02-28 09:50:58 -08:00
Slava Pestov
541757a491 AST: Remove TypeBase::isOpenedExistential()
At one point, OpenedArchetypeType did not exist as a separate subclass
of ArchetypeType, so this method did something. Now, it's just
equivalent to calling is<> or isa<>.

I also removed a couple of asserts that were obvious no-ops as a result.
2025-02-27 09:55:36 -05:00
Andrew Trick
edcaecc09d Fix BorrowedValue::visitInteriorPointerOperandHelper
to handle borrowed-from (as a ForwardingInstruction).
2025-02-25 23:08:55 -08:00
Andrew Trick
5f8b93c66a Fix interior liveness to report the escaping instruction as a use. 2025-02-25 23:08:55 -08:00
Andrew Trick
f29bb44d07 OwnershipUseVisitor::visitInnerBorrowUses: support dependent values
Add liveness support for dependent values: borrowed-from & mark_dependence so
they aren't reported as unknown uses.

Centralize the logic in BorrowingOperand::getScopeIntroducingUserResult
and BorrowingOperand::getDependentUserResult().
2025-02-25 23:08:55 -08:00
Andrew Trick
e8af00769e Remove adjacent phis from OwnershipLiveness.
The extra complexity for traversing phis is not needed now that it handles
borrowed-from instructions. Remove the redundant logic because it complicates
the liveness algorithm and generates confusing results.
2025-02-25 23:08:54 -08:00
Andrew Trick
1cb4d50877 Fix BorrowingOperand::visitScopeEndingUses() invariants.
This API only makes sense for a scoped borrow-introducer such as:
- reborrow
- owned mark_dependence

Borrowing operands that forward guaranteed values do not have scope-ending uses.
2025-02-25 23:08:54 -08:00
Andrew Trick
e78aa38204 Remove BorrowingOperand.getImplicitUses.
It is buggy/misleading because of dead-def handling. The current operand may be
re-pushed if it is a dead borrow scope.
2025-02-25 23:08:54 -08:00
Andrew Trick
b3a445fb55 Fix BorrowingOperand::getBorrowIntroducingUserResult()
To handle borrowing operands that produce a dependence value but do not create a
nested borrow scope. This includes non-reborrow borrowed-from and guaranteed
mark_dependence [nonescaping].
2025-02-25 23:08:54 -08:00
Andrew Trick
f1792d80b3 Fix BorrowingOperand.visitScopeEndingUses
Only return false if the visitor returns false. Clients were ignoring the
result.

If the BorrowingOperand does not create a borrow scope, call visitUnknownUse
instead.

Until we have complete lifetimes, to avoid breaking code that cannot handle dead
defs, consider a dead borrow scope to be an unknown use.
2025-02-25 23:08:54 -08:00
Erik Eckstein
e0b4f71af6 SIL: remove the alloc_vector instruction
It's not needed anymore, because the "FixedArray" experimental feature is replaced by inline-arrays.
2025-02-12 10:51:14 +01:00
Erik Eckstein
6407f9a0bd remove the allocVector builtin
It's not needed anymore, because the "FixedArray" experimental feature is replaced by inline-arrays.
2025-02-12 10:51:14 +01:00
Erik Eckstein
6a6d3f0b13 SIL: handle mark_dependence in the MemoryLifetimeVerifier
The check is not perfect, because it only checks that the base operand is alive _at_ the mark_dependence.
Ideally it should check that the base operand is alive during the whole lifetime of the value operand.
2025-02-10 17:57:47 +01:00
Erik Eckstein
a88cb49ee8 SIL: define a memory-read effect on the mark_dependence base value
If the base value of a mark_dependence is an address, that memory location must be initialized at the mark_dependence.
This requires that the mark_dependence is considered to read from the base address.
2025-02-10 17:57:47 +01:00
Andrew Trick
01c3343b05 Fix mark_dependence ownership: compatibility with owned values
This fixes an OSSA verification bug introduced here:

    commit 79b649854b
    Author: Meghana Gupta <meghanavgupta@gmail.com>
    Date:   Wed Jan 22 01:24:49 2025

        Fix operand ownership of mark_dependence [nonescaping] of address values

The bug only showed up with mark_dependence [nonescaping], which means mainly
affects `~Escapable` types. Adddressors happened to work because SILGen was
emitting a borrow scope around them.

Rather than reverting the change above, this fix migrates mark_dependence
[nonescaping] to an implicit borrow scope.

Fixes rdar://144199759 (Assert: mark_dependence [nonescaping]:
ownership incompatible with an owned value)
2025-02-05 16:23:14 -08:00
Andrew Trick
e705a6d7c3 Temporarily introduce AnyInteriorPointer operand ownership.
This is necessary to fix a recent OSSA bug that breaks common occurrences on
mark_dependence [nonescaping]. Rather than reverting that change above, we make
forward progress toward implicit borrows scopes, as was the original intention.

In the near future, all InteriorPointer instructions will create an implicit
borrow scope. This means we have the option of not emitting extraneous
begin/end_borrow instructions around intructions like ref_element_addr,
open_existential, and project_box. After that, we can also migrate
GuaranteedForwarding instructions like tuple_extract and struct_extract.
2025-02-05 16:23:02 -08:00
Anthony Latsis
34f9b80cbc Merge pull request #78750 from AnthonyLatsis/oryza-sativa
[Gardening] Fix some set but not used variables
2025-01-31 04:29:05 +00:00
Anthony Latsis
a84dfc8387 [Gardening] Fix some set but not used variables 2025-01-30 21:34:38 +00:00
Nate Chandler
95b7b06bef [Test] Renamed test case.
Replaced a - with a _.
2025-01-28 10:44:29 -08:00
eeckstein
95f1dfbf07 Merge pull request #78885 from eeckstein/fix-without-actually-escaping
Fix two problems with `withoutActuallyEscaping`
2025-01-27 07:59:02 +01:00
Andrew Trick
f0144ab7b1 Merge pull request #78830 from atrick/fix-lifedep-trivial-deadend
SILGenCleanup: extend to handle trivial local var scopes
2025-01-25 15:34:35 -08:00
Erik Eckstein
3ec5d7de24 SIL: replace the is_escaping_closure instruction with destroy_not_escaped_closure
The problem with `is_escaping_closure` was that it didn't consume its operand and therefore reference count checks were unreliable.
For example, copy-propagation could break it.
As this instruction was always used together with an immediately following `destroy_value` of the closure, it makes sense to combine both into a `destroy_not_escaped_closure`.
It
1. checks the reference count and returns true if it is 1
2. consumes and destroys the operand
2025-01-24 19:23:27 +01:00