Commit Graph

8906 Commits

Author SHA1 Message Date
Meghana Gupta
f5c5c9e36b In non-ossa, ban non-trivial stores to alloc_ref's projections even the dtor is not inlined
There is no implementation to handle insertion of compensating releases of the non-trivial store's src for this case.
This never really happens, because destructor analysis is very limited and we end up banning alloc_ref with ref count instructions.
2023-08-07 10:21:40 -07:00
Meghana Gupta
768d98e1c4 Add a TODO in destructor analysis 2023-08-07 10:21:40 -07:00
Meghana Gupta
15e5364d25 DeadObjectElimination: Handle keypaths with non-trivial operands in OSSA 2023-08-07 10:21:40 -07:00
Meghana Gupta
41697b061c DeadObjectElimination: Handle non-trivial stores while processing alloc_stack 2023-08-07 10:21:40 -07:00
Pavel Yaskevich
11f1b08ada [DI] Properties with init accessors without "initializes" act as stored
Adjust DI to treat init accessor properties that have only 'accesses'
or no restrictions as if they are stored properties, this means that
if such property doesn't have a default initializer users would have
to reference it explicitly in their custom initializers.

We also need to suppress default init synthesis for such cases which
would be done in a followup commit.

Resolves: rdar://113401979
2023-08-04 21:05:07 -07:00
Slava Pestov
6ae2a1deee Merge pull request #67739 from slavapestov/var-decl-type-in-context
AST: Rename VarDecl::getType() to VarDecl::getTypeInContext()
2023-08-04 21:44:22 -04:00
Michael Gottesman
c9be4bda49 Merge pull request #67677 from gottesmm/borrowed-base-silgenlvalue
[move-only] Ensure that we properly nest accesses to base values if the base is noncopyable or the accessor result is noncopyable.
2023-08-04 12:26:19 -07:00
Slava Pestov
9ebb5f2e03 AST: Rename VarDecl::getType() to VarDecl::getTypeInContext()
This is a futile attempt to discourage future use of getType() by
giving it a "scary" name.

