Commit Graph

480 Commits

Author SHA1 Message Date
Nate Chandler
1e5a7aab9a [SILVerifier] Added null check.
The deadEndBlocks field isn't always present so first check that it's
defined.
2023-09-20 13:38:06 -07:00
Yuta Saito
c5314bd3af Centralize KeyPath accessor calling convention logic to IRGen
KeyPath's getter/setter/hash/equals functions have their own calling
convention, which receives generic arguments and embedded indices from a
given KeyPath argument buffer.
The convention was previously implemented by:
1. Accepting an argument buffer as an UnsafeRawPointer and casting it to
   indices tuple pointer in SIL.
2. Bind generic arguments info from the given argument buffer while emitting
   prologue in IRGen by creating a new forwarding thunk.

This 2-phase lowering approach was not ideal, as it blocked KeyPath
projection optimization [^1], and also required having a target arch
specific signature lowering logic in SIL-level [^2].

This patch centralizes the KeyPath accessor calling convention logic to
IRGen, by introducing `@convention(keypath_accessor_XXX)` convention in
SIL and lowering it in IRGen. This change unblocks the KeyPath projection
optimization while capturing subscript indices, and also makes it easier
to support WebAssembly target.

[^1]: https://github.com/apple/swift/pull/28799
[^2]: https://forums.swift.org/t/wasm-support/16087/21
2023-09-20 11:25:39 -07:00
Erik Eckstein
f0b811c45f SIL: add the end_init_let_ref instruction
This instructions marks the point where all let-fields of a class are initialized.
This is important to ensure the correctness of ``ref_element_addr [immutable]`` for let-fields,
because in the initializer of a class, its let-fields are not immutable, yet.
2023-09-19 15:10:30 +02:00
Erik Eckstein
e5eb15dcbe Swift SIL: replace the set_deallocating instruction with begin_dealloc_ref
Codegen is the same, but `begin_dealloc_ref` consumes the operand and produces a new SSA value.
This cleanly splits the liferange to the region before and within the destructor of a class.
2023-09-19 15:10:30 +02:00
Kuba Mracek
d2bb064548 [embedded] Don't SILVerify VTable ABIs in embedded mode, as the specialized vtables have intentionally different ABIs from the non-generic one 2023-09-12 13:58:11 -07:00
Kuba Mracek
d0c2a4ccf8 [embedded] Initial support for generic classes in embedded Swift
- VTableSpecializer, a new pass that synthesizes a new vtable per each observed concrete type used
- Don't use full type metadata refs in embedded Swift
- Lazily emit specialized class metadata (LazySpecializedClassMetadata) in IRGen
- Don't emit regular class metadata for a class decl if it's generic (only emit the specialized metadata)
2023-09-12 09:44:54 -07:00
Michael Gottesman
ba06693745 Merge pull request #68228 from gottesmm/pr-088dba5d9c0854c0e00da0603eb99b770d99709c
[move-only] Rename mark_must_check -> mark_unresolved_non_copyable_value
2023-08-31 09:50:55 -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
Andrew Trick
5e1520e6cc SIL verification: non-address partial apply callee 2023-08-29 16:46:48 -07:00
Nate Chandler
7bddaf36a0 [SIL] Added tuple_pack_extract.
The new instruction is needed for opaque values mode to allow values to
be extracted from tuples containing packs which will appear for example
as function arguments.
2023-08-16 11:15:05 -07:00
Allan Shortlidge
e2bb7e8c8b SILOptimizer: Remove switch cases matching unavailable enum elements.
Unavailable enum elements cannot be instantiated at runtime without invoking
UB. Therefore the optimizer can consider a basic block unreachable if its only
predecessor is a block that terminates in a switch instruction matching an
unavailable enum element. Furthermore, removing the switch instruction cases
that refer to unavailable enum elements is _mandatory_ when
`-unavailable-decl-optimization=complete` is specified because otherwise
lowered IR for these instructions could refer to enum tag accessors that will
not be lowered, resulting in a failure during linking.

