Commit Graph

733 Commits

Author SHA1 Message Date
Joe Groff
b781005c0a SILGen: Reabstract subexpr lvalue before ABISafeConversion.
Fixes rdar://130016855. When preconcurrency compatibility introduces
implicit `@Sendable` conversions, the `ABISafeConversionExpr` representing
that conversion indicates an ABI-neutral conversion from the substituted
type of the original expression, so we need to reabstract in cases
where the original property is more generic than the type we're working
with.
2024-07-11 18:49:35 -07:00
Slava Pestov
977b444eb3 AST: Add a new overload of getContextSubstitutionMap() 2024-07-10 13:28:26 -04:00
Slava Pestov
fae01d9776 AST: Remove ModuleDecl parameter from more places 2024-07-06 12:05:46 -04:00
Joe Groff
636a19d11b Merge pull request #74707 from jckarter/consume-during-borrow-checks
MoveOnlyAddressChecker: More robust checking for consume-during-borrow.
2024-06-26 08:22:04 -07:00
Joe Groff
27a8852290 MoveOnlyAddressChecker: More robust checking for consume-during-borrow.
- While an opaque borrow access occurs to part of a value, the entire scope of
  the access needs to be treated as a liveness range, so add the `EndAccess`es
  to the liveness range.
- The SIL verifier may crash the compiler on SILGen-generated code when the
  developer's source contains consume-during-borrow code patterns. Allow
  `load_borrow` instructions to be marked `[unchecked]`, which suppresses
  verifier checks until the move checker runs and gets a chance to properly
  diagnose these errors.