We want people to use getInterfaceType() like with the other decl kinds.
2023-08-04 14:19:25 -04:00
Anton Korobeynikov
03334a8f92 [AutoDiff] Generalize handling of semantic result parameters (#67230)
Introduce the notion of "semantic result parameter". Handle differentiation of inouts via semantic result parameter abstraction. Do not consider non-wrt semantic result parameters as semantic results

Fixes #67174
2023-08-03 09:33:11 -07:00
Michael Gottesman
c3d2276241 [silgen] Eliminate two more cases around subscripts where we were not borrowing.
Also, the store_borrow work in the previous patch caused some additional issues
to crop up. I fixed them in this PR and added some tests in the process.
2023-08-02 11:09:31 -07:00
nate-chandler
b14c34a592 Merge pull request #67660 from nate-chandler/opaque-values/20230801/2/rewrite_consuming_uses_last
[AddressLowering] Rewrite lifetime-ends last.
2023-08-02 07:04:52 -07:00
Joe Groff
aa397c763e Merge pull request #67657 from jckarter/sil-type-consolidate-move-only-predicate
Remove redundant SILType::isMoveOnlyNominalType (NFC)
2023-08-01 17:33:34 -07:00
Kuba (Brecka) Mracek
8510bdd7f0 Merge pull request #67587 from kubamracek/move-target-const-folding-to-swift-simplification
Move target const folding to swift simplification
2023-08-01 15:19:26 -07:00
Nate Chandler
6aa44d83c9 [AddressLowering] Rewrite lifetime-ends last.
Previously, `end_borrow`s were rewritten last in order to be able to
find them when inserting `end_borrow`s on behalf of newly created
`load_borrow`s. Generalize this to rewriting all lifetime-ending users
last.  This is necessary for the lifetime utilities used by `isLoadCopy`
to remain accurate when rewriting a `copy_value` previously determined
to be from a load-copy pair.
2023-08-01 14:51:00 -07:00
Joe Groff
03eec7da2b Remove redundant SILType::isMoveOnlyNominalType (NFC)
and implement `SILType::isPureMoveOnly` in terms of `Type::isPureMoveOnly`.
2023-08-01 14:07:38 -07:00
Joe Groff
984b4f2387 Merge pull request #67633 from jckarter/raw-layout-initialization
Fix `@_rawLayout` initialization to avoid spurious lifetime ends.
2023-08-01 13:34:29 -07:00
Joe Groff
9b783560ad Fix @_rawLayout initialization to avoid spurious lifetime ends.
We can't really treat them as always-initialized because that makes move checking
think that there's a value to destroy even on initialization, causing deinits to
run on uninitialized memory. Remove my previous hack, and use a `zeroInitializer`
to initialize the value state when emitting `init`, which is where we really need
the bootstrapping-into-initialized behavior. rdar://113057256
2023-08-01 08:34:02 -07:00
Nate Chandler
4f16bb1a74 [Mem2Reg] Don't canonicalize undef.
They aren't the kind of values whose lifetimes are eligible for
canonicalization.

rdar://113121424
2023-07-31 16:20:37 -07:00
Nate Chandler
f276ebf37e [Mem2Reg] Only lifetime canonicalize in OSSA.
Bail both on collecting stores and canonicalizing values if the function
being optimized doesn't have ownership.
2023-07-31 16:16:28 -07:00
Kuba Mracek
ae6129cf69 Cache the IRGenModule even between SIL passes 2023-07-31 11:57:28 -07:00
Kuba Mracek
5dac59ce71 Move TargetConstantFolding pass to the simplification passes in Swift, enable using MemoryLayout's .size, .stride, .alignment fields in forced-const global initializers 2023-07-31 10:54:07 -07:00
swift-ci
1cca22bafe Merge pull request #67526 from nate-chandler/mem2reg/canonicalize-values
[Mem2Reg] Canonicalize promoted lifetimes.
2023-07-28 15:30:59 -07:00
Nate Chandler
b563c4ea3d [Mem2Reg] Canonicalize new phis.
Mem2Reg introduces new OSSA values in the form of phis.  Take
responsibility for canonicalizing their lifetimes.
2023-07-28 13:21:13 -07:00
Nate Chandler
52ce100ef4 [Mem2Reg] Canonicalize stored values.
Stored values may now be canonicalizable, now that they have one less
consuming use.
2023-07-28 13:19:52 -07:00
nate-chandler
5116600284 Merge pull request #67583 from nate-chandler/checked_cast_br/formal-source
[SIL] Add source formal type to checked_cast_br.
2023-07-28 10:54:06 -07:00
Joshua Turcotti
2eade1d1b5 Merge pull request #67511 from JTurcotti/tweaks
[SendNonSendable] Assorted Bugfixes and Tweaks
2023-07-28 09:24:36 -07:00
jturcotti
bb2f3c011e rename DeferredSendableChecking pass to SendNonSendable pass, handle more instructions such as try_apply and begin_apply, and fix bugs 2023-07-27 16:45:29 -07:00
Nate Chandler
e5d87f75a8 [SIL] Add source formal type to checked_cast_br.
It is necessary for opaque values where for casts that will newly start
out as checked_cast_brs and be lowered to checked_cast_addr_brs, since
the latter has the source formal type, IRGen relies on being able to
access it, and there's no way in general to obtain the source formal
type from the source lowered type.
2023-07-27 15:04:15 -07:00
Michael Gottesman
55892ef30d [silgen] Add a special visitor for accessing the base of noncopyable types.
We want these to be borrowed in most cases and to create an appropriate onion
wrapping. Since we are doing this in more cases now, we fix a bunch of cases
where we used to be forced to insert a copy since a coroutine or access would
end too early.
2023-07-27 10:00:28 -07:00
Nate Chandler
7fb9bcade8 [Mem2Reg] NFC: Lifted livePhiBlocks higher.
Move it all the way up into MemoryToRegisters::run in preparation for
using it to canonicalize new phis.
2023-07-26 21:27:35 -07:00
Nate Chandler
c9e0bb5a67 [Mem2Reg] NFC: Removed spurious typealias.
`BlockSetVector` is not much shorter than `BasicBlockSetVector`, and there's
no reason to tie the type to `StackAllocationPromoter`.
2023-07-26 21:27:35 -07:00
Nate Chandler
496761407c [Mem2Reg] NFC: Fixed comments.
Corrected the comments describing what the
`promoteSingleBlockAllocation` and `promoteMultiBlockAllocation`
functions do since they were no longer accurate.
2023-07-26 21:27:35 -07:00
Nate Chandler
e321fc4dc8 [Mem2Reg] NFC: Improved function name.
Previously there were the functions `promoteSingleAllocation` and
`removeSingleBlockAllocation`.  The distinction between these based on
the name alone is a bit subtle.  Shortened the name of
`promoteSingleAllocation` to `promoteAllocation`.
2023-07-26 21:27:35 -07:00
swift-ci
86b812b655 Merge pull request #63033 from nate-chandler/opaque-values/2/20221215
[AddressLowering] Project at storage.
2023-07-26 19:45:30 -07:00
Nate Chandler
a27b3909d4 [AddressLowering] Sink projections to uses.
Visit the tree of projections in post-order, sinking each to the lowest
position in the least common ancestor of all uses.
2023-07-26 16:41:57 -07:00
Nate Chandler
604150c194 [AddressLowering] Place projections below types.
Projections may involve opened archetypes.  They must be dominated by
the instructions which open those archetypes.

When determining the earliest storage point for a value and the point at
which to insert its projections, look for such obstructions in the
projection chain.  The first one found is the earliest storage point.
2023-07-26 16:41:57 -07:00
Nate Chandler
c9d84295eb [AddressLowering] Project at storage.
The pass rewrites opaque values in reverse post order of their
definitions.  When an opaque value is rewritten, both its definition and
its uses are rewritten.  When a def or a use is rewritten, in order to
materialize an address with which to rewrite, projection instructions
are created.  Previously, these projections were created at the site of
the def or use.  Some of these projection instructions may be reused when
rewriting later opaque values.

As a result, it's possible to have two opaque values `A` and `B` (which
are rewritten in that order) such that rewriting a use of `A` which
occurs "after" the def (or a use) of `B` creates a projection `P` which
is then used by that "earlier" def (or use) of `B`:

    ```
    A =
    B =     // relies on P
    use B
    use A   // creates some projection P
    ```