Resolves rdar://113872720.
2023-08-15 17:13:10 -07:00
Andrew Trick
f2287b9074 Enable SIL verification for on-stack partial_apply ownership. 2023-08-12 21:21:18 -07:00
Michael Gottesman
bac26aa8c5 [reference-bindings] Fix a verifier error and add a test that validates that we do not crash anymore. 2023-08-11 15:57:50 -07:00
Andrew Trick
8de369467c Revert "Verify that on-stack closures do not take owned arguments"
This reverts commit 20f99b2822.

The assert triggers in in the i386 build in the function:
// specialized Substring.UnicodeScalarView.replaceSubrange<A>(_:with:)
2023-08-11 08:53:04 -07:00
swift-ci
2667df0799 Merge pull request #67760 from atrick/fix-closure-moveonly-arg
Fix compiler crashes with consuming and borrowing keywords.
2023-08-11 00:32:41 -07:00
Michael Gottesman
33eedc1574 Merge pull request #67874 from gottesmm/pr-179e2ec3ed29bb0d8c35dc99f710a18571a0a24e
[sil] Convert AddressWalker from using virtual methods to use CRTP and add a transitive -> endpoint user API
2023-08-10 17:18:27 -07:00
Michael Gottesman
29350907fc Convert TransitiveAddressWalker to use CRTP instead of virtual functions. 2023-08-10 12:58:50 -07:00
Andrew Trick
20f99b2822 Verify that on-stack closures do not take owned arguments 2023-08-10 11:17:53 -07:00
Nate Chandler
f938287710 [SIL] Added unowned_copy_value. 2023-08-08 15:49:17 -07:00
Nate Chandler
8cea33ad8f [SIL] Verifier: Disable opaque values for ref_to.
The ref_to_* and *_to_ref instructions must not produce or take as their
operands values of address-only type.  The AddressLowering pass would
trap on encountering such illegal instructions already.  Enforce the
invariant in the verifier.
2023-08-08 15:47:13 -07:00
Nate Chandler
c007bae723 [SIL] Added weak_copy_value.
The new instruction wraps a value in a `@sil_weak` box and produces an
owned value. It is only legal in opaque values mode and is transformed
by `AddressLowering` to `store_weak`.
2023-08-08 15:47:13 -07:00
Nate Chandler
e135c5cac7 [SIL] Added strong_copy_weak_value.
The new instruction unwraps an `@sil_weak` box and produces an owned
value. It is only legal in opaque values mode and is transformed by
`AddressLowering` to `load_weak`.
2023-08-08 15:47:13 -07: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
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
Michael Gottesman
26081ffb82 [silgen] Teach accessor projection to use store_borrow if it has a non-tuple.
This prevents another type of copy of noncopyable value error.

I also as a small change, changed the tuple version to use a formal access
temporary since we are projecting a component out implying that the lifetime of
the temporary must end within the formal access. Otherwise, we cause the
lifetime of the temporary to outlive the access. This can be seen in the change
to read_accessor.swift where we used to extend the lifetime of the destroy_addr
outside of the coroutine access we are performing.
2023-07-31 14:23:11 -07:00
Pavel Yaskevich
49ef5e61bd [SILVerifier] NFC: Switch to use getNumInitializedProperties accessor 2023-07-28 09:34:05 -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
Nate Chandler
8c00a37f8d [SILVerifier] NFC: De-typo'd. 2023-07-19 16:06:11 -07:00
Nate Chandler
851434c2b6 [SILVerifier] Skip type access on skip resilience.
If resilience checks are bypassed, also bypass checks for type ABI
accessibility.
2023-07-18 11:57:02 -07:00
Pavel Yaskevich
00729ad958 Merge pull request #67107 from xedin/setterless-init-accessor-properties
[SILGen/DI] Add support for init accessor properties without setters
2023-07-07 00:16:07 -07:00
Pavel Yaskevich
135f2c2ea0 [SILGen] InitAccessors: Start supporting assign_or_init for properties without a setter
Implement "init accessor" component emission which is paired with
"init accessor" write strategy. Use `SILUndef` for a "setter" operand
of an "assign_or_init" instruction in cases when property with init
accessor doesn't have a setter. DI would detect re-initialization
attempts to produce diagnostics.
2023-07-03 22:07:19 -07:00
Meghana Gupta
17cba8540d Merge pull request #67072 from meg-gupta/forwardingwrappertypepr
Introduce ForwardingOperation wrapper type
2023-07-01 23:33:50 -07:00
Meghana Gupta
07863444d2 Introduce ForwardingOperation wrapper type
APIs on ForwardingInstruction should be written as static taking in
a SILInstruction as a parameter making it awkward.

