Commit Graph

742 Commits

Author SHA1 Message Date
Joe Groff
f9d9d75768 SILGen: Change codegen for loading from no-implicit-copy lvalues.
Previously, we would emit this as

  %1 = load [copy] %address
  %2 = moveonly_wrapper_to_copyable [owned] %1

which is difficult for move-only checking to handle, since %2 looks like a
consume of %1, making it difficult to determine %1's true lifetime. Change
this to

  %1 = moveonly_wrapper_to_copyable_addr %address
  %2 = load [copy] %address

which is handled better by move-only checking, improving the accuracy of
existing move-checking as well as fixing a spurious diagnostic when
indirect parameters get passed as by-value arguments to other functions.
2025-01-06 21:34:56 -08:00
Slava Pestov
47156e006b AST: Introduce ProtocolConformanceRef::forAbstract() 2024-11-16 16:16:06 -05:00
Nate Chandler
da71271d8f [CoroutineAccessors] Synthesize default req impls.
When a protocol which has a read (or modify) requirement is built with
the CoroutineAccessors feature, it gains a read2 (or modify2,
respectively) requirement.  For this to be compatible with binaries
built without the feature, a default implementation for these new
requirements must be provided.  Cause these new accessor requirements to
have default implementations by returning `true` from
`doesAccessorHaveBody` when the context is a `ProtocolDecl` and the
relevant availability check passes.
2024-11-07 16:47:09 -08:00
Nate Chandler
f1f0ccdeff [NFC] Improved predicate names. 2024-11-06 20:52:21 -08:00
Joe Groff
1772f021b1 Merge pull request #75193 from jckarter/reabstract-before-abi-safe-lvalue-conversion
SILGen: Reabstract subexpr lvalue before ABISafeConversion.
2024-10-28 12:00:26 -07:00
Nate Chandler
091368ba21 [CoroutineAccessors] Added read.
The name is a placeholder for the mutating single-yield coroutine
accessor.
2024-09-26 18:10:39 -07:00
Nate Chandler
98a2e6a7df [CoroutineAccessors] Added modify.
The name is a placeholder for the mutating single-yield coroutine
accessor.
2024-09-26 18:10:39 -07:00
Nate Chandler
ecba5db6e5 [NFC] AST: Added AccessorKind predicates.
And replaced direct comparisons with calls to predicates.  In
preparation for introducing parallel non-underscored accessors.
2024-09-25 21:06:36 -07:00
Joe Groff
4da65dfe84 Use ASSERT instead of assert 2024-07-12 13:15:08 -07:00
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