Commit Graph

699 Commits

Author SHA1 Message Date
Arnold Schwaighofer
9482b0c86b Preliminary SIL and IRGen support for error_indirect
IRGen lowering of non-fixed-sized typed errors and the SIL support necessary to
spell out IRGen test cases.
2023-10-12 18:09:52 -07:00
Evan Wilde
24d0db249b Merge remote-tracking branch 'main' into 'rebranch'
Conflicts:
  CMakeLists.txt
    Take new BRIDGING_MODE

  SwiftCompilerSources/Sources/SIL/GlobalVariable.swift
    Take new
2023-10-09 17:21:23 -07:00
Andrew Trick
69a884565a Fix ownership of select_enum instruction
This instruction was given forwarding ownership in the original OSSA
implementation. That will obviously lead to memory leaks. Remove
ownership from this instruction and verify that it is never used for
non-trivial types.
2023-10-08 01:34:48 -07:00
swift-ci
fc3a226c60 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-24 16:13:49 -07:00
Kuba Mracek
8f335b1a28 [embedded] Allow serialized internal/private functions in embedded mode 2023-09-23 14:00:31 -07:00
swift-ci
6637cc5a27 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-21 12:13:50 -07:00
Kavon Farvardin
a69bcf8a61 Merge pull request #67930 from kavon/copyable-requirement
Copyable as a Requirement Against the Machine
2023-09-21 11:49:23 -07:00
swift-ci
ac12fa71dc Merge remote-tracking branch 'origin/main' into rebranch 2023-09-20 17:33:50 -07:00
swift-ci
71cb84b24a Merge pull request #68657 from nate-chandler/nfc/20230920/1/add-null-check
[SILVerifier] Add null check for dead end blocks.
2023-09-20 17:18:49 -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
swift-ci
1b6470ca9c Merge remote-tracking branch 'origin/main' into rebranch 2023-09-20 15:07:15 -07:00
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
swift-ci
c2d0ed607a Merge remote-tracking branch 'origin/main' into rebranch 2023-09-19 11:33:34 -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
swift-ci
ae30cba296 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-13 10:20:48 -07: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
Sophia Poirier
86d368f364 Merge remote-tracking branch 'upstream/main' into fix-rebranch-automerger 2023-08-31 14:10:52 -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
swift-ci
1f38aa913d Merge remote-tracking branch 'origin/main' into rebranch 2023-08-30 08:56:03 -07:00
Andrew Trick
5e1520e6cc SIL verification: non-address partial apply callee 2023-08-29 16:46:48 -07:00
swift-ci
610b823cc8 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-23 10:54:00 -07:00
Erik Eckstein
bad87c4c1e MemoryLifetimeVerifier: relax the check for trivial enums a bit
Trivial enum cases in a memory location don't need to be destroyed.
Don't require that the store to such a memory location is statically known as a trivial enum case.
Instead just require that it's below a switch_enum successor for a trivial case.

Fixes a false alarm.

rdar://114274714
2023-08-23 12:48:46 +02:00
swift-ci
9d38c6b53e Merge remote-tracking branch 'origin/main' into rebranch 2023-08-17 14:34:52 -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
swift-ci
7283643631 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-16 09:14:19 -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
swift-ci
129ece8c2f Merge remote-tracking branch 'origin/main' into rebranch 2023-08-13 14:53:50 -07:00
Andrew Trick
f2287b9074 Enable SIL verification for on-stack partial_apply ownership. 2023-08-12 21:21:18 -07:00
swift-ci
d778dd73b8 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-11 21:54:27 -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
swift-ci
298e75c682 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-11 11:15:19 -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
4fe55c5732 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-11 00:35:20 -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
swift-ci
525350af1b Merge remote-tracking branch 'origin/main' into rebranch 2023-08-10 22:14:25 -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
Andrew Trick
83ce3a1777 Rename getArgumentOperandConvention to getCaptureConvention
The name was misleading and problematic. There is already a
getArgumentConvention which is completely different.
2023-08-10 11:17:53 -07:00
swift-ci
a4bb99bd1b Merge remote-tracking branch 'origin/main' into rebranch 2023-08-09 07:15:49 -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
Becca Royal-Gordon
3eebc6dddb Merge branch 'main' into rebranch
# Conflicts:
#	lib/SILOptimizer/Differentiation/Common.cpp
2023-08-04 15:09:50 -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