Commit Graph

6583 Commits

Author SHA1 Message Date
swift-ci
f7d877ee9c Merge remote-tracking branch 'origin/main' into rebranch 2022-07-11 15:13:44 -07:00
Michael Gottesman
09ed0f1e9a Merge pull request #60003 from gottesmm/pr-fce4cec67c5827dcedf3ac25ff0f92b24f6ae193
[no-implicit-copy] A few small patches to simplify a larger patch.
2022-07-11 15:09:10 -07:00
Michael Gottesman
98dbfaeb59 [no-implicit-copy] Assert in SILBuilder that mark_must_check only can take a MoveOnlyWrapped value.
In the future, we may not have this requirement, but for now it is a really
convenient way to track down places in SILGen where I have missed converting
from copyable to moveonlywrapped types.
2022-07-11 12:28:46 -07:00
Michael Gottesman
e9caee90eb [sil] Add a helper on ApplySite to set the ApplySite's SILValue callee in a generic way.
Just so that people do not have to touch operand numbers and potentially make a
mistake.
2022-07-11 12:28:46 -07:00
Michael Gottesman
ee7753c2f9 [sil] Make SILType::getCategoryType() use getRawASTType() instead of getASTType().
The reason why this makes sense is that this method is attempting to return the
current SILType but with a different category. So using getASTType() here and by
mistake removing move only would break semantics. Additionally, not making this
change breaks the expectation that this API would be idempotent.
2022-07-11 12:28:46 -07:00
Michael Gottesman
4a8ee40894 [no-implicit-copy] Make SILType::getRawASTType() public for now.
I keep on needing to use this in various internal APIs to the compiler that I
don't want to have to make a public forward declared internal API.
2022-07-11 12:28:45 -07:00
Erik Eckstein
64ba6fdf5d SIL: simplify the SILNode inline bitfields.
The use of the SWIFT_INLINE_BITFIELD macros in SILNode were a constant source of confusion and bugs.
With this refactoring I tried to simplify the definition of "shared fields" in SILNode, SILValue and SILInstruction classes:

