Commit Graph

2864 Commits

Author SHA1 Message Date
swift-ci
3a1a284787 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-02 07:17:28 -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
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
swift-ci
2919af9fa7 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-01 13:36:46 -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
swift-ci
e24988e633 Merge remote-tracking branch 'origin/main' into rebranch 2023-07-28 09:44:12 -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
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
swift-ci
1969199a8e Merge remote-tracking branch 'origin/main' into rebranch 2023-07-26 23:13:08 -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
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
Evan Wilde
0f38040832 [NFC] Update more APIs for std::optional
`std::optional` doesn't have `hasValue` or `getPointer`. Using the
implicit decay to boolean, and grabbing the pointer to the element by
expanding the optional and grabbing the reference address.
2023-07-25 12:28:28 -07:00
Evan Wilde
fd156f2717 More APInt API updates
Updating more APInt and bit-manipulation API changes.
2023-07-25 12:28:27 -07:00
Evan Wilde
309aed4925 Add SmallSetVector replacement
llvm::SmallSetVector changed semantics
(https://reviews.llvm.org/D152497) resulting in build failures in Swift.
The old semantics allowed usage of types that did not have an
`operator==` because `SmallDenseSet` uses `DenseSetInfo<T>::isEqual` to
determine equality. The new implementation switched to using
`std::find`, which internally uses `operator==`. This type is used
pretty frequently with `swift::Type`, which intentionally deletes
`operator==` as it is not the canonical type and therefore cannot be
compared in normal circumstances.

This patch adds a new type-alias to the Swift namespace that provides
the old semantic behavior for `SmallSetVector`. I've also gone through
and replaced usages of `llvm::SmallSetVector` with the
`Swift::SmallSetVector` in places where we're storing a type that
doesn't implement or explicitly deletes `operator==`. The changes to
`llvm::SmallSetVector` should improve compile-time performance, so I
left the `llvm::SmallSetVector` where possible.
2023-07-25 12:28:27 -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
Nate Chandler
473985ff12 [AddressLowering] Gardening: Detypo'd. 2023-07-24 16:57:14 -07:00
Nate Chandler
c9768e612f [AddressLowering] Gardening: Detypo'd. 2023-07-24 16:57:14 -07:00
Nate Chandler
a1d10997da [SIL] Promoted least-common ancestor to Dominance.
It's a general purpose helper and there will soon be another user.
2023-07-24 16:57:14 -07:00
Joe Groff
aee071bf4e Introduce an experimental @_rawLayout attribute.
This attribute can be attached to a noncopyable struct to specify that its
storage is raw, meaning the type definition is (with some limitations)
able to do as it pleases with the storage. This provides a basis for
implementing types for things like atomics, locks, and data structures
that use inline storage to store conditionally-initialized values.
The example in `test/Prototypes/UnfairLock.swift` demonstrates the use
of a raw layout type to wrap Darwin's `os_unfair_lock` APIs, allowing
a lock value to be stored inside of classes or other types without
needing a separate allocation, and using the borrow model to enforce
safe access to lock-guarded storage.
2023-07-24 14:28:19 -07:00
nate-chandler
14c599c4e3 Merge pull request #67443 from nate-chandler/nfc/20230720/1/addresslowering-deloop
[AddressLowering] NFC: Removed loop of length 1.
2023-07-21 07:03:25 -07:00
swift-ci
c3c84d3625 Merge pull request #67421 from JTurcotti/more-diags
[SendNonSendable] Improve diagnostics and fix bugs
2023-07-20 16:56:56 -07:00
Nate Chandler
253cd4b055 [AddressLowering] NFC: Removed loop of length 1. 2023-07-20 16:02:01 -07:00
jturcotti
853ef7cf3c fix bugs that present themselves when handling multiarg and varargs functions, including adding better debug dump methods 2023-07-20 14:01:08 -07:00
nate-chandler
8cb61d1b04 Merge pull request #67423 from nate-chandler/opaque-values/20230719/2/all_stores_within_guaranteed_argument_lifetime
[AddressLowering] Exit range check for args early.
2023-07-20 06:58:16 -07:00
nate-chandler
b1c5631519 Merge pull request #67384 from nate-chandler/opaque-values/20230718/1/emit_end_borrows/destructure_and_extract
[AddressLowering] End borrow scopes for extracts/destructures at enclosing guaranteed boundary.
2023-07-20 06:57:44 -07:00
Michael Gottesman
7aea9d44c3 Merge pull request #67414 from gottesmm/rdar112555589-112547982
[move-only] Fix two small errors around handling capturing of noncopyable self by local functions
2023-07-19 21:28:09 -07:00
Nate Chandler
52dd6a54ec [AddressLowering] Exit range check for args early.
When determining whether a copy_value is part of a copy->store pair, if
the value being copied is guaranteed, it is checked whether the store is
within the lifetime of all its guaranteed roots.  If one of those
guaranteed roots is a function argument, the store is certainly within
the lifetime, so exit early.
2023-07-19 17:34:28 -07:00
jturcotti
a83d7aa39c improve diagnostics about data races; highlight the individual expressions being sent and accessed as precisely as possible, and include information about specific non-sendable types and isolation crossings 2023-07-19 17:27:16 -07:00
Nate Chandler
4c5ce62c7f [AddressLowering] Fix extract's end_borrows.
An extract may have users that have escaping operand ownership.
Consequently, we can't rely on findInnerTransitiveGuaranteedUses as used
by emitEndBorrows.
2023-07-19 16:07:21 -07:00
Nate Chandler
04978e2cd0 [AddressLowering] Fixed destructures' end_borrows.
A destructure may have users that have escaping operand ownership.
Consequently, we can't rely on findInnerTransitiveGuaranteedUses as used
by emitEndBorrows.
2023-07-19 16:06:52 -07:00
Pavel Yaskevich
b6edb098cf Merge pull request #67294 from xedin/default-init-via-accessor-in-custom-initializers
[Sema/SIL] InitAccessors: Support default initialization of init accessor properties
2023-07-19 15:32:33 -07:00
Michael Gottesman
b060e5ba60 [move-only] Make sure we mark local function inout parameters with mark_must_check.
Originally, we were relying on capture info to determine if we needed to insert
this mark_must_check. This ignored that the way that we are handling
escaping/non-escaping is something that is approximated in the AST but actually
determined at SIL level. With that in mind, rather than relying on the capture
info here, just rely on us having an inout argument. The later SIL level
checking for inout escapes is able to handle mark_must_check and knows how to
turn off noncopyable errors in the closure where we detect the error to prevent
us from emitting further errors due to the mark_must_check here.

I discovered this while playing with the previous commit.

rdar://112555589
2023-07-19 15:02:04 -07:00
nate-chandler
445a65479b Merge pull request #67397 from nate-chandler/opaque-values/20230719/1/emit_end_borrows/begin_apply
[AddressLowering] End borrow scopes for begin_apply at coro endpoints.
2023-07-19 14:08:41 -07:00
Joshua Turcotti
992fc6c987 Merge pull request #67318 from JTurcotti/better-diags
[SendNonSendable] Diagnose consumption sites not requirement sites for flow-sensitive region-based Sendable Analysis
2023-07-19 09:38:40 -07:00
Nate Chandler
d98994e64f [AddressLowering] Fix begin_apply's end_borrows.
When a `load_borrow` is created on behalf of a `begin_apply`, it's
possible that it may have escaping users.  When it does,
`findInnerTransitiveGuaranteedUses` returns `false` and the uses it
finds are incomplete.  As a result the boundary computed in
`emitEndBorrows` will be incomplete.
2023-07-19 08:04:01 -07:00
Nate Chandler
d3461e58c0 [AddressLowering] Gardening: De-typo'd. 2023-07-19 08:00:08 -07:00
Pavel Yaskevich
52ac782184 [DI] InitAccessors: Use of SILModule::getFieldIndex is incompatible with DI data structures
DI cares only about stored fields of the current type but `SILModule::getFieldIndex`
goes through all of the supertypes as well.
2023-07-18 17:19:42 -07:00