Commit Graph

2592 Commits

Author SHA1 Message Date
Ben Barham
d72f5b12c4 Update StringRef::equals references to operator==
`equals` has been deprecated upstream, use `operator==` instead.
2024-06-27 19:14:06 -07:00
Meghana Gupta
42c1f9cb33 Fix mem2reg of lexical enum stack locations
When we have a non trivial enum lexical stack location, and we store a
 none value, after mem2reg we can end up with an ownership error
because of the leaking move_value [lexical].

This change avoids creating move_value [lexical] for such stores.

Do the same when we have store_borrow of none values, even though there
is no ownership error in this case, handle it like store for consistency
2024-06-27 17:34:56 -07:00
Meghana Gupta
32e72a6732 Allow TempRValueOpt of lexical alloc_stacks when base of copy source has guaranteed convention
A guaranteed function argument is live for the duration of the function.
It should be safe to allow TempRValueOpt when it is the base of the copy source of a lexical alloc_stack.
2024-06-27 16:18:15 -07:00
Akira Hatanaka
42bc49d3fe Add a new parameter convention @in_cxx for non-trivial C++ classes that are passed indirectly and destructed by the caller (#73019)
This corresponds to the parameter-passing convention of the Itanium C++
ABI, in which the argument is passed indirectly and possibly modified,
but not destroyed, by the callee.

@in_cxx is handled the same way as @in in callers and @in_guaranteed in
callees. OwnershipModelEliminator emits the call to destroy_addr that is
needed to destroy the argument in the caller.

rdar://122707697
2024-06-27 09:44:04 -07:00
Tim Kientzle
1098054291 Merge branch 'main' into tbkka-assertions2 2024-06-18 17:52:00 -07:00
Akira Hatanaka
d92f181ace Create two versions (for caller and callee) of the functions that answer questions about parameter convention (#74124)
Create two versions of the following functions:

isConsumedParameter
isGuaranteedParameter
SILParameterInfo::isConsumed
SILParameterInfo::isGuaranteed
SILArgumentConvention::isOwnedConvention
SILArgumentConvention::isGuaranteedConvention

These changes will be needed when we add a new convention for
non-trivial C++ types as the functions will return different answers
depending on whether they are called for the caller or the callee. This
commit doesn't change any functionality.
2024-06-18 09:06:09 -07:00
Doug Gregor
25830d6bc3 Merge pull request #74225 from DougGregor/flow-sensitive-actor-init-isolation
Teach `#isolation` to respect the flow-sensitive nature of actor initializers
2024-06-10 01:52:38 -07:00
Doug Gregor
d1ae73f436 Handle flow-sensitive #isolation in distributed actor initializers.
Distributed actors can be treated as actors by accessing the `asLocalActor`
property. When lowering `#isolation` in a distributed actor initializer,
use a separate builtin `flowSensitiveDistributedSelfIsolation` to
capture the conformance to `DistributedActor`, and have Definite
Initialization introduce the call to the `asLocalActor` getter when
needed.
2024-06-09 22:48:43 -07:00
Doug Gregor
956243cd7e Teach #isolation to respect the flow-sensitive nature of actor initializers
Actor initializers have a flow-sensitive property where they are isolated
to the actor being initialized only after the actor instance itself is
fully-initialized. However, this behavior was not being reflected in
the expansion of `#isolation`, which was always expanding to `self`,
even before `self` is fully formed.

This led to a source compatibility issue with code that used the async
for..in loop within an actor initializer *prior* to the point where the
actor was fully initialized, because the type checker is introducing
the `#isolation` (SE-0421) but Definite Initialization properly rejects
the use of `self` before it is initialized.

Address this issue by delaying the expansion of `#isolation` until
after the actor is fully initialized. In SILGen, we introduce a new
builtin for this case (and *just* this case) called
`flowSensitiveSelfIsolation`, which takes in `self` as its argument
and produces an `(any Actor)?`. Definite initialization does not treat
this as a use of `self`. Rather, it tracks these builtins and
replaces them either with `self` (if it is fully-initialized at this
point) or `nil` (if it is not fully-initialized at this point),
mirroring the flow-sensitive isolation semantics described in SE-0327.

Fixes rdar://127080037.
2024-06-07 14:54:20 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Nate Chandler
224d36c576 [DCE] Insts that define lexical values seem useful
Don't delete as dead instructions that define lexical values such as
`move_value [lexical]`.

rdar://129299803
2024-06-05 13:04:43 -07:00
Nate Chandler
aa3cbe0c67 [NFC] OwnedValueCan: Typed maximizeLifetime. 2024-06-03 15:45:23 -07:00
Nate Chandler
df008924da [NFC] OwnedValueCan: Typed pruneDebugMode. 2024-06-03 15:45:20 -07:00
Ellie Shin
9392a69810 Merge pull request #73754 from apple/elsh/serialized_kind
Support inlinability with [serialized_for_package]
2024-05-24 10:13:36 -07:00
Meghana Gupta
8b4469be1c Merge pull request #73852 from meg-gupta/fixdce
Don't delete allocations in DCE
2024-05-23 16:16:01 -07:00
Ellie Shin
5ccc4cd394 SIL function can be serialized with different kinds: [serialized] or
[serialized_for_package] if Package CMO is enabled. The latter kind
allows a function to be serialized even if it contains loadable types,
if Package CMO is enabled. Renamed IsSerialized_t as SerializedKind_t.

The tri-state serialization kind requires validating inlinability
depending on the serialization kinds of callee vs caller; e.g. if the
callee is [serialized_for_package], the caller must be _not_ [serialized].
Renamed `hasValidLinkageForFragileInline` as `canBeInlinedIntoCaller`
that takes in its caller's SerializedKind as an argument. Another argument
`assumeFragileCaller` is also added to ensure that the calle sites of
this function know the caller is serialized unless it's called for SIL
inlining optimization passes.

The [serialized_for_package] attribute is allowed for SIL function, global var,
v-table, and witness-table.

Resolves rdar://128406520
2024-05-23 15:53:02 -07:00
Kshitij Jain
64da348ee9 Merge pull request #73688 from jkshtj/main
[Autodiff] Adds logic to rewrite call-sites using functions specialized by the closure-spec optimization
2024-05-23 14:21:31 -07:00
Meghana Gupta
505d84fe74 Don't delete allocations in DCE 2024-05-23 12:59:00 -07:00
Kshitij
12faf79911 [Autodiff] Adds logic to rewrite call-sites using functions specialized by the closure-spec optimization 2024-05-21 12:02:28 -07:00
Slava Pestov
a1462ef184 SIL: Promote removeDeadBlock() from SILOptimizer to a method on SILBasicBlock 2024-05-21 13:52:58 -04:00
nate-chandler
4cf63a9394 Merge pull request #73576 from nate-chandler/gardening/20240510/1
[Gardening] SIL: Spelling of live range.
2024-05-14 15:50:08 -07:00
Emil Pedersen
15cab3a19f Merge pull request #73555 from Snowy1803/complete-getvarinfo
[DebugInfo] Return complete variable info from getVarInfo by default
2024-05-13 10:32:43 -07:00
Emil Pedersen
0be63d0422 [DebugInfo] Return complete variable info from getVarInfo by default
getVarInfo() now always returns a variable with a location and scope.
To opt out of this change, getVarInfo(false) returns an incomplete variable.
This can be used to work around bugs, but should only really be used for
printing.

The complete var info will also contain the type, except for debug_values,
as its type depends on another instruction, which may be inconsistent if
called mid-pass.

All locations in debug variables are now also stripped of flags, to avoid
issues when comparing or hashing debug variables.
2024-05-10 16:12:56 -07:00
Nate Chandler
71368be8d4 [Gardening] SIL: "Liferange" -> "Liverange" 2024-05-10 15:54:09 -07:00
Nate Chandler
87e4c65e28 [Gardening] SIL: "liferange" -> "liverange" 2024-05-10 15:54:07 -07:00
Emil Pedersen
7c9676e890 [DebugInfo] Fix var info after DeadObjectElimination
The scope of a store has to be the variable's scope.
The type should be set to the element's type, and only if not already set.
The variable's location should be set.
2024-05-08 16:43:34 -07:00
Emil Pedersen
3003155fb1 Merge pull request #73404 from Snowy1803/phixpansion
[DebugInfo] Fix PhiExpansion losing debug info
2024-05-06 10:17:55 -07:00
Nate Chandler
06921cfe84 [SIL] Hollow out Builtin.copy, deprecate _copy.
The copy operator has been implemented and doesn't use it.  Remove
`Builtin.copy` and `_copy` as much as currently possible.

Source compatibility requires that `_copy` remain in the stdlib.  It is
deprecated here and just uses the copy operator.

Handling old swiftinterfaces requires that `Builtin.copy` be defined.
Redefine it here as a passthrough--SILGen machinery will produce the
necessary copy_addr.

rdar://127502242
2024-05-03 15:56:25 -07:00
Emil Pedersen
b944e38ec3 [DebugInfo] Fix PhiExpansion losing debug info
When replacing a struct with its field, it now emits a debug_value
with a fragment, instead of dropping the debug_value.
2024-05-03 14:46:04 -07:00
Nate Chandler
5383df755a [NFC] LifetimeCompletion: Clarify modes.
Completion is done along a boundary, either the availability or the
liveness boundary.  Represent which with a type.  Update docs and names.
2024-05-01 08:57:01 -07:00
Emil Pedersen
ce68d74025 Merge pull request #73276 from Snowy1803/doc-and-fixes
[DebugInfo] Improve documentation & Fix discovered bugs
2024-04-29 10:22:46 -07:00
Emil Pedersen
c2c16f53dd [DebugInfo] Fix undef debug values being removed 2024-04-26 16:31:16 -07:00
Emil Pedersen
a31d15c438 Merge pull request #72964 from Snowy1803/mem2reg-salvage-store
[DebugInfo] Salvage all stores
2024-04-25 16:52:37 -07:00
Emil Pedersen
450db6e530 [DebugInfo] Add special cases for copy forwarding 2024-04-24 18:23:39 -07:00
Nate Chandler
7fd4311d7d [SIL] Verify complete lifetimes when option set.
Only pass DeadEndBlocks to verifyOwnership if OSSAVerifyComplete is not
set.  The verifier keys off of the nullness of DeadEndBlocks to decide
whether to verify complete lifetimes or not.
2024-04-24 12:59:45 -07:00
Emil Pedersen
523a769e34 [DebugInfo] [Mem2Reg] Move debug info promotion to salvageDebugInfo 2024-04-23 13:12:21 -07:00
Adrian Prantl
6357d12cfc Merge pull request #73009 from Snowy1803/debuginfo-small-fixes
[Debuginfo] Small fixes
2024-04-17 00:03:53 +02:00
Emil Pedersen
fac61c5e55 [DebugInfo] [SILSROA] Fix variable scope in some cases
SILBuilderWithScope ignores the scope of the debug value and uses the
scope of the next real instruction. We want to preserve the scope
of the original debug value, so we pass it explicitly.
2024-04-16 10:28:13 -07:00
Erik Eckstein
e14c1d1f62 SIL, Optimizer: update and handle borrowed-from instructions
Compute, update and handle borrowed-from instruction in various utilities and passes.
Also, used borrowed-from to simplify `gatherBorrowIntroducers` and `gatherEnclosingValues`.
Replace those utilities by `Value.getBorrowIntroducers` and `Value.getEnclosingValues`, which return a lazily computed Sequence of borrowed/enclosing values.
2024-04-10 13:38:10 +02:00
Erik Eckstein
44f4ea9099 DeadCodeElimination: fix debug logging of to-instruction when adding a reverse dependency 2024-04-10 13:38:10 +02:00
Meghana Gupta
2ef1aa5525 Merge pull request #72792 from meg-gupta/improvephireplace
Update SimplifyCFG's replacement of phi with its incoming value
2024-04-03 16:05:02 -07:00
Meghana Gupta
5bfa560b35 Update SimplifyCFG's replacement of phi with its incoming value
Previously we replaced phi with its incoming values when all incoming values were the same.
If the phi had itself as incoming value, it wasn't optimized. This PR handles such cases.
2024-04-03 10:46:05 -07:00
Emil Pedersen
e8ce02e0a3 [DebugInfo] Salvage debug info for allocations in SILSROA 2024-04-02 11:34:23 -07:00
Alejandro Alonso
36bf2ae3bf Merge pull request #72592 from Azoy/raw-layout-inst
[IRGen] Add Builtin.addressOfRawLayout
2024-03-29 07:38:37 -07:00
Alejandro Alonso
f5e10e2c0b Get rid of sil instruction and use a builtin for addressOfRawLayout 2024-03-27 11:36:29 -07:00
Emil Pedersen
4c8beefff4 [DebugInfo] Salvage debug info for stores removed by DeadObject-Elim
rdar://124283055
2024-03-26 10:02:34 -07:00
Erik Eckstein
a5320a6fcd EagerSpecializer: fix a SIL verifier crash
When inserting type checks for pre-specialized functions, the existing return-block can only be re-used if it has no arguments.
Otherwise we are creating an argument-less branch to a block with arguments.

rdar://124638266
2024-03-19 12:28:33 +01:00
Kuba Mracek
f5797941b7 [embedded] Specialize superclasses in VTableSpecializer as part of MandatoryPerformanceOptimizations 2024-03-15 21:30:08 -07:00
Ben Barham
9779c18da3 Rename startswith to starts_with
LLVM is presumably moving towards `std::string_view` -
`StringRef::startswith` is deprecated on tip. `SmallString::startswith`
was just renamed there (maybe with some small deprecation inbetween, but
if so, we've missed it).

The `SmallString::startswith` references were moved to
`.str().starts_with()`, rather than adding the `starts_with` on
`stable/20230725` as we only had a few of them. Open to switching that
over if anyone feels strongly though.
2024-03-13 22:25:47 -07:00
Meghana Gupta
2d27ec581c Merge pull request #72267 from meg-gupta/enablesilcombineempty
Enable SILCombine of inject_enum_addr for empty types
2024-03-12 20:34:09 -07:00