* Move `kind`, `locationKindAndFlags` and the 32-bit fields out of the 64-bitfield into their own member variables. This avoids _a lot_ of manual bit position computations.
* Now we have two separate "shared fields": an 8-bit field (e.g. for boolean flags) and a 32-bit field (e.g. for indices, which can potentially get large). Both fields can be used independently. Also, they are not "bit fields" per se. Instructions can use the field e.g. as a `bool`, `uint32_t`, or  - if multiple flags are to be stored - as a packed bit field.
* With these two separate fields, we don't have the need for defining bitfields both in a base class _and_ in a derived value/instruction class. We can get rid of the complex logic which handles such cases. Just keep a check to catch accidental overlaps of fields in base and derived classes.
* Still use preprocessor macros for the implementation, but much simpler ones than before.
* Add documentation.
2022-07-11 17:27:29 +02:00
Andrew Trick
1d589ce39a PrunedLiveness fix discoveredBlocks to be unique.
Avoid adding redundant discoveredBlocks. This will be used and tested
in upcoming OSSA utilities.
2022-07-08 23:02:53 -07:00
swift-ci
9cc8d34c93 Merge remote-tracking branch 'origin/main' into rebranch 2022-07-07 05:12:51 -07:00
eeckstein
224cac56ec Merge pull request #59916 from eeckstein/perf-annotation-fixes
Several fixes for performance diagnostics
2022-07-07 13:58:06 +02:00
swift-ci
d5231efc77 Merge remote-tracking branch 'origin/main' into rebranch 2022-07-07 03:52:56 -07:00
Erik Eckstein
30cd3869b9 Mangling: add a new mangling for generic specialization
For performance annotations we need the generic specializer to trop non-generic metatype argumentrs
(which we don't do in general). For this we need a separate mangling.
2022-07-07 08:34:53 +02:00
Egor Zhdan
38edc7f377 [cxx-interop][SwiftCompilerSources] Remove getCopiedBridgedStringRef and freeBridgedStringRef
`std::string`s can now be passed directly between Swift and C++.

rdar://83361087
2022-07-06 12:57:50 +01:00
swift-ci
bdabce9079 Merge remote-tracking branch 'origin/main' into rebranch 2022-07-05 15:55:11 -07:00
Konrad `ktoso` Malawski
728c007fb9 [Distributed] Implement witnesses for sync or non-throw dist reqs
[Distributed] generic and inner test; without one edge case

[Distributed] fix distributed_thunk test; unsure about those extra hops, could remove later

[Distributed] Remove type pretending in getSILFunctionType; it is not needed

It seems our constant replacement in the earlier phases is enough, and
we don't need this trick at all.

[Distributed] Use thunk when calling cross-actor on DA protocols
2022-07-04 19:02:11 +09:00
swift-ci
5c8f1fcb12 Merge remote-tracking branch 'origin/main' into rebranch 2022-07-02 17:03:37 -07:00
Michael Gottesman
198b974622 Merge pull request #59859 from gottesmm/pr-276c4e4220a25490659a285e8b94a36bd28ffede
[no-implicit-copy] Rename SILMoveOnlyType -> SILMoveOnlyWrappedType.
2022-07-01 23:17:43 -07:00
Michael Gottesman
8f3fe63fed [no-implicit-copy] Rename SILMoveOnlyType -> SILMoveOnlyWrappedType.
Since I am beginning to prepare for adding real move only types to the language,
I am renaming everything that has to do with copyable types "move only wrapped"
values instead of move only. The hope is this reduces/prevents any confusion in
between the two.
2022-07-01 17:26:13 -07:00
Michael Gottesman
4f6cce7bb8 Merge pull request #59833 from gottesmm/pr-816f80a06afa9ee661f077ea89193ef1cce5ece6
[no-implicit-copy] A few small fixes.
2022-07-01 15:46:43 -07:00
Michael Gottesman
5adb94ca9f [no-implicit-copy] Remove the move only bit in type lowering for now.
We currently do not need it so I am removing it. We /do/ use move only as a
TypeLowering itself though. Just not as a property.
2022-06-30 22:22:27 -07:00
swift-ci
756ed5f8b1 Merge remote-tracking branch 'origin/main' into rebranch 2022-06-30 18:55:17 -07:00
swift-ci
1ff1826cc7 Merge pull request #59715 from meg-gupta/updateloadborrowimmutability
Update LoadBorrowImmutability and PrunedLiveness to handle reborrows
2022-06-30 18:52:41 -07:00
Meghana Gupta
742052a063 Update PrunedLiveness
- To detect instructions occuring before definition
- To handle reborrows
2022-06-30 10:31:20 -07:00
swift-ci
e7f293814c Merge remote-tracking branch 'origin/main' into rebranch 2022-06-28 13:53:46 -07:00
Michael Gottesman
6a24087f90 Merge pull request #59611 from gottesmm/moveonly-rebase
[no-implicit-copy] Update SILGen/move checker to work with new patterns from copyable_to_moveonly and friends.
2022-06-28 13:45:15 -07:00
swift-ci
4ebba16c36 Merge remote-tracking branch 'origin/main' into rebranch 2022-06-27 09:53:38 -07:00
Doug Gregor
0219611576 Merge pull request #59711 from ktoso/wip-generic-distributed-call-clean
[1/3][Distributed] Make distributed thunks the witnesses, fix calls on generic DAs
2022-06-27 09:50:26 -07:00
swift-ci
b1383a1dbf Merge remote-tracking branch 'origin/main' into rebranch 2022-06-27 03:13:38 -07:00
Konrad `ktoso` Malawski
22b20afce6 [Distributed] make witness be the distributed thunk 2022-06-27 17:08:55 +09:00
Erik Eckstein
e6db6bb818 TargetConstantFolding: address review comments
* move the source file to SILOptimizer/IRGenTransforms
* add a file level comment
* document and verify that the pass runs after serialization
* catch overflows when truncating a constant value
2022-06-27 09:04:26 +02:00
Meghana Gupta
f0ef917afd Add new api BorrowedValue::visitTransitiveLifetimeEndingUses 2022-06-24 21:35:06 -07:00
Meghana Gupta
dc9308e13b Rename areUsesWithinLocalScope -> areUsesWithinTransitiveScope 2022-06-24 21:32:04 -07:00
swift-ci
1ec185309f Merge remote-tracking branch 'origin/main' into rebranch 2022-06-24 00:14:42 -07:00
Erik Eckstein
ca291fb147 SIL: store IRGenOptions in SILModule
SIL optimization passes can use the IRGen options to do target specific optimizations.
2022-06-23 22:16:42 +02:00
swift-ci
c2162eda0e Merge remote-tracking branch 'origin/main' into rebranch 2022-06-23 11:34:52 -07:00
Adrian Prantl
7c1c7b6249 Emit debug locations for hop_to_executor instructions.
The function prologue of async funclets inherits its source location
from the hop_to_executor instruction. This makes it easier to produce
logical backtraces, since the PC in logical frames will always point
to the start if the function.

rdar://89776340
2022-06-23 09:40:25 -07:00
Michael Gottesman
2f9d67de18 [move-only] Add a new pass called MoveOnlyTypeEliminator that runs after move only checking.
This pass lowers moveonly-ness from the IR after we have finished move only
checking. The transform can be configured in two ways: such that it only handles
trivial types and such that it does trivial and non-trivial types. For ease of
use, I created two top level transforms (TrivialMoveOnlyTypeEliminator and
MoveOnlyTypeElimintor) that invoke the two behaviors by configuring the
underlying transform slightly differently.

For now, I am running first the trivial-only and then the all of the above
lowering. The trivial only pass will remain at this part of the pipeline
forever, but with time we are going to move the lower everything pass later into
the pipeline once I have audited the optimizer pipeline to just not perform any
work on move only types. That being said, currently we do not have this
guarantee and this patch at least improves the world and lets us codegen no
implicit copy code again.
2022-06-22 15:31:57 -07:00
swift-ci
dc17e18651 Merge remote-tracking branch 'origin/main' into rebranch 2022-06-18 15:54:11 -07:00
Robert Widmann
ce4afc7e4d Recurse Into Existential Types With Generic Structure
Before the introduction of parameterized existential types, there
was no generic structure under these types. Now that there is, we'll
need to recurse into them to pick up any latent generic types
and lower them appropriately.

rdar://94320481
2022-06-18 12:36:50 -06:00
swift-ci
7e7803a999 Merge remote-tracking branch 'origin/main' into rebranch 2022-06-15 21:34:18 -07:00
Michael Gottesman
72523cf9d0 [move-only] Fix a few bugs around MoveOnlyWrapperToCopyableValue.
The main fixes are:

1. MoveOnlyWrapperToCopyableValue needed to be marked as a
   FirstArgOwnershipForwardingSingleValueInst instead of just as being an
   Ownership mixin. I discovered that in certain cases I was treating it that
   way (in the isa check for FirstArgOwnershipForwardingSingleValueInst), but we
   were inconsistent. Now we are consistent.

2. MoveOnlyWrapperToCopyableValue is always specified as being initialized as
   owned or guaranteed. What is key to understand though is that the
   owned/guaranteed property here is more a semantic property around whether the
   lifetime of the move only value is ending or if we are allowing it to escape
   as an moveonlywrapped unwrapped guaranteed parameter to a function. The main
   implication of this is that we can not just use the actual ownership kind to
   determine the type of moveonlywrapper_to_copyable we are using. This is b/c
   after ownership lowering, the resulting ownership kind will be none, meaning
   the instruction will be in an invalid state. Thus the need to represent this
   as a separate bit in the instruction. It may make sense to rename the forms
   of this instruction to be `[lifetime end]` and `[guaranteed function arg]`
   that way it is semantically clear. But I am going to do that change at
   another time.
2022-06-15 14:15:21 -07:00
Michael Gottesman
4eebe7c561 [typelowering] Rename isMoveOnly() -> isMoveOnlyWrapped()
Just updating type lowering API to match the names on SILType.
2022-06-15 14:15:21 -07:00
Michael Gottesman
8216a2a816 [move-only] Rename AbstractionPattern move only wrapper add/remove methods to match SILType's
Just forgot to change these when I changed the name of the SILType methods. In
summary:

1. withoutMoveOnly -> removingMoveOnlyWrapper
2. withMoveOnly -> addingMoveOnlyWrapper
2022-06-15 14:15:21 -07:00
swift-ci
0faccc23f2 Merge remote-tracking branch 'origin/main' into rebranch 2022-06-10 18:35:15 -07:00
Zoe Carver
dfb2348ab2 Merge pull request #59373 from zoecarver/nfc-operator-cleanup 2022-06-10 18:31:57 -07:00
zoecarver
9c32aace6c [nfc] Remove dead operator code pt. 1 2022-06-10 13:33:29 -07:00
swift-ci
88de6f4757 Merge remote-tracking branch 'origin/main' into rebranch 2022-06-10 13:13:37 -07:00
Michael Gottesman
7c7fb474ac Merge pull request #59355 from gottesmm/pr-20b996075d28e099e1c791eb80e78022f940f91e
[move-only] Add copyable_to_moveonlywrapper and moveonlywrapper_to_copyable instructions.
2022-06-10 12:59:46 -07:00
Michael Gottesman
e1006c62f9 [move-only] Add copyable_to_moveonlywrapper and moveonlywrapper_to_copyable instructions.
These instructions have the following attributes:

1. copyably_to_moveonlywrapper takes in a 'T' and maps it to a '@moveOnly
T'. This is semantically used when initializing a new moveOnly binding from a
copyable value. It semantically destroys its input @owned value and returns a
brand new independent @owned @moveOnly value. It also is used to convert a
trivial copyable value with type 'Trivial' into an owned non-trivial value of
type '@moveOnly Trivial'. If one thinks of '@moveOnly' as a monad, this is how
one injects a copyable value into the move only space.

2. moveonlywrapper_to_copyable takes in a '@moveOnly T' and produces a new 'T'
value. This is a 'forwarding' instruction where at parse time, we only allow for
one to choose it to be [owned] or [guaranteed].

* moveonlywrapper_to_copyable [owned] is used to signal the end of lifetime of
the '@moveOnly' wrapper. SILGen inserts these when ever a move only value has
its ownership passed to a situation where a copyable value is needed. Since it
is consuming, we know that the no implicit copy checker will ensure that if we
need a copy for it, the program will emit a diagnostic.

* moveonlywrapper_to_copyable [guaranteed] is used to pass a @moveOnly T value
as a copyable guaranteed parameter with type 'T' to a function. In the case of
using no-implicit-copy checking this is always fine since no-implicit-copy is a
local pattern. This would be an error when performing no escape
checking. Importantly, this instruction also is where in the case of an
@moveOnly trivial type, we convert from the non-trivial representation to the
trivial representation.

Some important notes:

1. In a forthcoming commit, I am going to rebase the no implicit copy checker on
top of these instructions. By using '@moveOnly' in the type system, we can
ensure that later in the SIL pipeline, we can have optimizations easily ignore
the code.

2. Be aware of is that due to SILGen only emitting '@moveOnly T' along immediate
accesses to the variable and always converts to a copyable representation when
calling other code, we can simply eliminate from the IR all moveonly-ness from
the IR using a lowering pass (that I am going to upstream). In the evil scheme
we are accomplishing here, we perform lowering of trivial values right after
ownership lowering and before diagnostics to simplify the pipeline.

On another note, I also fixed a few things in SILParsing around getASTType() vs
getRawASTType().
2022-06-09 19:47:31 -07:00
swift-ci
9a610e0adc Merge remote-tracking branch 'origin/main' into rebranch 2022-06-08 21:53:12 -07:00