Fixes rdar://124360175.
2024-06-25 14:10:02 -07:00
Tim Kientzle
1098054291 Merge branch 'main' into tbkka-assertions2 2024-06-18 17:52:00 -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
Meghana Gupta
470fa2f365 Remove resultDependsOn/resultDependsOnSelf 2024-06-05 11:36:16 -07:00
Joe Groff
38d4622d24 SILGen: Bug fix handling consuming/borrowing parameters and optional chaining.
Make sure we remove the `@moveOnly` marker while projecting the payload as expected
for the (no longer non-implicitly-copyable) projected result. Fixes rdar://116127887.
2024-05-15 16:57:40 -07:00
Joe Groff
82e566a23a SILGen: Treat Optional x! force unwrapping as a forwarding operation.
Like `?` or property access, `x!` can be borrowing, consuming, or mutated
through depending on the use site and the ownership of the base value.
Alter SILGen to emit `x!` as a borrowing operation when the result is only
used as a borrow. Fix the move-only checker not to treat the unreachable
branch as a dead path for values and try to destroy the value unnecessarily
and possibly out-of-order with cleanups on the value. Fixes rdar://127459955.
2024-05-08 15:35:07 -07:00
Joe Groff
90e1ecb864 Consistently mark borrowing and consuming parameters for move-only checking when captured.
When a `borrowing` or `consuming` parameter is captured by a closure,
we emit references to the binding within the closure as if it is non-implicitly
copyable, but we didn't mark the bindings inside the closure for move-only
checking to ensure the uses were correct, so improper consumes would go
undiagnosed and lead to assertion failures, compiler crashes, and/or
miscompiles. Fixes rdar://127382105
2024-05-01 13:41:28 -07:00
Konrad `ktoso` Malawski
6132386371 [Distributed] Complete handling of protocol calls and witnesses using adjusted mangling scheme (#72416) 2024-03-23 23:54:23 +09:00
John McCall
c7d3e8f559 [NFC] Generalize how Conversion works with reabstraction conversions and
force callers to specify the input lowered type as well.
2024-03-21 12:47:56 -04:00
Joe Groff
8a65c9be94 SIL: Optimizer fixes for noncopyable optional chains.
Don't attempt a SILCombine transform on `select_enum` that inserts a copy when an
enum is noncopyable. Adjust the cleanup handling for a consuming optional chain to
ensure a `destroy_value` still gets emitted on the `none` path; this shouldn't
actually matter since `none` is a trivial case, but the memory verifier isn't
that fancy during OSSA, and we can optimize it later. Fixes rdar://124426918.
2024-03-12 18:11:21 -07:00
Joe Groff
e90a7e6226 SILGen: Fixes for consuming noncopyable optional chaining.
Use the lvalue mechanism to build opaque formal accesses so that they
nest properly with writebacks. Don't put a cleanup on the lvalue because
that creates a double destroy. Fixes rdar://124362085.
2024-03-11 21:12:43 -07:00
Nate Chandler
7fecf6149c [NFC] SIL: Typed begin_borrow's isFixed. 2024-03-08 22:28:20 -08:00
Nate Chandler
70d90b4b43 [NFC] SIL: Typed begin_borrow's hasPointerEscape. 2024-03-08 22:27:52 -08:00
Nate Chandler
9f6c30919b [NFC] SIL: Typed begin_borrow's isLexical. 2024-03-08 22:27:50 -08:00
Joe Groff
828abb3f75 SILGen: Forward move-only ownership through optional chains.
Allow noncopyable values to be consumed, borrowed, or mutated transitively
through optional chains.
2024-03-06 13:44:02 -08:00
Nate Chandler
6100a1b495 Allow partial consumption of self in deinit.
Basic support for partial consumption in deinit without full support for
all future uses of drop_deinit.
2024-02-28 15:57:09 -08:00
Michael Gottesman
11f0ff6e32 [sil] Ensure that all SILValues have a parent function by making it so that SILUndef is uniqued at the function instead of module level.
For years, optimizer engineers have been hitting a common bug caused by passes
assuming all SILValues have a parent function only to be surprised by SILUndef.
Generally we see SILUndef not that often so we see this come up later in
testing. This patch eliminates that problem by making SILUndef uniqued at the
function level instead of the module level. This ensures that it makes sense for
SILUndef to have a parent function, eliminating this possibility since we can
define an API to get its parent function.

rdar://123484595
2024-02-27 13:14:47 -08:00
Joe Groff
6cb5e17e3e SILGen: Borrow any move-only or borrow-expr'ed accessor base.
Following up from #71795, we must borrow the base of any non-copyable
`borrowing`/`nonmutating` accessor, and we want to borrow the base
of any accessor appearing in a `borrow` expr. Fixes #71606.
2024-02-26 17:16:23 -08:00
Ben Barham
f292ec9784 Use the new template deduction guides rather than makeArrayRef
LLVM has removed `make*ArrayRef`, migrate all references to their
constructor equivalent.
2024-02-23 20:04:51 -08:00
Joe Groff
7f9b18432a Merge pull request #71795 from jckarter/yield-read-coroutine-result
SILGen: Emit the base of a read coroutine as a borrow in a `yield`/`borrow`/noncopyable context.
2024-02-21 20:40:36 -08:00
Joe Groff
eca40f3d63 SILGen: Emit the base of a read coroutine as a borrow in a yield/borrow/noncopyable context. 2024-02-21 14:35:53 -08:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Joe Groff
3decd816ed Merge pull request #71630 from jckarter/emit-value-as-borrow
SILGen: Handle emitting borrowed lvalues from value bindings.
2024-02-15 07:46:19 -08:00
Joe Groff
7fed21ae98 SILGen: Handle emitting borrowed lvalues from value bindings.
Replace the "must be an address" assertion with an implementation
that emits and borrows the base value. Fixes #71598.
2024-02-14 16:09:14 -08:00
Michael Gottesman
1f0527d47f [ast] Rename ParamSpecifier::{Transferring,ImplicitlyCopyableConsuming}.
The reason why I am doing this is that I am going to be changing transferring to
not be a true ParamSpecifier. Instead, it is going to be a bit on Param that
changes the default ParamSpecifier used. That being said, I cannot use consuming
for this purpose since consuming today implies no implicit copy semantics, which
we do not want unless the user specifically asks for it by writing consuming.
2024-02-14 13:04:21 -08:00
nate-chandler
2092536615 Merge pull request #71361 from nate-chandler/moveonly/20240202/1/borrow-thru-load
[SILGen] Look through loads for storage.
2024-02-02 21:11:30 -08:00
Nate Chandler
9f134ea0e3 [SILGen] Look thru loads for reference storage.
When emitting a guaranteed argument, a search is made for storage which
can be borrowed.  Look through LoadExprs during this search.
2024-02-02 16:04:00 -08:00
Guillaume Lessard
114f235d17 Merge pull request #71167 from vanvoorden/vanvoorden/inclusive-language
[Inclusive Language][Comments][Documentation] migrate "sanity" checks to "soundness" checks
2024-02-02 10:27:34 -08:00
Slava Pestov
af3ab14986 SILGen: Clean up substitution map construction to deal with Copyable 2024-01-31 21:55:52 -05:00
Rick van Voorden
f8ae46b3f3 [inclusive-language] changed sanity to soundness 2024-01-25 18:18:02 -08:00
Kavon Farvardin
d727011d9e [SILGen] tweak LogicalKeyPathApplicationComponent
A baked-in assumption was that the generic parameters of the KeyPath
family of types have no conformance requirements. That's no longer the
case with NoncopyableGenerics, so we need to dig up conformances when
forming the substitution map, as-needed.
2024-01-23 22:41:59 -08:00
Doug Gregor
07c6b78540 [SILGen] Ensure that we emit the distributed-actor-as-actor conformance
The distributed-actor-as-actor conformance is synthesized by the
frontend, so make sure that when we access the API that exposes it
(asLocalActor), we be sure to mark the conformance as "used".

This is a very specific workaround for general problem with
compiler-synthesized conformances. SIL deserialization can bring in a
reference to a conformance late in the SIL pipeline, after the point at
which SILGen can create the conformance. We should be able to address
this systemically to remove the hack.
2024-01-23 19:32:47 -08:00
Michael Gottesman
9513d298ec [region-isolation] Add parsing/serialization/type system support for a transferring OwnershipSpecifier. 2024-01-18 13:20:28 -08:00
Anthony Latsis
bd2f48d9d2 [NFC] AST: Introduce and use Identifier::isConstructor 2023-12-25 21:09:17 +03:00
Joe Groff
1b9a0712bf Move-only check the value projected from addressors.
Mark the result of a move-only addressor as unresolved. The pointed-at value
cannot be consumed so ensure that only [read] or [modify] accesses are
performed. Update the move-only checker to recognize code patterns
from addressors.
2023-12-15 10:10:44 -08:00
Meghana Gupta
b6326f5f24 Add initial support for _resultDependsOn
These attributes are used to establish lifetime dependence between
argument and the result.

Add them under NonEscapableTypes experimental feature
2023-12-06 16:38:38 -08:00
Kavon Farvardin
3a533b6338 [SILGen] handle TypeExpr in BorrowedBaseVisitor
A TypeExpr and other kinds of non-lvalue bases that the borrowed-base
visitor doesn't care about can be handled by calling back into the
original SILGenLValue instance.

resolves rdar://117082469
2023-11-16 00:18:16 -08:00
Joe Groff
1b5796ce90 SILGen: Treat projections from non-implicitly-copyable parameters as borrow bases. 2023-10-17 13:42:55 -07:00
Kavon Farvardin
f1142d5da4 [nfc] rename or eliminate isPureMoveOnly APIs
I think from SIL's perspective, it should only worry about whether the
type is move-only. That includes MoveOnlyWrapped SILTypes and regular
types that cannot be copied.

Most of the code querying `SILType::isPureMoveOnly` is in SILGen, where
it's very likely that the original AST type is sitting around already.
In such cases, I think it's fine to ask the AST type if it is
noncopyable. The clarity of only asking the ASTType if it's noncopyable
is beneficial, I think.
2023-09-20 15:23:17 -07:00
Michael Gottesman
37d60a08bb [move-only] Rename mark_must_check -> mark_unresolved_non_copyable_value.
I was originally hoping to reuse mark_must_check for multiple types of checkers.
In practice, this is not what happened... so giving it a name specifically to do
with non copyable types makes more sense and makes the code clearer.

Just a pure rename.
2023-08-30 22:29:30 -07:00
Michael Gottesman
543063ef0e [silgen] Make ManagedValue::forUnmanaged private and change users to use other more specific APIs.
I have been doing this over the past couple of days in preparation for changing
ManagedValue to specify the type of scope its cleanup is connected to.
2023-08-19 14:11:44 -07:00
Michael Gottesman
ff948f7309 [silgen] Convert even more cases of using trivial and values without ownership to use for*RValueWithoutOwnership APIs. 2023-08-15 11:04:01 -07:00
Nate Chandler
ded4d32c71 [OpaqueValues] Emit unowned copies.
In opaque values mode, emit the unowned copy instructions to convert as
follows:

strong_copy_unowned_value: `@owned $sil_unowned T` -> `@owned $T`
unowned_copy_value: `@owned T` -> `@owned $sil_unowned T`

Doing so is necessary in opaque values mode where it is needed to deal
with unowned values directly rather than indirectly via `load_unowned`s
and `store_unowned`s.
2023-08-08 15:49:17 -07:00
Nate Chandler
b616d14ff5 [OpaqueValues] Emit weak copies.
In opaque values mode, emit the new weak copy instructions to convert as
follows:

strong_copy_weak_value: `@owned $sil_weak T?` -> `@owned $T?`
weak_copy_value: `@owned $T?` -> `@owned $@sil_weak T?`

Doing so is necessary in opaque values mode where it is needed to deal
with weak values directly rather than indirectly via `load_weak`s and
`store_weak`s.
2023-08-08 15:47:13 -07:00
nate-chandler
0cfa74763f Merge pull request #67725 from nate-chandler/opaque-values/20230803/2/open-opaque-existential-value
[OpaqueValues] Open opaque existential value.
2023-08-08 06:57:00 -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