Introduce a ForwardingOperation wrapper type and move the apis from the
old "mixin" class to the wrapper type.

Add new api getForwardedOperands()
2023-07-01 10:42:38 -07:00
Pavel Yaskevich
fab9e4bc62 Merge pull request #66987 from xedin/refactor-init-accessors-to-carry-more-info
[SIL] InitAccessors: Refactor `assign_or_init` instruction to carry "self"
2023-06-30 11:46:01 -07:00
Meghana Gupta
c8001d86b1 Add a wrapper type SelectEnumOperation
SelectEnumInstBase will be templated in the next commit.
Instead of using templated SelectEnumInstBase everywhere, introduce
a new wrapper type SelectEnumOperation.
2023-06-28 14:29:10 -07:00
Pavel Yaskevich
80a1e2c2ba [SILGen] InitAccessors: Produce partial apply of init accessor ref to produce substituted closure
Instead of dealing with substitutions during raw SIL lowering,
let's produce a partial apply without argument to produce a
substituted reference that could be used by SILVerifier and
raw SIL lowering stages.
2023-06-28 12:28:15 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Meghana Gupta
6da1df23c8 Merge pull request #66825 from meg-gupta/addressphilast
Sink address projections in ArrayPropertyOpt and enable verification to ensure we have no address phis
2023-06-23 12:27:42 -07:00
Meghana Gupta
03b8c49371 Merge pull request #66645 from meg-gupta/mixinremovesmall
Simplify forwarding instruction definitions in SIL
2023-06-21 13:02:13 -07:00
Meghana Gupta
56629e1300 Verify we don't have any address phis 2023-06-21 12:24:26 -07:00
Meghana Gupta
acba067916 Update operand ownership of some concurrency instructions that were inacurrately marked as InteriorPointer.
Also add verification to check whenever a new instruction is marked with InteriorPointer,
the InteriorPointerOperand utility is updated.
2023-06-15 16:30:31 -07:00
Meghana Gupta
16c300c2af Remove OwnershipForwardingConversionInst, ConversionInst.
Add new ConversionOperation abstraction, use this in place of ConversionInst
2023-06-15 10:53:28 -07:00
Meghana Gupta
6df7ebbb4e Update and add new apis on ForwardingInstruction 2023-06-15 10:53:06 -07:00
Meghana Gupta
7cb3733e29 Rename OwnershipForwardingMixin -> ForwardingInstruction 2023-06-14 10:40:32 -07:00
Meghana Gupta
5d401fb70a Remove select_value SIL instruction 2023-06-13 14:13:43 -07:00
Pavel Yaskevich
78aee9560d [SILVerifier] InitAccessors: Adjust verifier to map init accessor ref into context before checking initialValue 2023-06-06 18:59:45 -07:00
Pavel Yaskevich
7b140f89b9 [SILGen] InitAccessors: AssignOrInit instruction should reference init accessor directly
Previously init accessor has been partially applied just like a setter but
that is no loger valid now that it operates on individual field references.
2023-06-06 18:59:13 -07:00
Holly Borla
eb3ed2b374 [SILGen] Emit AssignOrInitInst for assignment to a computed property with
an init accessor inside of an initializer.
2023-06-06 18:59:13 -07:00
Holly Borla
ac66a06199 [SIL] Add a new AssignOrInit instruction for init accessors.
This instruction is similar to AssignByWrapperInst, but instead of having
a destination operand, the initialization is fully factored into the init
function operand. Like AssignByWrapper, AssignOrInit has partial application
operands of both the initializer and the setter, and DI will lower the
instruction to a call based on whether the assignment is initialization or
a setter call.
2023-06-06 18:59:10 -07:00
Michael Gottesman
29672c503a Merge pull request #66381 from gottesmm/noimplicitcopy-borrow-consuming
[borrowing/consuming] Make borrowing and consuming parameters no implicit copy.
2023-06-06 21:41:18 -04:00