When rewriting the def (or that use, respectively) of `B`, the
projection which was created for the use of `A` will be reused.  And
previously, the projection would be created at the use of A.  But that
projection instruction was "after" the place where it is used when
rewriting the def or use of `B`.  That's invalid!

To address this, rather than creating projections at the instruction
being rewritten, instead create them "as early as possible".  The
locations where they will be created are chosen so as to dominate all
uses.
2023-07-26 16:41:57 -07:00
Joe Groff
705e317c3f Merge pull request #67425 from jckarter/raw-storage
[WIP] Raw storage and locks/atomics prototype
2023-07-26 08:49:02 -07:00
swift-ci
0f1b082615 Merge pull request #67519 from kavon/more-moveonly-diags
noncopyable diagnostics fix to correct error message wording
2023-07-25 17:07:19 -07:00
Kavon Farvardin
da4951b922 noncopyable diagnostics fix to correct error message wording
Turns out if you write `_ = consume s` you get different enough
SIL than `_ = s` that it fools the ad-hoc test for whether we've
mark-must-check'd a closure capture, since the former will have
a begin_access. There doesn't appear to be a simple way to reuse
the existing information or checking routine for this that was
used by the checker itself to flag this.
2023-07-25 14:10:50 -07:00
Andrew Savonichev
5abb580b3d [AutoDiff] Fix return type of subset parameters thunk function (#67487)
The patch resolves #67402.

When the original function has a tuple result type, we should append
thunkedLinearMap as the last element of the tuple to match the function
declaration. Before this patch, the compiler used to wrap the original result
tuple and thunkedLinearMap into another tuple, and caused the verifier error.

Before the patch:

  return %{{.*}} : $((Float, Double), @callee_guaranteed (Float) -> X.TangentVector)

After the patch:

  return %{{.*}} : $(Float, Double, @callee_guaranteed (Float) -> X.TangentVector)
2023-07-25 11:36:00 -07:00
Nate Chandler
de8e1829c3 [AddressLowering] Prevent existential multi-init. 2023-07-25 08:41:07 -07:00
Nate Chandler
5076e7be3c [AddressLowering] NFC: Moved assert above NPE.
Moved the assert that the value which opens an archetype exists before
the call to get its defining instruction which would be an NPE if the
value were in fact null.
2023-07-25 08:40:53 -07:00
Nate Chandler
a23bcef5f3 [AddressLowering] NFC: Extracted function.
Promoted the functionality from createStackAllocation to a named member
AddressLoweringState::getLatestOpeningInst  so that it can be employed
elsewhere.
2023-07-25 08:40:50 -07:00
Nate Chandler
a4aef5463e [AddressLowering] NFC: Add projection iterator.
Used the iterator to replace recursion in get*Storage functions with for
loops.
2023-07-25 08:40:47 -07:00
Nate Chandler
d9cf437ec3 [AddressLowering] NFC: Added const variant.
Of existing function getProjectedStorage.
2023-07-25 08:40:44 -07:00
Nate Chandler
e3428aeb95 [AddressLowering] NFC: Add more dump functions. 2023-07-25 08:40:39 -07:00
Nate Chandler
ba6b0192fe [AddressLowering] NFC: Comment projection chains.
Describe what all chains look like by analyzing the four theoretically
possible kinds of links--only three of the four are actually possible.
2023-07-25 08:40:37 -07:00
Nate Chandler
053cc775a3 [AddressLowering] Gardening: Undefaulted argument.
That there was a default wasn't used anywhere.
2023-07-24 16:57:14 -07:00
Nate Chandler
64ac0bda85 [AddressLowering] Gardening: Removed comment.
Per Andrew Trick, its author.
2023-07-24 16:57:14 -07:00